Re: [PERFORM] Help with optimizing a query over hierarchical data

2014-03-03 Thread Claudio Freire
On Mon, Mar 3, 2014 at 10:12 PM, Damon Snyder wrote: > >> Um... I think your problem is a misuse of CTE. Your CTE is building an > intermediate of several thousands of rows only to select a dozen > afterwards. You may want to consider a view or subquery, though I'm > not sure pg will be able to op

Re: [PERFORM] Help with optimizing a query over hierarchical data

2014-03-03 Thread Damon Snyder
Hi Claudio, See my comments inline below. > Um... I think your problem is a misuse of CTE. Your CTE is building an intermediate of several thousands of rows only to select a dozen afterwards. You may want to consider a view or subquery, though I'm not sure pg will be able to optimize much given yo

Re: [PERFORM] Query taking long time

2014-03-03 Thread Venkata Balaji Nagothi
On Mon, Mar 3, 2014 at 9:17 PM, acanada wrote: > Hello, > > Thankyou for your answer. > I have made more changes than a simple re-indexing recently. I have moved > the sorting field to the table in order to avoid the join clause. Now the > schema is very simple. The query only implies one table:

Re: [PERFORM] Help with optimizing a query over hierarchical data

2014-03-03 Thread Claudio Freire
Um... I think your problem is a misuse of CTE. Your CTE is building an intermediate of several thousands of rows only to select a dozen afterwards. You may want to consider a view or subquery, though I'm not sure pg will be able to optimize much given your use of window functions, which forces a ma

[PERFORM] Subselect an order of magnitude faster than nested joins

2014-03-03 Thread Eli Naeher
Hello, I have two versions of essentially the same query; one using nested joins, the other using subselects. The version using the subselect is roughly an order of magnitude faster (~70ms on my box and data vs ~900ms for the nested joins). Of course the obvious answer here is just to use the fast

Re: [PERFORM] Help with optimizing a query over hierarchical data

2014-03-03 Thread Damon Snyder
Hi Claudio, Thanks for responding. Here is the explain (http://explain.depesz.com/s/W3W) for the ordering by meta container starting on line 192 ( https://gist.github.com/drsnyder/9277054#file-object-ordering-setup-sql-L192 ). Here is the explain (http://explain.depesz.com/s/d1O) for the ordering

Re: [PERFORM] Query taking long time

2014-03-03 Thread Vladimir Sitnikov
> I have simplified the query and added the last advise that you told me: > > Query: > > explain analyze select * from (select * from entity_compounddict2document where name='ranitidine') as a order by a.hepval; > Do you need full result? If you need just top-n rows, then index on entity_compoun