extra TARGETENTRY when group by function( col )? - Mailing list pgsql-general

From Craig Harris
Subject extra TARGETENTRY when group by function( col )?
Date
Msg-id 20101222161336.8B85B1337990@mail.postgresql.org
Whole thread Raw
Responses Re: extra TARGETENTRY when group by function( col )?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

Given:

 

            create table t1 ( c1 timestamp without time zone, c2 int );

            explain verbose select to_char ( c1, ‘<whatever>’ ) from t1 group by to_char ( c1, ‘<whatever>’ );

 

does any one know why the SEQSCAN node has TWO TARGETENTRYs?

 

Why do we project “c1” as well as “to_char( c1 … )” ?

 

---

 

For cases where we compute an aggregate, such as:

 

            select min(c1), to_char(c1,…) from t1 group by to_char( c1,…)

 

it would make (some kind of) sense to project out “c1”.

 

But can’t the planner/optimizer distinguish these cases on the basis that ‘min’ is an aggregate function and ‘to_char’ is not?

 

The planner seems to be computing a minimal target list of columns (no expressions) first.  Guess I’m asking why it isn’t replaced.

pgsql-general by date:

Previous
From: Sim Zacks
Date:
Subject: Re: could not open relation...No such file or directory
Next
From: Adrian Klaver
Date:
Subject: Re: could not open relation...No such file or directory