Re: [SQL] qurey plan and indices

From: Patrick Giagnocavo <a222(at)redrose(dot)net>
To:
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] qurey plan and indices
Date: 1999-08-05 14:18:55
Message-ID: 37A99D4F.610E6F7C@redrose.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

MESZAROS Attila wrote:
>
> Hi,
>
> I've experienced a brutal speedup (order of 2) separateing the following
> subquery and making it manually:
>
> explain select name,description
> from descriptions
> where in (select name
> from descriptions
> where description like '%Bankverbindung%');
>
> Seq Scan on descriptions (cost=163.98 rows=3575 width=24)
> SubPlan
> -> Seq Scan on descriptions (cost=163.98 rows=2 width=12)
> [I had no patient to wait the resuls...]
>

Correct me if I am wrong, however if using

LIKE '%something%'
(which means, the field contains 'something' somewhere in the field)

there is never a chance to use the index you have created - a
sequential table scan MUST be made, thus you have to read all 3575
rows to return the set.

However, if you change your query so that you are looking for

LIKE 'Bankverbindung%'

then an index can be used becase you know what the first few
characters are known.

Hope this helps,

Cordially

Patrick Giagnocavo
a222(at)redrose(dot)net

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-08-05 14:26:16 Re: [SQL] primary key view failure
Previous Message rob caSSon 1999-08-05 13:52:23 primary key view failure