Warn about selecting data without index

This commit is contained in:
Jakub Vrana 2012-05-16 23:54:56 -07:00
parent b0666e537d
commit 739bcb0979
7 changed files with 76 additions and 17 deletions

View file

@ -233,23 +233,22 @@ username.form['auth[driver]'].onchange();
foreach ($indexes as $i => $index) { foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT") { if ($index["type"] == "FULLTEXT") {
echo "(<i>" . implode("</i>, <i>", array_map('h', $index["columns"])) . "</i>) AGAINST"; 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 checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
echo "<br>\n"; echo "<br>\n";
} }
} }
$i = 0; $_GET["where"] = (array) $_GET["where"];
foreach ((array) $_GET["where"] as $val) { reset($_GET["where"]);
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) { $change_next = "this.nextSibling.onchange();";
echo "<div><select name='where[$i][col]'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>"; for ($i = 0; $i <= count($_GET["where"]); $i++) {
echo html_select("where[$i][op]", $this->operators, $val["op"]); list(, $val) = each($_GET["where"]);
echo "<input name='where[$i][val]' value='" . h($val["val"]) . "'></div>\n"; if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) {
$i++; 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"; echo "</div></fieldset>\n";
} }
@ -264,7 +263,7 @@ username.form['auth[driver]'].onchange();
$i = 0; $i = 0;
foreach ((array) $_GET["order"] as $key => $val) { foreach ((array) $_GET["order"] as $key => $val) {
if (isset($columns[$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"; echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "</div>\n";
$i++; $i++;
} }
@ -297,11 +296,28 @@ username.form['auth[driver]'].onchange();
} }
/** Print action box in select /** Print action box in select
* @param array
* @return null * @return null
*/ */
function selectActionPrint() { function selectActionPrint($indexes) {
echo "<fieldset><legend>" . lang('Action') . "</legend><div>"; echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
echo "<input type='submit' value='" . lang('Select') . "'>"; 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"; echo "</div></fieldset>\n";
} }

View file

@ -227,6 +227,7 @@ $translations = array(
'Limit' => 'Limit', 'Limit' => 'Limit',
'Text length' => 'Délka textů', 'Text length' => 'Délka textů',
'Action' => 'Akce', 'Action' => 'Akce',
'Full table scan' => 'Průchod celé tabulky',
'Unable to select the table' => 'Nepodařilo se vypsat tabulku', 'Unable to select the table' => 'Nepodařilo se vypsat tabulku',
'No rows.' => 'Žádné řádky.', 'No rows.' => 'Žádné řádky.',
'%d row(s)' => array('%d řádek', '%d řádky', '%d řádků'), '%d row(s)' => array('%d řádek', '%d řádky', '%d řádků'),

View file

@ -227,6 +227,7 @@ $translations = array(
'Limit' => 'xx', 'Limit' => 'xx',
'Text length' => 'xx', 'Text length' => 'xx',
'Action' => 'xx', 'Action' => 'xx',
'Full table scan' => 'xx',
'Unable to select the table' => 'xx', 'Unable to select the table' => 'xx',
'No rows.' => 'xx', 'No rows.' => 'xx',
'%d row(s)' => array('xx', 'xx'), '%d row(s)' => array('xx', 'xx'),

View file

@ -209,7 +209,7 @@ if (!$columns) {
$adminer->selectOrderPrint($order, $columns, $indexes); $adminer->selectOrderPrint($order, $columns, $indexes);
$adminer->selectLimitPrint($limit); $adminer->selectLimitPrint($limit);
$adminer->selectLengthPrint($text_length); $adminer->selectLengthPrint($text_length);
$adminer->selectActionPrint(); $adminer->selectActionPrint($indexes);
echo "</form>\n"; echo "</form>\n";
$page = $_GET["page"]; $page = $_GET["page"];

View file

@ -167,7 +167,10 @@ function pageClick(href, page, event) {
* @param HTMLSelectElement * @param HTMLSelectElement
*/ */
function selectAddRow(field) { function selectAddRow(field) {
field.onchange = function () { }; field.onchange = function () {
selectFieldChange(field.form);
};
field.onchange();
var row = field.parentNode.cloneNode(true); var row = field.parentNode.cloneNode(true);
var selects = row.getElementsByTagName('select'); var selects = row.getElementsByTagName('select');
for (var i=0; i < selects.length; i++) { for (var i=0; i < selects.length; i++) {
@ -183,7 +186,44 @@ function selectAddRow(field) {
field.parentNode.parentNode.appendChild(row); 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 ? '' : '!'));
}

View file

@ -2,6 +2,7 @@ Adminer 3.4.0-dev:
Print current time next to executed SQL queries Print current time next to executed SQL queries
Highlight code in SQL command by CodeMirror Highlight code in SQL command by CodeMirror
Link to descending order Link to descending order
Warn about selecting data without index
Allow specifying database in login form Allow specifying database in login form
Link to original table in EXPLAIN of SELECT * FROM table t Link to original table in EXPLAIN of SELECT * FROM table t
MySQL: inform about disabled event_scheduler MySQL: inform about disabled event_scheduler

View file

@ -271,7 +271,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
function selectLengthPrint($text_length) { function selectLengthPrint($text_length) {
} }
function selectActionPrint() { function selectActionPrint($indexes) {
echo "<fieldset><legend>" . lang('Action') . "</legend><div>"; echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
echo "<input type='submit' value='" . lang('Select') . "'>"; echo "<input type='submit' value='" . lang('Select') . "'>";
echo "</div></fieldset>\n"; echo "</div></fieldset>\n";