Re: WIP patch: distinguish selectivity of < from <= and > from >=

From: Kuntal Ghosh <kuntalghosh(dot)2007(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: WIP patch: distinguish selectivity of < from <= and > from >=
Date: 2017-07-04 15:32:26
Message-ID: CAGz5QCKTW6YQNe6Ttqj-Zx_W34vmwz5jP_Cs1KC7j7yHriLVxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jul 4, 2017 at 9:23 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Aside from the mind-bendingly-tedious changes in pg_operator.h, the meat
> of the patch is in selfuncs.c's ineq_histogram_selectivity(), which now
> applies a correction for equal values in the cases where we were getting
> it wrong before. While this logic seems experimentally correct (see
> above), I have to admit that I've failed to wrap my brain around exactly
> why it's correct. The arguments that I've constructed so far seem to
> point in the direction of applying the opposite correction, which is
> demonstrably wrong. Perhaps someone whose college statistics class
> wasn't quite so long ago can explain this satisfactorily?
>
I guess that you're referring the last case, i.e.
explain analyze select * from tenk1 where thousand between 10 and 10;

IMHO, following are the things that I've understood.
The predicate internally got translated to predicate A (p >= 10) and
predicate B (p <=10);
In ineq_histogram_selectivity,
For predicate A, hist_selec = p
For predicate B, hist_selec = 1-p
In clauselist_selectivity,
we calculate the selectivity as = ((p) + (1 - p)) - 1= 0, rounded of to 1.0e-10.

After your changes,
In ineq_histogram_selectivity,
For predicate A, hist_selec = p + correction (since, isgt=iseq)
For predicate B, hist_selec = 1-p
In clauselist_selectivity,
we calculate the selectivity as = ((p + correction) + (1 - p)) - 1= correction,

The correction is calculated as = 1 / num_distinct_values = .001.

Since, the thousand column of tenk1 is uniformly distributed, this
turns out to be the exact selectivity. (rows = .001 * 1000 = 10)

Thoughts?

--
Thanks & Regards,
Kuntal Ghosh
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-07-04 15:50:21 Re: WIP patch: distinguish selectivity of < from <= and > from >=
Previous Message Tom Lane 2017-07-04 14:59:10 Re: WIP patch: distinguish selectivity of < from <= and > from >=