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

From Vasilis Ventirozos
Subject Re: Index usage for tstzrange?
Date
Msg-id CAF8jcqpsvu8ckR8OLxVYconNm=vJLUg-YJa3XC81bGSVV3bBoA@mail.gmail.com
Whole thread Raw
In response to Re: Index usage for tstzrange?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Index usage for tstzrange?
List pgsql-performance


On Thu, Mar 21, 2013 at 5:58 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Josh Berkus <josh@agliodbs.com> writes:
> I just noticed that if I use a tstzrange for convenience, a standard
> btree index on a timestamp won't get used for it.  Example:

> table a (
>       id int,
>       val text,
>       ts timestamptz
> );
> index a_ts on a(ts);

> SELECT * FROM a WHERE ts <@ tstzrange('2013-01-01','2013-01-01 00:10:00')

> ... will NOT use the index a_ts.

Well, no.  <@ is not a btree-indexable operator.

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.

                        regards, tom lane


--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

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)

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Index usage for tstzrange?
Next
From: Heikki Linnakangas
Date:
Subject: Re: Index usage for tstzrange?