MySQL, Sub-selects and IN()
johnewart.net
johnewart.net
IN (SELECT species_id FROM enemy_species WHERE enemy_id = 123)
is executed against every row in the table instead of just once, taking a REALLY long time.I think every everyone goes through that particular mysql learning curve - use a join instead.
Same thing they were saying back in the '90s for foreign keys, transactions, stored procedures...
I have to do the same when I teach new developers and friends about the replication problems with PG.
When you say "replication problems" then you probably mean silent slave corruption?
I'm sorry but this is still a MySQL-only feature. The PostgreSQL-replication can't go out of sync, and worse, it can't even silently fail.
In this regard (and some others) PostgreSQL sadly lacks all the fun and excitement that can be had with MySQL.
This is a major difference to MySQL replication, where silent divergence between Master/Slave is a common problem. You don't notice it until you run into spurious SQL errors or perform a manual table-checksum. In a worst case you don't notice it until that day when your master fails...
It's doing exactly what you told it to do.
The bug is a human bug of not understanding what you are asking even though it seems logical.
(I do know the answer - it's because they can do hash joins and MySQL can't).
Also it's been fixed in 6.0-alpha just not back-ported, so I'm not sure I agree here.
back around 2001, I was reading Celko's "SQL for Smarties"... MySQL didn't have subselects then so I rewrote more than half of the subselect queries with joins... The funny thing is that I'd run my converted queries in Oracle and find they'd run faster in Oracle if i did them that way.
Afaik a lot of .Net shops I know are fairly happy with it, to say the least.
My personal opinion: There are far less mentally and emotionally demanding things that do as good a job for zero outlay and don't suddenly steal your wallet whenever you try and scale them up.
Having said that, I've used it since SQL 6.5 and it supports small to medium workloads fine. It's also significantly less ugly and needy than Oracle.
I'd pick PostgreSQL if I was going solo on a project though.
Thanks for the rest of your feedback though :)
And licenses for MySQL Enterprise aren't that cheap either.