[PERFORM] LIMIT 1 poor query plan

2015-10-10 Thread Marcio Ribeiro
Hail there, Short question: Why would pg optimizer choose a worst (slower) query plan for a query with 'LIMIT 1' instead of, say, 'LIMIT 3'? Complete scenario: Query: 'SELECT * FROM a WHERE a.b_id = 42 ORDER BY created LIMIT 1' - b_id is a FK to b; - created is a datetime with the time of the cre

Re: [PERFORM] LIMIT 1 poor query plan

2015-10-10 Thread Tom Lane
Marcio Ribeiro writes: > Short question: > Why would pg optimizer choose a worst (slower) query plan for a > query with 'LIMIT 1' instead of, say, 'LIMIT 3'? > Complete scenario: > Query: 'SELECT * FROM a WHERE a.b_id = 42 ORDER BY created LIMIT 1' > - b_id is a FK to b; > - created is a datetime

Re: [PERFORM] LIMIT 1 poor query plan

2015-10-10 Thread Marcio Ribeiro
Yes, the composite index nailed it. Thanks mate :) On Sat, Oct 10, 2015 at 12:45 PM, Tom Lane wrote: > Marcio Ribeiro writes: > > Short question: > > Why would pg optimizer choose a worst (slower) query plan for a > > query with 'LIMIT 1' instead of, say, 'LIMIT 3'? > > > Complete scenario: >