Re: BUG #14302: SQL with LIMIT degrades performance seriously - Mailing list pgsql-bugs

From Francisco Olarte
Subject Re: BUG #14302: SQL with LIMIT degrades performance seriously
Date
Msg-id CA+bJJbyuQ2t4Q_2iaGuY9QvLnB+vDJ8C9LV7T01kASPA28jbsA@mail.gmail.com
Whole thread Raw
In response to Re: BUG #14302: SQL with LIMIT degrades performance seriously  (Kaijiang Chen <chenkaijiang@gmail.com>)
List pgsql-bugs
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.

pgsql-bugs by date:

Previous
From: Kaijiang Chen
Date:
Subject: Re: BUG #14302: SQL with LIMIT degrades performance seriously
Next
From: Francisco Olarte
Date:
Subject: Re: BUG #14302: SQL with LIMIT degrades performance seriously