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 11:19:47 +0100 (BST)
Message-ID: <Pine.LNX.4.64.0806301114130.4085@aragorn.flymine.org> (raw)
In-Reply-To: <DE73CABE-52BF-4130-8C34-1D10835E98CC@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>
On Mon, 30 Jun 2008, Moritz Onken wrote:
> I created a new column in "item" where I store the shortened url which makes
> "=" comparisons possible.
Good idea. Now create an index on that column.
> select count(1) from result where url in (select shorturl from item where
> shorturl = result.url);
What on earth is wrong with writing it like this?
SELECT COUNT(*) FROM (SELECT DISTINCT result.url FROM result, item WHERE
item.shorturl = result.url) AS a
That should do a fairly sensible join plan. There's no point in using
fancy IN or EXISTS syntax when a normal join will do.
Matthew
--
I have an inferiority complex. But it's not a very good one.
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.0806301114130.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>
* 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