Re: Opptimizing projections containing unused columns - Mailing list pgsql-general

From Tom Lane
Subject Re: Opptimizing projections containing unused columns
Date
Msg-id 22026.1224085568@sss.pgh.pa.us
Whole thread Raw
In response to Opptimizing projections containing unused columns  ("Andrus" <kobruleht2@hot.ee>)
Responses Re: Opptimizing projections containing unused columns  ("Grzegorz Jaśkiewicz" <gryzman@gmail.com>)
Re: Opptimizing projections containing unused columns  ("Andrus" <kobruleht2@hot.ee>)
List pgsql-general
"Andrus" <kobruleht2@hot.ee> writes:
> I have lot of autogenerated from projection queries in form
> SELECT source.c1, source.c2, t1.col1, t1.col2, ...
> FROM (SELECT c1, c2, c3, ..... , c20 FROM ... WHERE ... ) source
> LEFT JOIN t2 USING (somecolumn)
> Main SELECT uses only few columns (source.c1 and source.c2 in this sample)
> from source projection.

> 1. Does selecting of unused columns ( c3 ... c20) affect to query prefomance

Don't worry about it.  All modern Postgres versions ignore columns that
aren't actually used in the query --- at least for examples as simple as
this one.  In cases where you intentionally defeat optimization (eg via
OFFSET 0 in a sub-select) it's possible that the sub-select will compute
all its output columns even though the upper query doesn't use 'em all.

The width field in EXPLAIN output offers a good hint as to how many
columns the query is actually fetching.

            regards, tom lane

pgsql-general by date:

Previous
From: "Jaime Casanova"
Date:
Subject: Re: PL/pgSQL stored procedure returning multiple result sets (SELECTs)?
Next
From: Tom Lane
Date:
Subject: Re: NATURAL JOINs