Re: Query optimisation

From: "Richard Huxton" <dev(at)archonet(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Query optimisation
Date: 2000-12-11 18:16:50
Message-ID: 008401c0639e$89780260$1001a8c0@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

From: "Michel Vrand" <mvrand(at)pacwan(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joseph Shraibman 2000-12-12 01:45:58 Re: FOREIGN KEY errors.
Previous Message clayton cottingham 2000-12-11 18:06:48 Re: Where Can I find JDBC driver.