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?