Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d57929a

Browse files
committed
Avoid unnecessary single-child Append nodes.
Before commit d3cc37f, an inheritance parent whose only children were temp tables of other sessions would end up as a simple scan of the parent; but with that commit, we end up with an Append node, per a report from Ashutosh Bapat. Tweak the logic so that we go back to the old way, and update the function header comment for partitioning while we're at it. Ashutosh Bapat, reviewed by Amit Langote and adjusted by me. Discussion: http://postgr.es/m/CAFjFpReWJr1yTkHU=OqiMBmcYCMoSW3VPR39RBuQ_ovwDFBT5Q@mail.gmail.com
1 parent 1295a77 commit d57929a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/backend/optimizer/prep/prepunion.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,12 @@ expand_inherited_tables(PlannerInfo *root)
13601360
* table, but with inh = false, to represent the parent table in its role
13611361
* as a simple member of the inheritance set.
13621362
*
1363-
* A childless table is never considered to be an inheritance set; therefore
1364-
* a parent RTE must always have at least two associated AppendRelInfos.
1363+
* A childless table is never considered to be an inheritance set. For
1364+
* regular inheritance, a parent RTE must always have at least two associated
1365+
* AppendRelInfos: one corresponding to the parent table as a simple member of
1366+
* inheritance set and one or more corresponding to the actual children.
1367+
* Since a partitioned table is not scanned, it might have only one associated
1368+
* AppendRelInfo.
13651369
*/
13661370
static void
13671371
expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
@@ -1374,7 +1378,7 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
13741378
List *inhOIDs;
13751379
List *appinfos;
13761380
ListCell *l;
1377-
bool need_append;
1381+
bool has_child;
13781382
PartitionedChildRelInfo *pcinfo;
13791383
List *partitioned_child_rels = NIL;
13801384

@@ -1448,7 +1452,7 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
14481452

14491453
/* Scan the inheritance set and expand it */
14501454
appinfos = NIL;
1451-
need_append = false;
1455+
has_child = false;
14521456
foreach(l, inhOIDs)
14531457
{
14541458
Oid childOID = lfirst_oid(l);
@@ -1502,7 +1506,10 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
15021506
*/
15031507
if (childrte->relkind != RELKIND_PARTITIONED_TABLE)
15041508
{
1505-
need_append = true;
1509+
/* Remember if we saw a real child. */
1510+
if (childOID != parentOID)
1511+
has_child = true;
1512+
15061513
appinfo = makeNode(AppendRelInfo);
15071514
appinfo->parent_relid = rti;
15081515
appinfo->child_relid = childRTindex;
@@ -1582,7 +1589,7 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
15821589
* the parent table is harmless, so we don't bother to get rid of it;
15831590
* ditto for the useless PlanRowMark node.
15841591
*/
1585-
if (!need_append)
1592+
if (!has_child)
15861593
{
15871594
/* Clear flag before returning */
15881595
rte->inh = false;

0 commit comments

Comments
 (0)