From: | Michael Lewis <mlewis(at)entrata(dot)com> |
---|---|
To: | David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> |
Cc: | Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Jeremy Finzel <finzelj(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: BRIN index which is much faster never chosen by planner |
Date: | 2019-10-11 04:48:08 |
Message-ID: | CAHOFxGoge0hjTZrvsj92rZz6+OqVw+4UojV5xKFm2_vHgF2D_g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Oct 10, 2019 at 6:22 PM David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
wrote:
> The planner might be able to get a better estimate on the number of
> matching rows if the now() - interval '10 days' expression was
> replaced with 'now'::timestamptz - interval '10 days'. However, care
> would need to be taken to ensure the plan is never prepared since
> 'now' is evaluated during parse. The same care must be taken when
> creating views, functions, stored procedures and the like.
>
> The planner will just estimate the selectivity of now() - interval '10
> days' by using DEFAULT_INEQ_SEL, which is 0.3333333333333333, so it
> thinks it'll get 1/3rd of the table. Using 'now' will allow the
> planner to lookup actual statistics on that column which will likely
> give a much better estimate, which by the looks of it, likely will
> result in one of those BRIN index being used.
>
This surprised me a bit, and would have significant implications. I tested
a few different tables in our system and get the same row count estimate
with either WHERE condition. Perhaps I am missing a critical piece of what
you said.
explain
select * from charges where posted_on > now() - interval '10 days';
explain
select * from charges where posted_on > 'now'::timestamptz - interval '10
days';
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2019-10-11 05:13:33 | Re: let's make the list of reportable GUCs configurable (was Re: Add %r substitution for psql prompts to show recovery status) |
Previous Message | Masahiko Sawada | 2019-10-11 02:05:26 | Re: maintenance_work_mem used by Vacuum |