MySQL: Speed up updating rows without numeric or UTF-8 primary key

This commit is contained in:
Jakub Vrana 2013-06-04 19:40:17 -07:00
parent 8e0ead4678
commit 7dd90f56f1
9 changed files with 12 additions and 29 deletions

View file

@ -375,10 +375,6 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
return nl_br(h(preg_replace('~^(\\[[^]]*])+~m', '', $connection->error))); return nl_br(h(preg_replace('~^(\\[[^]]*])+~m', '', $connection->error)));
} }
function exact_value($val) {
return q($val);
}
function create_database($db, $collation) { function create_database($db, $collation) {
return queries("CREATE DATABASE " . idf_escape($db) . (eregi('^[a-z0-9_]+$', $collation) ? " COLLATE $collation" : "")); return queries("CREATE DATABASE " . idf_escape($db) . (eregi('^[a-z0-9_]+$', $collation) ? " COLLATE $collation" : ""));
} }

View file

@ -532,14 +532,6 @@ if (!defined("DRIVER")) {
} }
} }
/** Return expression for binary comparison
* @param string
* @return string
*/
function exact_value($val) {
return q($val) . " COLLATE utf8_bin";
}
/** Create database /** Create database
* @param string * @param string
* @param string * @param string
@ -983,7 +975,7 @@ if (!defined("DRIVER")) {
$return = "UNHEX($return)"; $return = "UNHEX($return)";
} }
if ($field["type"] == "bit") { if ($field["type"] == "bit") {
return "CONV($return, 2, 10) + 0"; $return = "CONV($return, 2, 10) + 0";
} }
if (ereg("geometry|point|linestring|polygon", $field["type"])) { if (ereg("geometry|point|linestring|polygon", $field["type"])) {
$return = "GeomFromText($return)"; $return = "GeomFromText($return)";

View file

@ -270,10 +270,6 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
return h($connection->error); //! highlight sqltext from offset return h($connection->error); //! highlight sqltext from offset
} }
function exact_value($val) {
return q($val);
}
function explain($connection, $query) { function explain($connection, $query) {
$connection->query("EXPLAIN PLAN FOR $query"); $connection->query("EXPLAIN PLAN FOR $query");
return $connection->query("SELECT * FROM plan_table"); return $connection->query("SELECT * FROM plan_table");

View file

@ -326,10 +326,6 @@ ORDER BY conkey, conname") as $row) {
return nl_br($return); return nl_br($return);
} }
function exact_value($val) {
return q($val);
}
function create_database($db, $collation) { function create_database($db, $collation) {
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " ENCODING " . idf_escape($collation) : "")); return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " ENCODING " . idf_escape($collation) : ""));
} }

View file

@ -348,10 +348,6 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
return h($connection->error); return h($connection->error);
} }
function exact_value($val) {
return q($val);
}
function check_sqlite_name($name) { function check_sqlite_name($name) {
// avoid creating PHP files on unsecured servers // avoid creating PHP files on unsecured servers
global $connection; global $connection;

View file

@ -333,9 +333,16 @@ function where($where, $fields = array()) {
$function_pattern = '(^[\w\(]+' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . '\)+$)'; //! columns looking like functions $function_pattern = '(^[\w\(]+' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . '\)+$)'; //! columns looking like functions
foreach ((array) $where["where"] as $key => $val) { foreach ((array) $where["where"] as $key => $val) {
$key = bracket_escape($key, 1); // 1 - back $key = bracket_escape($key, 1); // 1 - back
$return[] = (preg_match($function_pattern, $key) ? $key : idf_escape($key)) //! SQL injection $column = (preg_match($function_pattern, $key) ? $key : idf_escape($key)); //! SQL injection
. (($jush == "sql" && ereg('\\.', $val)) || $jush == "mssql" ? " LIKE " . exact_value(addcslashes($val, "%_\\")) : " = " . unconvert_field($fields[$key], exact_value($val))) // LIKE because of floats, but slow with ints, in MS SQL because of text $return[] = $column
. (($jush == "sql" && ereg('^[0-9]*\\.[0-9]*$', $val)) || $jush == "mssql"
? " LIKE " . q(addcslashes($val, "%_\\"))
: " = " . unconvert_field($fields[$key], q($val))
) // LIKE because of floats but slow with ints, in MS SQL because of text
; //! enum and set ; //! enum and set
if ($jush == "sql" && ereg("[^ -@]", $val)) { // not just [a-z] to catch non-ASCII characters
$return[] = "$column = " . q($val) . " COLLATE utf8_bin";
}
} }
foreach ((array) $where["null"] as $key) { foreach ((array) $where["null"] as $key) {
$return[] = idf_escape($key) . " IS NULL"; $return[] = idf_escape($key) . " IS NULL";

View file

@ -5,6 +5,7 @@ Don't use LIMIT 1 if inline updating unique row
Don't check previous checkbox on added column in create table (bug #3614245) Don't check previous checkbox on added column in create table (bug #3614245)
Order table list by name Order table list by name
Verify UTF-8 encoding of CSV import Verify UTF-8 encoding of CSV import
MySQL: Speed up updating rows without numeric or UTF-8 primary key
PostgreSQL: Fix detecting oid column in PDO PostgreSQL: Fix detecting oid column in PDO
PostgreSQL: Handle timestamp types (bug #3614086) PostgreSQL: Handle timestamp types (bug #3614086)
Add Korean translation Add Korean translation

View file

@ -143,7 +143,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
// find all used ids // find all used ids
$ids = array(); $ids = array();
foreach ($rows as $row) { foreach ($rows as $row) {
$ids[$row[$key]] = exact_value($row[$key]); $ids[$row[$key]] = q($row[$key]);
} }
// uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow // uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
$descriptions = $this->_values[$table]; $descriptions = $this->_values[$table];

View file

@ -21,7 +21,6 @@ Rank, Tree structure
MySQL: MySQL:
Data longer than max_allowed_packet can be sent by mysqli_stmt_send_long_data() Data longer than max_allowed_packet can be sent by mysqli_stmt_send_long_data()
COLLATE utf8_bin comparison doesn't use index with other than UTF-8 columns
SQLite: SQLite:
Copy tables Copy tables