From: | Jacob Coby <jcoby(at)listingbook(dot)com> |
---|---|
To: | badlydrawnbhoy <badlydrawnbhoy(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to optimize query that concatenates strings? |
Date: | 2006-07-07 15:41:44 |
Message-ID: | 44AE80B8.6010604@listingbook.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
badlydrawnbhoy wrote:
> Hi all,
>
> I've got a database of URLs, and when inserting new data into it I want
> to make sure that there are no functionally equivalent URLs already
> present. For example, 'umist.ac.uk' is functionally the same as
> 'umist.ac.uk/'.
>
> I find that searching for the latter form, using string concatentation
> to append the trailing slash, is much slower than searching for a
> simple string - the index on URL name isn't used to speed up the
> search.
>
> Here's an illustration
>
> url=# explain select exists(select * from url where url = 'umist.ac.uk'
> or url || '/' = 'umist.ac.uk') as present;
Well, in that example, you should just remove the OR conditional - it
just evaluates to false anyways.
>
> Is there any way I can force postgres to use the index when using the
> string concatenation in the query?
If you are always going to strcat with a '/', you could probably create
a functional index or add a new column for a normalized url (which is
what I'd lean towards).
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-07-07 15:54:26 | Re: Addressing: ERROR: could not access status of transaction |
Previous Message | Sven Willenberger | 2006-07-07 15:19:18 | VACUUM FULL versus CLUSTER ON |