01030_incorrect_count_summing_merge_tree.sql 4.3 KB
Newer Older
N
done  
Nikita Mikhaylov 已提交
1 2
select '-- SummingMergeTree with Nullable column without duplicates.';  

N
better  
Nikita Mikhaylov 已提交
3 4 5 6
drop table if exists tst;
create table tst (timestamp DateTime, val Nullable(Int8)) engine SummingMergeTree partition by toYYYYMM(timestamp) ORDER by (timestamp);
insert into tst values ('2018-02-01 00:00:00', 1), ('2018-02-02 00:00:00', 2);

N
Nikolai Kochetov 已提交
7
select * from tst final order by timestamp;
N
done  
Nikita Mikhaylov 已提交
8 9

select '-- 2 2';
N
better  
Nikita Mikhaylov 已提交
10 11 12
select count() from tst;
select count() from tst final;

N
done  
Nikita Mikhaylov 已提交
13
select '-- 2 2';
N
better  
Nikita Mikhaylov 已提交
14 15 16
select count() from tst where timestamp is not null;
select count() from tst final where timestamp is not null;

N
done  
Nikita Mikhaylov 已提交
17
select '-- 2 2';
N
better  
Nikita Mikhaylov 已提交
18 19 20
select count() from tst where val is not null;
select count() from tst final where val is not null;

N
Nikita Mikhaylov 已提交
21
select '-- 2 2 2 2';
N
better  
Nikita Mikhaylov 已提交
22 23
select count() from tst final where timestamp>0;
select count() from tst final prewhere timestamp > 0;
N
done  
Nikita Mikhaylov 已提交
24
select count() from tst final where timestamp > '2017-01-01 00:00:00';
N
Nikita Mikhaylov 已提交
25
select count() from tst final prewhere timestamp > '2017-01-01 00:00:00';
N
better  
Nikita Mikhaylov 已提交
26

N
done  
Nikita Mikhaylov 已提交
27
select '-- 2 2';
N
better  
Nikita Mikhaylov 已提交
28 29 30
select count() from tst final where val>0;
select count() from tst final prewhere val>0;

N
done  
Nikita Mikhaylov 已提交
31 32 33 34 35 36
select '-- SummingMergeTree with Nullable column with duplicates';

drop table if exists tst;
create table tst (timestamp DateTime, val Nullable(Int8)) engine SummingMergeTree partition by toYYYYMM(timestamp) ORDER by (timestamp);
insert into tst values ('2018-02-01 00:00:00', 1), ('2018-02-02 00:00:00', 2), ('2018-02-01 00:00:00', 3), ('2018-02-02 00:00:00', 4);

N
Nikolai Kochetov 已提交
37
select * from tst final order by timestamp;
N
done  
Nikita Mikhaylov 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

select '-- 4 2';
select count() from tst;
select count() from tst final;

select '-- 4 2';
select count() from tst where timestamp is not null;
select count() from tst final where timestamp is not null;

select '-- 4 2';
select count() from tst where val is not null;
select count() from tst final where val is not null;

select '-- 2 2 2 2';
select count() from tst final where timestamp>0;
select count() from tst final prewhere timestamp > 0;
select count() from tst final where timestamp > '2017-01-01 00:00:00';
select count() from tst final prewhere timestamp > '2017-01-01 00:00:00';

select '-- 2 2';
select count() from tst final where val>0;
select count() from tst final prewhere val>0;

select '-- SummingMergeTree without Nullable column without duplicates.';

N
better  
Nikita Mikhaylov 已提交
63 64 65 66
drop table if exists tst;
create table tst (timestamp DateTime, val Int8) engine SummingMergeTree partition by toYYYYMM(timestamp) ORDER by (timestamp);
insert into tst values ('2018-02-01 00:00:00', 1), ('2018-02-02 00:00:00', 2);

N
Nikolai Kochetov 已提交
67
select * from tst final order by timestamp;
N
done  
Nikita Mikhaylov 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80

select '-- 2 2';
select count() from tst;
select count() from tst final;

select '-- 2 2 ';
select count() from tst where timestamp is not null;
select count() from tst final where timestamp is not null;

select '-- 2 2';
select count() from tst where val is not null;
select count() from tst final where val is not null;

N
Nikita Mikhaylov 已提交
81
select '-- 2 2 2 2';
N
done  
Nikita Mikhaylov 已提交
82 83 84
select count() from tst final where timestamp>0;
select count() from tst final prewhere timestamp > 0;
select count() from tst final where timestamp > '2017-01-01 00:00:00';
N
Nikita Mikhaylov 已提交
85
select count() from tst final prewhere timestamp > '2017-01-01 00:00:00';
N
done  
Nikita Mikhaylov 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98

select '-- 2 2';
select count() from tst final where val>0;
select count() from tst final prewhere val>0;

drop table tst;

select '-- SummingMergeTree without Nullable column with duplicates.';

drop table if exists tst;
create table tst (timestamp DateTime, val Int8) engine SummingMergeTree partition by toYYYYMM(timestamp) ORDER by (timestamp);
insert into tst values ('2018-02-01 00:00:00', 1), ('2018-02-02 00:00:00', 2), ('2018-02-01 00:00:00', 3), ('2018-02-02 00:00:00', 4);

N
Nikolai Kochetov 已提交
99
select * from tst final order by timestamp;
N
done  
Nikita Mikhaylov 已提交
100 101

select '-- 4 2';
N
better  
Nikita Mikhaylov 已提交
102 103 104
select count() from tst;
select count() from tst final;

N
done  
Nikita Mikhaylov 已提交
105
select '-- 4 2';
N
better  
Nikita Mikhaylov 已提交
106 107 108
select count() from tst where timestamp is not null;
select count() from tst final where timestamp is not null;

N
done  
Nikita Mikhaylov 已提交
109
select '-- 4 2';
N
better  
Nikita Mikhaylov 已提交
110 111 112
select count() from tst where val is not null;
select count() from tst final where val is not null;

N
Nikita Mikhaylov 已提交
113
select '-- 2 2 2 2';
N
better  
Nikita Mikhaylov 已提交
114 115
select count() from tst final where timestamp>0;
select count() from tst final prewhere timestamp > 0;
N
done  
Nikita Mikhaylov 已提交
116 117
select count() from tst final where timestamp > '2017-01-01 00:00:00';
select count() from tst final prewhere timestamp > '2017-01-01 00:00:00';
N
better  
Nikita Mikhaylov 已提交
118

N
done  
Nikita Mikhaylov 已提交
119
select '-- 2 2';
N
better  
Nikita Mikhaylov 已提交
120 121 122 123
select count() from tst final where val>0;
select count() from tst final prewhere val>0;

drop table tst;