Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 93427650DBC for ; Mon, 30 Jun 2008 07:19:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 60948-06 for ; Mon, 30 Jun 2008 07:19:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ppsw-7.csi.cam.ac.uk (ppsw-7.csi.cam.ac.uk [131.111.8.137]) by postgresql.org (Postfix) with ESMTP id 7E7D2650CF5 for ; Mon, 30 Jun 2008 07:19:52 -0300 (ADT) X-Cam-SpamDetails: Not scanned X-Cam-AntiVirus: No virus found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from flymine.sysbiol.cam.ac.uk ([131.111.60.120]:59343 helo=flymine.flymine.org) by ppsw-7.csi.cam.ac.uk (ppsw.cam.ac.uk [131.111.8.137]:25) with esmtp id 1KDGU7-0001H8-Pm (Exim 4.67) for pgsql-performance@postgresql.org (return-path ); Mon, 30 Jun 2008 11:19:48 +0100 Received: from host103 ([192.168.128.103] helo=aragorn.flymine.org ident=Debian-exim) by flymine.flymine.org with esmtp (Exim 4.12) id 1KDGU7-0000By-00 for pgsql-performance@postgresql.org; Mon, 30 Jun 2008 11:19:47 +0100 Received: from mnw21 (helo=localhost) by aragorn.flymine.org with local-esmtp (Exim 4.69) (envelope-from ) id 1KDGU7-0007D2-R8 for pgsql-performance@postgresql.org; Mon, 30 Jun 2008 11:19:47 +0100 Date: Mon, 30 Jun 2008 11:19:47 +0100 (BST) From: Matthew Wakeling X-X-Sender: mnw21@aragorn.flymine.org To: pgsql-performance@postgresql.org Subject: Re: Planner should use index on a LIKE 'foo%' query In-Reply-To: Message-ID: References: <287E4428-BECC-46D6-BC47-EA94EA0121F0@houseofdesign.de> <20080628191931.GB13013@uio.no> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/227 X-Sequence-Number: 30577 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.