Re: [PERFORM] Slow query with indexed ORDER BY and LIMIT when using OR'd conditions

2014-07-22 Thread johno
> > No, it doesn't. Read it again ... or read up on row comparisons, > if you're unfamiliar with that notation. The above queries are > exactly equivalent per spec. > Wow, this is great. Thanks.

Re: [PERFORM] Slow query with indexed ORDER BY and LIMIT when using OR'd conditions

2014-07-21 Thread johno
On Tue, Jul 22, 2014 at 4:53 AM, Tom Lane wrote: > johno writes: > > I am trying to optimize a simple query that returns first 100 rows that > > have been updated since a given timestamp (ordered by timestamp and id > > desc). If there are several rows with the same

Re: [PERFORM] Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions

2014-07-21 Thread johno
> > > Try following my lead and bottom-post, please. > Sorry for that. > > Anyway, the query has no clue that because of the final LIMIT 100 that the > two different feeding queries are just going to happen to end up providing > the same result. Maybe, in this particular instance, it is theoret

Re: [PERFORM] Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions

2014-07-21 Thread johno
very similar scenario to how partitioned tables work and push down limit and where conditions. Why is this not possible in this case? Jano On Mon, Jul 21, 2014 at 11:54 PM, David G Johnston < david.g.johns...@gmail.com> wrote: > johno wrote > > Thanks for the quick reply David! > &

Re: [PERFORM] Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions

2014-07-21 Thread johno
, David G Johnston < david.g.johns...@gmail.com> wrote: > johno wrote > > The question is... why is the query planner unable to make this > > optimization for the slow query? What am I missing? > > Short answer - your first and last queries are not relationally equivalent

[PERFORM] Slow query with indexed ORDER BY and LIMIT when using OR'd conditions

2014-07-21 Thread johno
Hi there, I am trying to optimize a simple query that returns first 100 rows that have been updated since a given timestamp (ordered by timestamp and id desc). If there are several rows with the same timestamp I need to a second condition, that states that I want to return rows having the given t