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

Commitb522759

Browse files
committed
Copy partitioned_rels lists to avoid shared substructure.
Otherwise, set_plan_refs() can get applied to the same listmultiple times through different references, leading to chaos.Amit Langote, Dilip Kumar, and Robert Haas, reviewed by AshutoshBapat. Original report by Sveinn Sveinsson.Discussion:http://postgr.es/m/20170517141151.1435.79890@wrigleys.postgresql.org
1 parentcf5389f commitb522759

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

‎src/backend/optimizer/util/pathnode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ create_append_path(RelOptInfo *rel, List *subpaths, Relids required_outer,
12161216
pathnode->path.parallel_workers=parallel_workers;
12171217
pathnode->path.pathkeys=NIL;/* result is always considered
12181218
* unsorted */
1219-
pathnode->partitioned_rels=partitioned_rels;
1219+
pathnode->partitioned_rels=list_copy(partitioned_rels);
12201220
pathnode->subpaths=subpaths;
12211221

12221222
/*
@@ -1276,7 +1276,7 @@ create_merge_append_path(PlannerInfo *root,
12761276
pathnode->path.parallel_safe=rel->consider_parallel;
12771277
pathnode->path.parallel_workers=0;
12781278
pathnode->path.pathkeys=pathkeys;
1279-
pathnode->partitioned_rels=partitioned_rels;
1279+
pathnode->partitioned_rels=list_copy(partitioned_rels);
12801280
pathnode->subpaths=subpaths;
12811281

12821282
/*
@@ -3238,7 +3238,7 @@ create_modifytable_path(PlannerInfo *root, RelOptInfo *rel,
32383238
pathnode->operation=operation;
32393239
pathnode->canSetTag=canSetTag;
32403240
pathnode->nominalRelation=nominalRelation;
3241-
pathnode->partitioned_rels=partitioned_rels;
3241+
pathnode->partitioned_rels=list_copy(partitioned_rels);
32423242
pathnode->resultRelations=resultRelations;
32433243
pathnode->subpaths=subpaths;
32443244
pathnode->subroots=subroots;

‎src/test/regress/expected/inherit.out

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,3 +1918,34 @@ explain (costs off) select * from mcrparted where a = 20 and c > 20; -- scans mc
19181918
(7 rows)
19191919

19201920
drop table mcrparted;
1921+
-- check that partitioned table Appends cope with being referenced in
1922+
-- subplans
1923+
create table parted_minmax (a int, b varchar(16)) partition by range (a);
1924+
create table parted_minmax1 partition of parted_minmax for values from (1) to (10);
1925+
create index parted_minmax1i on parted_minmax1 (a, b);
1926+
insert into parted_minmax values (1,'12345');
1927+
explain (costs off) select min(a), max(a) from parted_minmax where b = '12345';
1928+
QUERY PLAN
1929+
-------------------------------------------------------------------------------------------------------
1930+
Result
1931+
InitPlan 1 (returns $0)
1932+
-> Limit
1933+
-> Merge Append
1934+
Sort Key: parted_minmax1.a
1935+
-> Index Only Scan using parted_minmax1i on parted_minmax1
1936+
Index Cond: ((a IS NOT NULL) AND (b = '12345'::text))
1937+
InitPlan 2 (returns $1)
1938+
-> Limit
1939+
-> Merge Append
1940+
Sort Key: parted_minmax1_1.a DESC
1941+
-> Index Only Scan Backward using parted_minmax1i on parted_minmax1 parted_minmax1_1
1942+
Index Cond: ((a IS NOT NULL) AND (b = '12345'::text))
1943+
(13 rows)
1944+
1945+
select min(a), max(a) from parted_minmax where b = '12345';
1946+
min | max
1947+
-----+-----
1948+
1 | 1
1949+
(1 row)
1950+
1951+
drop table parted_minmax;

‎src/test/regress/sql/inherit.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,13 @@ explain (costs off) select * from mcrparted where a > -1;-- scans all partition
661661
explain (costs off)select*from mcrpartedwhere a=20and abs(b)=10and c>10;-- scans mcrparted4
662662
explain (costs off)select*from mcrpartedwhere a=20and c>20;-- scans mcrparted3, mcrparte4, mcrparte5
663663
droptable mcrparted;
664+
665+
-- check that partitioned table Appends cope with being referenced in
666+
-- subplans
667+
createtableparted_minmax (aint, bvarchar(16)) partition by range (a);
668+
createtableparted_minmax1 partition of parted_minmax forvaluesfrom (1) to (10);
669+
createindexparted_minmax1ion parted_minmax1 (a, b);
670+
insert into parted_minmaxvalues (1,'12345');
671+
explain (costs off)selectmin(a),max(a)from parted_minmaxwhere b='12345';
672+
selectmin(a),max(a)from parted_minmaxwhere b='12345';
673+
droptable parted_minmax;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp