pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Extract column statistics from CTE references, if possible.
Date: Fri, 17 Nov 2023 19:36:41 +0000
Message-ID: <E1r44dt-005vfA-HI@gemulon.postgresql.org> (raw)

Extract column statistics from CTE references, if possible.

examine_simple_variable() left this as an unimplemented case years
ago, with the result that plans for queries involving un-flattened
CTEs might be much stupider than necessary.  It's not hard to extend
the existing logic for RTE_SUBQUERY cases to also be able to drill
down into CTEs, so let's do that.

There was some discussion of whether this patch breaks the idea
of a MATERIALIZED CTE being an optimization fence.  We concluded
it's okay, because we already allow the outer planner level to
see the estimated width and rowcount of the CTE result, and
letting it see column statistics too seems fairly equivalent.
Basically, what we expect of the optimization fence is that the
outer query should not affect the plan chosen for the CTE query.
Once that plan is chosen, it's okay for the outer planner level
to make use of whatever information we have about it.

Jian Guo and Tom Lane, per complaint from Hans Buschmann

Discussion: https://postgr.es/m/4504e67078d648cdac3651b2960da6e7@nidsa.net

Branch
------
master

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

Modified Files
--------------
src/backend/utils/adt/selfuncs.c   | 134 +++++++++++++++++++++++++++----------
src/test/regress/expected/with.out |  18 +++++
src/test/regress/sql/with.sql      |   7 ++
3 files changed, 124 insertions(+), 35 deletions(-)



Message-ID: <E1r44dt-005vfA-HI@gemulon.postgresql.org>
Permalink:  ../E1r44dt-005vfA-HI@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1r44dt-005vfA-HI@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: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Extract column statistics from CTE references, if possible.
  In-Reply-To: <E1r44dt-005vfA-HI@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