2023-09-04 13:51:00 +00:00
|
|
|
DROP TABLE IF EXISTS t1;
|
|
|
|
|
|
|
|
SET allow_experimental_statistic = 1;
|
|
|
|
SET allow_statistic_optimize = 1;
|
|
|
|
|
|
|
|
CREATE TABLE t1
|
|
|
|
(
|
|
|
|
a Int64,
|
|
|
|
b Float64,
|
|
|
|
pk String,
|
2023-09-08 00:27:17 +00:00
|
|
|
STATISTIC a, b TYPE tdigest,
|
2023-09-04 13:51:00 +00:00
|
|
|
) Engine = MergeTree() ORDER BY pk;
|
|
|
|
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
|
|
|
|
INSERT INTO t1 select number, -number, generateUUIDv4() FROM system.numbers LIMIT 10000;
|
|
|
|
|
|
|
|
SELECT 'After insert';
|
|
|
|
EXPLAIN SYNTAX SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
|
2023-09-08 00:27:17 +00:00
|
|
|
ALTER TABLE t1 DROP STATISTIC a, b TYPE tdigest;
|
2023-09-04 13:51:00 +00:00
|
|
|
|
|
|
|
SELECT 'After drop statistic';
|
|
|
|
EXPLAIN SYNTAX SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
|
2023-09-09 02:04:18 +00:00
|
|
|
SHOW CREATE TABLE t1;
|
2023-09-04 13:51:00 +00:00
|
|
|
|
2023-09-08 00:27:17 +00:00
|
|
|
ALTER TABLE t1 ADD STATISTIC a, b TYPE tdigest;
|
|
|
|
|
|
|
|
SELECT 'After add statistic';
|
|
|
|
|
2023-09-09 02:04:18 +00:00
|
|
|
SHOW CREATE TABLE t1;
|
2023-09-08 00:27:17 +00:00
|
|
|
|
|
|
|
ALTER TABLE t1 MATERIALIZE STATISTIC a, b TYPE tdigest;
|
2023-09-04 13:51:00 +00:00
|
|
|
INSERT INTO t1 select number, -number, generateUUIDv4() FROM system.numbers LIMIT 10000;
|
|
|
|
|
|
|
|
SELECT 'After materialize statistic';
|
|
|
|
EXPLAIN SYNTAX SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
|
|
|
|
OPTIMIZE TABLE t1 FINAL;
|
|
|
|
|
|
|
|
SELECT 'After merge';
|
|
|
|
EXPLAIN SYNTAX SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS t1;
|