How to use thinkphp table sharding

Source: Internet
Author: User
How to use thinkphp sharding for table sharding

I preset 10 tables: table_1, table_2, table_3... table_10
Partition is set in Model:
Protected $ partition = array (
'Field' => 'id ',
'Type' => 'id ',
'Exppr' => '',
'Num' => 10,
);
GetPartitionTableName () is also used ()
The official document indicates that the current data must be input. Which data table should be operated based on data analysis?
What data is passed in to the current data? the results of each experiment are combined queries! The current table name cannot be found!
Please help me! Or is there any proper method!


Reply to discussion (solution)

Your table sharding field is id
Therefore, the data array sent to getPartitionTableName must contain the element with the id of the join key.

But his algorithm is a little weird.

$ Field = $ data [$ this-> partition ['field']; switch ($ this-> partition ['type']) {case 'id ': // table sharding by id range $ step = $ this-> partition ['expr']; $ seq = floor ($ field/$ step) + 1; break ;......... return $ this-> getTableName (). '_'. $ seq;
According to your settings, it seems to be 'type' => 'Mod'
Case 'mod': // id-based module-based table sharding $ seq = ($ field % $ this-> partition ['num']) + 1; break;

Your table sharding field is id
Therefore, the data array sent to getPartitionTableName must contain the element with the id of the join key.

But his algorithm is a little weird.

$ Field = $ data [$ this-> partition ['field']; switch ($ this-> partition ['type']) {case 'id ': // table sharding by id range $ step = $ this-> partition ['expr']; $ seq = floor ($ field/$ step) + 1; break ;......... return $ this-> getTableName (). '_'. $ seq;
According to your settings, it seems to be 'type' => 'Mod'
Case 'mod': // id-based module-based table sharding $ seq = ($ field % $ this-> partition ['num']) + 1; break;

Why can't I see how many data entries will be written into the second table or the like? how can I handle CURD ~~~

Are you using getPartitionTableName to get the table name?
If the table name is used, isn't it the same as when the table name is not used?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.