Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does number of columns affect MYSQL speed?

Tags:

mysql

I have a table. I only need to run one type of query: to find a given unique in column 1, then get say, the first 3 columns out.

now, how much would it affect speed if I added an extra few columns to the table for basically "data storage". I know I should use a saparate table, but lets assume I am constrained to having just 1 table, so the only way is to add on some columns at the end.

So, if I add on some columns, say 10 at the end, 30 varchar each, will this slow down any query given in the first sentence? If so, by how much of a factor do you think compared to without the extra reduntant yet present columns?

like image 993
David19801 Avatar asked Dec 24 '10 22:12

David19801


1 Answers

Yes, extra data can slow down queries because it means fewer rows can fit into a page, and this means more disk accesses to read a certain number of rows and fewer rows can be cached in memory.

The exact factor in slow down is hard to predict. It could be negligible, but if you are near the boundary between being able to cache the entire table in memory or not, a few extra columns could make a big difference to the execution speed. The difference in the time it takes to fetch a row from a cache in memory or from disk is several orders of magnitude.

If you add a covering index the extra columns should have less of an impact as the query can use the relatively narrow index without needing to refer to the wider main table.

like image 150
Mark Byers Avatar answered Oct 25 '22 04:10

Mark Byers