pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Greg Stark <gsstark@MIT.EDU>
Cc: Alex Adriaanse <alex@innovacomputing.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Bad row estimates
Date: 04 Mar 2006 13:11:13 -0500
Message-ID: <87fylyrsfy.fsf@stark.xeocode.com> (raw)
In-Reply-To: <14850.1141488599@sss.pgh.pa.us>
References: <4408E91C.90104@innovacomputing.com>
	<87wtfasng0.fsf@stark.xeocode.com>
	<14850.1141488599@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.us> writes:

> Otherwise I think you really need a special datatype for time
> intervals and a GIST or r-tree index on it :-(.

You could actually take short cuts using expression indexes to do this. If it
works out well then you might want to implement a real data type to avoid the
overhead of the SQL conversion functions.

Here's an example. If I were to do this for real I would look for a better
datatype than the box datatype and I would wrap the whole conversion in an SQL
function. But this will serve to demonstrate:

stark=> create table interval_test (start_ts timestamp with time zone, end_ts timestamp with time zone);
CREATE TABLE

stark=> create index interval_idx on interval_test using gist (box(point(start_ts::abstime::integer, end_ts::abstime::integer) , point(start_ts::abstime::integer, end_ts::abstime::integer)));
CREATE INDEX

stark=> explain select * from interval_test where box(point(now()::abstime::integer,now()::abstime::integer),point(now()::abstime::integer,now()::abstime::integer)) ~ box(point(start_ts::abstime::integer, end_ts::abstime::integer) , point(start_ts::abstime::integer, end_ts::abstime::integer));
                                                                                                                                                                                                                              QUERY PLAN                                                                                                                                                                                                                               
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Index Scan using interval_idx on interval_test  (cost=0.07..8.36 rows=2 width=16)
   Index Cond: (box(point((((now())::abstime)::integer)::double precision, (((now())::abstime)::integer)::double precision), point((((now())::abstime)::integer)::double precision, (((now())::abstime)::integer)::double precision)) ~ box(point((((start_ts)::abstime)::integer)::double precision, (((end_ts)::abstime)::integer)::double precision), point((((start_ts)::abstime)::integer)::double precision, (((end_ts)::abstime)::integer)::double precision)))
(2 rows)

-- 
greg




view thread (8+ messages)  latest in thread

Message-ID: <87fylyrsfy.fsf@stark.xeocode.com>
Permalink:  ../87fylyrsfy.fsf@stark.xeocode.com/
Also on:    postgresql.org/message-id/87fylyrsfy.fsf@stark.xeocode.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: gsstark@mit.edu, tgl@sss.pgh.pa.us, alex@innovacomputing.com
  Subject: Re: Bad row estimates
  In-Reply-To: <87fylyrsfy.fsf@stark.xeocode.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox