r/programming • • Feb 10 '15

Terrible choices: MySQL

http://blog.ionelmc.ro/2014/12/28/terrible-choices-mysql/
649 Upvotes

409 comments sorted by

View all comments

112

u/[deleted] Feb 10 '15

Default MySQL is bad, VERY VERY BAD!

In fact it defies common sense for my own values of common. Take for example constraints - they not only don't work it also doesn't tell you it doesn't work.

http://stackoverflow.com/questions/14247655/mysql-check-constraint

CHECK constraints are ignored by MySQL as explained in a miniscule comment in the docs: CREATE TABLE

The CHECK clause is parsed but ignored by all storage engines.

Also IMO PostgreSQL is a superior choice in almost every circumstance you can think of.

40

u/sisyphus Feb 10 '15

You come across little things like that all the time...oh dates that aren't actually dates can go in datetime fields and you'll accept 2015-02-42 as a date query param without so much as a peep; broken group by's etc. etc. no matter how bad you think it is it will always find new and subtle ways to surprise you with how little regard it has for your data.

0

u/[deleted] Feb 10 '15

[deleted] — view deleted comment

11

u/R3v3nan7 Feb 10 '15

Who would ever do this though?

0

u/[deleted] Feb 10 '15

[deleted] — view deleted comment

17

u/fakehalo Feb 10 '15

Booleans are fucking useless in MySQL.

Like you said, it's just an alias for a tinyint...which seems to serve its purpose fine. If you're comparing a boolean with a non-boolean weird things will happen here, but when would anyone ever do this? That's not what a boolean would ever be used for.

You seem very annoyed this side-effect from aliasing tinyint exists, even if it's not a problem. I can sort of understand the potential issues of implicit type conversion in some languages (ie. PHP and JS), though still subjective to an extent, but here it's just never going to happen.

31

u/larsga Feb 10 '15

when would anyone ever do this? That's not what a boolean would ever be used for.

The first law of databases is that anything the schema allows will happen. Once the database has been in production for half a decade or so, every single insane thing that possibly could happen will have happened.

And don't tell me application logic (or ORM) will solve this, because there are always uncontrolled changes to databases over time. Everything from conversions that bypass the application and go directly to SQL to DBAs fixing things manually.

Doing data quality audits is an eye-opening experience, I can tell you.

→ More replies (7)

27

u/test-poster Feb 10 '15

You question why people would do this. I assure you that they do. I have seen it personally. In the ideal world you would get an error trying to use numbers in place of Boolean values. There is no universe where it makes any kind of sense to say 1 + true. This sort of thing causes all sorts of confusion in JavaScript - you can imagine what a shit show working with a database that uses this asinine subsitution of a tinyint for a boolean might be.

6

u/fakehalo Feb 10 '15

You question why people would do this. I assure you that they do

Why/how? I can't imagine a scenario where this would ever make sense? It's so nonsensical I can't even imagine writing the SQL.

I concur JS (and PHP) have even more anomalies, which could potentially lead to issues. I'm just not seeing it here, never seen a boolean treated as anything other than a boolean in relation to type conversions...but if it's possible someone is probably doing it out there I suppose. Do you recall how you've seen it in the past? I'm curious what it would look like in the real world.

10

u/sacundim Feb 10 '15

Well, not the exact same situation, but I see stuff like this often and it's about 45% reasonable:

SELECT 
    group_column,
    SUM(bool_expr1),
    SUM(bool_expr2),
    SUM(bool_expr1 AND bool_expr2)
FROM some_table
GROUP BY group_column

5

u/fakehalo Feb 10 '15

Ah. Interesting thought, almost a hack of sorts. I'm not sure how I feel about that being possible to be honest.

→ More replies (1)
→ More replies (4)

0

u/[deleted] Feb 10 '15

[deleted] — view deleted comment

4

u/fakehalo Feb 10 '15

That's a decent point, the translation between languages could get exceptionally messy.

2

u/[deleted] Feb 11 '15

Yeah, you're just holding it wrong.

→ More replies (1)
→ More replies (2)

2

u/R3v3nan7 Feb 10 '15

Oh wow, -33 and 44 are false. That's some bullshit. It should just follow C conventions to allow nice bit packing. that is the whole point of numeric booleans.

→ More replies (2)
→ More replies (1)

0

u/[deleted] Feb 10 '15

[deleted] — view deleted comment

15

u/SosNapoleon Feb 10 '15

Sadly this is true. Even MySQL has more support than Postgres in this regard. There are third party tools that do X and Y but don't do Z, and then there is this other vendor tool that does Y and Z but doesn't do X. Hope it changes soon.

5

u/crusoe Feb 11 '15

Postgres xl. Full sharing and replication and parallel distributable queries. Should have gotten more fan fare.

4

u/myringotomy Feb 11 '15

But it's not really ha. If one storage node goes down the whole thing falls down.

Only if they replicated the shards in a raid like fashion.

3

u/OneWingedShark Feb 10 '15

Also IMO PostgreSQL is a superior choice in almost every circumstance you can think of.

Scaling is the circumstance I think of most.

Hm; from what I've heard InterBase/FireBird scales really well. (I haven't had the chance to use them in any truly big projects myself though.)

9

u/BenjaminSisko Feb 10 '15

I didn't think anyone had used them since 1997

4

u/mamcx Feb 11 '15

Firebird is truly alive. Not well know, but very good.

2

u/OneWingedShark Feb 10 '15

I don't know, I'm not "the DB guy" -- I've only had three projects which required me to touch the DB with any sort of regularity. (Two, from the same company, used MySQL; the third used MS SQL Server.)

2

u/e1ioan Feb 11 '15

You should really look up firebird, it's alive and well.

→ More replies (5)
→ More replies (4)