In addition to necessary indexes and proper SELECT queries (only select needed columns), for wide tables, 2 basic tips apply well:
- Define your column as small as possible.
- Avoid using dynamic columns such as VARCHAR or TEXT as much as possible when you have large number of columns per table. Try using fixed length columns such as CHAR. This is to trade off disk storage for performance.
For instance, for columns ‘name’, ‘gender’, ‘age’, ‘bio’ in ‘person’ table with as many as 100 or even more columns, to maximize performance, they are best to be defined as:
- name – CHAR(70)
- gender – TINYINT(1)
- age – TINYINT(2)
- bio – TEXT
The idea is to define columns as small as possible and in fixed length where reasonably possible. Dynamic columns should be to the end of the table structure so fixed length columns ALL come before them. MySQL would then have a better time predicting the position of a column to perform select or update, otherwise it would have to read through the entire row byte by byte to find it.
It goes without saying this would introduce tremendous disk storage wasted with large amount of rows, but as you want performance I guess that would be the cost.
Another tip is as you go along you would find columns that are much more frequently used (selected or updated) than the others, you should separate them into another table to form a one to one relationship to the other table that contains infrequent used columns and perform queries with less columns involved.