pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <rhaas@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Treat number of disabled nodes in a path as a separate cost metr
Date: Wed, 21 Aug 2024 14:12:43 +0000
Message-ID: <E1sgm4p-000mJW-Ii@gemulon.postgresql.org> (raw)

Treat number of disabled nodes in a path as a separate cost metric.

Previously, when a path type was disabled by e.g. enable_seqscan=false,
we either avoided generating that path type in the first place, or
more commonly, we added a large constant, called disable_cost, to the
estimated startup cost of that path. This latter approach can distort
planning. For instance, an extremely expensive non-disabled path
could seem to be worse than a disabled path, especially if the full
cost of that path node need not be paid (e.g. due to a Limit).
Or, as in the regression test whose expected output changes with this
commit, the addition of disable_cost can make two paths that would
normally be distinguishible in cost seem to have fuzzily the same cost.

To fix that, we now count the number of disabled path nodes and
consider that a high-order component of both the startup cost and the
total cost. Hence, the path list is now sorted by disabled_nodes and
then by total_cost, instead of just by the latter, and likewise for
the partial path list.  It is important that this number is a count
and not simply a Boolean; else, as soon as we're unable to respect
disabled path types in all portions of the path, we stop trying to
avoid them where we can.

Because the path list is now sorted by the number of disabled nodes,
the join prechecks must compute the count of disabled nodes during
the initial cost phase instead of postponing it to final cost time.

Counts of disabled nodes do not cross subquery levels; at present,
there is no reason for them to do so, since the we do not postpone
path selection across subquery boundaries (see make_subplan).

Reviewed by Andres Freund, Heikki Linnakangas, and David Rowley.

Discussion: http://postgr.es/m/CA+TgmoZ_+MS+o6NeGK2xyBv-xM+w1AfFVuHE4f_aq6ekHv7YSQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e22253467942fdb100087787c3e1e3a8620c54b2

Modified Files
--------------
contrib/file_fdw/file_fdw.c                   |   1 +
contrib/postgres_fdw/postgres_fdw.c           |  46 +++++-
contrib/postgres_fdw/postgres_fdw.h           |   1 +
src/backend/optimizer/path/costsize.c         | 155 +++++++++++++------
src/backend/optimizer/path/joinpath.c         |  15 +-
src/backend/optimizer/plan/createplan.c       |   2 +
src/backend/optimizer/plan/planner.c          |   1 +
src/backend/optimizer/prep/prepunion.c        |   6 +-
src/backend/optimizer/util/pathnode.c         | 212 +++++++++++++++++++-------
src/include/nodes/pathnodes.h                 |   2 +
src/include/optimizer/cost.h                  |  10 +-
src/include/optimizer/pathnode.h              |  12 +-
src/test/isolation/specs/horizons.spec        |   1 -
src/test/regress/expected/btree_index.out     |  12 +-
src/test/regress/expected/select_parallel.out |   8 +-
15 files changed, 357 insertions(+), 127 deletions(-)



Message-ID: <E1sgm4p-000mJW-Ii@gemulon.postgresql.org>
Permalink:  ../E1sgm4p-000mJW-Ii@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1sgm4p-000mJW-Ii@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: rhaas@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Treat number of disabled nodes in a path as a separate cost metr
  In-Reply-To: <E1sgm4p-000mJW-Ii@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox