Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql - how many columns is too many?

Tags:

sql

mysql

I'm setting up a table that might have upwards of 70 columns. I'm now thinking about splitting it up as some of the data in the columns won't be needed every time the table is accessed. Then again, if I do this I'm left with having to use joins.

At what point, if any, is it considered too many columns?

like image 910
Brad Avatar asked Sep 24 '09 20:09

Brad


People also ask

How many columns is too many columns?

There isn't a number that's too many. That said, it sounds like, based on your description, that you're not dealing with a properly structured table. 180 columns to define a user and 280 columns to define a thing... That can't possibly be normalized or a fact table.

Can you have too many columns in a database?

In the NO-SQL world (cassandra/hbase for example) there are no constraints on the number of columns and it's actually considered a good practice to have many columns. This also comes from the way it is stored (no gaps).

Does number of columns affect performance in MySQL?

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.

Is it bad to have too many columns in MySQL?

It's considered too many once it's above the maximum limit supported by the database. The fact that you don't need every column to be returned by every query is perfectly normal; that's why SELECT statement lets you explicitly name the columns you need.


1 Answers

It's considered too many once it's above the maximum limit supported by the database.

The fact that you don't need every column to be returned by every query is perfectly normal; that's why SELECT statement lets you explicitly name the columns you need.

As a general rule, your table structure should reflect your domain model; if you really do have 70 (100, what have you) attributes that belong to the same entity there's no reason to separate them into multiple tables.

like image 197
ChssPly76 Avatar answered Oct 03 '22 10:10

ChssPly76