Forum OpenACS Q&A: Response to some advice on a search...

Collapse
Posted by Gilbert Wong on

First, you don't need a offers_location_id in the offers_location_map since each job_id and location_id combination is unique. You can define that table as:

create table offers_locations_map (
location_id integer references job_locations(location_id),
job_id integer references job_offers(job_id),
primary key (location_id,job_id)
);

Another thing you might want to do is to count the job locations in the TCL code instead of running triggers in the DB.

Regarding the search, I think Alex has the right idea. Because you are doing a join, if you do a condition like:

select
...
where jo.job_id = olm.job_id
and olm.location_id = jl.location_id
and jl.postal_code > :bind_variable
and lower(jo.title)=lower('%title%')

I would think that the database would be smart enough only search the jo table once for that condition and throw out those rows that don't match.