Home > Backend Development > PHP Tutorial > Horizontal sub-table and vertical sub-table Horizontal ruler and vertical ruler Vertical horizontal ruler Horizontal viewing angle and vertical viewing angle

Horizontal sub-table and vertical sub-table Horizontal ruler and vertical ruler Vertical horizontal ruler Horizontal viewing angle and vertical viewing angle

WBOY
Release: 2016-07-29 08:55:05
Original
1822 people have browsed it

I recently encountered a problem, how to split tables if the amount of data is relatively large?

Take the information table as an example:
I build 100 such tables in advance, message_00, message_01, message_02……….message_98, message_99. Then based on the user’s ID, I determine which table the user’s chat information should be placed in. You can get it by hashing, you can get it by finding the remainder, there are many ways, everyone thinks of their own. Use the hash method below to get the table name:
View copy and print?
function get_hash_table($table,$userid) {
$str = crc32($userid);
if($str<0) {
$hash = '0'.substr(abs($str), 0, 1);
}else{
$hash = substr($str, 0, 2);
}
return $table.'_' .$hash;
}
echo get_hash_table('message','user18991'); //The result is message_10

This is how to get the data table

The original indication is hard-coded
You are Just get the table name through the function

Half of the Cm s like news splits the table according to classification. This is called vertical segmentation
The user type is called horizontal segmentation

For example: list This table has 50W piece of data, you write a judgment in PHP. Every time you write this table, judge whether it reaches 50W. If it reaches , write it into the list_1 table, write an automatic increase table


, and then query which table it is based on the conditions. Then in Perform operations


The above has introduced the horizontal sub-table and vertical sub-table, including vertical and horizontal content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template