Number of Columns X performance in tables

Asked

Viewed 118 times

4

I am working with Mysql 10.x in a table that already has 60 columns, but it turns and moves I need to include more columns, I usually dismember in several tables precisely to not create a very large table in terms of number of fields.

I was reading about the limits on the Mysql site and saw that the field number and size is far from reaching the limit of Mysql, but I usually avoid very large tables

Doubts:

If I dismember my tables too much I will not be slower in the searches due to excessive use of joins?

I must create a table with as many fields as I find necessary without dismembering?

  • I think the number of columns does not significantly affect performance, as long as you select only the columns you need, instead of SELECT * FROM ... ago SELECT col1, col2 FROM...

  • 1

    60 columns? It seems to me a lot, nor is the performance point itself, but your table is probably denormalized, I can not think of a simple entity that has so many columns like this, should review it from the modeling point of view. The database has mechanisms to be relational, that is, allow you to relate a lot, but honestly I was curious, which 60 columns would be those that need everything at once in a single query? can you ask the question? can you help with the analysis

  • I don’t know if it would help to put in the question, this table comes from a JSON that I take from a webservice, it comes with "subchaves" where I dismember in other tables, I try to maintain the structure that comes from them to not have problems when changing something, only in the main have about 50 fields, There’s more to my control fields, which means it’s already born big, and I have no control over it, and dismembering would be chaos at my base. My question is to get an idea if I should insert my fields in the same table, I think if fragmenting too much can get slow.

  • Mysql 10.x? Are you sure? The latest version is not 8.x?

  • On my Server it looks like this: Mysql version: 10.2.36-Mariadb

1 answer

3


The number of columns does not affect performance by itself. Of course, more data there is a higher cost, but it’s not even proportional, it’s amortized, so the more data you’re dealing with, the trend (exception) is for overall performance to improve a little in various scenarios. The cost to bring two data tends to be less than twice the cost of bringing a data (disregarding the data size difference).

If you have to deal with a lot of data then deal, no problem, the databases were made for this. If you have data that you shouldn’t handle, which is very rare for someone to do something like this, then you should improve it.

Splits into several tables is making a pseudo normalization and then it is almost certain that it will have performance fall, maybe even very big because it will have to make a join shape or other. You can see more about:

Then you’ll start doing one-on-one relationships needlessly, slowing everything down. It’s the opposite of what you imagine. The data needs to be picked up in different places instead of being picked up together. It should be obvious that even a bricklayer knows that picking up a brick in each place is worse than picking it all up together, but for some reason programmers don’t know.

Note that there is a myth about bringing all fields to be slower. Yes, that’s usually true, but it’s not that simple, and most people make simplifications. This may not be true, or be quite the opposite, it depends a lot on the scenario. See Why using "SELECT * FROM table" is bad?. Reading this you can see that the question is complex.

Either way, it changes a lot less than you think, and will only be relevant in extreme cases. In general the person has a ridiculously small database and thinks it has one of the largest databases in the world and that it needs absurd optimizations.

The decision of where to put the data should be primarily logical, do what is right conceptually, this alone should already give a good performance. In cases where there really is some real problem, and not imaginary, then one should think of an organization out of the ordinary, thinking about optimization and obtain extraordinary gains.

60 columns is quite low, really has many cases to store all this or more. The size of these columns will affect much more than the amount of them. But as said before, just because it has more data. Split does not decrease the amount of data.

It seems that the problem asks for fields together in a table for logical and performance reasons.

  • Thank you for the reply Maniero, I know that it is difficult to give a direct answer for several questions, but in your opinion, should I create in a table only how many fields are needed when the data do not require 1 for N? After reading your answer and other matters I think that while the data do not give rise to "children" type Request -> Items should keep everything in the same table.

  • 1

    Yes, that’s what’s in the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.