From: Richard Huxton <dev@archonet.com>
To: pgsql-sql@postgresql.org
Subject: Re: Query optimisation
Date: Mon, 11 Dec 2000 18:16:50 -0000
Message-ID: <008401c0639e$89780260$1001a8c0@archonet.com> (raw)
References: <l03130308b65aa0d64c4a@[195.200.188.2]>
From: "Michel Vrand" <mvrand@pacwan.fr>
> $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
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-sql@postgresql.org
Cc: dev@archonet.com
Subject: Re: Query optimisation
In-Reply-To: <008401c0639e$89780260$1001a8c0@archonet.com>
References: <l03130308b65aa0d64c4a@[195.200.188.2]> <008401c0639e$89780260$1001a8c0@archonet.com>
* 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