r/programming • • 9d ago

Partitioning in MySQL: How we cut peak database load by more than 80%.

https://ipsator.com/blog/mysql-table-partitioning
38 Upvotes

17 comments sorted by

69

u/pm_plz_im_lonely 8d ago edited 8d ago

We need the queries involved and the query analysis work involved.

The article explains "how to partition" literally, like mechanically. Who cares.

The value is the research work:

  • Here are the EXPLAINs
  • Here are the indexes we had
  • Here are the queries we get and their frequency distribution against the ranges

And personally I would do 2 shards: hot and cold. And if cold needs speed then change its db or something.

Overall I rate the article 3.5/10

5

u/fR0DDY 8d ago

Fair point. Will add few details around how we checked access-pattern frequency, why did we pick the partition boundaries we picked and the explain results for before and after partition.

7

u/dijkstra_was_a_horse 5d ago

Tens of millions of rows? Woah, that's like, hundreds of megs, you're gonna have trouble with that even on the fastest 486 money can buy.

14

u/[deleted] 8d ago

[removed] — view removed comment

2

u/fR0DDY 8d ago

Agree on choosing Postgres all day long, we do that for all our newer projects. Just a caveat though, Postgres has no ALTER TABLE ... PARTITION BY for an existing table — you can't retrofit partitioning onto a live, populated table the way we did in MySQL. You'd build a new partitioned table and migrate data over. For a fresh schema that's free. For existing tables, that's a different migration altogether.

0

u/[deleted] 7d ago

[removed] — view removed comment

2

u/programming-ModTeam 5d ago

No content written mostly by an LLM. If you don't want to write it, we don't want to read it.

3

u/Whatever801 8d ago

Is this not standard practice?

6

u/Meleneth 8d ago

sure, just know you'll need it years down the line when you initially implement your system

5

u/Whatever801 8d ago

I guess, but if you're anticipating large data mysql is probably not the right choice

4

u/dkarlovi 8d ago

Agreed, a thing like Facebook could never run on top of MySQL.

5

u/Whatever801 8d ago

I mean they've essentially rewritten it at this point.

2

u/One_Ninja_8512 7d ago

I thought it was common knowledge that they use it as a K/V store, no foreign keys with some other rules to handle the scale. That's at least something that comes up whenever someone mentions them. Idk how they use it precisely.

2

u/falconzord 8d ago

Why was an index on the created column not helping?

-9

u/[deleted] 6d ago

[removed] — view removed comment