postgresql/src/backend
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
..
access Remove unused struct member, enforce multi_insert callback presence. 2019-04-04 17:39:39 -07:00
bootstrap tableam: relation creation, VACUUM FULL/CLUSTER, SET TABLESPACE. 2019-03-28 20:01:43 -07:00
catalog GSSAPI encryption support 2019-04-03 15:02:33 -04:00
commands Remove unused struct member, enforce multi_insert callback presence. 2019-04-04 17:39:39 -07:00
executor Use Append rather than MergeAppend for scanning ordered partitions. 2019-04-05 19:20:43 -04:00
foreign Update copyright for 2019 2019-01-02 12:44:25 -05:00
jit Renaming for new subscripting mechanism 2019-02-01 12:50:32 -03:00
lib Further code review for new integerset code. 2019-03-25 12:23:48 -04:00
libpq GSSAPI encryption support 2019-04-03 15:02:33 -04:00
main Replace @postgresql.org with @lists.postgresql.org for mailinglists 2019-01-19 19:06:35 +01:00
nodes Use Append rather than MergeAppend for scanning ordered partitions. 2019-04-05 19:20:43 -04:00
optimizer Use Append rather than MergeAppend for scanning ordered partitions. 2019-04-05 19:20:43 -04:00
parser Catch syntax error in generated column definition 2019-04-01 10:46:37 +02:00
partitioning Use Append rather than MergeAppend for scanning ordered partitions. 2019-04-05 19:20:43 -04:00
po Translation updates 2018-06-25 12:37:18 +02:00
port Revert "Consistently test for in-use shared memory." 2019-04-05 00:00:52 -07:00
postmaster Wake up interested backends when a checkpoint fails. 2019-04-06 09:31:48 +13:00
regex Collations with nondeterministic comparison 2019-03-22 12:12:43 +01:00
replication Add facility to copy replication slots 2019-04-05 18:05:18 -03:00
rewrite Perform RLS subquery checks as the right user when going via a view. 2019-04-02 08:13:59 +01:00
snowball Update copyright for 2019 2019-01-02 12:44:25 -05:00
statistics Reduce overhead of pg_mcv_list (de)serialization 2019-04-03 21:23:40 +02:00
storage Revert "Consistently test for in-use shared memory." 2019-04-05 00:00:52 -07:00
tcop Log all statements from a sample of transactions 2019-04-03 18:43:59 -03:00
tsearch Move hash_any prototype from access/hash.h to utils/hashutils.h 2019-03-11 13:17:50 -03:00
utils Fix compiler warning 2019-04-05 09:23:07 +02:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
nls.mk Translation updates 2018-06-25 12:37:18 +02:00