Re: ORDER BY, LIMIT and indexes - Mailing list pgsql-performance

From Tom Lane
Subject Re: ORDER BY, LIMIT and indexes
Date
Msg-id 3619.1375851178@sss.pgh.pa.us
Whole thread Raw
In response to Re: ORDER BY, LIMIT and indexes  (Claudio Freire <klaussfreire@gmail.com>)
List pgsql-performance
Claudio Freire <klaussfreire@gmail.com> writes:
> Alternatively, a token startup cost could be added to those kinds of
> filtered sequential scans, when the filtering term is selective
> enough. That would offset the cost just a little bit, but enough to
> favor index over sequential on the right cases.

Maybe not so "token".  Really, if there's a filter condition having a
selectivity of say 1/N, we should expect to have to skip over O(N) tuples
before finding a match.  (Not sure at this late hour if the expectation is
N, or N/2, or something else ... but anyway it's in that ballpark.)  We
don't take that into account in computing the startup time of a plan node,
but I'm thinking we should.  In this particular example, that would
penalize the seqscan plan and not the indexscan plan, because in the
indexscan case the condition is being applied by the index; it's not an
after-the-fact filter.

            regards, tom lane


pgsql-performance by date:

Previous
From: Sergey Konoplev
Date:
Subject: Re: ORDER BY, LIMIT and indexes
Next
From:
Date:
Subject: Re: [PERFORM] Sub-optimal plan for a paginated query on a view with another view inside of it.