2020-05-10 02:29:53 +00:00
|
|
|
DROP TABLE IF EXISTS src_table;
|
|
|
|
|
2020-04-30 15:39:09 +00:00
|
|
|
create table src_table Engine=Memory as system.numbers;
|
|
|
|
CREATE MATERIALIZED VIEW dst_mv Engine=Memory as select *, (SELECT count() FROM src_table) AS cnt FROM src_table;
|
|
|
|
insert into src_table select * from numbers(2);
|
|
|
|
insert into src_table select * from numbers(2);
|
|
|
|
insert into src_table select * from numbers(2);
|
2020-05-06 09:15:18 +00:00
|
|
|
select * from dst_mv order by number;
|
2020-04-30 15:39:09 +00:00
|
|
|
|
|
|
|
CREATE TABLE dest_table (`Date` Date, `Id` UInt64, `Units` Float32) ENGINE = Memory;
|
|
|
|
create table left_table as dest_table;
|
|
|
|
create table right_table as dest_table;
|
|
|
|
insert into right_table select toDate('2020-01-01') + number, number, number / 2 from numbers(10);
|
|
|
|
|
|
|
|
CREATE MATERIALIZED VIEW dest_table_mv TO dest_table as select * FROM (SELECT * FROM left_table) AS t1 INNER JOIN (WITH (SELECT DISTINCT Date FROM left_table LIMIT 1) AS dt SELECT * FROM right_table WHERE Date = dt) AS t2 USING (Date, Id);
|
|
|
|
|
|
|
|
insert into left_table select toDate('2020-01-01'), 0, number * 2 from numbers(3);
|
|
|
|
select 'the rows get inserted';
|
2020-05-11 04:33:06 +00:00
|
|
|
select * from dest_table order by Date, Id, Units;
|
2020-04-30 15:39:09 +00:00
|
|
|
|
|
|
|
insert into left_table select toDate('2020-01-01'), 5, number * 2 from numbers(3);
|
|
|
|
select 'no new rows';
|
2020-05-11 04:33:06 +00:00
|
|
|
select * from dest_table order by Date, Id, Units;
|
2020-04-30 15:39:09 +00:00
|
|
|
|
|
|
|
truncate table left_table;
|
|
|
|
insert into left_table select toDate('2020-01-01') + 5, 5, number * 2 from numbers(3);
|
|
|
|
select 'the rows get inserted';
|
2020-05-11 04:33:06 +00:00
|
|
|
select * from dest_table order by Date, Id, Units;
|
2020-05-08 13:55:28 +00:00
|
|
|
|
|
|
|
drop table dest_table_mv;
|
|
|
|
drop table left_table;
|
|
|
|
drop table right_table;
|
|
|
|
drop table dest_table;
|
2020-11-11 15:29:36 +00:00
|
|
|
drop table src_table;
|
|
|
|
drop view dst_mv;
|