Skip to content

Commit baf8fc2

Browse files
committed
optimize find_deepest_partition() for single tables
1 parent f1a62b3 commit baf8fc2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/planner_tree_modification.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ modifytable_contains_fdw(List *rtable, ModifyTable *node)
885885

886886
/*
887887
* Find a single deepest subpartition using quals.
888-
* Return InvalidOid if it's not possible.
888+
* It's always better to narrow down the set of tables to be scanned.
889+
* Return InvalidOid if it's not possible (e.g. table is not partitioned).
889890
*/
890891
static Oid
891892
find_deepest_partition(Oid relid, Index rti, Expr *quals)
@@ -931,8 +932,13 @@ find_deepest_partition(Oid relid, Index rti, Expr *quals)
931932
Oid *children = PrelGetChildrenArray(prel),
932933
child = children[irange_lower(irange)];
933934

935+
/* Scan this partition */
936+
result = child;
937+
934938
/* Try to go deeper and see if there are subpartitions */
935-
result = find_deepest_partition(child, rti, quals);
939+
child = find_deepest_partition(child, rti, quals);
940+
if (OidIsValid(child))
941+
result = child;
936942
}
937943
break;
938944

@@ -943,8 +949,6 @@ find_deepest_partition(Oid relid, Index rti, Expr *quals)
943949
/* Don't forget to close 'prel'! */
944950
close_pathman_relation_info(prel);
945951
}
946-
/* Otherwise, return this table */
947-
else result = relid;
948952

949953
return result;
950954
}

0 commit comments

Comments
 (0)