Thread: performance of like queries

performance of like queries

From
Kevin Kempter
Date:
Hi List;

any suggestions for improving "LIKE '%text%'" queries?


Thanks in advance

Re: performance of like queries

From
"Joshua D. Drake"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kevin Kempter wrote:
> Hi List;
>
> any suggestions for improving "LIKE '%text%'" queries?

faster disks :)

take a look at pg_tgrm and tsearch2.

Sincerely,

Joshua D. Drake


>
>
> Thanks in advance
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>


- --

      === The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564   24x7/Emergency: +1.800.492.2240
PostgreSQL solutions since 1997  http://www.commandprompt.com/
            UNIQUE NOT NULL
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHArLMATb/zqfZUUQRAiaSAJ4lbVKrKEgr9OnO6jDguALtnonm7QCggtsx
W7dsy40KbvizyYBQYpvsIvw=
=2J2G
-----END PGP SIGNATURE-----

Re: performance of like queries

From
"Marcin Stępnicki"
Date:
On 10/2/07, Kevin Kempter <kevin@kevinkempterllc.com> wrote:
> Hi List;
>
> any suggestions for improving "LIKE '%text%'" queries?

http://www.depesz.com/index.php/2007/09/15/speeding-up-like-xxx/

Re: performance of like queries

From
Chris Browne
Date:
kevin@kevinkempterllc.com (Kevin Kempter) writes:
> any suggestions for improving "LIKE '%text%'" queries?

If you know that the 'text' portion of that query won't change, then
you might create a partial index on the boolean condition.

That is,

  create index index_foo_text on my_table (tfield) where (tfield like '%text%');

I somehow doubt that is the case; more likely you want to be able to
search for:
   select * from my_table where tfield like '%this%';
   select * from my_table where tfield like '%that%';
   select * from my_table where tfield like '%the other thing%';

There are basically three choices, at that point:

1.  Get more memory, and hope that you can have all the data get
cached in memory.

2.  Get more better disk, so that you can scan the table faster on
disk.

3.  Look into tsearch2, which provides a full text search capability.
--
(format nil "~S@~S" "cbbrowne" "linuxdatabases.info")
http://cbbrowne.com/info/x.html
"We're  born with a  number  of  powerful instincts,  which are  found
across all cultures.   Chief amongst these are  a dislike of snakes, a
fear of falling, and a hatred of popup windows" -- Vlatko Juric-Kokic