Forum OpenACS Q&A: Response to Weird PostgreSQL SELECT processing

Collapse
Posted by Jonathan Ellis on
I guess warp_user_access is the function you're talking about?

the "where placement_id = 177" is in your subquery. it doesn't look like you need a subquery here; just do something like

select p.placement_id, count(pl.*) as whatever
from placements p, placement_log pl
where p.placement_id = pl.placement_id
  and p.placement_id = 177
  and warp_user_access(...)
group by p.placement_id
Still, PG could evaluate the warp_user_access before the placement_id = 177 if the planner thinks it can throw away more rows that way.

(I'm assuming there's more to this query than what you're showing because otherwise you don't need to join to the placements table at all to get your count...)