Skip to content

Commit ba30201

Browse files
committed
Add tableoid junk column to processed_tlist only for top-level parent.
(Note that the column is added to RelOptInfo reltarget of all nodes in the hierarchy anyway; but only tle with top-level varno must get to *main* tlist, i.e. processed_tlist.) Previously it was added for each parent in the tree, i.e. multiple times in case of multi-level partitioning, leading to ERROR: variable not found in subplan target lists errors in setref. As comments say, this code better be rewritten to actually let parent deal with its isParent flag. And to recurce with toplever rc. Probably should be done if adjacent bugs arise.
1 parent 2a13ed7 commit ba30201

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

expected/pathman_subpartitions.out

+33
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,39 @@ UPDATE subpartitions.abc SET id1 = -1, id2 = -1 RETURNING tableoid::regclass, *;
424424

425425
DROP TABLE subpartitions.abc CASCADE;
426426
NOTICE: drop cascades to 9 other objects
427+
--- basic check how rowmark plays along with subparts; PGPRO-2755
428+
CREATE TABLE subpartitions.a1(n1 integer);
429+
CREATE TABLE subpartitions.a2(n1 integer not null, n2 integer not null);
430+
SELECT create_range_partitions('subpartitions.a2', 'n1', 1, 2, 0);
431+
create_range_partitions
432+
-------------------------
433+
0
434+
(1 row)
435+
436+
SELECT add_range_partition('subpartitions.a2', 10, 20, 'subpartitions.a2_1020');
437+
add_range_partition
438+
-----------------------
439+
subpartitions.a2_1020
440+
(1 row)
441+
442+
SELECT create_range_partitions('subpartitions.a2_1020'::regclass, 'n2'::text, array[30,40], array['subpartitions.a2_1020_3040']);
443+
create_range_partitions
444+
-------------------------
445+
1
446+
(1 row)
447+
448+
INSERT INTO subpartitions.a2 VALUES (10, 30), (11, 31), (12, 32), (19, 39);
449+
INSERT INTO subpartitions.a1 VALUES (12), (19), (20);
450+
SELECT a2.* FROM subpartitions.a1 JOIN subpartitions.a2 ON a2.n1=a1.n1 FOR UPDATE;
451+
n1 | n2
452+
----+----
453+
12 | 32
454+
19 | 39
455+
(2 rows)
456+
457+
DROP TABLE subpartitions.a2 CASCADE;
458+
NOTICE: drop cascades to 4 other objects
459+
DROP TABLE subpartitions.a1;
427460
DROP SCHEMA subpartitions CASCADE;
428461
NOTICE: drop cascades to function subpartitions.partitions_tree(regclass,text)
429462
DROP EXTENSION pg_pathman;

sql/pathman_subpartitions.sql

+17-1
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,24 @@ SELECT tableoid::regclass, * FROM subpartitions.abc ORDER BY id1, id2, val;
139139
SET pg_pathman.enable_partitionrouter = ON;
140140
UPDATE subpartitions.abc SET id1 = -1, id2 = -1 RETURNING tableoid::regclass, *;
141141

142+
DROP TABLE subpartitions.abc CASCADE;
143+
144+
145+
--- basic check how rowmark plays along with subparts; PGPRO-2755
146+
CREATE TABLE subpartitions.a1(n1 integer);
147+
CREATE TABLE subpartitions.a2(n1 integer not null, n2 integer not null);
148+
SELECT create_range_partitions('subpartitions.a2', 'n1', 1, 2, 0);
149+
150+
SELECT add_range_partition('subpartitions.a2', 10, 20, 'subpartitions.a2_1020');
151+
SELECT create_range_partitions('subpartitions.a2_1020'::regclass, 'n2'::text, array[30,40], array['subpartitions.a2_1020_3040']);
152+
INSERT INTO subpartitions.a2 VALUES (10, 30), (11, 31), (12, 32), (19, 39);
153+
INSERT INTO subpartitions.a1 VALUES (12), (19), (20);
154+
155+
SELECT a2.* FROM subpartitions.a1 JOIN subpartitions.a2 ON a2.n1=a1.n1 FOR UPDATE;
156+
157+
DROP TABLE subpartitions.a2 CASCADE;
158+
DROP TABLE subpartitions.a1;
142159

143160

144-
DROP TABLE subpartitions.abc CASCADE;
145161
DROP SCHEMA subpartitions CASCADE;
146162
DROP EXTENSION pg_pathman;

src/include/rangeset.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* ------------------------------------------------------------------------
22
*
33
* rangeset.h
4-
* IndexRange functions
54
*
65
* Copyright (c) 2015-2016, Postgres Professional
76
*
@@ -17,7 +16,10 @@
1716

1817

1918
/*
20-
* IndexRange contains a set of selected partitions.
19+
* IndexRange is essentially a segment [lower; upper]. This module provides
20+
* functions for efficient working (intersection, union) with Lists of
21+
* IndexRange's; this is used for quick selection of partitions. Numbers are
22+
* indexes of partitions in PartRelationInfo's children.
2123
*/
2224
typedef struct {
2325
/* lossy == should we use quals? */

src/pg_pathman.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ append_child_relation(PlannerInfo *root,
437437
Relation child_relation;
438438
AppendRelInfo *appinfo;
439439
Index child_rti;
440-
PlanRowMark *child_rowmark;
440+
PlanRowMark *child_rowmark = NULL;
441441
Node *childqual;
442442
List *childquals;
443443
ListCell *lc1,
@@ -493,6 +493,10 @@ append_child_relation(PlannerInfo *root,
493493

494494

495495
/* Create rowmarks required for child rels */
496+
/*
497+
* XXX: vanilla recurses down with *top* rowmark, not immediate parent one.
498+
* Not sure about example where this matters though.
499+
*/
496500
if (parent_rowmark)
497501
{
498502
child_rowmark = makeNode(PlanRowMark);
@@ -511,6 +515,13 @@ append_child_relation(PlannerInfo *root,
511515
root->rowMarks = lappend(root->rowMarks, child_rowmark);
512516

513517
/* Adjust tlist for RowMarks (see planner.c) */
518+
/*
519+
* XXX Saner approach seems to
520+
* 1) Add tle to top parent and processed_tlist once in rel_pathlist_hook.
521+
* 2) Mark isParent = true
522+
* *parent* knows it is parent, after all; why should child bother?
523+
* 3) Recursion (code executed in childs) starts at 2)
524+
*/
514525
if (!parent_rowmark->isParent && !root->parse->setOperations)
515526
{
516527
append_tle_for_rowmark(root, parent_rowmark);
@@ -636,6 +647,10 @@ append_child_relation(PlannerInfo *root,
636647
if (parent_rte->relid != child_oid &&
637648
child_relation->rd_rel->relhassubclass)
638649
{
650+
/* See XXX above */
651+
if (child_rowmark)
652+
child_rowmark->isParent = true;
653+
639654
pathman_rel_pathlist_hook(root,
640655
child_rel,
641656
child_rti,

0 commit comments

Comments
 (0)