Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id ABCEC9FB447 for ; Sat, 7 Apr 2007 14:27:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 96852-04 for ; Sat, 7 Apr 2007 14:27:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from olive.qinip.net (olive.qinip.net [62.100.30.40]) by postgresql.org (Postfix) with ESMTP id 5D0D89FB43A for ; Sat, 7 Apr 2007 14:27:55 -0300 (ADT) Received: from [10.0.0.21] (h8441139206.dsl.speedlinq.nl [84.41.139.206]) by olive.qinip.net (Postfix) with ESMTP id EFB721811F; Sat, 7 Apr 2007 19:27:50 +0200 (MEST) Message-ID: <4617D4D4.2080509@tweakers.net> Date: Sat, 07 Apr 2007 19:28:52 +0200 From: Arjen van der Meijden User-Agent: Thunderbird 2.0b2 (Windows/20070116) MIME-Version: 1.0 To: Tilo Buschmann CC: Tom Lane , PostgreSQL Performance Subject: Re: fast DISTINCT or EXIST References: <20070407124713.1d4efe63@wonderland> <46178F65.5090807@tweakers.net> <9293.1175961248@sss.pgh.pa.us> <20070407182407.297e7e35@wonderland> In-Reply-To: <20070407182407.297e7e35@wonderland> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/195 X-Sequence-Number: 24072 On 7-4-2007 18:24 Tilo Buschmann wrote: > Unfortunately, the query above will definitely not work correctly, if > someone searches for "a" or "the". That are two words you may want to consider not searching on at all. As Tom said, its not very likely to be fixed in PostgreSQL. But you can always consider using application logic (or a pgpsql function, you could even use a set returning function to replace the double-limit subselects in your in-statement) which will automatically fetch more records when the initial guess turns out to be wrong, obviously using something like a NOT IN to remove the initially returned cd.id's for the next batches. Then again, even 'a' or 'the' will not likely be in *all* tracks of a cd, so you can also use the 'average amount of tracks per cd' (about 10 or 11?) as your multiplier rather than my initial 3. Obviously you'll loose performance with each increment of that value. Best regards, Arjen