Received: from www-uk-05.digiserve.com ([195.172.23.63]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eBBIWxm46980 for ; Mon, 11 Dec 2000 13:32:59 -0500 (EST) (envelope-from dev@archonet.com) Received: from mainbox.archonet.com (mwynhau.demon.co.uk [193.237.186.96]) by www-uk-05.digiserve.com (8.9.1/8.9.1) with ESMTP id SAA16600 for ; Mon, 11 Dec 2000 18:34:35 GMT Received: from client (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with SMTP id 578CC2A2E4 for ; Mon, 11 Dec 2000 18:16:54 +0000 (GMT) Message-ID: <008401c0639e$89780260$1001a8c0@archonet.com> From: "Richard Huxton" To: References: Subject: Re: Query optimisation Date: Mon, 11 Dec 2000 18:16:50 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200012/69 X-Sequence-Number: 400 From: "Michel Vrand" > $conditions may be > > 1/ ...AND groupes.nom = '$something' AND.... > or > 2/ ...AND groupes.nom ~* '$something' AND.... > > In the first case, the query is reasonnably fast (0.30 s for 4 items on > 15000) > In the second case, the query becomes very slow (more than 31 s for the same > result) > > to give example, in the first case $something = "Beatles" > in the second case $something = "beatl" > > How to optimise speed ? I tried to type EXPLAIN but I do not understand the > result : > You are right - the index *does* make that much difference. The problem is that ~* matches *anywhere* in the string so it can't use the index - it has to read each entry. If you want to match the start of the entry, I know of one way to make the index work. Use groupes.nom>='beatl' AND groupes.nom<='beatlz' And that should work - although 'z' is a poor character to use - pick the highest valid character in your character set. You might also want to look in the archives for the thread on pgsql-general with a subject of 'Simple Question: Case sensitivity' - Richard Huxton