Live data from Hacker News

Is 20M of rows still a valid soft limit of MySQL table in 2023?

yishenggong.com

71–80 of 86 posts

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#71
post #70

Earlier quoted context omitted.

Learn about MVCC storage. You might have multiple running concurrent transactions. Which is the "true" row count? Hint: you have to count.

Makes me wonder if anybody would find a SELECT APPROXIMATELY COUNT(*) useful, which would ignore the impact of current transactions.

Many DB systems have some sort of HLL function to provide a similar approximation (although I think you’re overestimating the costs that MVCC impose on large datasets).

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#72
I see no problems of benchmark apart from you'd be avoiding table scans in prod for tables of those sizes - that kind of benchmark kind of pointless. Well, it shows a point, but not something you would want to use anyway.

Once data is cached, using indexed lookups are fast, 0.5ms.

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#73
post #34

Earlier quoted context omitted.

Is that web scale?

You run MongoDB as a backing store. Very web much scale.

I prefer/dev/null for write heavy workloads that need long term storage. There’s plenty of data in modern physics to suggest that there’s no information loss from going into a black hole, so there shouldn’t be any problems. Put “architected web scale data singularity with bulletproof disaster recovery plan” in your CV. You don’t need to mention the recovery plan is to interview for new jobs when someone starts asking to access the data.

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#74
post #70

Earlier quoted context omitted.

Learn about MVCC storage. You might have multiple running concurrent transactions. Which is the "true" row count? Hint: you have to count.

Makes me wonder if anybody would find a SELECT APPROXIMATELY COUNT(*) useful, which would ignore the impact of current transactions.

While not "SELECT APPROXIMATELY COUNT (*)," both MySQL and PostgreSQL both offer various metadata tables with approximate (albeit completely unfiltered) total row counts.

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#75
post #70

Earlier quoted context omitted.

Makes me wonder if anybody would find a SELECT APPROXIMATELY COUNT(*) useful, which would ignore the impact of current transactions.

Many DB systems have some sort of HLL function to provide a similar approximation (although I think you’re overestimating the costs that MVCC impose on large datasets).

Note that HLL is used for counting `unique` things. You don't need HLL for counting the rows of the table.

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#76

Earlier quoted context omitted.

Generally speaking, why does SELECT COUNT(*) takes so much? I'd expect that the database maintains internal bookkeeping structures with table metadata that contain the number of rows in each table. I reckon this is probably not true? If so, is it because it keeping a counter like that up-to-date would be inefficient Edit: I just realized I might be misunderstanding what that query does

Learn about MVCC storage. You might have multiple running concurrent transactions. Which is the "true" row count? Hint: you have to count.

Seems like you could just count the number of primary key entries in the index.

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#77

Earlier quoted context omitted.

Agreed. I have a handful of tables with over 2 billion rows and have experienced no issues. One database is 2.5TB in size. I feel like 20 million rows is a relatively small MySQL table.

What types of data with over two billion rows?

We have two tables at nearly 2 billion rows for line items on invoices (we aggregate data for a substantial portion of a major industry). We have ~20 tables that are over 100 million rows but less than 1 billion. Looks like another ~20 tables over 20 million.

To get this info on your own mysql db: `select * from information_schema.TABLES;`. As previously disclaimed, the TABLE_ROWS here are an estimate generally, see https://dev.mysql.com/doc/mysql-infoschema-excerpt/5.7/en/in...

(same in MySQL 8; we use both 5.7 and 8)

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#78
post #70

Earlier quoted context omitted.

Learn about MVCC storage. You might have multiple running concurrent transactions. Which is the "true" row count? Hint: you have to count.

Makes me wonder if anybody would find a SELECT APPROXIMATELY COUNT(*) useful, which would ignore the impact of current transactions.

[deleted]

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#79
post #70

Earlier quoted context omitted.

Learn about MVCC storage. You might have multiple running concurrent transactions. Which is the "true" row count? Hint: you have to count.

Makes me wonder if anybody would find a SELECT APPROXIMATELY COUNT(*) useful, which would ignore the impact of current transactions.

Doesn't SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED do that? Or maybe a NOLOCK hint equivalent in MySQL?

Re: Is 20M of rows still a valid soft limit of MySQL table in 2023?

#80

Earlier quoted context omitted.

Learn about MVCC storage. You might have multiple running concurrent transactions. Which is the "true" row count? Hint: you have to count.

Seems like you could just count the number of primary key entries in the index.

Essentially what SELECT COUNT(*) does in InnoDB is choose the smallest index and fully scans that, in parallel if there's no WHERE clause.

Meanwhile the primary key is typically the largest index, since with InnoDB's clustered index design, the primary key is the table. So it's usually not the best choice for counting unless there are no secondary indexes.

As other commenters mentioned, the query also must account for MVCC, which means properly counting only the rows that existed at the time your transaction started. If your workload has a lot of UPDATEs and/or DELETEs, this means traversing a lot of old row versions in UNDO spaces, which makes it slower.

Post reply on HN