Re: Index usage for tstzrange? - Mailing list pgsql-performance

From Heikki Linnakangas
Subject Re: Index usage for tstzrange?
Date
Msg-id 514CD2D9.4080008@vmware.com
Whole thread Raw
In response to Index usage for tstzrange?  (Josh Berkus <josh@agliodbs.com>)
List pgsql-performance
On 21.03.2013 17:55, Alexander Korotkov wrote:
> On Thu, Mar 21, 2013 at 12:52 PM, Heikki Linnakangas<
>> The immediate fix is attached, but this made me realize that rangesel() is
>> still missing estimation for the "element<@ range" operator. It shouldn't
>> be hard to implement, I'm pretty sure we have all the statistics we need
>> for that.
>
> Probably we could even call existing scalarltsel and scalargtsel for this
> case.

I came up with the attached. I didn't quite use scalarltsel, but I used
the scalarineqsel function, which contains the "guts" of scalarltsel and
scalargtsel.

One thing I wasn't quite sure of (from the patch):

>     /*
>      * We use the data type's default < operator. This is bogus, if the range
>      * type's rngsubopc operator class is different. In practice, that ought
>      * to be rare. It would also be bogus to use the < operator from the
>      * rngsubopc operator class, because the statistics are collected using
>      * using the default operator class, anyway.
>      *
>      * For the same reason, use the default collation. The statistics are
>      * collected with the default collation.
>      */

Does that make sense? The other option would be to use the < operator
from the rngsubopc op class, even though the scalar statistics are
collected with the default b-tree < operator. As long as the two sort
roughly the same way, you get reasonable results either way. Yet another
option would be to use histogram_selectivity() instead of
ineq_histogram_selectivity(), if the range's rngsubopc opclass isn't the
type's default opclass. histogram_selectivity() works with any operator
regardless of the sort ordering, basically using the histogram values
merely as a sample, rather than as a histogram. But I'm reluctant to
make this any more complicated, as using a non-default opclass for the
range type is rare.

- Heikki

Attachment

pgsql-performance by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Performance of query
Next
From: Cindy Makarowsky
Date:
Subject: Re: Performance of query