Re: Re: SQL Where Like - Range it?!

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ashley Clark <aclark(at)ghoti(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: SQL Where Like - Range it?!
Date: 2001-04-30 05:11:21
Message-ID: 10630.988607481@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ashley Clark <aclark(at)ghoti(dot)org> writes:
> db=3D# explain SELECT name from builders where name ~ '^A' or name ~ '^B';
> NOTICE: QUERY PLAN:

> Index Scan using builders_name_key, builders_name_key on builders
> (cost=3D0.00..10.25 rows=3D16 width=3D12)

> db=3D# explain SELECT name from builders where name ~ '^[AB]';
> NOTICE: QUERY PLAN:

> Seq Scan on builders (cost=3D0.00..9.44 rows=3D355 width=3D12)

> These are the same query, why would the one using index scan have a
> higher cost that the combined condition query?

Always remember that the cost estimates quoted by EXPLAIN are estimates,
not reality.

In this case the reason for the difference is that the planner doesn't
have any detailed understanding of the semantics of bracket-expressions
in regexps, so it doesn't realize that ^[AB] could usefully use an
index. It wants to see ^ followed by at least one character of fixed
pattern before it will think about an indexscan ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Lawrence 2001-04-30 05:15:48 Rebuilding database from table files
Previous Message Bruce Momjian 2001-04-30 03:48:52 Re: Why do things slow down without a VACUUM?