pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alex Hayward <xelah-pgsql@xelah.com>
To: pgsql-performance@postgresql.org
Subject: Re: Query take 101 minutes, help, please
Date: Wed, 7 Sep 2005 19:40:57 +0100 (BST)
Message-ID: <Pine.LNX.4.58.0509071935300.27397@sphinx.mythic-beasts.com> (raw)
In-Reply-To: <fc5b04ca0509071009388d72f1@mail.gmail.com>
References: <d20db5e605090709227c2c3596@mail.gmail.com>
	<fc5b04ca0509071009388d72f1@mail.gmail.com>

On Wed, 7 Sep 2005, Meetesh Karia wrote:

> PG is creating the union of January, February and March tables first and
> that doesn't have an index on it. If you're going to do many queries using
> the union of those three tables, you might want to place their contents into
> one table and create an index on it.
>
> Otherwise, try something like this:
>
> SELECT "Rut Cliente"
> FROM "Internet_Abril"
> WHERE "Rut Cliente" NOT IN (SELECT "Rut Cliente" FROM
> "Internet_Enero")
> AND "Rut Cliente" NOT IN (SELECT "Rut Cliente" FROM
> "Internet_Febrero")
> AND "Rut Cliente" NOT IN (SELECT "Rut Cliente" FROM
> "Internet_Marzo");

You may also wish to try:

SELECT "Rut Cliente"
FROM "Internet_Abril"
WHERE NOT EXISTS
  (SELECT 1 FROM "Internet_Enero"
   WHERE "Internet_Enero"."Rut Cliente"="Internet_Abril"."Rut Cliente")
AND NOT EXISTS
  (SELECT 1 FROM "Internet_Febrero"
   WHERE "Internet_Febrero"."Rut Cliente"="Internet_Abril"."Rut Cliente")
AND NOT EXISTS
  (SELECT 1 FROM "Internet_Marzo"
   WHERE "Internet_Marzo"."Rut Cliente"="Internet_Abril"."Rut Cliente")

which will probably scan the indexes on the January, February and March
indexes once for each row in the April table.




view thread (5+ messages)

Message-ID: <Pine.LNX.4.58.0509071935300.27397@sphinx.mythic-beasts.com>
Permalink:  ../Pine.LNX.4.58.0509071935300.27397@sphinx.mythic-beasts.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.58.0509071935300.27397@sphinx.mythic-beasts.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: xelah-pgsql@xelah.com
  Subject: Re: Query take 101 minutes, help, please
  In-Reply-To: <Pine.LNX.4.58.0509071935300.27397@sphinx.mythic-beasts.com>
  References: <d20db5e605090709227c2c3596@mail.gmail.com> <fc5b04ca0509071009388d72f1@mail.gmail.com> <Pine.LNX.4.58.0509071935300.27397@sphinx.mythic-beasts.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