mirror of
https://github.com/vrana/adminer.git
synced 2025-08-05 06:07:57 +02:00
PostgreSQL: Display index expressions
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
- Warn about exceeded max_file_uploads in import
|
||||
- MySQL 5.0-: Do not load partitioning info in alter table (bug #1099)
|
||||
- PostgreSQL: Show structure of inherited tables
|
||||
- PostgreSQL: Display index expressions
|
||||
- PostgreSQL: Add SQL operator to select
|
||||
- PostgreSQL: Hide only partitions, not all inherited tables from menu
|
||||
- PostgreSQL 11-: Avoid duplicate oid in table status (bug #1089)
|
||||
|
@@ -529,7 +529,7 @@ ORDER BY a.attnum") as $row
|
||||
$table_oid = driver()->tableOid($table);
|
||||
$columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2);
|
||||
foreach (
|
||||
get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption, (indpred IS NOT NULL)::int as indispartial, pg_am.amname as algorithm, pg_get_expr(pg_index.indpred, pg_index.indrelid, true) AS partial
|
||||
get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption, amname, pg_get_expr(indpred, indrelid, true) AS partial, pg_get_expr(indexprs, indrelid) AS indexpr
|
||||
FROM pg_index
|
||||
JOIN pg_class ON indexrelid = oid
|
||||
JOIN pg_am ON pg_am.oid = pg_class.relam
|
||||
@@ -537,19 +537,18 @@ WHERE indrelid = $table_oid
|
||||
ORDER BY indisprimary DESC, indisunique DESC", $connection2) as $row
|
||||
) {
|
||||
$relname = $row["relname"];
|
||||
$return[$relname]["type"] = ($row["indispartial"] ? "INDEX" : ($row["indisprimary"] ? "PRIMARY" : ($row["indisunique"] ? "UNIQUE" : "INDEX")));
|
||||
$return[$relname]["type"] = ($row["partial"] ? "INDEX" : ($row["indisprimary"] ? "PRIMARY" : ($row["indisunique"] ? "UNIQUE" : "INDEX")));
|
||||
$return[$relname]["columns"] = array();
|
||||
$return[$relname]["descs"] = array();
|
||||
$return[$relname]["algorithm"] = $row["algorithm"];
|
||||
$return[$relname]["algorithm"] = $row["amname"];
|
||||
$return[$relname]["partial"] = $row["partial"];
|
||||
if ($row["indkey"]) {
|
||||
$indexpr = preg_split('~(?<=\)), (?=\()~', $row["indexpr"]); //! '), (' used in expression
|
||||
foreach (explode(" ", $row["indkey"]) as $indkey) {
|
||||
$return[$relname]["columns"][] = $columns[$indkey];
|
||||
$return[$relname]["columns"][] = ($indkey ? $columns[$indkey] : array_shift($indexpr));
|
||||
}
|
||||
foreach (explode(" ", $row["indoption"]) as $indoption) {
|
||||
$return[$relname]["descs"][] = (intval($indoption) & 1 ? '1' : null); // 1 - INDOPTION_DESC
|
||||
}
|
||||
}
|
||||
$return[$relname]["lengths"] = array();
|
||||
}
|
||||
return $return;
|
||||
|
@@ -12,6 +12,7 @@ if (preg_match('~MyISAM|M?aria' . (min_version(5.7, '10.2.2') ? '|InnoDB' : '')
|
||||
$index_types[] = "SPATIAL";
|
||||
}
|
||||
$indexes = indexes($TABLE);
|
||||
$fields = fields($TABLE);
|
||||
$primary = array();
|
||||
if (JUSH == "mongo") { // doesn't support primary key
|
||||
$primary = $indexes["_id_"];
|
||||
@@ -38,7 +39,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
|
||||
if ($column != "") {
|
||||
$length = idx($index["lengths"], $key);
|
||||
$desc = idx($index["descs"], $key);
|
||||
$set[] = idf_escape($column) . ($length ? "(" . (+$length) . ")" : "") . ($desc ? " DESC" : "");
|
||||
$set[] = ($fields[$column] ? idf_escape($column) : $column) . ($length ? "(" . (+$length) . ")" : "") . ($desc ? " DESC" : "");
|
||||
$columns[] = $column;
|
||||
$lengths[] = ($length ?: null);
|
||||
$descs[] = $desc;
|
||||
@@ -81,7 +82,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
|
||||
|
||||
page_header(lang('Indexes'), $error, array("table" => $TABLE), h($TABLE));
|
||||
|
||||
$fields = array_keys(fields($TABLE));
|
||||
$fields_keys = array_keys($fields);
|
||||
if ($_POST["add"]) {
|
||||
foreach ($row["indexes"] as $key => $index) {
|
||||
if ($index["columns"][count($index["columns"])] != "") {
|
||||
@@ -138,7 +139,7 @@ if (support("partial_indexes")) {
|
||||
if ($primary) {
|
||||
echo "<tr><td>PRIMARY<td>";
|
||||
foreach ($primary["columns"] as $key => $column) {
|
||||
echo select_input(" disabled", $fields, $column);
|
||||
echo select_input(" disabled", $fields_keys, $column);
|
||||
echo "<label><input disabled type='checkbox'>" . lang('descending') . "</label> ";
|
||||
}
|
||||
echo "<td><td>\n";
|
||||
@@ -158,7 +159,7 @@ foreach ($row["indexes"] as $index) {
|
||||
foreach ($index["columns"] as $key => $column) {
|
||||
echo "<span>" . select_input(
|
||||
" name='indexes[$j][columns][$i]' title='" . lang('Column') . "'",
|
||||
($fields ? array_combine($fields, $fields) : $fields),
|
||||
($fields && ($column == "" || $fields[$column]) ? array_combine($fields_keys, $fields_keys) : array()),
|
||||
$column,
|
||||
"partial(" . ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . ", '" . js_escape(JUSH == "sql" ? "" : $_GET["indexes"] . "_") . "')"
|
||||
);
|
||||
|
Reference in New Issue
Block a user