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

Commit b5415e3

Browse files
committed
Support parameterized TidPaths.
Up to now we've not worried much about joins where the join key is a relation's CTID column, reasoning that storing a table's CTIDs in some other table would be pretty useless. However, there are use-cases for this sort of query involving self-joins, so that argument doesn't really hold water. This patch allows generating plans for joins on CTID that use a nestloop with inner TidScan, similar to what we might do with an index on the join column. This is the most efficient way to join when the outer side of the nestloop is expected to yield relatively few rows. This change requires upgrading tidpath.c and the generated TidPaths to work with RestrictInfos instead of bare qual clauses, but that's long-postponed technical debt anyway. Discussion: https://postgr.es/m/17443.1545435266@sss.pgh.pa.us
1 parent 6f19a8c commit b5415e3

File tree

8 files changed

+415
-140
lines changed

8 files changed

+415
-140
lines changed

src/backend/optimizer/path/costsize.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -1202,15 +1202,18 @@ cost_tidscan(Path *path, PlannerInfo *root,
12021202
ntuples = 0;
12031203
foreach(l, tidquals)
12041204
{
1205-
if (IsA(lfirst(l), ScalarArrayOpExpr))
1205+
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
1206+
Expr *qual = rinfo->clause;
1207+
1208+
if (IsA(qual, ScalarArrayOpExpr))
12061209
{
12071210
/* Each element of the array yields 1 tuple */
1208-
ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) lfirst(l);
1211+
ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) qual;
12091212
Node *arraynode = (Node *) lsecond(saop->args);
12101213

12111214
ntuples += estimate_array_length(arraynode);
12121215
}
1213-
else if (IsA(lfirst(l), CurrentOfExpr))
1216+
else if (IsA(qual, CurrentOfExpr))
12141217
{
12151218
/* CURRENT OF yields 1 tuple */
12161219
isCurrentOf = true;

0 commit comments

Comments
 (0)