mysql query large data points table

mysql query large data points table

When the amount of data surge, we will select the library table hash like manner to optimize data access speed, exemplified:

100 million data points 100 table

1. First create 100 tables

$i=0;
while($i<=99){
echo "$newNumber \r\n";
$sql="CREATE TABLE code_".$i." (
full_code char(10) NOT NULL,
create_time int(10) unsigned NOT NULL,
PRIMARY KEY (full_code),
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
mysql_query($sql);
$i++;

2. The sub-table rules:

full_code as the primary key, made hash of full_code

$table_name=get_hash_table('code',$full_code);

function get_hash_table($table,$code,$s=100){
$hash = sprintf("%u", crc32($code));
echo $hash;
$hash1 = intval(fmod($hash, $s));
return $table."_".$hash1;
}

Such data acquisition front insert table data stored by get_hash_table.

3. Use the merge storage engine to achieve a complete code table

CREATE TABLE IF NOT EXISTS code (
full_code char(10) NOT NULL,
create_time int(10) unsigned NOT NULL,
INDEX(full_code)
) TYPE=MERGE UNION=(code_0,code_1,code_2.......) INSERT_METHOD=LAST ;

By select * from code you can get all the data full_code.

Guess you like

Origin www.cnblogs.com/djwhome/p/12536068.html