From 6b9b63369545c8cf3115d44d78b802bff1244143 Mon Sep 17 00:00:00 2001 From: Jelte Fennema Date: Wed, 15 Jan 2020 11:29:28 +0100 Subject: [PATCH] Add more tests for prepared statements --- src/test/regress/expected/cte_inline.out | 130 +++++++++++++++++++++ src/test/regress/expected/cte_inline_0.out | 130 +++++++++++++++++++++ src/test/regress/sql/cte_inline.sql | 27 +++++ 3 files changed, 287 insertions(+) diff --git a/src/test/regress/expected/cte_inline.out b/src/test/regress/expected/cte_inline.out index c61527562..e6d2145e3 100644 --- a/src/test/regress/expected/cte_inline.out +++ b/src/test/regress/expected/cte_inline.out @@ -951,12 +951,24 @@ DEBUG: Router planner cannot handle multi-shard select queries PREPARE inlined_cte_without_params AS WITH cte_1 AS (SELECT count(*) FROM test_table GROUP BY key) SELECT * FROM cte_1; +PREPARE non_inlined_cte_without_params AS + WITH cte_1 AS (SELECT * FROM test_table) + SELECT + *, (SELECT 1) + FROM + cte_1; PREPARE inlined_cte_has_parameter_on_non_dist_key(int) AS WITH cte_1 AS (SELECT count(*) FROM test_table WHERE value::int = $1 GROUP BY key) SELECT * FROM cte_1; PREPARE inlined_cte_has_parameter_on_dist_key(int) AS WITH cte_1 AS (SELECT count(*) FROM test_table WHERE key > $1 GROUP BY key) SELECT * FROM cte_1; +PREPARE non_inlined_cte_has_parameter_on_dist_key(int) AS + WITH cte_1 AS (SELECT * FROM test_table where key > $1) + SELECT + *, (SELECT 1) + FROM + cte_1; PREPARE retry_planning(int) AS WITH cte_1 AS (SELECT * FROM test_table WHERE key > $1) SELECT json_object_agg(DISTINCT key, value) FROM cte_1; @@ -992,6 +1004,44 @@ EXECUTE inlined_cte_without_params; --------------------------------------------------------------------- (0 rows) +EXECUTE non_inlined_cte_without_params; +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + EXECUTE inlined_cte_has_parameter_on_non_dist_key(1); DEBUG: CTE cte_1 is going to be inlined via distributed planning DEBUG: Router planner cannot handle multi-shard select queries @@ -1080,6 +1130,86 @@ DEBUG: Router planner cannot handle multi-shard select queries --------------------------------------------------------------------- (0 rows) +EXECUTE non_inlined_cte_has_parameter_on_dist_key(1); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 1) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(2); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 2) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(3); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 3) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(4); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 4) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(5); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 5) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(6); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 6) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + EXECUTE retry_planning(1); DEBUG: CTE cte_1 is going to be inlined via distributed planning DEBUG: Router planner cannot handle multi-shard select queries diff --git a/src/test/regress/expected/cte_inline_0.out b/src/test/regress/expected/cte_inline_0.out index e24c26d69..0ec39e590 100644 --- a/src/test/regress/expected/cte_inline_0.out +++ b/src/test/regress/expected/cte_inline_0.out @@ -908,12 +908,24 @@ DEBUG: Router planner cannot handle multi-shard select queries PREPARE inlined_cte_without_params AS WITH cte_1 AS (SELECT count(*) FROM test_table GROUP BY key) SELECT * FROM cte_1; +PREPARE non_inlined_cte_without_params AS + WITH cte_1 AS (SELECT * FROM test_table) + SELECT + *, (SELECT 1) + FROM + cte_1; PREPARE inlined_cte_has_parameter_on_non_dist_key(int) AS WITH cte_1 AS (SELECT count(*) FROM test_table WHERE value::int = $1 GROUP BY key) SELECT * FROM cte_1; PREPARE inlined_cte_has_parameter_on_dist_key(int) AS WITH cte_1 AS (SELECT count(*) FROM test_table WHERE key > $1 GROUP BY key) SELECT * FROM cte_1; +PREPARE non_inlined_cte_has_parameter_on_dist_key(int) AS + WITH cte_1 AS (SELECT * FROM test_table where key > $1) + SELECT + *, (SELECT 1) + FROM + cte_1; PREPARE retry_planning(int) AS WITH cte_1 AS (SELECT * FROM test_table WHERE key > $1) SELECT json_object_agg(DISTINCT key, value) FROM cte_1; @@ -955,6 +967,44 @@ EXECUTE inlined_cte_without_params; --------------------------------------------------------------------- (0 rows) +EXECUTE non_inlined_cte_without_params; +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_without_params; + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + EXECUTE inlined_cte_has_parameter_on_non_dist_key(1); DEBUG: CTE cte_1 is going to be inlined via distributed planning DEBUG: Router planner cannot handle multi-shard select queries @@ -1115,6 +1165,86 @@ DEBUG: Plan is router executable --------------------------------------------------------------------- (0 rows) +EXECUTE non_inlined_cte_has_parameter_on_dist_key(1); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 1) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(2); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 2) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(3); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 3) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(4); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 4) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(5); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 5) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + +EXECUTE non_inlined_cte_has_parameter_on_dist_key(6); +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: CTE cte_1 is going to be inlined via distributed planning +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: generating subplan XXX_1 for CTE cte_1: SELECT key, value, other_value FROM cte_inline.test_table WHERE (key OPERATOR(pg_catalog.>) 6) +DEBUG: Router planner cannot handle multi-shard select queries +DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT key, value, other_value, (SELECT 1) FROM (SELECT intermediate_result.key, intermediate_result.value, intermediate_result.other_value FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer, value text, other_value jsonb)) cte_1 +DEBUG: Creating router plan +DEBUG: Plan is router executable + key | value | other_value | ?column? +--------------------------------------------------------------------- +(0 rows) + EXECUTE retry_planning(1); DEBUG: CTE cte_1 is going to be inlined via distributed planning DEBUG: Router planner cannot handle multi-shard select queries diff --git a/src/test/regress/sql/cte_inline.sql b/src/test/regress/sql/cte_inline.sql index 992b45663..a8ee57df6 100644 --- a/src/test/regress/sql/cte_inline.sql +++ b/src/test/regress/sql/cte_inline.sql @@ -474,16 +474,29 @@ ORDER BY PREPARE inlined_cte_without_params AS WITH cte_1 AS (SELECT count(*) FROM test_table GROUP BY key) SELECT * FROM cte_1; +PREPARE non_inlined_cte_without_params AS + WITH cte_1 AS (SELECT * FROM test_table) + SELECT + *, (SELECT 1) + FROM + cte_1; PREPARE inlined_cte_has_parameter_on_non_dist_key(int) AS WITH cte_1 AS (SELECT count(*) FROM test_table WHERE value::int = $1 GROUP BY key) SELECT * FROM cte_1; PREPARE inlined_cte_has_parameter_on_dist_key(int) AS WITH cte_1 AS (SELECT count(*) FROM test_table WHERE key > $1 GROUP BY key) SELECT * FROM cte_1; +PREPARE non_inlined_cte_has_parameter_on_dist_key(int) AS + WITH cte_1 AS (SELECT * FROM test_table where key > $1) + SELECT + *, (SELECT 1) + FROM + cte_1; PREPARE retry_planning(int) AS WITH cte_1 AS (SELECT * FROM test_table WHERE key > $1) SELECT json_object_agg(DISTINCT key, value) FROM cte_1; + EXECUTE inlined_cte_without_params; EXECUTE inlined_cte_without_params; EXECUTE inlined_cte_without_params; @@ -491,6 +504,13 @@ EXECUTE inlined_cte_without_params; EXECUTE inlined_cte_without_params; EXECUTE inlined_cte_without_params; +EXECUTE non_inlined_cte_without_params; +EXECUTE non_inlined_cte_without_params; +EXECUTE non_inlined_cte_without_params; +EXECUTE non_inlined_cte_without_params; +EXECUTE non_inlined_cte_without_params; +EXECUTE non_inlined_cte_without_params; + EXECUTE inlined_cte_has_parameter_on_non_dist_key(1); EXECUTE inlined_cte_has_parameter_on_non_dist_key(2); EXECUTE inlined_cte_has_parameter_on_non_dist_key(3); @@ -505,6 +525,13 @@ EXECUTE inlined_cte_has_parameter_on_dist_key(4); EXECUTE inlined_cte_has_parameter_on_dist_key(5); EXECUTE inlined_cte_has_parameter_on_dist_key(6); +EXECUTE non_inlined_cte_has_parameter_on_dist_key(1); +EXECUTE non_inlined_cte_has_parameter_on_dist_key(2); +EXECUTE non_inlined_cte_has_parameter_on_dist_key(3); +EXECUTE non_inlined_cte_has_parameter_on_dist_key(4); +EXECUTE non_inlined_cte_has_parameter_on_dist_key(5); +EXECUTE non_inlined_cte_has_parameter_on_dist_key(6); + EXECUTE retry_planning(1); EXECUTE retry_planning(2); EXECUTE retry_planning(3);