Oh, the other thing you could try experimenting with are these two parameters.
Your query has *way* more tables than the default values for these so you
would have to raise them substantially. Given that the query was running in
30s you may find that this increases the planning time by more time than it
saves in the query -- the reason these limits exist at all..
geqo_threshold
join_collapse_limit
from_collapse_limit
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's On-Demand Production Tuning