From dfc26f9a2a6be14b22254be73ad9a3eca0c7aa12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Villemain?= Date: Thu, 27 Feb 2025 05:05:12 +0100 Subject: [PATCH] Fix insert planner crash -- TODO crash Citus --- INSERT INTO domain_indirection_test (f1,f3.if1, f3.if2) SELECT 0, 1, 2; +INSERT INTO domain_indirection_test (f1,f3.if1, f3.if2) SELECT 0, 1, 2; +ERROR: cannot plan distributed INSERT INTO ... SELECT query +HINT: Do not use array references and field stores on the INSERT target list. INSERT INTO domain_indirection_test (f1,f3.if1) VALUES (0, 1); ERROR: inserting or modifying composite type fields is not supported HINT: Use the column name to insert or update the composite type as a single value -- TODO here: not the expected ERROR -- INSERT INTO domain_indirection_test (f1,f3.if1) SELECT 0, 1; -- ERROR: could not find a conversion path from type 23 to 17619 UPDATE domain_indirection_test SET domain_array[0].if2 = 5; ERROR: inserting or modifying composite type fields is not supported HINT: Use the column name to insert or update the composite type as a single value -- TODO here: not the expected ERROR --- src/backend/distributed/planner/insert_select_planner.c | 5 +++++ src/test/regress/sql/distributed_types.sql | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/planner/insert_select_planner.c b/src/backend/distributed/planner/insert_select_planner.c index db5c3d4ff..f8f0b8b8c 100644 --- a/src/backend/distributed/planner/insert_select_planner.c +++ b/src/backend/distributed/planner/insert_select_planner.c @@ -1082,6 +1082,11 @@ ReorderInsertSelectTargetLists(Query *originalQuery, RangeTblEntry *insertRte, TargetEntry *newSubqueryTargetEntry = NULL; AttrNumber originalAttrNo = get_attnum(insertRelationId, oldInsertTargetEntry->resname); + Node *expr; + + /* we need to explore the underlying expression */ + expr = (Node *) oldInsertTargetEntry->expr; + expr = strip_implicit_coercions(expr); /* we need to explore the underlying expression */ Node *expr = strip_implicit_coercions((Node *) oldInsertTargetEntry->expr); diff --git a/src/test/regress/sql/distributed_types.sql b/src/test/regress/sql/distributed_types.sql index ac44457da..205faf9c7 100644 --- a/src/test/regress/sql/distributed_types.sql +++ b/src/test/regress/sql/distributed_types.sql @@ -270,14 +270,10 @@ SELECT create_distributed_table('domain_indirection_test', 'f1'); -- not supported (field indirection to underlying composite type) INSERT INTO domain_indirection_test (f1,f3.if1, f3.if2) VALUES (0, 1, 2); INSERT INTO domain_indirection_test (f1,f3.if1, f3.if2) SELECT 0, 1, 2; --- INSERT INTO domain_indirection_test (f1,f3.if1, f3.if2) SELECT 0, 1, 2; INSERT INTO domain_indirection_test (f1,f3.if1) VALUES (0, 1); INSERT INTO domain_indirection_test (f1,f3.if1) SELECT 0, 1; --- INSERT INTO domain_indirection_test (f1,f3.if1) SELECT 0, 1; --- ERROR: could not find a conversion path from type 23 to 17619 UPDATE domain_indirection_test SET domain_array[0].if2 = 5; UPDATE domain_indirection_test SET domain_array[0].if2 = (SELECT 5); -UPDATE domain_indirection_test SET domain_array[0].if2 = (SELECT 5); -- below are supported as we don't do any field indirection INSERT INTO field_indirection_test_2 (ct2_col, int_col, ct1_col)