Too many tables; MySQL can only use 61 tables in a join

后端 未结 4 635
迷失自我
迷失自我 2020-12-09 11:51

What is the best way to export data from multiple tables in MySQL. I\'m basically working with product details. Say a product has 150 attributes of data. How can I export t

4条回答
  •  被撕碎了的回忆
    2020-12-09 12:24

    If you have this many attributes, I expect that it is a sparse database, so you have a great deal of wasted space.

    You may want to look at using an Entity-Attribute-Value database instead, if possible.

    http://en.wikipedia.org/wiki/Entity-attribute-value_model

    What this buys you is a way to refactor the database, but have it be more extensible, and reduce how many tables you need. You should be able to come down to 4-6 tables (2-3 entity tables with their attributes). It is a bit more difficult to create the queries as all the queries will be dynamic, but it will simplify your export, and the database maintenance should be simpler.

    If you must use this schema you may want to create several triggers and then you can call the trigger, which is joining several tables, and then make your query, but you will take a huge performance hit.

    UPDATE:

    Since an EAV table is being used, and MySQL doesn't do a pivot function you may want to read the answer to this question: How to pivot a MySQL entity-attribute-value schema How to pivot a MySQL entity-attribute-value schema

提交回复
热议问题