Skip to content

Commit

Permalink
Handle MERGE command in reference join pushdown
Browse files Browse the repository at this point in the history
At the moment, the MERGE command is not supported on distributed
hypertables. This patch ensures that the join pushdown code ignores the
invocation by the MERGE command.
  • Loading branch information
jnidzwetzki committed Feb 28, 2023
1 parent e6f6eb3 commit 7887576
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tsl/src/fdw/data_node_scan_plan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,12 @@ data_node_generate_pushdown_join_paths(PlannerInfo *root, RelOptInfo *joinrel, R
if (joinrel->fdw_private)
return;

/* Distributed hypertables are not supported by MERGE at the moment. Ensure that
* we perform our planning only on SELECTs.
*/
if (root->parse->commandType != CMD_SELECT)
return;

#ifdef ENABLE_DEAD_CODE
/*
* This code does not work for joins with lateral references, since those
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/expected/dist_ref_table_join-12.out
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,25 @@ DEBUG: join pushdown on reference table is not supported for the used query
Output: metric_name.name
(30 rows)

-------
-- MERGE is supported in PG >= 15. Currently, it is not supported in TimescaleDB
-- on distributed hypertables. Perform a MERGE here to check if the join pushdown
-- can handle the MERGE command properly. ON_ERROR_STOP is disabled for this test.
-- Older PostgreSQL versions report an error because MERGE is not supported. This
-- will be ignored due to the setting.
-------
\set ON_ERROR_STOP 0
MERGE INTO metric as target_0
USING metric as input_0
inner join (select id from metric_name as input_1) as subq_0
ON (TRUE)
ON target_0.id = input_0.id
WHEN MATCHED
THEN DO NOTHING
WHEN NOT MATCHED
THEN DO NOTHING;
ERROR: syntax error at or near "MERGE" at character 1
\set ON_ERROR_STOP 1
-------
-- Tests without enable_per_data_node_queries (no pushdown supported)
-------
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/expected/dist_ref_table_join-13.out
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,25 @@ DEBUG: join pushdown on reference table is not supported for the used query
Output: metric_name.name
(30 rows)

-------
-- MERGE is supported in PG >= 15. Currently, it is not supported in TimescaleDB
-- on distributed hypertables. Perform a MERGE here to check if the join pushdown
-- can handle the MERGE command properly. ON_ERROR_STOP is disabled for this test.
-- Older PostgreSQL versions report an error because MERGE is not supported. This
-- will be ignored due to the setting.
-------
\set ON_ERROR_STOP 0
MERGE INTO metric as target_0
USING metric as input_0
inner join (select id from metric_name as input_1) as subq_0
ON (TRUE)
ON target_0.id = input_0.id
WHEN MATCHED
THEN DO NOTHING
WHEN NOT MATCHED
THEN DO NOTHING;
ERROR: syntax error at or near "MERGE" at character 1
\set ON_ERROR_STOP 1
-------
-- Tests without enable_per_data_node_queries (no pushdown supported)
-------
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/expected/dist_ref_table_join-14.out
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,25 @@ DEBUG: join pushdown on reference table is not supported for the used query
Output: metric_name.name
(30 rows)

-------
-- MERGE is supported in PG >= 15. Currently, it is not supported in TimescaleDB
-- on distributed hypertables. Perform a MERGE here to check if the join pushdown
-- can handle the MERGE command properly. ON_ERROR_STOP is disabled for this test.
-- Older PostgreSQL versions report an error because MERGE is not supported. This
-- will be ignored due to the setting.
-------
\set ON_ERROR_STOP 0
MERGE INTO metric as target_0
USING metric as input_0
inner join (select id from metric_name as input_1) as subq_0
ON (TRUE)
ON target_0.id = input_0.id
WHEN MATCHED
THEN DO NOTHING
WHEN NOT MATCHED
THEN DO NOTHING;
ERROR: syntax error at or near "MERGE" at character 1
\set ON_ERROR_STOP 1
-------
-- Tests without enable_per_data_node_queries (no pushdown supported)
-------
Expand Down
28 changes: 28 additions & 0 deletions tsl/test/expected/dist_ref_table_join-15.out
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,34 @@ DEBUG: join pushdown on reference table is not supported for the used query
Output: metric_name.name
(30 rows)

-------
-- MERGE is supported in PG >= 15. Currently, it is not supported in TimescaleDB
-- on distributed hypertables. Perform a MERGE here to check if the join pushdown
-- can handle the MERGE command properly. ON_ERROR_STOP is disabled for this test.
-- Older PostgreSQL versions report an error because MERGE is not supported. This
-- will be ignored due to the setting.
-------
\set ON_ERROR_STOP 0
MERGE INTO metric as target_0
USING metric as input_0
inner join (select id from metric_name as input_1) as subq_0
ON (TRUE)
ON target_0.id = input_0.id
WHEN MATCHED
THEN DO NOTHING
WHEN NOT MATCHED
THEN DO NOTHING;
LOG: statement: MERGE INTO metric as target_0
USING metric as input_0
inner join (select id from metric_name as input_1) as subq_0
ON (TRUE)
ON target_0.id = input_0.id
WHEN MATCHED
THEN DO NOTHING
WHEN NOT MATCHED
THEN DO NOTHING;
ERROR: The MERGE command does not support hypertables in this version
\set ON_ERROR_STOP 1
-------
-- Tests without enable_per_data_node_queries (no pushdown supported)
-------
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/sql/dist_ref_table_join.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,25 @@ FROM metric JOIN metric_name ON texteq(concat('cpu', textin(int4out(metric.id)))
GROUP BY name
ORDER BY name;

-------
-- MERGE is supported in PG >= 15. Currently, it is not supported in TimescaleDB
-- on distributed hypertables. Perform a MERGE here to check if the join pushdown
-- can handle the MERGE command properly. ON_ERROR_STOP is disabled for this test.
-- Older PostgreSQL versions report an error because MERGE is not supported. This
-- will be ignored due to the setting.
-------
\set ON_ERROR_STOP 0
MERGE INTO metric as target_0
USING metric as input_0
inner join (select id from metric_name as input_1) as subq_0
ON (TRUE)
ON target_0.id = input_0.id
WHEN MATCHED
THEN DO NOTHING
WHEN NOT MATCHED
THEN DO NOTHING;
\set ON_ERROR_STOP 1

-------
-- Tests without enable_per_data_node_queries (no pushdown supported)
-------
Expand Down

0 comments on commit 7887576

Please sign in to comment.