PostgreSQL: Added support for materialized views
This commit is contained in:
parent
51986426b7
commit
abc8be3317
|
@ -82,7 +82,7 @@ if ($adminer->homepage()) {
|
||||||
echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
|
echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
|
||||||
echo '<th>' . (support("table") || support("indexes") ? '<a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>' : h($name));
|
echo '<th>' . (support("table") || support("indexes") ? '<a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>' : h($name));
|
||||||
if ($view) {
|
if ($view) {
|
||||||
echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . lang('View') . '</a>';
|
echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . (preg_match('~materialized~i', $type) ? lang('Materialized View') : lang('View')) . '</a>';
|
||||||
echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
|
echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
|
||||||
} else {
|
} else {
|
||||||
foreach (array(
|
foreach (array(
|
||||||
|
@ -144,6 +144,7 @@ if ($adminer->homepage()) {
|
||||||
|
|
||||||
echo '<p class="links"><a href="' . h(ME) . 'create=">' . lang('Create table') . "</a>\n";
|
echo '<p class="links"><a href="' . h(ME) . 'create=">' . lang('Create table') . "</a>\n";
|
||||||
echo (support("view") ? '<a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n" : "");
|
echo (support("view") ? '<a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n" : "");
|
||||||
|
echo (support("materializedview") ? '<a href="' . h(ME) . 'view=&materialized=1">' . lang('Create materialized view') . "</a>\n" : "");
|
||||||
|
|
||||||
if (support("routine")) {
|
if (support("routine")) {
|
||||||
echo "<h3 id='routines'>" . lang('Routines') . "</h3>\n";
|
echo "<h3 id='routines'>" . lang('Routines') . "</h3>\n";
|
||||||
|
|
|
@ -225,7 +225,12 @@ if (isset($_GET["pgsql"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function tables_list() {
|
function tables_list() {
|
||||||
return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema() ORDER BY table_name");
|
return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema()
|
||||||
|
UNION ALL
|
||||||
|
SELECT matviewname, 'MATERIALIZED VIEW'
|
||||||
|
FROM pg_matviews
|
||||||
|
WHERE schemaname = current_schema()
|
||||||
|
ORDER BY table_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
function count_tables($databases) {
|
function count_tables($databases) {
|
||||||
|
@ -234,9 +239,9 @@ if (isset($_GET["pgsql"])) {
|
||||||
|
|
||||||
function table_status($name = "") {
|
function table_status($name = "") {
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach (get_rows("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN 'table' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\", relhasoids::int AS \"Oid\", reltuples as \"Rows\"
|
foreach (get_rows("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN 'table' WHEN 'mv' THEN 'materialized view' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\", relhasoids::int AS \"Oid\", reltuples as \"Rows\"
|
||||||
FROM pg_class
|
FROM pg_class
|
||||||
WHERE relkind IN ('r','v')
|
WHERE relkind IN ('r','v','mv')
|
||||||
AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
|
AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
|
||||||
" . ($name != "" ? "AND relname = " . q($name) : "ORDER BY relname")
|
" . ($name != "" ? "AND relname = " . q($name) : "ORDER BY relname")
|
||||||
) as $row) { //! Index_length, Auto_increment
|
) as $row) { //! Index_length, Auto_increment
|
||||||
|
@ -246,7 +251,7 @@ AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema(
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_view($table_status) {
|
function is_view($table_status) {
|
||||||
return $table_status["Engine"] == "view";
|
return in_array($table_status["Engine"], array("view", "materialized view"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function fk_support($table_status) {
|
function fk_support($table_status) {
|
||||||
|
@ -467,21 +472,23 @@ ORDER BY conkey, conname") as $row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drop_views($views) {
|
function drop_views($views) {
|
||||||
return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
|
return drop_tables($views);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drop_tables($tables) {
|
function drop_tables($tables) {
|
||||||
return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
|
foreach ($tables as $table) {
|
||||||
|
$status = table_status($table);
|
||||||
|
if (!queries("DROP " . strtoupper($status["Engine"]) . " " . table($table))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function move_tables($tables, $views, $target) {
|
function move_tables($tables, $views, $target) {
|
||||||
foreach ($tables as $table) {
|
foreach (array_merge($tables, $views) as $table) {
|
||||||
if (!queries("ALTER TABLE " . table($table) . " SET SCHEMA " . idf_escape($target))) {
|
$status = table_status($table);
|
||||||
return false;
|
if (!queries("ALTER " . strtoupper($status["Engine"]) . " " . table($table) . " SET SCHEMA " . idf_escape($target))) {
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($views as $table) {
|
|
||||||
if (!queries("ALTER VIEW " . table($table) . " SET SCHEMA " . idf_escape($target))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,7 +619,7 @@ AND typelem = 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
function support($feature) {
|
function support($feature) {
|
||||||
return preg_match('~^(database|table|columns|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
|
return preg_match('~^(database|table|columns|sql|indexes|comment|view|materializedview|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
|
||||||
}
|
}
|
||||||
|
|
||||||
$jush = "pgsql";
|
$jush = "pgsql";
|
||||||
|
|
|
@ -180,11 +180,13 @@ $translations = array(
|
||||||
'Values' => 'Hodnoty',
|
'Values' => 'Hodnoty',
|
||||||
|
|
||||||
'View' => 'Pohled',
|
'View' => 'Pohled',
|
||||||
|
'Materialized View' => 'Materializovaný pohled',
|
||||||
'View has been dropped.' => 'Pohled byl odstraněn.',
|
'View has been dropped.' => 'Pohled byl odstraněn.',
|
||||||
'View has been altered.' => 'Pohled byl změněn.',
|
'View has been altered.' => 'Pohled byl změněn.',
|
||||||
'View has been created.' => 'Pohled byl vytvořen.',
|
'View has been created.' => 'Pohled byl vytvořen.',
|
||||||
'Alter view' => 'Pozměnit pohled',
|
'Alter view' => 'Pozměnit pohled',
|
||||||
'Create view' => 'Vytvořit pohled',
|
'Create view' => 'Vytvořit pohled',
|
||||||
|
'Create materialized view' => 'Vytvořit materializovaný pohled',
|
||||||
|
|
||||||
'Indexes' => 'Indexy',
|
'Indexes' => 'Indexy',
|
||||||
'Indexes have been altered.' => 'Indexy byly změněny.',
|
'Indexes have been altered.' => 'Indexy byly změněny.',
|
||||||
|
|
|
@ -180,11 +180,13 @@ $translations = array(
|
||||||
'Values' => 'xx',
|
'Values' => 'xx',
|
||||||
|
|
||||||
'View' => 'xx',
|
'View' => 'xx',
|
||||||
|
'Materialized View' => 'xx',
|
||||||
'View has been dropped.' => 'xx',
|
'View has been dropped.' => 'xx',
|
||||||
'View has been altered.' => 'xx',
|
'View has been altered.' => 'xx',
|
||||||
'View has been created.' => 'xx',
|
'View has been created.' => 'xx',
|
||||||
'Alter view' => 'xx',
|
'Alter view' => 'xx',
|
||||||
'Create view' => 'xx',
|
'Create view' => 'xx',
|
||||||
|
'Create materialized view' => 'xx',
|
||||||
|
|
||||||
'Indexes' => 'xx',
|
'Indexes' => 'xx',
|
||||||
'Indexes have been altered.' => 'xx',
|
'Indexes have been altered.' => 'xx',
|
||||||
|
|
|
@ -8,16 +8,26 @@ if ($_POST && !$error) {
|
||||||
$location = ME . "table=" . urlencode($name);
|
$location = ME . "table=" . urlencode($name);
|
||||||
$message = lang('View has been altered.');
|
$message = lang('View has been altered.');
|
||||||
|
|
||||||
if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite") {
|
if ($_GET["materialized"]) {
|
||||||
|
$type = "MATERIALIZED VIEW";
|
||||||
|
} else {
|
||||||
|
$type = "VIEW";
|
||||||
|
if ($jush == "pgsql") {
|
||||||
|
$status = table_status($name);
|
||||||
|
$type = ($status ? strtoupper($status["Engine"]) : $type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type != "MATERIALIZED VIEW") {
|
||||||
query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message);
|
query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message);
|
||||||
} else {
|
} else {
|
||||||
$temp_name = $name . "_adminer_" . uniqid();
|
$temp_name = $name . "_adminer_" . uniqid();
|
||||||
drop_create(
|
drop_create(
|
||||||
"DROP VIEW " . table($TABLE),
|
"DROP $type " . table($TABLE),
|
||||||
"CREATE VIEW " . table($name) . $as,
|
"CREATE $type " . table($name) . $as,
|
||||||
"DROP VIEW " . table($name),
|
"DROP $type " . table($name),
|
||||||
"CREATE VIEW " . table($temp_name) . $as,
|
"CREATE $type " . table($temp_name) . $as,
|
||||||
"DROP VIEW " . table($temp_name),
|
"DROP $type " . table($temp_name),
|
||||||
($_POST["drop"] ? substr(ME, 0, -1) : $location),
|
($_POST["drop"] ? substr(ME, 0, -1) : $location),
|
||||||
lang('View has been dropped.'),
|
lang('View has been dropped.'),
|
||||||
$message,
|
$message,
|
||||||
|
|
Loading…
Reference in a new issue