Re: Extracting only the columns needed for a query - Mailing list pgsql-hackers
From | Dmitry Dolgov |
---|---|
Subject | Re: Extracting only the columns needed for a query |
Date | |
Msg-id | 20200313191048.dfkelhzyjq7osqyl@localhost Whole thread Raw |
In response to | Re: Extracting only the columns needed for a query (Melanie Plageman <melanieplageman@gmail.com>) |
Responses |
Re: Extracting only the columns needed for a query
Re: Extracting only the columns needed for a query |
List | pgsql-hackers |
> On Tue, Feb 18, 2020 at 03:26:16PM -0800, Melanie Plageman wrote: > > > > I believe it would be beneficial to add this potential API extension > > patch into > > > the thread (as an example of an interface defining how scanCols could be > > used) > > > and review them together. > > > > As for including some code that uses the scanCols, after discussing > > off-list with a few folks, there are three options I would like to > > pursue for doing this. > > > > One option I will pursue is using the scanCols to inform the columns > > needed to be spilled for memory-bounded hashagg (mentioned by Jeff > > here [1]). > > > > > > The third is exercising it with a test only but providing an example > > of how a table AM API user like Zedstore uses the columns during > > planning. > > > > Basically, scanCols are simply columns that need to be scanned. It is > probably okay if it is only used by table access method API users, as > Pengzhou's patch illustrates. Thanks for update. Sure, that would be fine. At the moment I have couple of intermediate commentaries. In general implemented functionality looks good. I've checked how it works on the existing tests, almost everywhere required columns were not missing in scanCols (which is probably the most important part). Sometimes exressions were checked multiple times, which could potentially introduce some overhead, but I believe this effect is negligible. Just to mention some counterintuitive examples, for this kind of query SELECT min(q1) FROM INT8_TBL; the same column was checked 5 times in my tests, since it's present also in baserestrictinfo, and build_minmax_path does one extra round of planning and invoking make_one_rel. I've also noticed that for partitioned tables every partition is evaluated separately. IIRC they structure cannot differ, does it makes sense then? Another interesting example is Values Scan (e.g. in an insert statements with multiple records), can an abstract table AM user leverage information about columns in it? One case, where I believe columns were missing, is statements with returning: INSERT INTO foo (col1) VALUES ('col1'), ('col2'), ('col3') RETURNING *; Looks like in this situation there is only expression in reltarget is for col1, but returning result contains all columns. And just out of curiosity, what do you think about table AM specific columns e.g. ctid, xmin/xmax etc? I mean, they're not included into scanCols and should not be since they're heap AM related. But is there a chance that there would be some AM specific columns relevant to e.g. the columnar storage that would also make sense to put into scanCols?
pgsql-hackers by date: