Re: query speed joining tables - Mailing list pgsql-sql

From Josh Berkus
Subject Re: query speed joining tables
Date
Msg-id 200301131347.49013.josh@agliodbs.com
Whole thread Raw
In response to query speed joining tables  (Christopher Smith <christopherl_smith@yahoo.com>)
Responses Re: query speed joining tables  (Christopher Smith <christopherl_smith@yahoo.com>)
List pgsql-sql
Chris,

Here are probably your two main query problems:

> strpos(user_match_details.ethnicity,'Asian') !=0 AND

It is impossible for Postgres to use an index for the above as it is written.
I would suggest one of two improvements;
1) Modify the schema so that multiple ethnicity details are kept in a
sub-table rather than a free-form text field you have to search, or:
2) Create a cachable function for "contains_asian" and index on that.

> user_details_p.zipcode in (select zips_max.destination from zips_max where
zips_max.origin='90210' )
> order by user_login.last_login desc;

Use a "WHERE EXISTS" clause instead of "IN".

--
-Josh BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: Christopher Smith
Date:
Subject: query speed joining tables
Next
From: Christopher Smith
Date:
Subject: Re: query speed joining tables