UUID inefficiency
You are about to encounter the performance disaster that comes when mixing UUIDs with huge tables.
Even a simple that fetches one row by the primary key will usually involve a disk hit. This adds up to a lot of I/O -- probably too much to tolerate.
50M selects/day = 600/second. Can your disk system handle nearly 600 reads/second?
Off-record
Another issue -- There are a lot of 'large' columns. And, with an average of 2KB per row, there are probably many rows that use "off-record" storage. This involves another disk hit. What is the ROW_FORMAT
?
A partial mitigation of this problem is to be sure to avoid SELECT *
and specify only the columns that you actually need. This may avoid some of the extra disk hits.
This suggestion applies especially to VALUE
and ALERT
.
Lazy evaluate
If the selects have filtering (WHERE
, LIMIT
, etc) that is not adequately indexed, you may be fetching those bulky columns, only to discard them when filtering.
It is sometimes possible to avoid extra I/O by building a derived table that does the filtering, leaving the outer SELECT
to fetch only the minimal number of columns. (Show us a non-trivial query you are using; we can discuss further.)
Shrink UUIDs
What type UUIDs are you using? If it is "Type 1", like MySQL uses, the bits of the id can be rearranged to make them roughly chronological; this helps dramatically with certain queries.
89f7eecd-a2ac-11eb-a9c1-5c80b6213dd8
^ This digit is the "type"
Details: http://mysql.rjweb.org/doc.php/uuid
Even without that, the 36-byte UUIDs can easily be shrunk to 16 bytes for putting in a BINARY(16)
instead of 38 bytes for what you have (36 for the string, 2 for the unnecessary VAR
.)
The above link discusses this shrinkage. Also, 8.0 has the necessary functions built in.
MariaDB 10.7 "will have" a UUID datatype that obviates most of what is discussed in this Answer.
Compress
(I am not in favor of InnoDB's compression, so I won't mention it. Anyway, it is not likely to provide more than 2x compression.)
If you compress those XML strings, they will shrink by a factor of (about) 3. That would save about 2TB.
But do the compression (and uncompression) in the client; this offloads the server and decreases the bandwidth between client and server.
XML is a bulky way to represent data, but it may be non-trivial to reformat it. (Hence, I only mention compression.)
Note, after compression, the column should be VARBINARY(...)
or ...BLOB
, not a text type.
Ditto for other columns that are "text" and typically "big".
Split table
I do not forsee any significant benefit or drawbacks from splitting off the two bulky columns. The fact that they are "off-record" means that InnoDB is already providing most of the benefit that you propose. (MyISAM would benefit from your split. But don't use that engine.)
This is some benefit from splitting the table, but possibly not enough benefit (in your case) to warrant the change. This is especially the case if the new table also had a uuid as the PK, even if it is the same as the current ID.
10M Inserts
10 million 1-row INSERT
statements? That would be something like 30M disk hits with your current design. How many writes per second can your disk support?
I would suggest things like "batching" the inserts. A single INSERT
with 100 rows normally runs 10 times as fast as 100 single-row inserts. But there are 3 random hits -- One for the PK, one for each secondary index. So, I don't know if this 10x speedup will really happen in your case.
RAM
The more RAM the better. With, say, 7TB of RAM (25TB in the future), much of what I have said goes away. But that is not practical today. Hence, I am pushing for shrinking the table size, avoiding UUIDs or making them chronological (if useful), etc.
If 5% of a uuid-based index can fit in the buffer_pool, then 95% of selects will need to hit the disk. This is the principle behind much of my discussion.
Note: the PK is an index, but includes all the data.
Note: A lookup via a secondary index involves two BTree lookups. If each is based on a uuid, then there is a good chance of two disk hits.
Note: Your two-table approach would involve 2 lookups. Each one might be less than the "95%" above, but still.
Partitioning and parallel query
Aurora is ahead of MySQL (and MariaDB) in this area. But still, there is not much benefit to be had.
The effort to each into a different partition eliminates the benefit of a shallower BTree. (It may even slow things down.)
Parallel query helps if you are CPU-bound. But I predict that you are I/O-bound and will meltdown at 25TB. Each of the parallel queries will spend most of their time waiting for a block to be read from disk.
I assume the 50M Selects/day are coming from separate connections? And lots of them are happening "at the same time"? That gives you "parallel" execution of queries. I think Aurora's "parallel query" is aimed at a single, complex, SELECT
that can benefit from multiple threads doing parts of the task simultaneously.
A way that PARTITIONing
can benefit is when you need a 2-dimensional index. For example: WHERE some date range AND some other test
. By partitioning on date while having the PRIMARY KEY
helping with the 'other test', "partition pruning" picks which partition to look in, then the PK more quickly reaches for the rows desired. (This does not seem to be your use case.)
Your main queries would not benefit from any form of PARTITIONing
. So, I recommend against partitioning.
Indexes
Given that nearly all the SELECTs
are these two:
select * from app_uses where ID='5labcvnaxvb11egw4w0or0wq4';
SELECT * FROM app_uses where OBJ_ID = '5ldfjkhgdfkjhg631exlwu9tkrsmv'
ORDER BY DATE_TIME DESC;
These are optimal:
PRIMARY KEY(ID) -- as you have
INDEX(OBJ_ID, DATE_TIME) -- replace key(obj_id) with this
The suggested change in the second case avoids the need to sort the result since the desired rows can simply be fetched in the desired order. (This is not likely to make much performance difference unless it is a lot of rows. The UUID issues dominate performance issues.)