ClickHouse/tests/queries/0_stateless/02864_statistics_operate.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
2.2 KiB
MySQL
Raw Normal View History

2023-09-04 13:51:00 +00:00
DROP TABLE IF EXISTS t1;
2024-05-17 15:16:49 +00:00
SET allow_experimental_statistics = 1;
SET allow_statistics_optimize = 1;
2023-09-04 13:51:00 +00:00
2024-02-20 15:38:05 +00:00
CREATE TABLE t1
2023-09-04 13:51:00 +00:00
(
2024-04-24 16:20:48 +00:00
a Float64 STATISTICS(tdigest),
b Int64 STATISTICS(tdigest),
2023-09-04 13:51:00 +00:00
pk String,
2023-09-13 06:26:25 +00:00
) Engine = MergeTree() ORDER BY pk
SETTINGS min_bytes_for_wide_part = 0;
2023-09-04 13:51:00 +00:00
SHOW CREATE TABLE t1;
INSERT INTO t1 select number, -number, generateUUIDv4() FROM system.numbers LIMIT 10000;
SELECT 'After insert';
2024-02-20 15:38:05 +00:00
SELECT replaceRegexpAll(explain, '__table1\.|_UInt8', '') FROM (EXPLAIN actions=1 SELECT count(*) FROM t1 WHERE b < 10 and a < 10) WHERE explain LIKE '%Prewhere%' OR explain LIKE '%Filter column%';
2023-09-04 13:51:00 +00:00
SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
2023-09-13 06:26:25 +00:00
SELECT count(*) FROM t1 WHERE b < NULL and a < '10';
2023-09-04 13:51:00 +00:00
2024-04-24 16:20:48 +00:00
ALTER TABLE t1 DROP STATISTICS a, b;
2023-09-04 13:51:00 +00:00
SELECT 'After drop statistic';
2024-02-20 15:38:05 +00:00
SELECT replaceRegexpAll(explain, '__table1\.|_UInt8', '') FROM (EXPLAIN actions=1 SELECT count(*) FROM t1 WHERE b < 10 and a < 10) WHERE explain LIKE '%Prewhere%' OR explain LIKE '%Filter column%';
2023-09-04 13:51:00 +00:00
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
2024-04-24 16:20:48 +00:00
ALTER TABLE t1 ADD STATISTICS a, b TYPE tdigest;
2023-09-08 00:27:17 +00:00
SELECT 'After add statistic';
2023-09-09 02:04:18 +00:00
SHOW CREATE TABLE t1;
2023-09-08 00:27:17 +00:00
2024-04-24 16:20:48 +00:00
ALTER TABLE t1 MATERIALIZE STATISTICS a, b;
2023-09-04 13:51:00 +00:00
INSERT INTO t1 select number, -number, generateUUIDv4() FROM system.numbers LIMIT 10000;
SELECT 'After materialize statistic';
2024-02-20 15:38:05 +00:00
SELECT replaceRegexpAll(explain, '__table1\.|_UInt8', '') FROM (EXPLAIN actions=1 SELECT count(*) FROM t1 WHERE b < 10 and a < 10) WHERE explain LIKE '%Prewhere%' OR explain LIKE '%Filter column%';
2023-09-04 13:51:00 +00:00
SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
OPTIMIZE TABLE t1 FINAL;
SELECT 'After merge';
2024-02-20 15:38:05 +00:00
SELECT replaceRegexpAll(explain, '__table1\.|_UInt8', '') FROM (EXPLAIN actions=1 SELECT count(*) FROM t1 WHERE b < 10 and a < 10) WHERE explain LIKE '%Prewhere%' OR explain LIKE '%Filter column%';
2023-09-04 13:51:00 +00:00
SELECT count(*) FROM t1 WHERE b < 10 and a < 10;
2023-10-03 22:58:26 +00:00
ALTER TABLE t1 RENAME COLUMN b TO c;
SHOW CREATE TABLE t1;
SELECT 'After rename';
2024-02-20 15:38:05 +00:00
SELECT replaceRegexpAll(explain, '__table1\.|_UInt8', '') FROM (EXPLAIN actions=1 SELECT count(*) FROM t1 WHERE c < 10 and a < 10) WHERE explain LIKE '%Prewhere%' OR explain LIKE '%Filter column%';
2023-10-03 22:58:26 +00:00
SELECT count(*) FROM t1 WHERE c < 10 and a < 10;
2023-09-04 13:51:00 +00:00
DROP TABLE IF EXISTS t1;