ISSUES-8971 add test for predicate optimizer & view

This commit is contained in:
zhang2014 2020-02-05 19:41:03 +08:00
parent 16bb4e975d
commit 370615de93
3 changed files with 23 additions and 18 deletions

View File

@ -0,0 +1,4 @@
SELECT \n date, \n id, \n name, \n value\nFROM \n(\n SELECT \n date, \n id, \n name, \n value\n FROM default.test\n WHERE id = 1\n)\nWHERE id = 1
SELECT \n date, \n id, \n name, \n value\nFROM \n(\n SELECT \n date, \n id, \n name, \n value\n FROM default.test\n WHERE id = 2\n)\nWHERE id = 2
SELECT id\nFROM \n(\n SELECT \n date, \n id, \n name, \n value\n FROM default.test\n WHERE id = 1\n)\nWHERE id = 1
SELECT id\nFROM \n(\n SELECT \n date, \n id, \n name, \n value\n FROM default.test\n WHERE id = 1\n) AS s\nWHERE id = 1

View File

@ -0,0 +1,19 @@
DROP TABLE IF EXISTS test;
DROP TABLE IF EXISTS test_view;
CREATE TABLE test(date Date, id Int8, name String, value Int64) ENGINE = MergeTree(date, (id, date), 8192);
CREATE VIEW test_view AS SELECT * FROM test;
SET enable_debug_queries = 1;
SET enable_optimize_predicate_expression = 1;
-- Optimize predicate expression with view
ANALYZE SELECT * FROM test_view WHERE id = 1;
ANALYZE SELECT * FROM test_view WHERE id = 2;
ANALYZE SELECT id FROM test_view WHERE id = 1;
ANALYZE SELECT s.id FROM test_view AS s WHERE s.id = 1;
SELECT * FROM (SELECT toUInt64(b), sum(id) AS b FROM test) WHERE `toUInt64(sum(id))` = 3; -- { serverError 47 }
DROP TABLE IF EXISTS test;
DROP TABLE IF EXISTS test_view;

View File

@ -1,18 +0,0 @@
DROP TABLE IF EXISTS test.test;
DROP TABLE IF EXISTS test.test_view;
CREATE TABLE test.test(date Date, id Int8, name String, value Int64) ENGINE = MergeTree(date, (id, date), 8192);
CREATE VIEW test.test_view AS SELECT * FROM test.test;
SET enable_optimize_predicate_expression = 1;
SET enable_debug_queries = 1;
-- Optimize predicate expression with view
-- TODO: simple view is not replaced with subquery inside syntax analyzer
ANALYZE SELECT * FROM test.test_view WHERE id = 1;
ANALYZE SELECT * FROM test.test_view WHERE id = 2;
ANALYZE SELECT id FROM test.test_view WHERE id = 1;
ANALYZE SELECT s.id FROM test.test_view AS s WHERE s.id = 1;
-- TODO: this query shouldn't work, because the name `toUInt64(sum(id))` is undefined for user
SELECT * FROM (SELECT toUInt64(b), sum(id) AS b FROM test.test) WHERE `toUInt64(sum(id))` = 3;