pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Riess <mlriess@gmx.de>
To: pgsql-performance@postgresql.org
Subject: Re: Can this query go faster???
Date: Tue, 06 Dec 2005 10:51:25 +0100
Message-ID: <dn3muo$i9c$1@news.hub.org> (raw)
In-Reply-To: <1133862229.8837.61.camel@Panoramix>
References: <1133862229.8837.61.camel@Panoramix>

> Hi,
> 
> Is it possible to get this query run faster than it does now, by adding
> indexes, changing the query?
> 
> SELECT customers.objectid FROM prototype.customers, prototype.addresses
> WHERE
> customers.contactaddress = addresses.objectid
> ORDER BY zipCode asc, housenumber asc
> LIMIT 1 OFFSET 283745
> 
> Explain:
> 
> Limit  (cost=90956.71..90956.71 rows=1 width=55)
>   ->  Sort  (cost=90247.34..91169.63 rows=368915 width=55)
>         Sort Key: addresses.zipcode, addresses.housenumber
>         ->  Hash Join  (cost=14598.44..56135.75 rows=368915 width=55)
>               Hash Cond: ("outer".contactaddress = "inner".objectid)
>               ->  Seq Scan on customers  (cost=0.00..31392.15
> rows=368915 width=80)
>               ->  Hash  (cost=13675.15..13675.15 rows=369315 width=55)
>                     ->  Seq Scan on addresses  (cost=0.00..13675.15
> rows=369315 width=55)
> 
> The customers table has an index on contactaddress and objectid.
> The addresses table has an index on zipcode+housenumber and objectid.

When the resulting relation contains all the info from both tables, 
indexes won't help, seq scan is inevitable.



view thread (14+ messages)  latest in thread

Message-ID: <dn3muo$i9c$1@news.hub.org>
Permalink:  ../dn3muo$i9c$1@news.hub.org/
Also on:    postgresql.org/message-id/dn3muo$i9c$1@news.hub.org

 · 

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: mlriess@gmx.de
  Subject: Re: Can this query go faster???
  In-Reply-To: <dn3muo$i9c$1@news.hub.org>

* 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