pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthew Wakeling <matthew@flymine.org>
To: pgsql-performance@postgresql.org
Subject: Re: Planner should use index on a LIKE 'foo%' query
Date: Mon, 30 Jun 2008 13:52:08 +0100 (BST)
Message-ID: <Pine.LNX.4.64.0806301348220.4085@aragorn.flymine.org> (raw)
In-Reply-To: <9EE32DF9-562C-45EF-829D-A877CBEC3C37@houseofdesign.de>
References: <287E4428-BECC-46D6-BC47-EA94EA0121F0@houseofdesign.de>
	<20080628191931.GB13013@uio.no>
	<EBA8A1BD-AF92-4203-93E4-2A7D7ADEA94B@houseofdesign.de>
	<DE73CABE-52BF-4130-8C34-1D10835E98CC@houseofdesign.de>
	<Pine.LNX.4.64.0806301114130.4085@aragorn.flymine.org>
	<9EE32DF9-562C-45EF-829D-A877CBEC3C37@houseofdesign.de>

On Mon, 30 Jun 2008, Moritz Onken wrote:
>> SELECT COUNT(*) FROM (SELECT DISTINCT result.url FROM result, item WHERE
>>  item.shorturl = result.url) AS a
>
> I tried the this approach but it's slower than WHERE IN in my case.

However there's a lot more scope for improving a query along these lines, 
like adding indexes, or CLUSTERing on an index. It depends what other 
queries you are wanting to run.

I don't know how much update/insert activity there will be on your 
database. However, if you were to add an index on the URL on both tables, 
then CLUSTER both tables on those indexes, and ANALYSE, then this query 
should run as a merge join, and be pretty quick.

However, this is always going to be a long-running query, because it 
accesses at least one whole table scan of a large table.

Matthew

-- 
"Finger to spiritual emptiness underlying everything."
        -- How a foreign C manual referred to a "pointer to void."



view thread (12+ messages)  latest in thread

Message-ID: <Pine.LNX.4.64.0806301348220.4085@aragorn.flymine.org>
Permalink:  ../Pine.LNX.4.64.0806301348220.4085@aragorn.flymine.org/
Also on:    postgresql.org/message-id/Pine.LNX.4.64.0806301348220.4085@aragorn.flymine.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 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: matthew@flymine.org
  Subject: Re: Planner should use index on a LIKE 'foo%' query
  In-Reply-To: <Pine.LNX.4.64.0806301348220.4085@aragorn.flymine.org>
  References: <287E4428-BECC-46D6-BC47-EA94EA0121F0@houseofdesign.de> <20080628191931.GB13013@uio.no> <EBA8A1BD-AF92-4203-93E4-2A7D7ADEA94B@houseofdesign.de> <DE73CABE-52BF-4130-8C34-1D10835E98CC@houseofdesign.de> <Pine.LNX.4.64.0806301114130.4085@aragorn.flymine.org> <9EE32DF9-562C-45EF-829D-A877CBEC3C37@houseofdesign.de> <Pine.LNX.4.64.0806301348220.4085@aragorn.flymine.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