pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PgSQL Performance ML <pgsql-performance@postgresql.org>
Subject: Re: Suggestions wanted for 7.2.4 query
Date: Sun, 4 May 2003 09:07:03 -0700
Message-ID: <200305040907.03306.josh@agliodbs.com> (raw)
In-Reply-To: <25878.1052023320@sss.pgh.pa.us>
References: <200305031928.52906.josh@agliodbs.com>
	<25878.1052023320@sss.pgh.pa.us>

Tom,

> > SELECT sv_events.*, FALSE AS fuzzy_team FROM sv_events WHERE  EXISTS (
> > SELECT event_id FROM event_days
> >  WHERE event_days.event_id = sv_events.event_id AND  (event_day BETWEEN
> > ('2003-04-08'::TIMESTAMP WITHOUT TIME ZONE)
> >   AND ('2003-06-17 23:59'::TIMESTAMP WITHOUT TIME ZONE) ) );
>
> Is event_days.event_id unique?  If so, try

Regrettably, no.   Event_days is an iterative list of all of the days covered 
by the event.   What's unique is event_days_pk, which is event_id, event_day.  
If I did a direct join to event_days, multi-day events would appear on the 
search results more than once .... which we *don't* want.

> This at least gives you some glimmer of a chance that the restriction on
> event_day can be used to avoid computing the entire join represented by
> sv_events.  With the exists() form, there's no chance...

Hmmm.  There are other ways I can get at the date limit for sv_events; I'll 
try that.  Unfortunately, those ways require a seq scan on events, so I'm not 
sure we have a net gain here (that is, I can't imagine that  a two-column 
date calculation between two parameters could be indexed)

 However, by my reading, 75% of the cost of the query is the unindexed join 
between "events" and "cases".    Are you saying that the planner being vague 
about what will be returned from the EXISTS clause is what's triggering the 
seq scan on "cases"?

-- 
Josh Berkus
Aglio Database Solutions
San Francisco




view thread (7+ messages)  latest in thread

Message-ID: <200305040907.03306.josh@agliodbs.com>
Permalink:  ../200305040907.03306.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200305040907.03306.josh@agliodbs.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: josh@agliodbs.com, tgl@sss.pgh.pa.us
  Subject: Re: Suggestions wanted for 7.2.4 query
  In-Reply-To: <200305040907.03306.josh@agliodbs.com>
  References: <200305031928.52906.josh@agliodbs.com> <25878.1052023320@sss.pgh.pa.us> <200305040907.03306.josh@agliodbs.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