Re: Index usage for tstzrange?

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Vasilis Ventirozos <v(dot)ventirozos(at)gmail(dot)com>
Cc: postgres performance list <pgsql-performance(at)postgresql(dot)org>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Subject: Re: Index usage for tstzrange?
Date: 2013-03-21 08:52:42
Message-ID: 514ACA5A.2080401@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 21.03.2013 06:07, Vasilis Ventirozos wrote:
> On Thu, Mar 21, 2013 at 5:58 AM, Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> What I find more disturbing is that this is what I get from the example
>> in HEAD:
>>
>> regression=# explain SELECT * FROM a WHERE ts<@
>> tstzrange('2013-01-01','2013-01-01 00:10:00');
>> ERROR: XX000: type 1184 is not a range type
>> LOCATION: range_get_typcache, rangetypes.c:1451
>>
>> Haven't traced through it to determine exactly what's happening, but
>> isn't this a legitimate usage? And if it isn't, surely a more
>> user-facing error ought to be getting thrown somewhere upstream of here.
>
> It is a legit usage, this is from a test i did myself (9.2.3)
>
> test=# explain SELECT * FROM a WHERE ts<@
> tstzrange('2013-01-01','2013-04-01 00:10:00');
> QUERY PLAN
> ------------------------------------------------------------------------------------
> Seq Scan on a (cost=0.00..23.75 rows=1 width=44)
> Filter: (ts<@ '["2013-01-01 00:00:00+02","2013-04-01
> 00:10:00+03")'::tstzrange)

Looks like the range type cost estimation patch broke this, back in
August already. The case of var <@ constant, where constant is a range
and var is an element, that's broken. The cost estimation function,
rangesel(), incorrectly assumes that the 'var' is always a range type.

It's a bit worrying that no-one noticed until now. I'll add a test for
that operator to the rangetypes regression test.

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.

- Heikki

Attachment Content-Type Size
fix-element-contained-by-range-op.patch text/x-diff 1.0 KB

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Josh Berkus 2013-03-22 00:05:31 Re: Index usage for tstzrange?
Previous Message Vasilis Ventirozos 2013-03-21 04:07:25 Re: Index usage for tstzrange?