]> git.joonet.de Git - adminer.git/commitdiff
Warn about selecting data without index
authorJakub Vrana <jakub@vrana.cz>
Thu, 17 May 2012 06:54:56 +0000 (23:54 -0700)
committerJakub Vrana <jakub@vrana.cz>
Thu, 17 May 2012 07:13:13 +0000 (00:13 -0700)
adminer/include/adminer.inc.php
adminer/lang/cs.inc.php
adminer/lang/xx.inc.php
adminer/select.inc.php
adminer/static/functions.js
changes.txt
editor/include/adminer.inc.php

index 8cca2c7db668548c89f6b11c98d82d18922af71f..868deb787fc61ee9af59b3157d4cf9d0a32c2df7 100644 (file)
@@ -233,23 +233,22 @@ username.form['auth[driver]'].onchange();
                foreach ($indexes as $i => $index) {
                        if ($index["type"] == "FULLTEXT") {
                                echo "(<i>" . implode("</i>, <i>", array_map('h', $index["columns"])) . "</i>) AGAINST";
-                               echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "'>";
+                               echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "' onchange='selectFieldChange(this.form);'>";
                                echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
                                echo "<br>\n";
                        }
                }
-               $i = 0;
-               foreach ((array) $_GET["where"] as $val) {
-                       if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
-                               echo "<div><select name='where[$i][col]'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
-                               echo html_select("where[$i][op]", $this->operators, $val["op"]);
-                               echo "<input name='where[$i][val]' value='" . h($val["val"]) . "'></div>\n";
-                               $i++;
+               $_GET["where"] = (array) $_GET["where"];
+               reset($_GET["where"]);
+               $change_next = "this.nextSibling.onchange();";
+               for ($i = 0; $i <= count($_GET["where"]); $i++) {
+                       list(, $val) = each($_GET["where"]);
+                       if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) {
+                               echo "<div><select name='where[$i][col]' onchange='$change_next'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
+                               echo html_select("where[$i][op]", $this->operators, $val["op"], $change_next);
+                               echo "<input name='where[$i][val]' value='" . h($val["val"]) . "' onchange='" . ($val ? "selectFieldChange(this.form)" : "selectAddRow(this)") . ";'></div>\n";
                        }
                }
-               echo "<div><select name='where[$i][col]' onchange='this.nextSibling.nextSibling.onchange();'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, null, true) . "</select>";
-               echo html_select("where[$i][op]", $this->operators, "=");
-               echo "<input name='where[$i][val]' onchange='selectAddRow(this);'></div>\n";
                echo "</div></fieldset>\n";
        }
        
@@ -264,7 +263,7 @@ username.form['auth[driver]'].onchange();
                $i = 0;
                foreach ((array) $_GET["order"] as $key => $val) {
                        if (isset($columns[$val])) {
-                               echo "<div><select name='order[$i]'><option>" . optionlist($columns, $val, true) . "</select>";
+                               echo "<div><select name='order[$i]' onchange='selectFieldChange(this.form);'><option>" . optionlist($columns, $val, true) . "</select>";
                                echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "</div>\n";
                                $i++;
                        }
@@ -297,11 +296,28 @@ username.form['auth[driver]'].onchange();
        }
        
        /** Print action box in select
+       * @param array
        * @return null
        */
-       function selectActionPrint() {
+       function selectActionPrint($indexes) {
                echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
                echo "<input type='submit' value='" . lang('Select') . "'>";
+               echo " <span id='noindex' title='" . lang('Full table scan') . "'></span>";
+               echo "<script type='text/javascript'>\n";
+               echo "var indexColumns = ";
+               $columns = array();
+               foreach ($indexes as $index) {
+                       if ($index["type"] != "FULLTEXT") {
+                               $columns[reset($index["columns"])] = 1;
+                       }
+               }
+               $columns[""] = 1;
+               foreach ($columns as $key => $val) {
+                       json_row($key);
+               }
+               echo ";\n";
+               echo "selectFieldChange(document.getElementById('form'));\n";
+               echo "</script>\n";
                echo "</div></fieldset>\n";
        }
        
index b9f6e9562d8db36e61890616d4d44da66a5f6592..26f73d57146db73feef82de3db09605386a3a045 100644 (file)
@@ -227,6 +227,7 @@ $translations = array(
        'Limit' => 'Limit',
        'Text length' => 'Délka textů',
        'Action' => 'Akce',
+       'Full table scan' => 'Průchod celé tabulky',
        'Unable to select the table' => 'Nepodařilo se vypsat tabulku',
        'No rows.' => 'Žádné řádky.',
        '%d row(s)' => array('%d řádek', '%d řádky', '%d řádků'),
index 15b795a76e9ceecc05f3293dde849dcbef6ab3da..eefb999108251dc1cc9dbb67af0beb690568a246 100644 (file)
@@ -227,6 +227,7 @@ $translations = array(
        'Limit' => 'xx',
        'Text length' => 'xx',
        'Action' => 'xx',
+       'Full table scan' => 'xx',
        'Unable to select the table' => 'xx',
        'No rows.' => 'xx',
        '%d row(s)' => array('xx', 'xx'),
index c98fc2de8f42854ca2bc49c9d91359173b192837..1e239faff86b63b1fbff72db8c39bee60e2de02c 100644 (file)
@@ -209,7 +209,7 @@ if (!$columns) {
        $adminer->selectOrderPrint($order, $columns, $indexes);
        $adminer->selectLimitPrint($limit);
        $adminer->selectLengthPrint($text_length);
-       $adminer->selectActionPrint();
+       $adminer->selectActionPrint($indexes);
        echo "</form>\n";
        
        $page = $_GET["page"];
index 455b4989ba7d807df785849c8774d78d8d02ae0c..6933bd52a456a10ca312a7e64cfa713bd92bd294 100644 (file)
@@ -167,7 +167,10 @@ function pageClick(href, page, event) {
 * @param HTMLSelectElement
 */
 function selectAddRow(field) {
-       field.onchange = function () { };
+       field.onchange = function () {
+               selectFieldChange(field.form);
+       };
+       field.onchange();
        var row = field.parentNode.cloneNode(true);
        var selects = row.getElementsByTagName('select');
        for (var i=0; i < selects.length; i++) {
@@ -183,7 +186,44 @@ function selectAddRow(field) {
        field.parentNode.parentNode.appendChild(row);
 }
 
-
+/** Check whether the query will be executed with index
+* @param HTMLFormElement
+*/
+function selectFieldChange(form) {
+       var ok = (function () {
+               var inputs = form.getElementsByTagName('input');
+               for (var i=0; i < inputs.length; i++) {
+                       var input = inputs[i];
+                       if (/^fulltext/.test(input.name) && input.value) {
+                               return true;
+                       }
+               }
+               var ok = true;
+               var selects = form.getElementsByTagName('select');
+               for (var i=0; i < selects.length; i++) {
+                       var select = selects[i];
+                       var col = selectValue(select);
+                       var match = /^(where.+)col\]/.exec(select.name);
+                       if (match) {
+                               var op = selectValue(form[match[1] + 'op]']);
+                               var val = form[match[1] + 'val]'].value;
+                               if (col in indexColumns && (!/LIKE|REGEXP/.test(op) || (op == 'LIKE' && val.charAt(0) != '%'))) {
+                                       return true;
+                               } else if (col || val) {
+                                       ok = false;
+                               }
+                       }
+                       if (col && /^order/.test(select.name)) {
+                               if (!(col in indexColumns)) {
+                                        ok = false;
+                               }
+                               break;
+                       }
+               }
+               return ok;
+       })();
+       setHtml('noindex', (ok ? '' : '!'));
+}
 
 
 
index bff4c4b88a2fc340fd044c563a878ff37e4c9993..9dd4d3c8a2db4e34f60b430e64f419d142b761c9 100644 (file)
@@ -2,6 +2,7 @@ Adminer 3.4.0-dev:
 Print current time next to executed SQL queries
 Highlight code in SQL command by CodeMirror
 Link to descending order
+Warn about selecting data without index
 Allow specifying database in login form
 Link to original table in EXPLAIN of SELECT * FROM table t
 MySQL: inform about disabled event_scheduler
index 4e8861778b507eeab591f5ca9d0a6063f509a221..1fc4157436c7d6bd5d7cfe1622aae30eb6f77422 100644 (file)
@@ -271,7 +271,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
        function selectLengthPrint($text_length) {
        }
        
-       function selectActionPrint() {
+       function selectActionPrint($indexes) {
                echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
                echo "<input type='submit' value='" . lang('Select') . "'>";
                echo "</div></fieldset>\n";