mirror of https://github.com/citusdata/citus.git
Improve some tests around local execution and CTE inlining on pg 12
parent
4f60e3a149
commit
219f3676a0
|
@ -699,6 +699,9 @@ ORDER BY
|
||||||
|
|
||||||
-- multi-shard CTE is followed by a query which could be executed locally, but
|
-- 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
|
-- 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)
|
WITH all_data AS (SELECT * FROM distributed_table)
|
||||||
SELECT
|
SELECT
|
||||||
count(*)
|
count(*)
|
||||||
|
@ -706,13 +709,27 @@ FROM
|
||||||
distributed_table, all_data
|
distributed_table, all_data
|
||||||
WHERE
|
WHERE
|
||||||
distributed_table.key = all_data.key AND distributed_table.key = 1
|
distributed_table.key = all_data.key AND distributed_table.key = 1
|
||||||
-- the following is to avoid CTE inlining
|
|
||||||
AND EXISTS (SELECT * FROM all_data);
|
AND EXISTS (SELECT * FROM all_data);
|
||||||
count
|
count
|
||||||
-------
|
-------
|
||||||
1
|
1
|
||||||
(1 row)
|
(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
|
-- get ready for the next commands
|
||||||
TRUNCATE reference_table, distributed_table, second_distributed_table;
|
TRUNCATE reference_table, distributed_table, second_distributed_table;
|
||||||
-- local execution of returning of reference tables
|
-- local execution of returning of reference tables
|
||||||
|
|
|
@ -685,6 +685,9 @@ ORDER BY
|
||||||
|
|
||||||
-- multi-shard CTE is followed by a query which could be executed locally, but
|
-- 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
|
-- 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)
|
WITH all_data AS (SELECT * FROM distributed_table)
|
||||||
SELECT
|
SELECT
|
||||||
count(*)
|
count(*)
|
||||||
|
@ -692,13 +695,27 @@ FROM
|
||||||
distributed_table, all_data
|
distributed_table, all_data
|
||||||
WHERE
|
WHERE
|
||||||
distributed_table.key = all_data.key AND distributed_table.key = 1
|
distributed_table.key = all_data.key AND distributed_table.key = 1
|
||||||
-- the following is to avoid CTE inlining
|
|
||||||
AND EXISTS (SELECT * FROM all_data);
|
AND EXISTS (SELECT * FROM all_data);
|
||||||
count
|
count
|
||||||
-------
|
-------
|
||||||
1
|
1
|
||||||
(1 row)
|
(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
|
-- get ready for the next commands
|
||||||
TRUNCATE reference_table, distributed_table, second_distributed_table;
|
TRUNCATE reference_table, distributed_table, second_distributed_table;
|
||||||
-- local execution of returning of reference tables
|
-- local execution of returning of reference tables
|
||||||
|
|
|
@ -419,6 +419,9 @@ ORDER BY
|
||||||
|
|
||||||
-- multi-shard CTE is followed by a query which could be executed locally, but
|
-- 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
|
-- 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)
|
WITH all_data AS (SELECT * FROM distributed_table)
|
||||||
SELECT
|
SELECT
|
||||||
count(*)
|
count(*)
|
||||||
|
@ -426,9 +429,18 @@ FROM
|
||||||
distributed_table, all_data
|
distributed_table, all_data
|
||||||
WHERE
|
WHERE
|
||||||
distributed_table.key = all_data.key AND distributed_table.key = 1
|
distributed_table.key = all_data.key AND distributed_table.key = 1
|
||||||
-- the following is to avoid CTE inlining
|
|
||||||
AND EXISTS (SELECT * FROM all_data);
|
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
|
-- get ready for the next commands
|
||||||
TRUNCATE reference_table, distributed_table, second_distributed_table;
|
TRUNCATE reference_table, distributed_table, second_distributed_table;
|
||||||
|
|
Loading…
Reference in New Issue