Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIWeg-00073j-4S for pgsql-performance@arkaria.postgresql.org; Thu, 21 Mar 2013 03:59:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UIWef-0006cr-1B for pgsql-performance@arkaria.postgresql.org; Thu, 21 Mar 2013 03:59:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIWee-0006cl-1N for pgsql-performance@postgresql.org; Thu, 21 Mar 2013 03:59:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UIWeW-0002X2-5I for pgsql-performance@postgresql.org; Thu, 21 Mar 2013 03:59:03 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r2L3woga001327; Wed, 20 Mar 2013 23:58:50 -0400 (EDT) From: Tom Lane To: Josh Berkus cc: "pgsql-performance@postgresql.org" , Jeff Davis Subject: Re: Index usage for tstzrange? In-reply-to: <514A5088.6060101@agliodbs.com> References: <514A5088.6060101@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Wed, 20 Mar 2013 17:12:56 -0700" Date: Wed, 20 Mar 2013 23:58:50 -0400 Message-ID: <1326.1363838330@sss.pgh.pa.us> X-Pg-Spam-Score: -4.4 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Josh Berkus 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