Working around optimizer bugs
Only if you can't get the statistics or cost data to work as expected should you then take drastic measures like disabling optimizer features. But knowing that flags such as enable_hashjoin
and enable_seqscan
exist can be valuable for another reason altogether. Sometimes, bad optimizer behavior can result from a database bug or limitation. If you know or suspect that, toggling optimizer features off can help you determine which code path might be involved in your issue. Also, there's nothing wrong with temporarily working around a bad plan by putting one of these optimizer hacks into place as a triage measure, to buy yourself time to figure out what's really wrong. Resist doing that in the server configuration through—these sort of changes belong in the code that executes the individual problem queries, not server wide.