Unofficial Hacker News client - receive Push Notifications on replies.
To get push notifications on iPhone or iPad, add Hack and Chat to your Home Screen: tap
Share → Add to Home Screen, then open the installed app and enable push in Settings.
With a perfect optimizer and perfect knowledge of ordinality and statistics, I think performance would be the same. However in practice, I do not believe it always reorders predicates reliably for optimal performance.
My experience is that order does matter in MySQL and especially in DWH environments where the optimizer may not be aware of things like partitioning.
The hypergraph optimizer orders expensive predicates last (where “expensive” is stuff like subqueries). The old (default) optimizer only does reordering more-or-less by accident, AFAIK.
This is true, but the optimizer considers them so. They're more expensive than e.g. adding two ints.
Of course, if they're rewritten to a semijoin or similar, they won't be subqueries anymore or indeed not conditions at all, so sorting them is not applicable.
Now I'm really confused. Your orignal comment reads like reordering changes semantics, so the two id= checks cannot be fused since reordering would be required for that. But now it sounds like reordering keeps semantics and is "just" left on the table by a simple optimizer, which isn't really relevant because the original comment is about a hypothetical optimization anyway...
It is only about optimization yes. But the way it works today, but it is not guaranteed that collapsing the ORs to INs is optimal when it reorders _other_ predicates.
It certainly could, and MySQL has a number of such rewrites, just not that specific one AFAIK. (You'd need to worry about things like picking out the IN part from a series of tests within the OR trees if there are other conditions in there, but it's certainly possible.)
I'm not going to trust any performance and tuning analysis that repeatedly quotes and graphs the runtime as seconds when it's measured in milliseconds.
Damn. After working 1.5 years with MySQL, I wonder if there is anything good with that database server.
My favorite thing to hate though is still locking and non-locking reads in REPEATABLE READ. Even if it’s documented, it still doesn’t make it right.
> It is not recommended to mix locking statements (UPDATE, INSERT, DELETE, or SELECT ... FOR ...) with non-locking SELECT statements in a single REPEATABLE READ transaction, because typically in such cases you want SERIALIZABLE. This is because a non-locking SELECT statement presents the state of the database from a read view which consists of transactions committed before the read view was created, and before the current transaction's own writes, while the locking statements use the most recent state of the database to use locking. In general, these two different table states are inconsistent with each other and difficult to parse.
The query planner is relatively straightforward and performance optimisations are commonly not derived from as complex reasoning as required when using Postgres or SQL Server.
The Galera-clustering the company behind TFA provides is pretty simple to set up as well, at least if you're good with Linux and systemd.
WHERE id = 1 OR id = 2... Should be abled to be reduced to WHERE id IN (1,2...)
However WHERE id = 1 OR name = 'John' OR id = 2 Maybe can't be reduced to WHERE id IN (1,2) OR name = 'John'
Replies (2)
Replies (2)
My experience is that order does matter in MySQL and especially in DWH environments where the optimizer may not be aware of things like partitioning.
Replies (2)
Replies (1)
Subqueries aren't always going to be more expensive
Replies (1)
Of course, if they're rewritten to a semijoin or similar, they won't be subqueries anymore or indeed not conditions at all, so sorting them is not applicable.
Replies (1)
Replies (1)
My favorite thing to hate though is still locking and non-locking reads in REPEATABLE READ. Even if it’s documented, it still doesn’t make it right.
> It is not recommended to mix locking statements (UPDATE, INSERT, DELETE, or SELECT ... FOR ...) with non-locking SELECT statements in a single REPEATABLE READ transaction, because typically in such cases you want SERIALIZABLE. This is because a non-locking SELECT statement presents the state of the database from a read view which consists of transactions committed before the read view was created, and before the current transaction's own writes, while the locking statements use the most recent state of the database to use locking. In general, these two different table states are inconsistent with each other and difficult to parse.
Replies (1)
The Galera-clustering the company behind TFA provides is pretty simple to set up as well, at least if you're good with Linux and systemd.