pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joseph Shraibman <jks@selectacast.net>
Cc: Richard Huxton <dev@archonet.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: two seperate queries run faster than queries ORed together
Date: Mon, 22 Mar 2004 13:24:19 -0500
Message-ID: <6875.1079979859@sss.pgh.pa.us> (raw)
In-Reply-To: <405F2893.5090805@selectacast.net>
References: <c3d3sm$fdg$1@news.hub.org>
	<200403221655.28667.dev@archonet.com>
	<405F2893.5090805@selectacast.net>

Joseph Shraibman <jks@selectacast.net> writes:
> No, pkey is not the primary key in this case. The number of entries in u 
> that have pkey 260 and not boolfield is 344706.

... and every one of those rows *must* be included in the join input,
regardless of its status value, because it might join to some d row that
has status=3.  Conversely, every single row of d must be considered in
the join because it might join to some u row with status=3.  So any way
you slice it, this query requires a large and expensive join operation,
no matter that there are only a few rows with the right status values in
the other table.

I'd rewrite the query if I were you.

			regards, tom lane



view thread (8+ messages)  latest in thread

Message-ID: <6875.1079979859@sss.pgh.pa.us>
Permalink:  ../6875.1079979859@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6875.1079979859@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, jks@selectacast.net, dev@archonet.com
  Subject: Re: two seperate queries run faster than queries ORed together
  In-Reply-To: <6875.1079979859@sss.pgh.pa.us>

* 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