X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7EA19476485 for ; Sun, 4 May 2003 12:07:52 -0400 (EDT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id ACD33476481 for ; Sun, 4 May 2003 12:07:47 -0400 (EDT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3007182; Sun, 04 May 2003 09:07:47 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Tom Lane Subject: Re: Suggestions wanted for 7.2.4 query Date: Sun, 4 May 2003 09:07:03 -0700 User-Agent: KMail/1.4.3 Cc: PgSQL Performance ML References: <200305031928.52906.josh@agliodbs.com> <25878.1052023320@sss.pgh.pa.us> In-Reply-To: <25878.1052023320@sss.pgh.pa.us> MIME-Version: 1.0 Message-Id: <200305040907.03306.josh@agliodbs.com> Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, hits=-33.0 required=5.0 tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/39 X-Sequence-Number: 1818 Tom, > > SELECT sv_events.*, FALSE AS fuzzy_team FROM sv_events WHERE EXISTS ( > > SELECT event_id FROM event_days > > WHERE event_days.event_id =3D sv_events.event_id AND (event_day BETWE= EN > > ('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 cover= ed=20 by the event. What's unique is event_days_pk, which is event_id, event_da= y.=20=20 If I did a direct join to event_days, multi-day events would appear on the= =20 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= =20 try that. Unfortunately, those ways require a seq scan on events, so I'm n= ot=20 sure we have a net gain here (that is, I can't imagine that a two-column= =20 date calculation between two parameters could be indexed) However, by my reading, 75% of the cost of the query is the unindexed join= =20 between "events" and "cases". Are you saying that the planner being vagu= e=20 about what will be returned from the EXISTS clause is what's triggering the= =20 seq scan on "cases"? --=20 Josh Berkus Aglio Database Solutions San Francisco