From: David Rowley <david.rowley@2ndquadrant.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Cc: pgsql-committers <pgsql-committers@postgresql.org>
Subject: Re: pgsql: Clarify use of temporary tables within partition trees
Date: Tue, 3 Jul 2018 23:16:55 +1200
Message-ID: <CAKJS1f8ZerDq68ZTk9djC8unduhzCYN2ubHt_ornhtWSn_WByQ@mail.gmail.com> (raw)
In-Reply-To: <20180703095343.GE11732@paquier.xyz>
References: <CAKJS1f8f8+3FOBhSoopo15uzHsY76+L8cMKhMwBi+x+bvBU7tg@mail.gmail.com>
<20180703061119.GA11732@paquier.xyz>
<CAKJS1f8h8283Vb2NcQH+YOMErdDQZWGuqGoe-gX6yT8TKGf0MA@mail.gmail.com>
<5db5fe6e-4a73-6a24-09e4-060b9f132ea9@lab.ntt.co.jp>
<b7cc212d-8455-c548-5a71-3cbf6133abd6@lab.ntt.co.jp>
<20180703070551.GC11732@paquier.xyz>
<d5059f0a-9a93-942f-5a8a-ecd13fc26b94@lab.ntt.co.jp>
<CAKJS1f8Wt3CoYY-7AqtbszBLPrQMaH3xLRd2pSCKDARhQRT__A@mail.gmail.com>
<20180703091507.GD11732@paquier.xyz>
<CAKJS1f-SB+cAgS82KNYcBbiHR=NYFpx8s9J6+B01vdWOeeDrqw@mail.gmail.com>
<20180703095343.GE11732@paquier.xyz>
On 3 July 2018 at 21:53, Michael Paquier <michael@paquier.xyz> wrote:
> Your patch removes this part:
> - /*
> - * If the partitioned table has no partitions or all the partitions are
> - * temporary tables from other backends, treat this as non-inheritance
> - * case.
> - */
> - if (!has_child)
> - parentrte->inh = false;
>
> And adds this equivalent part:
> + /*
> + * If the partitioned table has no partitions, treat this as the
> + * non-inheritance case.
> + */
> + if (partdesc->nparts == 0)
> + {
> + parentrte->inh = false;
> + return;
> + }
>
> As far as I can see from the coverage report, the former is not tested,
> and corresponds to the case of a partition leaf which is itself
> partitioned but has no partitions, and the new portion is equivalent to
> the part removed. That ought to be tested, particularly as Amit
> mentions that there could be improvements with moving it around in
> future versions.
Oh okay. Yeah, you can hit that with a partitionless sub-partitioned table.
I've added a test in the attached v4.
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Attachments:remove_dead_code_from_expand_partitioned_rtentry_v4.patch (application/octet-stream, 3.5K) downloaddiff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.cindex 2d470240d5..7d75e1eda9 100644--- a/src/backend/optimizer/prep/prepunion.c+++ b/src/backend/optimizer/prep/prepunion.c@@ -1681,7 +1681,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
int i;
RangeTblEntry *childrte;
Index childRTindex;
- bool has_child = false;
PartitionDesc partdesc = RelationGetPartitionDesc(parentrel);
check_stack_depth();
@@ -1707,6 +1706,16 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
top_parentrc, parentrel,
appinfos, &childrte, &childRTindex);
+ /*+ * If the partitioned table has no partitions, treat this as the+ * non-inheritance case.+ */+ if (partdesc->nparts == 0)+ {+ parentrte->inh = false;+ return;+ }+
for (i = 0; i < partdesc->nparts; i++)
{
Oid childOID = partdesc->oids[i];
@@ -1715,15 +1724,13 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
/* Open rel; we already have required locks */
childrel = heap_open(childOID, NoLock);
- /* As in expand_inherited_rtentry, skip non-local temp tables */+ /*+ * Temporary partitions belonging to other sessions should have been+ * disallowed at definition, but for paranoia's sake, let's double+ * check.+ */
if (RELATION_IS_OTHER_TEMP(childrel))
- {- heap_close(childrel, lockmode);- continue;- }-- /* We have a real partition. */- has_child = true;+ elog(ERROR, "temporary relation from another session found as partition");
expand_single_inheritance_child(root, parentrte, parentRTindex,
parentrel, top_parentrc, childrel,
@@ -1738,14 +1745,6 @@ expand_partitioned_rtentry(PlannerInfo *root, RangeTblEntry *parentrte,
/* Close child relation, but keep locks */
heap_close(childrel, NoLock);
}
-- /*- * If the partitioned table has no partitions or all the partitions are- * temporary tables from other backends, treat this as non-inheritance- * case.- */- if (!has_child)- parentrte->inh = false;
}
/*
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.outindex 1fab5136d2..319d03ca0b 100644--- a/src/test/regress/expected/select.out+++ b/src/test/regress/expected/select.out@@ -951,3 +951,18 @@ select * from (values (2),(null),(1)) v(k) where k = k;
1
(2 rows)
+-- test partitioned tables behave sanely when there are no leaf partitions+create table list_parted_tbl (a int,b int) partition by list (a);+create table list_parted_tbl1 partition of list_parted_tbl for values in(1) partition by list(b);+select * from list_parted_tbl;+ a | b +---+---+(0 rows)++explain (costs off) select * from list_parted_tbl;+ QUERY PLAN +--------------------------+ Result+ One-Time Filter: false+(2 rows)+diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sqlindex c80429e7d0..b93c0738f2 100644--- a/src/test/regress/sql/select.sql+++ b/src/test/regress/sql/select.sql@@ -254,3 +254,9 @@ drop function sillysrf(int);
-- (see bug #5084)
select * from (values (2),(null),(1)) v(k) where k = k order by k;
select * from (values (2),(null),(1)) v(k) where k = k;
++-- test partitioned tables behave sanely when there are no leaf partitions+create table list_parted_tbl (a int,b int) partition by list (a);+create table list_parted_tbl1 partition of list_parted_tbl for values in(1) partition by list(b);+select * from list_parted_tbl;+explain (costs off) select * from list_parted_tbl;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: david.rowley@2ndquadrant.com, michael@paquier.xyz, Langote_Amit_f8@lab.ntt.co.jp, robertmhaas@gmail.com, ashutosh.bapat@enterprisedb.com
Subject: Re: pgsql: Clarify use of temporary tables within partition trees
In-Reply-To: <CAKJS1f8ZerDq68ZTk9djC8unduhzCYN2ubHt_ornhtWSn_WByQ@mail.gmail.com>
References: <CAKJS1f8f8+3FOBhSoopo15uzHsY76+L8cMKhMwBi+x+bvBU7tg@mail.gmail.com> <20180703061119.GA11732@paquier.xyz> <CAKJS1f8h8283Vb2NcQH+YOMErdDQZWGuqGoe-gX6yT8TKGf0MA@mail.gmail.com> <5db5fe6e-4a73-6a24-09e4-060b9f132ea9@lab.ntt.co.jp> <b7cc212d-8455-c548-5a71-3cbf6133abd6@lab.ntt.co.jp> <20180703070551.GC11732@paquier.xyz> <d5059f0a-9a93-942f-5a8a-ecd13fc26b94@lab.ntt.co.jp> <CAKJS1f8Wt3CoYY-7AqtbszBLPrQMaH3xLRd2pSCKDARhQRT__A@mail.gmail.com> <20180703091507.GD11732@paquier.xyz> <CAKJS1f-SB+cAgS82KNYcBbiHR=NYFpx8s9J6+B01vdWOeeDrqw@mail.gmail.com> <20180703095343.GE11732@paquier.xyz> <CAKJS1f8ZerDq68ZTk9djC8unduhzCYN2ubHt_ornhtWSn_WByQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox