Thread: extra TARGETENTRY when group by function( col )?
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.
"Craig Harris" <harris@SummerEyes.com> writes: > does any one know why the SEQSCAN node has TWO TARGETENTRYs? It doesn't stop to notice that the Var is not referenced by any upper nodes in this particular scenario. regards, tom lane