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

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

2014-07-21 Thread David G Johnston
johno wrote > Oh, yes I do understand that if I remove the outer limit, the semantics of > the query would change. However I am looking for the counterexample *with* > the limit clauses. Maybe I just don't understand what relationally > equivalent means, sorry about that. > > BTW this is to my und

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

2014-07-21 Thread johno
Oh, yes I do understand that if I remove the outer limit, the semantics of the query would change. However I am looking for the counterexample *with* the limit clauses. Maybe I just don't understand what relationally equivalent means, sorry about that. BTW this is to my understanding a very simila

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

2014-07-21 Thread David G Johnston
johno wrote > Thanks for the quick reply David! > > However I am still unsure how these two queries are not relationally > equivalent. I am struggling to find a counterexample where the first and > third query (in email, not in gist) would yield different results. Any > ideas? Remove the outer LI

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

2014-07-21 Thread johno
Thanks for the quick reply David! However I am still unsure how these two queries are not relationally equivalent. I am struggling to find a counterexample where the first and third query (in email, not in gist) would yield different results. Any ideas? Jano On Mon, Jul 21, 2014 at 11:31 PM, Da

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

2014-07-21 Thread David G Johnston
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 and the optimizer cannot change the behavior of the query which it is optimizing. i.e. you