Re: CTE with JOIN of two tables is much faster than a regular query

2018-08-18 Thread Ravi Krishna
> What can I do to improve the performance of the regular query without using a > CTE? Why do you care ? When I find that I can write a SQL 3 different ways, I will go for the most efficient one. So why not accept the CTE version of this SQL. Just curious.

Re: CTE with JOIN of two tables is much faster than a regular query

2018-08-18 Thread Tom Lane
Stephen Frost writes: > * kpi6...@gmail.com (kpi6...@gmail.com) wrote: >> The CTE mentioned below completes the query in 4.5 seconds while the regular >> query takes 66 seconds. > Unfortunately, we don't currently pay attention to things like average > string length when considering the cost of p

Re: CTE with JOIN of two tables is much faster than a regular query

2018-08-18 Thread Stephen Frost
Greetings, * kpi6...@gmail.com (kpi6...@gmail.com) wrote: > The CTE mentioned below completes the query in 4.5 seconds while the regular > query takes 66 seconds. I read from EXPLAIN ANALYSE that the regular query > starts with a full table scan over "Doc" while the CTE joins the two tables > firs

Re: CTE with JOIN of two tables is much faster than a regular query

2018-08-18 Thread Andreas Kretschmer
Am 18.08.2018 um 11:36 schrieb kpi6...@gmail.com: What can I do to improve the performance of the regular query without using a CTE? try to rewrite it to a subselect: select ... from ... join (selec ... from ... where ...) x on ... Regards, Andreas -- 2ndQuadrant - The PostgreSQL Suppor