2022-07-24 22:27:02 +00:00
|
|
|
select '-- check that distinct with and w/o optimization produce the same result';
|
|
|
|
|
|
|
|
drop table if exists distinct_in_order sync;
|
|
|
|
drop table if exists ordinary_distinct sync;
|
|
|
|
|
2023-05-04 16:35:18 +00:00
|
|
|
select '-- DISTINCT columns are the same as in ORDER BY';
|
2023-08-13 02:47:05 +00:00
|
|
|
create table distinct_in_order (CounterID UInt32, EventDate Date) engine=MergeTree() order by (CounterID, EventDate) SETTINGS index_granularity = 8192, index_granularity_bytes = '10Mi';
|
2022-07-25 07:56:50 +00:00
|
|
|
insert into distinct_in_order select distinct CounterID, EventDate from test.hits order by CounterID, EventDate settings optimize_distinct_in_order=1;
|
2023-08-13 02:47:05 +00:00
|
|
|
create table ordinary_distinct (CounterID UInt32, EventDate Date) engine=MergeTree() order by (CounterID, EventDate) SETTINGS index_granularity = 8192, index_granularity_bytes = '10Mi';
|
2022-07-25 07:56:50 +00:00
|
|
|
insert into ordinary_distinct select distinct CounterID, EventDate from test.hits order by CounterID, EventDate settings optimize_distinct_in_order=0;
|
2022-07-24 22:27:02 +00:00
|
|
|
select distinct * from distinct_in_order except select * from ordinary_distinct;
|
|
|
|
|
|
|
|
drop table if exists distinct_in_order sync;
|
|
|
|
drop table if exists ordinary_distinct sync;
|
|
|
|
|
2023-05-04 16:35:18 +00:00
|
|
|
select '-- DISTINCT columns has prefix in ORDER BY columns';
|
2023-08-13 02:47:05 +00:00
|
|
|
create table distinct_in_order (CounterID UInt32, EventDate Date) engine=MergeTree() order by (CounterID, EventDate) SETTINGS index_granularity = 8192, index_granularity_bytes = '10Mi';
|
2022-07-25 07:56:50 +00:00
|
|
|
insert into distinct_in_order select distinct CounterID, EventDate from test.hits order by CounterID settings optimize_distinct_in_order=1;
|
2023-08-13 02:47:05 +00:00
|
|
|
create table ordinary_distinct (CounterID UInt32, EventDate Date) engine=MergeTree() order by (CounterID, EventDate) SETTINGS index_granularity = 8192, index_granularity_bytes = '10Mi';
|
2022-07-25 07:56:50 +00:00
|
|
|
insert into ordinary_distinct select distinct CounterID, EventDate from test.hits order by CounterID settings optimize_distinct_in_order=0;
|
2022-07-24 22:27:02 +00:00
|
|
|
select distinct * from distinct_in_order except select * from ordinary_distinct;
|
|
|
|
|
|
|
|
drop table if exists distinct_in_order sync;
|
|
|
|
drop table if exists ordinary_distinct sync;
|