From 1a31f82d1e144acb8ab911348bd476008f7b7946 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 11 Aug 2022 07:44:42 +0200 Subject: [PATCH 1/3] Add a test for #10575 --- ...counting_resources_in_subqueries.reference | 0 ...00175_counting_resources_in_subqueries.sql | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/queries/1_stateful/00175_counting_resources_in_subqueries.reference create mode 100644 tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql diff --git a/tests/queries/1_stateful/00175_counting_resources_in_subqueries.reference b/tests/queries/1_stateful/00175_counting_resources_in_subqueries.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql b/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql new file mode 100644 index 00000000000..a6e441a8471 --- /dev/null +++ b/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql @@ -0,0 +1,20 @@ +-- the work for scalar subquery is properly accounted: +SET max_rows_to_read = 1000000; +SELECT 1 = (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } + +-- the work for subquery in IN is properly accounted: +SET max_rows_to_read = 1000000; +SELECT 1 IN (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } + +-- this query reads from the table twice: +SET max_rows_to_read = 15000000; +SELECT count() IN (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)) FROM hits WHERE NOT ignore(AdvEngineID); -- { serverError 158 } + +-- the resources are properly accounted even if the subquery is evaluated in advance to facilitate the index analysis. +-- this query is using index and filter out the second reading pass. +SET max_rows_to_read = 1000000; +SELECT count() FROM hits WHERE CounterID > (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } + +-- this query is using index but have to read all the data twice. +SET max_rows_to_read = 15000000; +SELECT count() FROM hits WHERE CounterID < (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } From 0069a949c4997b66a614e0a1dad694191a546671 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 11 Aug 2022 10:04:31 +0200 Subject: [PATCH 2/3] Fix test --- .../1_stateful/00175_counting_resources_in_subqueries.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql b/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql index a6e441a8471..d63429522e0 100644 --- a/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql +++ b/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql @@ -4,17 +4,17 @@ SELECT 1 = (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)); -- { s -- the work for subquery in IN is properly accounted: SET max_rows_to_read = 1000000; -SELECT 1 IN (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } +SELECT 1 IN (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } -- this query reads from the table twice: SET max_rows_to_read = 15000000; -SELECT count() IN (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)) FROM hits WHERE NOT ignore(AdvEngineID); -- { serverError 158 } +SELECT count() IN (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)) FROM test.hits WHERE NOT ignore(AdvEngineID); -- { serverError 158 } -- the resources are properly accounted even if the subquery is evaluated in advance to facilitate the index analysis. -- this query is using index and filter out the second reading pass. SET max_rows_to_read = 1000000; -SELECT count() FROM hits WHERE CounterID > (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } +SELECT count() FROM test.hits WHERE CounterID > (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } -- this query is using index but have to read all the data twice. SET max_rows_to_read = 15000000; -SELECT count() FROM hits WHERE CounterID < (SELECT count() FROM hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } +SELECT count() FROM test.hits WHERE CounterID < (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } From 76c2bcd2582513e33d31ce7fee82012fb2238f3f Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 13 Aug 2022 02:20:31 +0200 Subject: [PATCH 3/3] Fix test --- .../1_stateful/00175_counting_resources_in_subqueries.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql b/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql index d63429522e0..fe7837d7ff1 100644 --- a/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql +++ b/tests/queries/1_stateful/00175_counting_resources_in_subqueries.sql @@ -16,5 +16,5 @@ SET max_rows_to_read = 1000000; SELECT count() FROM test.hits WHERE CounterID > (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 } -- this query is using index but have to read all the data twice. -SET max_rows_to_read = 15000000; +SET max_rows_to_read = 10000000; SELECT count() FROM test.hits WHERE CounterID < (SELECT count() FROM test.hits WHERE NOT ignore(AdvEngineID)); -- { serverError 158 }