Forum OpenACS Q&A: Response to Outer Join

Collapse
5: Response to Outer Join (response to 1)
Posted by Don Baccus on
Postgres doesn't execute queries on index values alone, ala Oracle and many other more mature RDBMS systems.  So the count() really does chug through all the qualified rows (deciding which rows to chug through can make use of an index).

"not exists" will examine the same rows, but will stop the moment a row is found that matches the criteria.  count(*) will examine each row.

And the subselect is done many, many times for a typical UNION'd outer  join if the table's got a lot of rows in it.

The "not exists" form will always be slightly faster (as there's overhead with aggregate functions which need to be set up once, then called for each row) and sometimes much faster, depending on the actual data in the table.

I'm at a serious disadvantage here - I actually know how Postgres works.