Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8109191

Browse files
committed
fix bogus varno in PartitionFilter's targetlist (issue #112)
1 parent9ebc833 commit8109191

File tree

5 files changed

+202
-4
lines changed

5 files changed

+202
-4
lines changed

‎expected/pathman_inserts.out

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,171 @@ NOTICE: AFTER INSERTION TRIGGER ON TABLE storage_14 HAS EXPIRED. INSERTED ROW:
853853
256 | 128 | test_inserts.storage_14
854854
(27 rows)
855855

856+
/* test EXPLAIN (VERBOSE) - for PartitionFilter's targetlists */
857+
EXPLAIN (VERBOSE, COSTS OFF)
858+
INSERT INTO test_inserts.storage (b, d, e) SELECT i, i, i
859+
FROM generate_series(1, 10) i
860+
RETURNING e * 2, b, tableoid::regclass;
861+
QUERY PLAN
862+
-------------------------------------------------------------------------------
863+
Insert on test_inserts.storage
864+
Output: (storage.e * 2), storage.b, (storage.tableoid)::regclass
865+
-> Custom Scan (PartitionFilter)
866+
Output: NULL::integer, storage.b, NULL::integer, storage.d, storage.e
867+
-> Function Scan on pg_catalog.generate_series i
868+
Output: NULL::integer, i.i, NULL::integer, i.i, i.i
869+
Function Call: generate_series(1, 10)
870+
(7 rows)
871+
872+
EXPLAIN (VERBOSE, COSTS OFF)
873+
INSERT INTO test_inserts.storage (d, e) SELECT i, i
874+
FROM generate_series(1, 10) i;
875+
QUERY PLAN
876+
-------------------------------------------------------------------------------
877+
Insert on test_inserts.storage
878+
-> Custom Scan (PartitionFilter)
879+
Output: NULL::integer, storage.b, NULL::integer, storage.d, storage.e
880+
-> Function Scan on pg_catalog.generate_series i
881+
Output: NULL::integer, NULL::integer, NULL::integer, i.i, i.i
882+
Function Call: generate_series(1, 10)
883+
(6 rows)
884+
885+
EXPLAIN (VERBOSE, COSTS OFF)
886+
INSERT INTO test_inserts.storage (b) SELECT i
887+
FROM generate_series(1, 10) i;
888+
QUERY PLAN
889+
-----------------------------------------------------------------------------------
890+
Insert on test_inserts.storage
891+
-> Custom Scan (PartitionFilter)
892+
Output: NULL::integer, storage.b, NULL::integer, storage.d, storage.e
893+
-> Function Scan on pg_catalog.generate_series i
894+
Output: NULL::integer, i.i, NULL::integer, NULL::text, NULL::bigint
895+
Function Call: generate_series(1, 10)
896+
(6 rows)
897+
898+
EXPLAIN (VERBOSE, COSTS OFF)
899+
INSERT INTO test_inserts.storage (b, d, e) SELECT b, d, e
900+
FROM test_inserts.storage;
901+
QUERY PLAN
902+
----------------------------------------------------------------------------------------------
903+
Insert on test_inserts.storage
904+
-> Custom Scan (PartitionFilter)
905+
Output: NULL::integer, storage.b, NULL::integer, storage.d, storage.e
906+
-> Result
907+
Output: NULL::integer, storage_11.b, NULL::integer, storage_11.d, storage_11.e
908+
-> Append
909+
-> Seq Scan on test_inserts.storage_11
910+
Output: storage_11.b, storage_11.d, storage_11.e
911+
-> Seq Scan on test_inserts.storage_1
912+
Output: storage_1.b, storage_1.d, storage_1.e
913+
-> Seq Scan on test_inserts.storage_2
914+
Output: storage_2.b, storage_2.d, storage_2.e
915+
-> Seq Scan on test_inserts.storage_3
916+
Output: storage_3.b, storage_3.d, storage_3.e
917+
-> Seq Scan on test_inserts.storage_4
918+
Output: storage_4.b, storage_4.d, storage_4.e
919+
-> Seq Scan on test_inserts.storage_5
920+
Output: storage_5.b, storage_5.d, storage_5.e
921+
-> Seq Scan on test_inserts.storage_6
922+
Output: storage_6.b, storage_6.d, storage_6.e
923+
-> Seq Scan on test_inserts.storage_7
924+
Output: storage_7.b, storage_7.d, storage_7.e
925+
-> Seq Scan on test_inserts.storage_8
926+
Output: storage_8.b, storage_8.d, storage_8.e
927+
-> Seq Scan on test_inserts.storage_9
928+
Output: storage_9.b, storage_9.d, storage_9.e
929+
-> Seq Scan on test_inserts.storage_10
930+
Output: storage_10.b, storage_10.d, storage_10.e
931+
-> Seq Scan on test_inserts.storage_12
932+
Output: storage_12.b, storage_12.d, storage_12.e
933+
-> Seq Scan on test_inserts.storage_13
934+
Output: storage_13.b, storage_13.d, storage_13.e
935+
-> Seq Scan on test_inserts.storage_14
936+
Output: storage_14.b, storage_14.d, storage_14.e
937+
(34 rows)
938+
939+
EXPLAIN (VERBOSE, COSTS OFF)
940+
INSERT INTO test_inserts.storage (b, d) SELECT b, d
941+
FROM test_inserts.storage;
942+
QUERY PLAN
943+
----------------------------------------------------------------------------------------------
944+
Insert on test_inserts.storage
945+
-> Custom Scan (PartitionFilter)
946+
Output: NULL::integer, storage.b, NULL::integer, storage.d, storage.e
947+
-> Result
948+
Output: NULL::integer, storage_11.b, NULL::integer, storage_11.d, NULL::bigint
949+
-> Append
950+
-> Seq Scan on test_inserts.storage_11
951+
Output: storage_11.b, storage_11.d
952+
-> Seq Scan on test_inserts.storage_1
953+
Output: storage_1.b, storage_1.d
954+
-> Seq Scan on test_inserts.storage_2
955+
Output: storage_2.b, storage_2.d
956+
-> Seq Scan on test_inserts.storage_3
957+
Output: storage_3.b, storage_3.d
958+
-> Seq Scan on test_inserts.storage_4
959+
Output: storage_4.b, storage_4.d
960+
-> Seq Scan on test_inserts.storage_5
961+
Output: storage_5.b, storage_5.d
962+
-> Seq Scan on test_inserts.storage_6
963+
Output: storage_6.b, storage_6.d
964+
-> Seq Scan on test_inserts.storage_7
965+
Output: storage_7.b, storage_7.d
966+
-> Seq Scan on test_inserts.storage_8
967+
Output: storage_8.b, storage_8.d
968+
-> Seq Scan on test_inserts.storage_9
969+
Output: storage_9.b, storage_9.d
970+
-> Seq Scan on test_inserts.storage_10
971+
Output: storage_10.b, storage_10.d
972+
-> Seq Scan on test_inserts.storage_12
973+
Output: storage_12.b, storage_12.d
974+
-> Seq Scan on test_inserts.storage_13
975+
Output: storage_13.b, storage_13.d
976+
-> Seq Scan on test_inserts.storage_14
977+
Output: storage_14.b, storage_14.d
978+
(34 rows)
979+
980+
EXPLAIN (VERBOSE, COSTS OFF)
981+
INSERT INTO test_inserts.storage (b) SELECT b
982+
FROM test_inserts.storage;
983+
QUERY PLAN
984+
--------------------------------------------------------------------------------------------
985+
Insert on test_inserts.storage
986+
-> Custom Scan (PartitionFilter)
987+
Output: NULL::integer, storage.b, NULL::integer, storage.d, storage.e
988+
-> Result
989+
Output: NULL::integer, storage_11.b, NULL::integer, NULL::text, NULL::bigint
990+
-> Append
991+
-> Seq Scan on test_inserts.storage_11
992+
Output: storage_11.b
993+
-> Seq Scan on test_inserts.storage_1
994+
Output: storage_1.b
995+
-> Seq Scan on test_inserts.storage_2
996+
Output: storage_2.b
997+
-> Seq Scan on test_inserts.storage_3
998+
Output: storage_3.b
999+
-> Seq Scan on test_inserts.storage_4
1000+
Output: storage_4.b
1001+
-> Seq Scan on test_inserts.storage_5
1002+
Output: storage_5.b
1003+
-> Seq Scan on test_inserts.storage_6
1004+
Output: storage_6.b
1005+
-> Seq Scan on test_inserts.storage_7
1006+
Output: storage_7.b
1007+
-> Seq Scan on test_inserts.storage_8
1008+
Output: storage_8.b
1009+
-> Seq Scan on test_inserts.storage_9
1010+
Output: storage_9.b
1011+
-> Seq Scan on test_inserts.storage_10
1012+
Output: storage_10.b
1013+
-> Seq Scan on test_inserts.storage_12
1014+
Output: storage_12.b
1015+
-> Seq Scan on test_inserts.storage_13
1016+
Output: storage_13.b
1017+
-> Seq Scan on test_inserts.storage_14
1018+
Output: storage_14.b
1019+
(34 rows)
1020+
8561021
/* test gap case (missing partition in between) */
8571022
CREATE TABLE test_inserts.test_gap(val INT NOT NULL);
8581023
INSERT INTO test_inserts.test_gap SELECT generate_series(1, 30);

‎sql/pathman_inserts.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,33 @@ FROM generate_series(-2, 130, 5) i
163163
RETURNING e*2, b, tableoid::regclass;
164164

165165

166+
/* test EXPLAIN (VERBOSE) - for PartitionFilter's targetlists*/
167+
EXPLAIN (VERBOSE, COSTS OFF)
168+
INSERT INTOtest_inserts.storage (b, d, e)SELECT i, i, i
169+
FROM generate_series(1,10) i
170+
RETURNING e*2, b, tableoid::regclass;
171+
172+
EXPLAIN (VERBOSE, COSTS OFF)
173+
INSERT INTOtest_inserts.storage (d, e)SELECT i, i
174+
FROM generate_series(1,10) i;
175+
176+
EXPLAIN (VERBOSE, COSTS OFF)
177+
INSERT INTOtest_inserts.storage (b)SELECT i
178+
FROM generate_series(1,10) i;
179+
180+
EXPLAIN (VERBOSE, COSTS OFF)
181+
INSERT INTOtest_inserts.storage (b, d, e)SELECT b, d, e
182+
FROMtest_inserts.storage;
183+
184+
EXPLAIN (VERBOSE, COSTS OFF)
185+
INSERT INTOtest_inserts.storage (b, d)SELECT b, d
186+
FROMtest_inserts.storage;
187+
188+
EXPLAIN (VERBOSE, COSTS OFF)
189+
INSERT INTOtest_inserts.storage (b)SELECT b
190+
FROMtest_inserts.storage;
191+
192+
166193
/* test gap case (missing partition in between)*/
167194
CREATETABLEtest_inserts.test_gap(valINTNOT NULL);
168195
INSERT INTOtest_inserts.test_gapSELECT generate_series(1,30);

‎src/include/partition_filter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ ResultRelInfoHolder * select_partition_for_insert(Datum value, Oid value_type,
141141

142142
Plan*make_partition_filter(Plan*subplan,
143143
Oidparent_relid,
144+
Indexparent_rti,
144145
OnConflictActionconflict_action,
145146
List*returning_list);
146147

‎src/partition_filter.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ select_partition_for_insert(Datum value, Oid value_type,
481481
*/
482482

483483
Plan*
484-
make_partition_filter(Plan*subplan,Oidparent_relid,
484+
make_partition_filter(Plan*subplan,
485+
Oidparent_relid,
486+
Indexparent_rti,
485487
OnConflictActionconflict_action,
486488
List*returning_list)
487489
{
@@ -511,7 +513,10 @@ make_partition_filter(Plan *subplan, Oid parent_relid,
511513

512514
/* No physical relation will be scanned */
513515
cscan->scan.scanrelid=0;
514-
cscan->custom_scan_tlist=subplan->targetlist;
516+
517+
/* Prepare 'custom_scan_tlist' for EXPLAIN (VERBOSE) */
518+
cscan->custom_scan_tlist=copyObject(cscan->scan.plan.targetlist);
519+
ChangeVarNodes((Node*)cscan->custom_scan_tlist,INDEX_VAR,parent_rti,0);
515520

516521
/* Pack partitioned table's Oid and conflict_action */
517522
cscan->custom_private=list_make3(makeInteger(parent_relid),

‎src/planner_tree_modification.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ partition_filter_visitor(Plan *plan, void *context)
423423
lc3=lnext(lc3);
424424
}
425425

426-
lfirst(lc1)=make_partition_filter((Plan*)lfirst(lc1),
427-
relid,
426+
lfirst(lc1)=make_partition_filter((Plan*)lfirst(lc1),relid,
427+
modify_table->nominalRelation,
428428
modify_table->onConflictAction,
429429
returning_list);
430430
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp