]> git.joonet.de Git - adminer.git/commitdiff
MySQL: Speed up updating rows without numeric or UTF-8 primary key
authorJakub Vrana <jakub@vrana.cz>
Wed, 5 Jun 2013 02:40:17 +0000 (19:40 -0700)
committerJakub Vrana <jakub@vrana.cz>
Wed, 5 Jun 2013 02:40:17 +0000 (19:40 -0700)
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/functions.inc.php
changes.txt
editor/include/adminer.inc.php
todo.txt

index 90e639f55d4b5169bc8ac7b617d2e20dc8808a42..17049760ca50c2fb723f67fc72610779df49ffda 100644 (file)
@@ -375,10 +375,6 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
                return nl_br(h(preg_replace('~^(\\[[^]]*])+~m', '', $connection->error)));
        }
        
-       function exact_value($val) {
-               return q($val);
-       }
-
        function create_database($db, $collation) {
                return queries("CREATE DATABASE " . idf_escape($db) . (eregi('^[a-z0-9_]+$', $collation) ? " COLLATE $collation" : ""));
        }
index 747a625ba5a698f4b3b09b0f9ca8a65c993e319b..552230ddcfd1b5f28ff94b134624b0aaddaddf6c 100644 (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
        * @param string
        * @param string
@@ -983,7 +975,7 @@ if (!defined("DRIVER")) {
                        $return = "UNHEX($return)";
                }
                if ($field["type"] == "bit") {
-                       return "CONV($return, 2, 10) + 0";
+                       $return = "CONV($return, 2, 10) + 0";
                }
                if (ereg("geometry|point|linestring|polygon", $field["type"])) {
                        $return = "GeomFromText($return)";
index beae86842ec0365ba762abbee4bce8c41ca632c6..f6545c12d4f7c757c08abd0439ff64eed5b44541 100644 (file)
@@ -270,10 +270,6 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
                return h($connection->error); //! highlight sqltext from offset
        }
        
-       function exact_value($val) {
-               return q($val);
-       }
-       
        function explain($connection, $query) {
                $connection->query("EXPLAIN PLAN FOR $query");
                return $connection->query("SELECT * FROM plan_table");
index 3cbe23b4c499da908b7d097e6099127a2331e87d..2f4af7ad3d0136126f49cb33d69f5bf62249e767 100644 (file)
@@ -326,10 +326,6 @@ ORDER BY conkey, conname") as $row) {
                return nl_br($return);
        }
        
-       function exact_value($val) {
-               return q($val);
-       }
-       
        function create_database($db, $collation) {
                return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " ENCODING " . idf_escape($collation) : ""));
        }
index 7c062d17b5ac6f02ec7ecdc669cc0ddc8db298c0..9059451b604efae54dd70250a8ca7942fe339928 100644 (file)
@@ -348,10 +348,6 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                return h($connection->error);
        }
        
-       function exact_value($val) {
-               return q($val);
-       }
-       
        function check_sqlite_name($name) {
                // avoid creating PHP files on unsecured servers
                global $connection;
index 8dbf25b4b9da646fc93712045ccbcf657d097e02..0d32ce24d669564567785c3caf3d5db53e984dd4 100644 (file)
@@ -333,9 +333,16 @@ function where($where, $fields = array()) {
        $function_pattern = '(^[\w\(]+' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . '\)+$)'; //! columns looking like functions
        foreach ((array) $where["where"] as $key => $val) {
                $key = bracket_escape($key, 1); // 1 - back
-               $return[] = (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
+               $column = (preg_match($function_pattern, $key) ? $key : idf_escape($key)); //! SQL injection
+               $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
+               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) {
                $return[] = idf_escape($key) . " IS NULL";
index a65716fc764df8cc2a8f7ad69caaa04f79763a1b..9db1bb72ca3755ce4dc98b11a4381326d77db246 100644 (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)
 Order table list by name
 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: Handle timestamp types (bug #3614086)
 Add Korean translation
index 4f1cfd9be76c6a451b5ec4f86894aa6ea8fe8bbd..81c92c1b90fbbf6e1a887b549f05ca49f985239f 100644 (file)
@@ -143,7 +143,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
                                // find all used ids
                                $ids = array();
                                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
                                $descriptions = $this->_values[$table];
index 5e04a7bf5d28d3687aae4273db053609d325b0b5..0424e290124c70b0df37a48052d3da0115b9a3d4 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -21,7 +21,6 @@ Rank, Tree structure
 
 MySQL:
 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:
 Copy tables