I need to store 150 different tiny integer values (range from 0 to 7) into a MySQL database table row. All of those would be read and written to together every time there’s an SELECT, INSERT or UPDATE. The table would mostly be updated, there would be 1 insert, and then about 1000 updates on the row. DELETES and SELECTS would happen really rarely, if ever.
Performance wise, is it better to use 150 tinyint columns, or a varchar(300)?
My main concern it the time it takes MySQL to process 150 column definitions when result set is prepared vs double-size that would require double RAM if cached. I expect to have hundreds of thousands of rows, so each bit of performance counts.
I’d store them in a BINARY column, one per byte. The dataset should easily fit in memory, 150b*500k = 75Mb. I don’t think the overhead of postprocessing a byte array would be more than the db overhead of working with the columns for queries and selects. INSERTs and UPDATEs will take parsing time from the DB, along with being ugly to construct. The difference is probably in the millisecond range though, so I’d do what makes sense for decoding on your application end.