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