$result = bmark_query($sql, $dbh);
# print $sql . "\n";
$sql = 'create index login_index on users_no_partition (login)';
$result = bmark_query($sql, $dbh);
# print $sql . "\n";
for ($i = 0; $i < $max_rows; $i++) {
    $sql = "insert into users_no_partition (login, pass) values (\"" . md5(rand(1, 5000) . microtime()) . "user{$i}\", \"" . md5("pass{$i}") . "\")";
    $result = bmark_query($sql, $dbh);
    # print $sql . "\n";
}
$timer->setMarker('No_Partition');
echo "Elapsed time between Start and Test_Code_Partition: " . $timer->timeElapsed('Start', 'No_Partition') . "\n";
$prefix = "users_";
$k = 1;
for ($i = 0; $i < $parts; $i++) {
    $table = $prefix . padNumber($i, 2);
    $sql = "drop table if exists {$table}";
    # print "table: $table\n";
    # print $sql . "\n";
    $result = bmark_query($sql, $dbh);
    $sql = "CREATE TABLE {$table} ( id INT NOT NULL primary key AUTO_INCREMENT , login varchar(255), email varchar(255), im varchar(255), twitter varchar(255), pass varchar(255), datejoined datetime)  ENGINE=InnoDB DEFAULT CHARSET=utf8";
    $result = bmark_query($sql, $dbh);
    $sql = "create index login_index on {$table} (login)";
    $result = bmark_query($sql, $dbh);
    for ($j = 0; $j < $perpart; $j++) {
        $sql = "insert into {$table} (id, login, pass) values ({$k}, \"" . md5(rand(1, 5000) . microtime()) . "user{$j}\", \"" . md5('pass$j') . "\")";
        $result = bmark_query($sql, $dbh);
        $k++;
    }
}
// create & update the meta table used for the php partition
Exemple #2
0
 function find($table_type, $field, $value, $like = '', $partition_flag = '')
 {
     // drizzle
     if (strcmp($this->database_type, 'drizzle') == 0) {
         if (strcmp($like, 'like') == 0) {
             $like = 'like';
             $value = "'%{$value}'";
         } else {
             $like = '=';
         }
         if (strcmp($partition_flag, 'nopart') == 0) {
             $sql = "select * from {$table_type}" . "_no_partition where {$field} {$like} '{$value}'";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         if (strcmp($partition_flag, 'drizzle') == 0) {
             $sql = "select * from {$table_type} where {$field} {$like} '{$value}'";
             print "partition sql: {$sql}\n";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         // iterate through the tables using the meta_table
         $sql = "select * from meta_table where tablename like \"" . $table_type . "%\"";
         print $sql . "\n";
         try {
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 throw new Exception('meta_table query failed');
             }
         } catch (Exception $e) {
             echo drizzle_con_error($this->connection) . "\n";
             echo "Caught active server error exception:\n", $e->getMessage(), " ", $e->getFile(), ": Line ", $e->getLine(), "\n", $e->getTraceAsString(), "\n";
         }
         drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
         while ($row = drizzle_row_next($result)) {
             print_r($row);
             $current_table = $row[1];
             $iterator = $row[2];
             $last_user_id = $row[3];
         }
         print "current_table: {$current_table}\n";
         // awesome, we got meta data
         // we need to now:
         // go through each table
         // find the info
         // return the info
         // get current_table number
         preg_match('/_[0-9]+/', $current_table, $matches);
         $bar_number = $matches[0];
         preg_match('/[0-9]+/', $bar_number, $matches);
         $table_number = $matches[0];
         // get how long the number is b/c of padding issues later
         $num_length = strlen($table_number);
         $i_table_number = (int) $table_number;
         // for ($i = 0; $i <= $i_table_number; $i++) {
         $i = 0;
         $i_sent = 0;
         $myarray = array();
         while ($i_sent <= 0) {
             // search each partition
             $curr_table = $table_type . "_" . padNumber($i, $num_length);
             $sql = "select * from {$curr_table} where {$field} {$like} '{$value}'";
             print $sql . "\n";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             print "count (myarray) : " . count($myarray) . "\n";
             if (count($myarray) >= 1) {
                 print "count > 1\n";
                 $i_sent = 1;
             }
             if ($i >= $i_table_number) {
                 print "{$i} <= {$i_table_number}\n";
                 $i_sent = 1;
             }
             $i++;
         }
         /*
         			$sql = "select * from $table where $field $like $value";
         			$result = mysql_query($sql, $this->connection);
         			if (!$result) {
         				die('Invalid query: ' . mysql_error());
         			}
         			while($row = mysql_fetch_assoc($result))
         			{
         			  $array[] = $row; 
         			}
         */
         print_r($myarray);
         return $myarray;
     }
     // end of drizzle portion
     // mysql
     if (strcmp($this->database_type, 'mysql') == 0) {
         if (strcmp($like, 'like') == 0) {
             $like = 'like';
             $value = "'%{$value}'";
         } else {
             $like = '=';
         }
         if (strcmp($partition_flag, 'nopart') == 0) {
             $sql = "select SQL_CACHE * from {$table_type}" . "_no_partition where {$field} {$like} '{$value}'";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         if (strcmp($partition_flag, 'mysql') == 0) {
             $sql = "select SQL_CACHE * from {$table_type} where {$field} {$like} '{$value}'";
             print "partition sql: {$sql}\n";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         // iterate through the tables using the meta_table
         $sql = "select SQL_CACHE * from meta_table where tablename like \"" . $table_type . "%\"";
         print $sql . "\n";
         $result = mysql_query($sql, $this->connection);
         if (!$result) {
             die('Cannnot access meta table: ' . mysql_error());
         }
         while ($row = mysql_fetch_assoc($result)) {
             $current_table = $row['tablename'];
             $iterator = $row['iterator'];
             $last_user_id = $row['last_user_id'];
         }
         print "current_table: {$current_table}\n";
         // awesome, we got meta data
         // we need to now:
         // go through each table
         // find the info
         // return the info
         // get current_table number
         preg_match('/_[0-9]+/', $current_table, $matches);
         $bar_number = $matches[0];
         preg_match('/[0-9]+/', $bar_number, $matches);
         $table_number = $matches[0];
         // get how long the number is b/c of padding issues later
         $num_length = strlen($table_number);
         $i_table_number = (int) $table_number;
         // for ($i = 0; $i <= $i_table_number; $i++) {
         $i = 0;
         $i_sent = 0;
         $myarray = array();
         while ($i_sent <= 0) {
             // search each partition
             $curr_table = $table_type . "_" . padNumber($i, $num_length);
             $sql = "select SQL_CACHE * from {$curr_table} where {$field} {$like} '{$value}'";
             print $sql . "\n";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             print "count (myarray) : " . count($myarray) . "\n";
             if (count($myarray) >= 1) {
                 print "count > 1\n";
                 $i_sent = 1;
             }
             if ($i >= $i_table_number) {
                 print "{$i} <= {$i_table_number}\n";
                 $i_sent = 1;
             }
             $i++;
         }
         /*
         			$sql = "select * from $table where $field $like $value";
         			$result = mysql_query($sql, $this->connection);
         			if (!$result) {
         				die('Invalid query: ' . mysql_error());
         			}
         			while($row = mysql_fetch_assoc($result))
         			{
         			  $array[] = $row; 
         			}
         */
         print_r($myarray);
         return $myarray;
     }
     // end of mysql portion
 }