mysql - 分库后如果显示各分库下合并的数据
PHP中文网
PHP中文网 2017-04-17 14:49:14
0
3
645

B2C电商,假如有用户表,订单表,商品表,针对用户ID,进行hash后,分库,假设分为A,B,C,D四个库,相应的不同用户下的订单也存放在对应的A,B,C,D库里,商品表做冗余存放在所有库里,
那如果要在后台订单里看到所有的订单,这时候要怎么处理,把A,B,C,D的订单合并起来再排序?这套规则有组件可以实现吗?还是要自己写代码?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
小葫芦

The structure of the order table is the same. It is recommended to process it at the database layer. SQL statement union query, and then perform order by and limit processing. The terminal directly gets the processed data; the code solution will consume memory

Ty80

The sub-library and sub-table itself is a double-edged sword. If the single volume is 10 or millions, it is not recommended to divide it now.
Regarding the query conditions you mentioned, if the demand is quite large and the query time is quite large, I suggest building a separate database and summarizing the data from the previous sub-databases (only the data needed for querying is summarized). Just read the bin log and write ETL. In addition to solving your needs, another advantage is that it is very convenient to analyze statistics.
Or you can directly use Alibaba’s open source middleware to isolate the database and business programs

PHPzhong

If you want to divide the database and tables according to the user dimension, you need to divide the database and tables again according to the order dimension, so there will be data redundancy

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!