News for hackers. Stuff that matters.
Re:A Hairy PostgreSQL Incident by smackeyacky on Friday February 11, 2022 @01:30AM (#30297786)
I always use the rule of thumb that if you need optimizer hints for your query, its time to fix the query or the indexes. Of course in the teeth of an outage that generally isn't an option.

The tools on SQL server for query optimization are better then postgres, but that doesn't always mean problems like the OP don't still occur. I have had more than one SQL server query plan go to hell over time as the tables grew and the optimizer started to make odd decisions.

Edit: to make this a little clearer, I regard the SQL server query optimizer system as "lawful evil". It follows its own rules relentlessly.

Re:A Hairy PostgreSQL Incident by tanelpoder on Friday February 11, 2022 @02:20AM (#30298113)
Yep, when the app code and the schema/partitioning/index design works _with_ the database as intended, not _against_ the database engine’s intended use, a whole class of SQL performance and plan stability problems tends to go away.

Yep, agreed, hints should be temporary workarounds (or just experimentation aid when developing/testing SQL performance to validate some hypothesis). But many of these temporary workarounds end up being permanent temporary workarounds :-) That’s why Oracle now has hints and parameters to make the optimizer ignore all other hints in the SQL code :-)

Re:A Hairy PostgreSQL Incident by smackeyacky on Friday February 11, 2022 @05:18AM (#30299599)
Working out which hints are operating must be difficult.
Re:A Hairy PostgreSQL Incident by j16sdiz on Friday February 11, 2022 @06:23AM (#30300103)
For a cost-based-optimizer to work, the cost tuneables must be good. These are very difficult to get right in practice.
Re:A Hairy PostgreSQL Incident by dap on Friday February 11, 2022 @09:25AM (#30301813)
How would you fix the query or indexes here? The CTE seems clearly a hack, effectively functioning as a hint. It doesn’t seem like it counts as fixing the query.

I’m skeptical of this rule of thumb. I’m sure people misuse hints. But if someone thinks they “need” hints, my guess is they’ve tried changing the query and indexes.