query planner: automatic rescribe of LIKE to BETWEEN ?

From: Ulrich Habel <espero7757(at)gmx(dot)net>
To: pgsql-performance(at)postgresql(dot)org
Subject: query planner: automatic rescribe of LIKE to BETWEEN ?
Date: 2006-08-22 17:22:59
Message-ID: 200608221922.59734.espero7757@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello all,
had an idea of optimizing a query that may work generally.

In case a 'column' is indexed, following two alterations could be done
I think:

A)

select ... where column ~ '^Foo' --> Seq Scan

into that:

select ... where column BETWEEN 'Foo' AND 'FooZ' --> Index Scan

of course 'Z' should be the last possible character internally used of the
DBMS.

That would work as long as there is no in-case-sensitive search being done.

another rescribtion:

B)

select ... where column ~ '^Foo$' --> Seq Scan

into that:

select ... where column = 'Foo' --> Bitmap Heap Scan

That speeds up things, too.

That would also apply to 'LIKE' and 'SIMILAR TO' operations, I think.

Is there any idea to make the "Query Planner" more intelligent to do these
convertions automatically?

Anythings speeks against this hack?

Regards
Uli Habel

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Alvaro Herrera 2006-08-22 17:45:39 Re: query planner: automatic rescribe of LIKE to BETWEEN ?
Previous Message Joshua D. Drake 2006-08-22 16:15:44 Re: How to get higher tps