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

2014-03-04 Thread Damon Snyder
Hi Claudio, Thanks for the help! Damon On Mon, Mar 3, 2014 at 8:20 PM, Claudio Freire wrote: > 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 d

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] 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

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] Help with optimizing a query over hierarchical data

2014-03-01 Thread Claudio Freire
On Fri, Feb 28, 2014 at 5:01 PM, Damon Snyder wrote: > The primary query that I'm trying to optimize executes in about 1600ms on my > laptop and about 800ms on production-like hardware (more for the score > version). My target is to get the data fetch down below 100ms if possible. Could you post

[PERFORM] Help with optimizing a query over hierarchical data

2014-03-01 Thread Damon Snyder
Hi Everyone, We have a data set and access pattern that is causing us some performance issues. The data set is hierarchical with about 2 million rows at the lowest level (object), followed by 500k at the next level (container) and approximately 10 at the highest level (category). The way the data