Skip to content

Commit f0f13a3

Browse files
committed
Fix estimates for ModifyTable paths without RETURNING.
In the past, we always estimated that a ModifyTable node would emit the same number of rows as its subpaths. Without a RETURNING clause, the correct estimate is zero. Fix, in preparation for a proposed parallel write patch that is sensitive to that number. A remaining problem is that for RETURNING queries, the estimated width is based on subpath output rather than the RETURNING tlist. Reviewed-by: Greg Nancarrow <gregn4422@gmail.com> Discussion: https://postgr.es/m/CAJcOf-cXnB5cnMKqWEp2E2z7Mvcd04iLVmV%3DqpFJrR3AcrTS3g%40mail.gmail.com
1 parent 3fb6765 commit f0f13a3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/backend/optimizer/util/pathnode.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -3583,15 +3583,18 @@ create_modifytable_path(PlannerInfo *root, RelOptInfo *rel,
35833583
if (lc == list_head(subpaths)) /* first node? */
35843584
pathnode->path.startup_cost = subpath->startup_cost;
35853585
pathnode->path.total_cost += subpath->total_cost;
3586-
pathnode->path.rows += subpath->rows;
3587-
total_size += subpath->pathtarget->width * subpath->rows;
3586+
if (returningLists != NIL)
3587+
{
3588+
pathnode->path.rows += subpath->rows;
3589+
total_size += subpath->pathtarget->width * subpath->rows;
3590+
}
35883591
}
35893592

35903593
/*
35913594
* Set width to the average width of the subpath outputs. XXX this is
3592-
* totally wrong: we should report zero if no RETURNING, else an average
3593-
* of the RETURNING tlist widths. But it's what happened historically,
3594-
* and improving it is a task for another day.
3595+
* totally wrong: we should return an average of the RETURNING tlist
3596+
* widths. But it's what happened historically, and improving it is a task
3597+
* for another day.
35953598
*/
35963599
if (pathnode->path.rows > 0)
35973600
total_size /= pathnode->path.rows;

0 commit comments

Comments
 (0)