On Wed, Aug 31, 2016 at 6:09 AM, Kaijiang Chen <chenkaijiang@gmail.com> wrote:
> In the sql "select * from renren.user_relations where parent_id=846346 order
> by user_id LIMIT 10;", planner can query the number of rows (with
> parent_id=846346) from the btree index, right?
> If so, planner will know that it's better to sort the rows (actually less
> than 2000) than to scan 10M rows.
mmmm, AFAIK planner does NOT query, it plans using stored statistics.
This is why some data distribution, which are a bad match for the
postgres ways of storing stats, tend to plan ( oacasionally ) badly.
Francisco Olarte.