mysql table with 40+ columns

前端 未结 4 1736
旧巷少年郎
旧巷少年郎 2021-01-20 20:55

I have 40+ columns in my table and i have to add few more fields like, current city, hometown, school, work, uni, collage..

These user data wil be pulled for many m

4条回答
  •  失恋的感觉
    2021-01-20 21:33

    At a certain point you should look at the "short row model", also know as entity-key-value stores,as well as the traditional "long row model".

    If you look at the schema used by WordPress you will see that there is a table wp_posts with 23 columns and a related table wp_post_meta with 4 columns (meta_id, post_id, meta_key, meta_value). The meta table is a "short row model" table that allows WordPress to have an infinite collection of attributes for a post.

    Neither the "long row model" or the "short row model" is the best model, often the best choice is a combination of the two. As @nevillek pointed out searching and validating "short row" is not easy, fetching data can involve pivoting which is annoyingly difficult in MySql and Oracle.

    The "long row model" is easier to validate, relate and fetch, but it can be very inflexible and inefficient when the data is sparse. Some rows may have only a few of the values non-null. Also you can't add new columns without modifying the schema, which could force a system outage, depending on your architecture.

    I recently worked on a financial services system that had over 700 possible facts for each instrument, most had less than 20 facts. This could have been built by setting up dozens of tables, each for a particular asset class, or as a table with 700 columns, but we chose to use a combination of a table with about 20 columns containing the most popular facts and a 4 column table which contained the other facts. This design was efficient but was difficult ot access, so we built a few table functions in PL/SQL to assist with this.

提交回复
热议问题