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

Commitfc057b2

Browse files
committed
Remove dead code for temporary relations in partition planning
Since recent commit1c7c317, temporary relations cannot be mixed withpermanent relations within the same partition tree, and the same countsfor temporary relations created by other sessions, which the plannersimply discarded. Instead be paranoid and issue an error, as thoseshould be blocked at definition time, at least for now.At the same time, a test case is added to stress what has been movedwhen expand_partitioned_rtentry gets called recursively but bumps on apartitioned relation with no partitions which should be handled the sameway as the non-inheritance case. This code may be reworked in a closefuture, and covering this code path will limit surprises.Reported-by: David RowleyAuthor: David RowleyReviewed-by: Amit Langote, Robert Haas, Michael PaquierDiscussion:https://postgr.es/m/CAKJS1f_HyV1txn_4XSdH5EOhBMYaCwsXyAj6bHXk9gOu4JKsbw@mail.gmail.com
1 parent2c059c8 commitfc057b2

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

‎src/backend/optimizer/prep/prepunion.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
16811681
inti;
16821682
RangeTblEntry*childrte;
16831683
IndexchildRTindex;
1684-
boolhas_child= false;
16851684
PartitionDescpartdesc=RelationGetPartitionDesc(parentrel);
16861685

16871686
check_stack_depth();
@@ -1707,6 +1706,16 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
17071706
top_parentrc,parentrel,
17081707
appinfos,&childrte,&childRTindex);
17091708

1709+
/*
1710+
* If the partitioned table has no partitions, treat this as the
1711+
* non-inheritance case.
1712+
*/
1713+
if (partdesc->nparts==0)
1714+
{
1715+
parentrte->inh= false;
1716+
return;
1717+
}
1718+
17101719
for (i=0;i<partdesc->nparts;i++)
17111720
{
17121721
OidchildOID=partdesc->oids[i];
@@ -1715,15 +1724,13 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
17151724
/* Open rel; we already have required locks */
17161725
childrel=heap_open(childOID,NoLock);
17171726

1718-
/* As in expand_inherited_rtentry, skip non-local temp tables */
1727+
/*
1728+
* Temporary partitions belonging to other sessions should have been
1729+
* disallowed at definition, but for paranoia's sake, let's double
1730+
* check.
1731+
*/
17191732
if (RELATION_IS_OTHER_TEMP(childrel))
1720-
{
1721-
heap_close(childrel,lockmode);
1722-
continue;
1723-
}
1724-
1725-
/* We have a real partition. */
1726-
has_child= true;
1733+
elog(ERROR,"temporary relation from another session found as partition");
17271734

17281735
expand_single_inheritance_child(root,parentrte,parentRTindex,
17291736
parentrel,top_parentrc,childrel,
@@ -1738,14 +1745,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
17381745
/* Close child relation, but keep locks */
17391746
heap_close(childrel,NoLock);
17401747
}
1741-
1742-
/*
1743-
* If the partitioned table has no partitions or all the partitions are
1744-
* temporary tables from other backends, treat this as non-inheritance
1745-
* case.
1746-
*/
1747-
if (!has_child)
1748-
parentrte->inh= false;
17491748
}
17501749

17511750
/*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,16 @@ select * from (values (2),(null),(1)) v(k) where k = k;
951951
1
952952
(2 rows)
953953

954+
-- Test partitioned tables with no partitions, which should be handled the
955+
-- same as the non-inheritance case when expanding its RTE.
956+
create table list_parted_tbl (a int,b int) partition by list (a);
957+
create table list_parted_tbl1 partition of list_parted_tbl
958+
for values in (1) partition by list(b);
959+
explain (costs off) select * from list_parted_tbl;
960+
QUERY PLAN
961+
--------------------------
962+
Result
963+
One-Time Filter: false
964+
(2 rows)
965+
966+
drop table list_parted_tbl;

‎src/test/regress/sql/select.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,11 @@ drop function sillysrf(int);
254254
-- (see bug #5084)
255255
select*from (values (2),(null),(1)) v(k)where k= korder by k;
256256
select*from (values (2),(null),(1)) v(k)where k= k;
257+
258+
-- Test partitioned tables with no partitions, which should be handled the
259+
-- same as the non-inheritance case when expanding its RTE.
260+
createtablelist_parted_tbl (aint,bint) partition by list (a);
261+
createtablelist_parted_tbl1 partition of list_parted_tbl
262+
forvaluesin (1) partition by list(b);
263+
explain (costs off)select*from list_parted_tbl;
264+
droptable list_parted_tbl;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp