1
0
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:
Jakub Vrana
2025-06-06 10:18:52 +02:00
parent 86ffeb2a1e
commit e282d6eb89
3 changed files with 15 additions and 14 deletions

View File

@@ -4,6 +4,7 @@
- Warn about exceeded max_file_uploads in import - Warn about exceeded max_file_uploads in import
- MySQL 5.0-: Do not load partitioning info in alter table (bug #1099) - MySQL 5.0-: Do not load partitioning info in alter table (bug #1099)
- PostgreSQL: Show structure of inherited tables - PostgreSQL: Show structure of inherited tables
- PostgreSQL: Display index expressions
- PostgreSQL: Add SQL operator to select - PostgreSQL: Add SQL operator to select
- PostgreSQL: Hide only partitions, not all inherited tables from menu - PostgreSQL: Hide only partitions, not all inherited tables from menu
- PostgreSQL 11-: Avoid duplicate oid in table status (bug #1089) - PostgreSQL 11-: Avoid duplicate oid in table status (bug #1089)

View File

@@ -529,7 +529,7 @@ ORDER BY a.attnum") as $row
$table_oid = driver()->tableOid($table); $table_oid = driver()->tableOid($table);
$columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2); $columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2);
foreach ( 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 FROM pg_index
JOIN pg_class ON indexrelid = oid JOIN pg_class ON indexrelid = oid
JOIN pg_am ON pg_am.oid = pg_class.relam JOIN pg_am ON pg_am.oid = pg_class.relam
@@ -537,18 +537,17 @@ WHERE indrelid = $table_oid
ORDER BY indisprimary DESC, indisunique DESC", $connection2) as $row ORDER BY indisprimary DESC, indisunique DESC", $connection2) as $row
) { ) {
$relname = $row["relname"]; $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]["columns"] = array();
$return[$relname]["descs"] = array(); $return[$relname]["descs"] = array();
$return[$relname]["algorithm"] = $row["algorithm"]; $return[$relname]["algorithm"] = $row["amname"];
$return[$relname]["partial"] = $row["partial"]; $return[$relname]["partial"] = $row["partial"];
if ($row["indkey"]) { $indexpr = preg_split('~(?<=\)), (?=\()~', $row["indexpr"]); //! '), (' used in expression
foreach (explode(" ", $row["indkey"]) as $indkey) { 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) { foreach (explode(" ", $row["indoption"]) as $indoption) {
$return[$relname]["descs"][] = (intval($indoption) & 1 ? '1' : null); // 1 - INDOPTION_DESC $return[$relname]["descs"][] = (intval($indoption) & 1 ? '1' : null); // 1 - INDOPTION_DESC
}
} }
$return[$relname]["lengths"] = array(); $return[$relname]["lengths"] = array();
} }

View File

@@ -12,6 +12,7 @@ if (preg_match('~MyISAM|M?aria' . (min_version(5.7, '10.2.2') ? '|InnoDB' : '')
$index_types[] = "SPATIAL"; $index_types[] = "SPATIAL";
} }
$indexes = indexes($TABLE); $indexes = indexes($TABLE);
$fields = fields($TABLE);
$primary = array(); $primary = array();
if (JUSH == "mongo") { // doesn't support primary key if (JUSH == "mongo") { // doesn't support primary key
$primary = $indexes["_id_"]; $primary = $indexes["_id_"];
@@ -38,7 +39,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
if ($column != "") { if ($column != "") {
$length = idx($index["lengths"], $key); $length = idx($index["lengths"], $key);
$desc = idx($index["descs"], $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; $columns[] = $column;
$lengths[] = ($length ?: null); $lengths[] = ($length ?: null);
$descs[] = $desc; $descs[] = $desc;
@@ -81,7 +82,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
page_header(lang('Indexes'), $error, array("table" => $TABLE), h($TABLE)); page_header(lang('Indexes'), $error, array("table" => $TABLE), h($TABLE));
$fields = array_keys(fields($TABLE)); $fields_keys = array_keys($fields);
if ($_POST["add"]) { if ($_POST["add"]) {
foreach ($row["indexes"] as $key => $index) { foreach ($row["indexes"] as $key => $index) {
if ($index["columns"][count($index["columns"])] != "") { if ($index["columns"][count($index["columns"])] != "") {
@@ -138,7 +139,7 @@ if (support("partial_indexes")) {
if ($primary) { if ($primary) {
echo "<tr><td>PRIMARY<td>"; echo "<tr><td>PRIMARY<td>";
foreach ($primary["columns"] as $key => $column) { 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 "<label><input disabled type='checkbox'>" . lang('descending') . "</label> ";
} }
echo "<td><td>\n"; echo "<td><td>\n";
@@ -158,7 +159,7 @@ foreach ($row["indexes"] as $index) {
foreach ($index["columns"] as $key => $column) { foreach ($index["columns"] as $key => $column) {
echo "<span>" . select_input( echo "<span>" . select_input(
" name='indexes[$j][columns][$i]' title='" . lang('Column') . "'", " 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, $column,
"partial(" . ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . ", '" . js_escape(JUSH == "sql" ? "" : $_GET["indexes"] . "_") . "')" "partial(" . ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . ", '" . js_escape(JUSH == "sql" ? "" : $_GET["indexes"] . "_") . "')"
); );