Single faster POST query with primary key
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@822 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
0a26222205
commit
16c4ddb42d
|
@ -3,6 +3,12 @@ $functions = array("char_length", "from_unixtime", "hex", "lower", "round", "sec
|
||||||
$grouping = array("avg", "count", "distinct", "group_concat", "max", "min", "sum"); // distinct is short for COUNT(DISTINCT)
|
$grouping = array("avg", "count", "distinct", "group_concat", "max", "min", "sum"); // distinct is short for COUNT(DISTINCT)
|
||||||
$table_status = table_status($_GET["select"]);
|
$table_status = table_status($_GET["select"]);
|
||||||
$indexes = indexes($_GET["select"]);
|
$indexes = indexes($_GET["select"]);
|
||||||
|
$primary = null; // empty array means that all primary fields are selected
|
||||||
|
foreach ($indexes as $index) {
|
||||||
|
if ($index["type"] == "PRIMARY") {
|
||||||
|
$primary = array_flip($index["columns"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL");
|
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL");
|
||||||
if (eregi('^(MyISAM|Maria)$', $table_status["Engine"])) {
|
if (eregi('^(MyISAM|Maria)$', $table_status["Engine"])) {
|
||||||
$operators[] = "AGAINST";
|
$operators[] = "AGAINST";
|
||||||
|
@ -17,6 +23,9 @@ foreach ($fields as $key => $field) {
|
||||||
if (ereg('text|blob', $field["type"])) {
|
if (ereg('text|blob', $field["type"])) {
|
||||||
$text_length = (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
|
$text_length = (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
|
||||||
}
|
}
|
||||||
|
if (!$_GET["columns"]) {
|
||||||
|
unset($primary[$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$rights += $field["privileges"];
|
$rights += $field["privileges"];
|
||||||
}
|
}
|
||||||
|
@ -29,8 +38,12 @@ foreach ((array) $_GET["columns"] as $key => $val) {
|
||||||
if (!in_array($val["fun"], $grouping)) {
|
if (!in_array($val["fun"], $grouping)) {
|
||||||
$group[] = $select[$key];
|
$group[] = $select[$key];
|
||||||
}
|
}
|
||||||
|
if (!$val["fun"]) {
|
||||||
|
unset($primary[$val["col"]]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$where = array(); // where expressions - will be joined by AND
|
$where = array(); // where expressions - will be joined by AND
|
||||||
foreach ($indexes as $i => $index) {
|
foreach ($indexes as $i => $index) {
|
||||||
if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
|
if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
|
||||||
|
@ -59,29 +72,32 @@ foreach ((array) $_GET["where"] as $val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = array(); // order expressions - will be joined by comma
|
$order = array(); // order expressions - will be joined by comma
|
||||||
foreach ((array) $_GET["order"] as $key => $val) {
|
foreach ((array) $_GET["order"] as $key => $val) {
|
||||||
if (isset($columns[$val]) || in_array($val, $select, true)) {
|
if (isset($columns[$val]) || in_array($val, $select, true)) {
|
||||||
$order[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
|
$order[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
|
$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
|
||||||
$from = ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "");
|
$from = ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "");
|
||||||
$group_by = ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "");
|
$group_by = ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "");
|
||||||
|
|
||||||
if ($_POST && !$error) {
|
if ($_POST && !$error) {
|
||||||
|
$where_check = "(" . implode(") OR (", array_map('where_check', $_POST["check"])) . ")";
|
||||||
if ($_POST["export"]) {
|
if ($_POST["export"]) {
|
||||||
dump_headers($_GET["select"]);
|
dump_headers($_GET["select"]);
|
||||||
dump_table($_GET["select"], "");
|
dump_table($_GET["select"], "");
|
||||||
if (is_array($_POST["check"])) {
|
if (!is_array($_POST["check"]) || $primary === array()) {
|
||||||
|
dump_data($_GET["select"], "INSERT", "SELECT $from" . (is_array($_POST["check"]) ? ($where ? " AND " : " WHERE ") . "($where_check)" : "") . $group_by);
|
||||||
|
} else {
|
||||||
$union = array();
|
$union = array();
|
||||||
foreach ($_POST["check"] as $val) {
|
foreach ($_POST["check"] as $val) {
|
||||||
// where may not be unique so OR can't be used
|
// where is not unique so OR can't be used
|
||||||
$union[] = "(SELECT $from " . ($where ? "AND " : "WHERE ") . where_check($val) . $group_by . " LIMIT 1)";
|
$union[] = "(SELECT $from " . ($where ? "AND " : "WHERE ") . where_check($val) . $group_by . " LIMIT 1)";
|
||||||
}
|
}
|
||||||
dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
|
dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
|
||||||
} else {
|
|
||||||
dump_data($_GET["select"], "INSERT", "SELECT $from$group_by");
|
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +105,7 @@ if ($_POST && !$error) {
|
||||||
$sent = 0;
|
$sent = 0;
|
||||||
if ($_POST["all"] || $_POST["check"]) {
|
if ($_POST["all"] || $_POST["check"]) {
|
||||||
$field = idf_escape($_POST["email_field"]);
|
$field = idf_escape($_POST["email_field"]);
|
||||||
$result = $dbh->query("SELECT DISTINCT $field FROM " . idf_escape($_GET["select"]) . " WHERE $field IS NOT NULL AND $field != ''" . ($where ? " AND " . implode(" AND ", $where) : "") . ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('where_check', $_POST["check"])) . "))"));
|
$result = $dbh->query("SELECT DISTINCT $field FROM " . idf_escape($_GET["select"]) . " WHERE $field IS NOT NULL AND $field != ''" . ($where ? " AND " . implode(" AND ", $where) : "") . ($_POST["all"] ? "" : " AND ($where_check)"));
|
||||||
while ($row = $result->fetch_row()) {
|
while ($row = $result->fetch_row()) {
|
||||||
$sent += mail($row[0], email_header($_POST["email_subject"]), $_POST["email_message"], "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit" . ($_POST["email_from"] ? "\nFrom: " . email_header($_POST["email_from"]) : ""));
|
$sent += mail($row[0], email_header($_POST["email_subject"]), $_POST["email_message"], "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit" . ($_POST["email_from"] ? "\nFrom: " . email_header($_POST["email_from"]) : ""));
|
||||||
}
|
}
|
||||||
|
@ -113,12 +129,12 @@ if ($_POST && !$error) {
|
||||||
$command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . "\nFROM " . idf_escape($_GET["select"]) : " SET\n" . implode(",\n", $set));
|
$command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . "\nFROM " . idf_escape($_GET["select"]) : " SET\n" . implode(",\n", $set));
|
||||||
}
|
}
|
||||||
if ($_POST["delete"] || $set) {
|
if ($_POST["delete"] || $set) {
|
||||||
if ($_POST["all"]) {
|
if ($_POST["all"] || ($primary === array() && $_POST["check"])) {
|
||||||
$result = queries($command . ($where ? "\nWHERE " . implode(" AND ", $where) : ""));
|
$result = queries($command . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
|
||||||
$affected = $dbh->affected_rows;
|
$affected = $dbh->affected_rows;
|
||||||
} else {
|
} else {
|
||||||
foreach ((array) $_POST["check"] as $val) {
|
foreach ((array) $_POST["check"] as $val) {
|
||||||
// where may not be unique so OR can't be used
|
// where is not unique so OR can't be used
|
||||||
$result = queries($command . "\nWHERE " . where_check($val) . "\nLIMIT 1");
|
$result = queries($command . "\nWHERE " . where_check($val) . "\nLIMIT 1");
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue