Re: [7.0.3] optimizing a LIKE query ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: The Hermit Hacker <scrappy(at)hub(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [7.0.3] optimizing a LIKE query ...
Date: 2001-04-04 23:06:03
Message-ID: 12999.986425563@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

The Hermit Hacker <scrappy(at)hub(dot)org> writes:
> I'm figuring that if I can somehow get the query (using subselects,
> maybe?), to have the LIKE part of the query work only on the 6k records
> returned by the "=" part of it, the overall results should be faster ...

In 7.0.* I think the only way to do that is to select into a temp table
and then apply the LIKE while selecting from the temp table.

In 7.1 you could possibly force the order by using a subselect (although
offhand I think the planner might be smart enough to see through that,
and do what it thinks is right anyway). The real problem is the planner
thinks that LIKE '%http://www.postgresql.org/%%' is really selective; it
has no idea that most of your table mentions pgsql.org URLs :-(. We
need better statistics to fix this properly. (On my list for 7.2.)

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-04-04 23:07:23 Re: Need to do an ALTER TABLE.
Previous Message Tom Lane 2001-04-04 22:47:01 Re: [SQL] performance inconsistency