From 219f3676a07e2e69e0714155791c7da8495532a9 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Tue, 24 Sep 2019 11:51:05 +0200 Subject: [PATCH] Improve some tests around local execution and CTE inlining on pg 12 --- .../expected/local_shard_execution.out | 19 ++++++++++++++++++- .../expected/local_shard_execution_0.out | 19 ++++++++++++++++++- .../regress/sql/local_shard_execution.sql | 14 +++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/test/regress/expected/local_shard_execution.out b/src/test/regress/expected/local_shard_execution.out index 7f3bbb3ee..e97c6dde5 100644 --- a/src/test/regress/expected/local_shard_execution.out +++ b/src/test/regress/expected/local_shard_execution.out @@ -699,6 +699,9 @@ ORDER BY -- multi-shard CTE is followed by a query which could be executed locally, but -- since the query started with a parallel query, it doesn't use local execution +-- note that if we allow Postgres to inline the CTE (e.g., not have the EXISTS +-- subquery), then it'd pushdown the filters and the query becomes single-shard, +-- locally executable query WITH all_data AS (SELECT * FROM distributed_table) SELECT count(*) @@ -706,13 +709,27 @@ FROM distributed_table, all_data WHERE distributed_table.key = all_data.key AND distributed_table.key = 1 - -- the following is to avoid CTE inlining AND EXISTS (SELECT * FROM all_data); count ------- 1 (1 row) +-- in pg12, the following CTE can be inlined, still the query becomes +-- a subquery that needs to be recursively planned and a parallel +-- query, so do not use local execution +WITH all_data AS (SELECT age FROM distributed_table) +SELECT + count(*) +FROM + distributed_table, all_data +WHERE + distributed_table.key = all_data.age AND distributed_table.key = 1; + count +------- + 0 +(1 row) + -- get ready for the next commands TRUNCATE reference_table, distributed_table, second_distributed_table; -- local execution of returning of reference tables diff --git a/src/test/regress/expected/local_shard_execution_0.out b/src/test/regress/expected/local_shard_execution_0.out index b37e37a9a..2b67c40fc 100644 --- a/src/test/regress/expected/local_shard_execution_0.out +++ b/src/test/regress/expected/local_shard_execution_0.out @@ -685,6 +685,9 @@ ORDER BY -- multi-shard CTE is followed by a query which could be executed locally, but -- since the query started with a parallel query, it doesn't use local execution +-- note that if we allow Postgres to inline the CTE (e.g., not have the EXISTS +-- subquery), then it'd pushdown the filters and the query becomes single-shard, +-- locally executable query WITH all_data AS (SELECT * FROM distributed_table) SELECT count(*) @@ -692,13 +695,27 @@ FROM distributed_table, all_data WHERE distributed_table.key = all_data.key AND distributed_table.key = 1 - -- the following is to avoid CTE inlining AND EXISTS (SELECT * FROM all_data); count ------- 1 (1 row) +-- in pg12, the following CTE can be inlined, still the query becomes +-- a subquery that needs to be recursively planned and a parallel +-- query, so do not use local execution +WITH all_data AS (SELECT age FROM distributed_table) +SELECT + count(*) +FROM + distributed_table, all_data +WHERE + distributed_table.key = all_data.age AND distributed_table.key = 1; + count +------- + 0 +(1 row) + -- get ready for the next commands TRUNCATE reference_table, distributed_table, second_distributed_table; -- local execution of returning of reference tables diff --git a/src/test/regress/sql/local_shard_execution.sql b/src/test/regress/sql/local_shard_execution.sql index 7cd7e4027..1aea11abc 100644 --- a/src/test/regress/sql/local_shard_execution.sql +++ b/src/test/regress/sql/local_shard_execution.sql @@ -419,6 +419,9 @@ ORDER BY -- multi-shard CTE is followed by a query which could be executed locally, but -- since the query started with a parallel query, it doesn't use local execution +-- note that if we allow Postgres to inline the CTE (e.g., not have the EXISTS +-- subquery), then it'd pushdown the filters and the query becomes single-shard, +-- locally executable query WITH all_data AS (SELECT * FROM distributed_table) SELECT count(*) @@ -426,9 +429,18 @@ FROM distributed_table, all_data WHERE distributed_table.key = all_data.key AND distributed_table.key = 1 - -- the following is to avoid CTE inlining AND EXISTS (SELECT * FROM all_data); +-- in pg12, the following CTE can be inlined, still the query becomes +-- a subquery that needs to be recursively planned and a parallel +-- query, so do not use local execution +WITH all_data AS (SELECT age FROM distributed_table) +SELECT + count(*) +FROM + distributed_table, all_data +WHERE + distributed_table.key = all_data.age AND distributed_table.key = 1; -- get ready for the next commands TRUNCATE reference_table, distributed_table, second_distributed_table;