News for hackers. Stuff that matters.
Re:Migrating Facebook to MySQL 8.0 by munk-a on Thursday July 22, 2021 @03:13PM (#27922950)
I carried out a (quite ill-advised in retrospect) migration from MySQL to Postgres on a mature codebase with absolutely no automated test coverage and it went pretty smoothly. We had some bumpy performance directly after the production migration but we were able to reach parity after about two months of observing and adding targeted indices.

I absolutely adore Postgres's tweaks to the SQL language, that dialect is amazing and has served us extremely well. And, since we passed pg10 a while back, the performance tuning you can do on it is pretty amazing.

Re:Migrating Facebook to MySQL 8.0 by twic on Thursday July 22, 2021 @03:34PM (#27923191)
> I absolutely adore Postgres's tweaks to the SQL language

Do you mean additions to the SQL standard, or bits of the standard that MySQL doesn't implement, or something else?

The reason i ask is that i also enjoy writing SQL for PostgreSQL, but as far as i know, i am sticking to standard SQL. Perhaps there are things i'm missing, or things i like which i haven't realised are nonstandard!

Re:Migrating Facebook to MySQL 8.0 by felixfbecker on Thursday July 22, 2021 @04:02PM (#27923587)
There is definitely stuff that is non-standard, like the casting with :: in addition to CAST AS.

But it's true that PSQL sticks very closely to the standard or only adds on top of it, while MySQL is very uncomformant.

Funnily enough, I actually first used Postgres over MySQL a long time ago when I moved from PHP to NodeJS, and was annoyed that MySQL uses backticks for identifiers while PSQL uses SQL standard double quotes, because in JS multi-line strings (for SQL queries) are also use backticks and I was annoyed by escaping. Sometimes it's the little things...

Re:Migrating Facebook to MySQL 8.0 by petergeoghegan on Thursday July 22, 2021 @04:47PM (#27924117)
It is practically essential for any RDBMS to provide non-standard statements and features. For example, even CREATE INDEX isn't in the SQL standard, since the SQL standard deliberately avoids talking about what it considers to be implementation details. This is probably a good goal in many ways. But what counts as an implementation detail is open to interpretation.

You could say the same thing about the isolation levels. They are supposed to be platonic ideals, free from any implementation baggage. But the reality is that you can tell that the people that originally defined how they work were mostly (perhaps entirely) thinking about old school two-phase locking.

I'm not a critic of the standard -- it's imperfections (which are arguably contradictions) reflect real world differences that are hard or impossible to resolve. Just pointing out that this is how it is.

Re:Migrating Facebook to MySQL 8.0 by munk-a on Thursday July 22, 2021 @05:22PM (#27924503)
Oh, it's totally fair to criticize the standard. Those clowns lock their deliberation and standard definitions behind huge paywalls.

The best way to learn the SQL standard is to read the Postgres docs since they clearly call out non-compliances - there is no other easy to access and clear explanation of the SQL standard.

Re:Migrating Facebook to MySQL 8.0 by dzolob on Thursday July 22, 2021 @10:37PM (#27926590)
Any “platonic ideals” mention outside its natural scope deserves attention.
Re:Migrating Facebook to MySQL 8.0 by dmitryminkovsky on Thursday July 22, 2021 @10:54PM (#27926669)
You don't think the backticks lend a nice old school vibe?
Re:Migrating Facebook to MySQL 8.0 by paulddraper on Thursday July 22, 2021 @06:47PM (#27925282)
> as far as i know, i am sticking to standard SQL

PostgreSQL documentation is very good about comparing each feature to the standard.

For example, the SQL standard specifies that triggers fire in the historical order they are added to the table.

PostgreSQL chose to fire them alphabetically.

Technically nonconformant, but in practical terms, far better.

Re:Migrating Facebook to MySQL 8.0 by dijit on Thursday July 22, 2021 @07:24PM (#27925530)
Also the c++ bindings are very mature.

This was surprising for my old tech lead who was sheepish on moving away from MySQL.

He would later refer to the MySQL bindings as “brain dead”

Re:Migrating Facebook to MySQL 8.0 by ipaddr on Thursday July 22, 2021 @07:45PM (#27925697)
Why would alphabetically be better? Wouldn't you want first in first out?
Re:Migrating Facebook to MySQL 8.0 by setr on Friday July 23, 2021 @01:25AM (#27927516)
Alphabetical makes it so two databases with the same triggers have the same behavior. FIFO breaks that, because now it depends on trigger construction order (eg when dump/restoring) and is totally invisible to the user.

Additionally, modifying a trigger by drop/creating it would change behavior, unless you also drop/create every trigger (in the original order)

Re:Migrating Facebook to MySQL 8.0 by ipaddr on Friday July 23, 2021 @03:52AM (#27928283)
Thank you most important thing I learned today.
Re:Migrating Facebook to MySQL 8.0 by zaphirplane on Saturday July 24, 2021 @12:30AM (#27938407)
What is an example where the order of execution is required, not contrived or bad practise. Looking for a good use case
Re:Migrating Facebook to MySQL 8.0 by setr on Saturday July 24, 2021 @01:52AM (#27938801)
Easiest I can imagine is a user-facing id that gets incremented by trigger (e.g. select max(col)+1 — autoincrement/serial doesn’t guarantee contiguity, or even reasonable increments…).

And then any second trigger that relies on that value

Re:Migrating Facebook to MySQL 8.0 by paulddraper on Saturday July 24, 2021 @11:24AM (#27941701)
Oh, I think it's probably bad practice to knowingly depend on that.

But I also think that it's unnecessarily problematic to make the order non-deterministic.

Re:Migrating Facebook to MySQL 8.0 by Pamar on Friday July 23, 2021 @06:05AM (#27929012)
Not only what @setr answered but consider also that by having a consistent ruling you can actually design or alter the order of triggers just by naming them according to a specific scheme.

It just makes easier to understand what happens when triggers are invoked, without having to actually force specific cases by direct experimentation.

I did not even know that the standard prescribed a FIFO order, looks like a pretty bad idea to me, actually.

Re:Migrating Facebook to MySQL 8.0 by jolux on Thursday July 22, 2021 @07:51PM (#27925754)
It means that the order they fire is imperative and determined by how you run your migrations.
Re:Migrating Facebook to MySQL 8.0 by paulddraper on Thursday July 22, 2021 @10:09PM (#27926479)
The problem is that it doesn't leave you a great way to adjust order. It's just kinda weird.

(To be fair, table columns share this characteristic.)

Re:Migrating Facebook to MySQL 8.0 by marcosdumay on Thursday July 22, 2021 @10:40PM (#27926605)
> To be fair, table columns share this characteristic.

The table columns order is meaningless, but the triggers order is very relevant.

Re:Migrating Facebook to MySQL 8.0 by paulddraper on Saturday July 24, 2021 @11:26AM (#27941718)
Table column order is not meaningless.

``` INSERT INTO foo SELECT * FROM bar ```

The harder problem however, is order in composite types.

Re:Migrating Facebook to MySQL 8.0 by marcosdumay on Saturday July 24, 2021 @03:14PM (#27943654)
Yeah, I do really recommend people not to do that sort of thing when they ask me.
Re:Migrating Facebook to MySQL 8.0 by throwaway2037 on Friday July 23, 2021 @03:17AM (#27928088)
Why was this down-voted? It is a good question. I thought exactly the same myself. And the reply from @setr is helpful. (Hat tip) I never thought about the impact of dump/restore!
Re:Migrating Facebook to MySQL 8.0 by gunapologist99 on Thursday July 22, 2021 @04:29PM (#27923897)
If you use any of the really amazing JSON or Array stuff, you're stepping outside of the standard.. but it's worth it!
Re:Migrating Facebook to MySQL 8.0 by dkersten on Thursday July 22, 2021 @05:32PM (#27924604)
I absolutely love Postgres' JSON and array support. Its saved me from needing a document database in a few cases, which drastically simplified the overall deployment (one DB instead of two, or trying to represent relational stuff in a document DB). I really like JSON for stuff that is user defined, that I don't need to query into, but postgres' support means I still can should I ever need to. Which has happened once or twice for debugging.
Re:Migrating Facebook to MySQL 8.0 by 1propionyl on Thursday July 22, 2021 @08:49PM (#27926111)
100%. I've dealt with many small-to-medium sized projects where the usual approach would have been some form of EAV mess.

Just using a BSON column for such attributes hits the Pareto 80/20 sweet spot, _and_ I can query against them much more easily than in an EAV schema (far fewer joins).

They're great for when the schema is mostly normalized, but there's just a little bit of denormalized stuff that doesn't warrant completely architecting the schema around it.

Re:Migrating Facebook to MySQL 8.0 by fn1 on Friday July 23, 2021 @09:33AM (#27930456)
> but postgres' support means I still can should I ever need to.

And since postgres supports indices on arbitrary expressions you can use CREATE INDEX for the json-queries in your WHERE:

CREATE INDEX ON publishers((info->>'name'));

Re:Migrating Facebook to MySQL 8.0 by dkersten on Friday July 23, 2021 @04:38PM (#27935356)
Yes, Postgres' jsonb and array support lets you not only query into these fields, but also, like you say, index into them too. Its really the best of both worlds: you get a great solid relational database, but if you need document database features, you don't really lose out on anything by using json, except that the queries are a bit more ugly. I'm super happy with postgres these days, its rock solid and full of fantastic features.
Re:Migrating Facebook to MySQL 8.0 by mdaniel on Thursday July 22, 2021 @11:28PM (#27926870)
The word "any" there is mildly misleading about the JSON things, since there is now SQL/JSON which PG supports: https://www.postgresql.org/docs/13/functions-json.html#FUNCT...

It would be horribly painful to stick to _just_ SQL/JSON for manipulations, and I have absolutely zero idea what the coverage is in other platforms, but portability isn't completely off the table like it used to be

Re:Migrating Facebook to MySQL 8.0 by eatonphil on Thursday July 22, 2021 @03:59PM (#27923551)
MySQL does not conform to the standard in a number of ways. On the one hand, thankfully you can turn on ANSI MODE. On the other hand if you're using MySQL you've probably got a bunch of devs used to their non-ANSI SQL and turning on ANSI MODE may break stuff they do.

https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mo...

Re:Migrating Facebook to MySQL 8.0 by munk-a on Thursday July 22, 2021 @05:45PM (#27924744)
Personally, back before JSON became a standard thing - I made heavy use of HSTORE to clean up some insanely cludgey string packing BS we'd been doing - leveraging recursive CTEs using the UNION definition allowed us to move a fixed tier system into a self-referential one that saved us a lot of headaches as well.

Other folks have mentioned :: instead of CAST AS (which is really nice when you need to write it a bunch of times) but it's mostly the diverse built-in function set and constraint support that keeps me an enthusiastic Postgres supporter.

Re:Migrating Facebook to MySQL 8.0 by jacobmischka on Thursday July 22, 2021 @04:00PM (#27923559)
I assume they mean non-standard additions in PostgreSQL. A lot of the very handy pg functions are non-standard, as well as the rich text matching capabilities, many data types, and even the RETURNING clause, I believe.
Re:Migrating Facebook to MySQL 8.0 by tapoxi on Thursday July 22, 2021 @03:27PM (#27923106)
We also did a MySQL 5.7 to PG 9.6 migration (thanks to https://pgloader.io/) and we got some pretty immediate speed improvements (2-5x).

We shot ourselves in the foot a few weeks later with some poorly written RLS policies, but it was overall a smooth experience.

Re:Migrating Facebook to MySQL 8.0 by dijit on Thursday July 22, 2021 @07:26PM (#27925546)
pgloader is great.

Sadly for me when I tried to make a PoC of Postgres for our eCommerce platform I found that we had violated our constraints and lost data.

That was the day I went from MySQL agnostic to MySQL hating.

It largely doesn’t matter that the defaults could be configured to be more strict. We live in a world where people are trying to avoid hiring sysadmin and that database was set up by a developer. It should not have been a default.

Re:Migrating Facebook to MySQL 8.0 by evanelias on Thursday July 22, 2021 @07:37PM (#27925628)
> It largely doesn’t matter that the defaults could be configured to be more strict. We live in a world where people are trying to avoid hiring sysadmin and that database was set up by a developer. It should not have been a default.

Everyone agrees with this. That's why they changed the default nearly 6 years ago.

Yes, the old default was terrible. But there's no way to change the past, so why complain about it for years and years?

All versions with this bad default have hit end-of-life, what more can be done?

Re:Migrating Facebook to MySQL 8.0 by lucideer on Thursday July 22, 2021 @03:16PM (#27922987)
I am very much an example of one of those previously MySQL devs that now uses Postgres for new projects, though I've never done a migration between the two.
Re:Migrating Facebook to MySQL 8.0 by code_duck on Thursday July 22, 2021 @03:20PM (#27923036)
I had an app with a fairly complex and large set of tables and data and migrated it from mySQL to pg with very little trouble. It was a few years back, but from what I recall a re-wrote a few queries in my data layer and that’s about it. Much easier than it was to setup nginx to take over some Apache duties.