Have we tried to treat CTE as SubQuery in planner? - Mailing list pgsql-hackers

From Andy Fan
Subject Have we tried to treat CTE as SubQuery in planner?
Date
Msg-id CAKU4AWqSbsHBwYopeDRka96wDxHM8Ftuj2myVBFipSwB1eL_bA@mail.gmail.com
Whole thread Raw
Responses Re: Have we tried to treat CTE as SubQuery in planner?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Have we tried to treat CTE as SubQuery in planner?  (Julien Rouhaud <rjuju123@gmail.com>)
Re: Have we tried to treat CTE as SubQuery in planner?  (Jesse Zhang <sbjesse@gmail.com>)
List pgsql-hackers
Hi: 

Take the following example: 

insert into cte1  select i, i from generate_series(1, 1000000)i;
create index on cte1(a);

explain 
with cte1 as  (select * from cte1)
select * from c where a = 1;

It needs to do seq scan on the above format, however it is pretty
quick if we change the query to  
select * from (select * from cte1) c where a = 1;  

I know how we treat cte and subqueries differently currently,
I just don't know why we can't treat cte as a subquery, so lots of
subquery related technology can apply to it.  Do we have any 
discussion about this?  

Thanks

--
Best Regards
Andy Fan

pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: Supporting = operator in gin/gist_trgm_ops
Next
From: Tom Lane
Date:
Subject: Re: Have we tried to treat CTE as SubQuery in planner?