I have two statements that accomplish the same task and I'm trying to decide
which to use. One uses a sub-select, and the other just does a few more joins.
I expect that giving the SELECT statement's themseleves won't get me much help, so here is the output of the EXPLAIN
querythat I ran on both of them. I read
the FAQ on EXPLAIN a bit but I'm still confused.
So could somebody help me understand why it appears as though the first query
will run much faster (?) than the second?
--snip!--
Nested Loop (cost=81.80..114.17 rows=33 width=68) InitPlan -> Seq Scan on l_portal_statuses (cost=0.00..22.50
rows=10width=4) -> Merge Join (cost=81.80..86.63 rows=3 width=52) -> Merge Join (cost=59.13..63.43 rows=33
width=44) -> Sort (cost=22.67..22.67 rows=10 width=28) -> Seq Scan on contacts m
(cost=0.00..22.50rows=10 width=28) -> Sort (cost=36.47..36.47 rows=333 width=16) -> Seq Scan on
buildingsb (cost=0.00..22.50 rows=333 width=16) -> Sort (cost=22.67..22.67 rows=10 width=8) -> Seq Scan
oncontracts c (cost=0.00..22.50 rows=10 width=8) -> Index Scan using executives_pkey on executives e
(cost=0.00..8.14rows=10 width=16)
--------------------------------------------------------------------------------
Merge Join (cost=174.38..247.30 rows=333 width=76) -> Index Scan using executives_pkey on executives e
(cost=0.00..60.00rows=1000 width=16) -> Sort (cost=174.38..174.38 rows=33 width=60) -> Merge Join
(cost=167.58..173.53rows=33 width=60) -> Merge Join (cost=59.13..63.43 rows=33 width=44) -> Sort
(cost=22.67..22.67 rows=10 width=28) -> Seq Scan on contacts m (cost=0.00..22.50 rows=10 width=28)
-> Sort (cost=36.47..36.47 rows=333 width=16) -> Seq Scan on buildings b (cost=0.00..22.50
rows=333width=16) -> Sort (cost=108.44..108.44 rows=100 width=16) -> Merge Join
(cost=92.50..105.12rows=100 width=16) -> Sort (cost=69.83..69.83 rows=1000 width=12)
-> Seq Scan on contracts c (cost=0.00..20.00 rows=1000 width=12) -> Sort (cost=22.67..22.67
rows=10width=4) -> Seq Scan on l_portal_statuses l (cost=0.00..22.50 rows=10 width=4)
--snip!--
Hopefully that's not too ugly.
TIA
-- Dave