Re: Extracting only the columns needed for a query

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Extracting only the columns needed for a query
Date: 2019-06-15 04:58:23
Message-ID: CAKJS1f85SF6CUdTX25kVhrOA-imygaHZOrPD2n_QokCMZunD+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 15 Jun 2019 at 13:46, Melanie Plageman
<melanieplageman(at)gmail(dot)com> wrote:
>
> While hacking on zedstore, we needed to get a list of the columns to
> be projected--basically all of the columns needed to satisfy the
> query. The two use cases we have for this is
> 1) to pass this column list down to the AM layer for the AM to leverage it
> 2) for use during planning to improving costing
> In other threads, such as [1], there has been discussion about the
> possible benefits for all table types of having access to this set of
> columns.
>
> Focusing on how to get this used cols list (as opposed to how to pass
> it down to the AM), we have tried a few approaches to constructing it
> and wanted to get some ideas on how best to do it.
>
> We are trying to determine which phase to get the columns -- after
> parsing, after planning, or during execution right before calling the
> AM.

For planning, isn't this information already available via either
targetlists or from the RelOptInfo->attr_needed array combined with
min_attr and max_attr?

If it's going to be too much overhead to extract vars from the
targetlist during executor startup then maybe something can be done
during planning to set a new Bitmapset field of attrs in
RangeTblEntry. Likely that can be built easily by looking at
attr_needed in RelOptInfo. Parse is too early to set this as which
attributes are needed can change during planning. For example, look at
remove_rel_from_query() in analyzejoins.c. If you don't need access to
this during planning then maybe setrefs.c is a good place to set
something. Although, it would be nice not to add this overhead when
the executor does not need this information. I'm unsure how the
planner could know that though, other than by having another tableam
callback function to tell it.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2019-06-15 05:45:04 Re: [PATCH] Stop ALTER SYSTEM from making bad assumptions
Previous Message Alvaro Herrera 2019-06-15 03:43:37 Re: pgsql: Avoid spurious deadlocks when upgrading a tuple lock