Re: Very slow query

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "Chad Thompson" <chad(at)weblinkservices(dot)com>, "pgsql-novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Very slow query
Date: 2002-07-30 21:03:11
Message-ID: 200207301403.11943.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Chad,

> Its the substring function that slows things down so much. Is there a
better way to compare these string values?
> substr(cr.phonenum, 1,6) is the same speed. (and according to the docs,
basicly the same function)

Yeah. You can index it:

CREATE FUNCTION phonenum_substr (
VARCHAR ) RETURNS VARCHAR AS '
SELECT substr(cr.phonenum, 1, 6);
' LANGUAGE 'sql' WITH (ISCACHABLE, ISSTRICT);
-- this lets you index on the substring, as the straight substr function is
not indexable as of Postgres 7.2.1

Then:
CREATE INDEX idx_cr_phonenum_substr ON phonenum_substr(cr.phonenum);

This should speed things up.

--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Ron Johnson 2002-07-30 21:30:15 Re: Very slow query
Previous Message Chad Thompson 2002-07-30 20:20:00 Very slow query