postgresql/src/include/nodes
Tom Lane 959d00e9db Use Append rather than MergeAppend for scanning ordered partitions.
If we need ordered output from a scan of a partitioned table, but
the ordering matches the partition ordering, then we don't need to
use a MergeAppend to combine the pre-ordered per-partition scan
results: a plain Append will produce the same results.  This
both saves useless comparison work inside the MergeAppend proper,
and allows us to start returning tuples after istarting up just
the first child node not all of them.

However, all is not peaches and cream, because if some of the
child nodes have high startup costs then there will be big
discontinuities in the tuples-returned-versus-elapsed-time curve.
The planner's cost model cannot handle that (yet, anyway).
If we model the Append's startup cost as being just the first
child's startup cost, we may drastically underestimate the cost
of fetching slightly more tuples than are available from the first
child.  Since we've had bad experiences with over-optimistic choices
of "fast start" plans for ORDER BY LIMIT queries, that seems scary.
As a klugy workaround, set the startup cost estimate for an ordered
Append to be the sum of its children's startup costs (as MergeAppend
would).  This doesn't really describe reality, but it's less likely
to cause a bad plan choice than an underestimated startup cost would.
In practice, the cases where we really care about this optimization
will have child plans that are IndexScans with zero startup cost,
so that the overly conservative estimate is still just zero.

David Rowley, reviewed by Julien Rouhaud and Antonin Houska

Discussion: https://postgr.es/m/CAKJS1f-hAqhPLRk_RaSFTgYxd=Tz5hA7kQ2h4-DhJufQk8TGuw@mail.gmail.com
2019-04-05 19:20:43 -04:00
..
bitmapset.h Add support for multivariate MCV lists 2019-03-27 18:32:18 +01:00
execnodes.h tableam: Add table_multi_insert() and revamp/speed-up COPY FROM buffering. 2019-04-04 16:28:18 -07:00
extensible.h Rename nodes/relation.h to nodes/pathnodes.h. 2019-01-29 16:49:25 -05:00
lockoptions.h Don't include heapam.h from others headers. 2019-01-14 16:24:41 -08:00
makefuncs.h Make some small planner API cleanups. 2019-01-29 15:26:44 -05:00
memnodes.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
nodeFuncs.h Make some small planner API cleanups. 2019-01-29 15:26:44 -05:00
nodes.h tableam: introduce table AM infrastructure. 2019-03-06 09:54:38 -08:00
params.h Refactor ParamListInfo initialization 2019-03-14 13:30:09 +01:00
parsenodes.h Generated columns 2019-03-30 08:15:57 +01:00
pathnodes.h Use Append rather than MergeAppend for scanning ordered partitions. 2019-04-05 19:20:43 -04:00
pg_list.h Standardize some more loops that chase down parallel lists. 2019-02-28 14:25:01 -05:00
plannodes.h Speed up planning when partitions can be pruned at plan time. 2019-03-30 18:58:55 -04:00
primnodes.h tableam: introduce table AM infrastructure. 2019-03-06 09:54:38 -08:00
print.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
readfuncs.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
replnodes.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
supportnodes.h Allow extensions to generate lossy index conditions. 2019-02-11 21:26:14 -05:00
tidbitmap.h tableam: bitmap table scan. 2019-03-31 18:37:57 -07:00
value.h Update copyright for 2019 2019-01-02 12:44:25 -05:00