Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing serialized objects in MySQL and performance

We want to store a serialized object in a table along with a unique internal ID. We'd only ever want to read/write/(rarely)update the rows. We'd never interact with the serialized field just the ID. We're using InnoDB,

Firstly;

Would it be right to store the serialization as a text type field?

Secondly;

If we do not directly interact with the serialized field other than r/w will it affect the performance of our database at all?

Finally;

Would it be better to store the serialized object in our filesystem instead?

To give a little insight into why we're storing them in the first place, we receive an object from a supplier, a user needs to select several options and we need to send the EXACT object back with the modified (selected) components.

like image 227
Anthony Avatar asked Feb 03 '26 03:02

Anthony


1 Answers

  1. Yes storing it as a text field (type TEXT) is correct but you can also store it in binary (type BLOB) if you're worried about character encoding.

  2. No, if you are only ever looking up by ID which is a primary key then it shouldn't have too much of a performance effect.

  3. If you're using MySQL to store the ID's, you might as well store the serialized object in the table, unless you have huge amounts of serialized data that could use up lot's of disk space but then storing it in the file system would have the same problem.

like image 75
fire Avatar answered Feb 04 '26 16:02

fire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!