1 | <?php |
---|
2 | |
---|
3 | $connections = array( |
---|
4 | array( |
---|
5 | 'host' => 'localhost', |
---|
6 | 'port' => '3306', |
---|
7 | 'user' => 'root', |
---|
8 | 'pass' => 'root', |
---|
9 | ), |
---|
10 | ); |
---|
11 | |
---|
12 | $engines = array( 'myisam', 'innodb' ); |
---|
13 | $row_counts = array( 100000, 1000000, 10000000 ); |
---|
14 | $percent_underscores = array( 10, 30, 60, 90 ); |
---|
15 | $unique_keys_count = array( 10, 100, 1000, 10000 ); |
---|
16 | |
---|
17 | $queries = array( |
---|
18 | 'original' => "SELECT meta_key |
---|
19 | FROM wp_postmeta |
---|
20 | GROUP BY meta_key |
---|
21 | HAVING meta_key NOT LIKE '\_%' |
---|
22 | ORDER BY meta_key |
---|
23 | LIMIT 30", |
---|
24 | 'range' => "SELECT DISTINCT meta_key FROM wp_postmeta |
---|
25 | WHERE meta_key NOT BETWEEN '_' AND '_z' |
---|
26 | HAVING meta_key NOT LIKE '\_%' |
---|
27 | ORDER BY meta_key", |
---|
28 | 'notlike' => "SELECT DISTINCT meta_key |
---|
29 | FROM wp_postmeta |
---|
30 | WHERE meta_key NOT LIKE '\_%' |
---|
31 | ORDER BY meta_key |
---|
32 | LIMIT 30" |
---|
33 | ); |
---|
34 | |
---|
35 | foreach ( $connections as $connection ) { |
---|
36 | $dbh = new mysqli( $connection['host'], $connection['user'], $connection['pass'], null, $connection['port'] ); |
---|
37 | if ( $dbh->connect_error ) { |
---|
38 | die( 'Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error ); |
---|
39 | } |
---|
40 | |
---|
41 | foreach( $engines as $engine ) { |
---|
42 | $dbh->query( "DROP DATABASE IF EXISTS 24498_test" ); |
---|
43 | $dbh->query( "CREATE DATABASE 24498_test" ); |
---|
44 | $dbh->query( "USE 24498_test" ); |
---|
45 | $dbh->query( "CREATE TABLE wp_postmeta ( |
---|
46 | id BIGINT UNSIGNED AUTO_INCREMENT, |
---|
47 | meta_key varchar(255), |
---|
48 | PRIMARY KEY(id), |
---|
49 | KEY meta_key(meta_key(191)) |
---|
50 | ) ENGINE=$engine" ); |
---|
51 | |
---|
52 | $results = array(); |
---|
53 | foreach( $row_counts as $rows ) { |
---|
54 | $results[ $rows ] = array(); |
---|
55 | foreach( $percent_underscores as $percent_underscore ) { |
---|
56 | $results[ $rows ][ $percent_underscore ] = array(); |
---|
57 | foreach( $unique_keys_count as $unique_keys ) { |
---|
58 | $results[ $rows ][ $percent_underscore ][ $unique_keys ] = array(); |
---|
59 | $keys = array(); |
---|
60 | for( $ii = 0; $ii < $unique_keys; $ii++ ) { |
---|
61 | $keys[] = substr( str_shuffle( md5( microtime( true ) ) ), 0, 10 ); |
---|
62 | } |
---|
63 | |
---|
64 | $values = array(); |
---|
65 | for( $ii = 0; $ii < $rows; $ii++ ) { |
---|
66 | $underscore = rand( 0, 100 ) < $percent_underscore ? '_' : ''; |
---|
67 | $key = $underscore . $keys[ rand( 0, $unique_keys - 1 ) ]; |
---|
68 | $values[] = $key; |
---|
69 | } |
---|
70 | $values_string = "('" . implode( "'),('", $values ) . "')"; |
---|
71 | $dbh->query( "INSERT INTO wp_postmeta (meta_key) VALUES $values_string" ); |
---|
72 | |
---|
73 | foreach( $queries as $name => $query ) { |
---|
74 | $results[ $rows ][ $percent_underscore ][ $unique_keys ][ $name ] = array(); |
---|
75 | for( $ii = 0; $ii < 100; $ii++ ) { |
---|
76 | $now = microtime( true ); |
---|
77 | $dbh->query( $query ); |
---|
78 | $results[ $rows ][ $percent_underscore ][ $unique_keys ][ $name ][] = microtime( true ) - $now; |
---|
79 | } |
---|
80 | rsort( $results[ $rows ][ $percent_underscore ][ $unique_keys ][ $name ] ); |
---|
81 | echo "$engine, $rows, $percent_underscore, $unique_keys, $name: " . $results[ $rows ][ $percent_underscore ][ $unique_keys ][ $name ][49] . "\n"; |
---|
82 | } |
---|
83 | |
---|
84 | $dbh->query( "TRUNCATE TABLE wp_postmeta" ); |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|