why or how solve problem on mysql.
table xxx
-> id primary key
-> name varchar 255
-> data longblob
when I store to this table 100 files, each 100MB, the table would have 10GB
and then try to select any row... it takes to long
SELECT name FROM xxx WHERE id = 50 LIMIT 1;
takes about 8 second
my problem is probably in that, mysql reads whole row before it return name
, which is only 255 characters ... so when I want to list names of 100 files, mysql reads 10 GB and return about 2 KB of result.
Queries can become slow for various reasons ranging from improper index usage to bugs in the storage engine itself. However, in most cases, queries become slow because developers or MySQL database administrators neglect to monitor them and keep an eye on their performance.
LONGBLOB: A binary large object column with a maximum length of 4294967295 (2^32 - 1) bytes, or 4GB in storage. Each LONGBLOB value is stored using a four-byte length prefix that indicates the number of bytes in the value.
BLOB: Can handle up to 65,535 bytes of data. MEDIUMBLOB: The maximum length supported is 16,777,215 bytes. LONGBLOB: Stores up to 4,294,967,295 bytes of data.
Try splitting the blobs into a separate table.
For example, you could have a table xxx
containing the columns id
and name
, and another table xxx_data
containing the columns id
and data
. If you only want the name, you don't need to query the xxx_data
table at all; if you need both the name and the data, you can join the tables together using the shared primary key id
:
SELECT id, name, data
FROM xxx JOIN xxx_data USING (id)
WHERE id = ...
For more information and optimization ideas, see e.g. 10 tips for optimizing MySQL queries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With