Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for indexes on materialized views (initially for postgresql) #467

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions adminer/drivers/elastic.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ function information_schema() {
function is_view($table_status) {
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return false;
}

function indexes($table, $connection2 = null) {
return array(
array("type" => "PRIMARY", "columns" => array("_id")),
Expand Down
9 changes: 9 additions & 0 deletions adminer/drivers/mongo.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,15 @@ function information_schema() {
function is_view($table_status) {
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return false;
}

function convert_field($field) {
}

Expand Down
9 changes: 9 additions & 0 deletions adminer/drivers/mssql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ function is_view($table_status) {
return $table_status["Engine"] == "VIEW";
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return !is_view($table_status);
}

function fk_support($table_status) {
return true;
}
Expand Down
9 changes: 9 additions & 0 deletions adminer/drivers/mysql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,15 @@ function is_view($table_status) {
return $table_status["Engine"] === null;
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return !is_view($table_status);
}

/** Check if table supports foreign keys
* @param array result of table_status
* @return bool
Expand Down
9 changes: 9 additions & 0 deletions adminer/drivers/oracle.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ function is_view($table_status) {
return $table_status["Engine"] == "view";
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return !is_view($table_status);
}

function fk_support($table_status) {
return true;
}
Expand Down
9 changes: 9 additions & 0 deletions adminer/drivers/pgsql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ function is_view($table_status) {
return in_array($table_status["Engine"], array("view", "materialized view"));
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status){
return $table_status["Engine"] != "view";
}

function fk_support($table_status) {
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions adminer/drivers/sqlite.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ function is_view($table_status) {
return $table_status["Engine"] == "view";
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return !is_view($table_status);
}
function fk_support($table_status) {
global $connection;
return !$connection->result("SELECT sqlite_compileoption_used('OMIT_FOREIGN_KEY')");
Expand Down
45 changes: 23 additions & 22 deletions adminer/table.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$adminer->tableStructurePrint($fields);
}

if (!is_view($table_status)) {
if (index_support($table_status)) {
if (support("indexes")) {
echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
$indexes = indexes($TABLE);
Expand All @@ -28,31 +28,32 @@
}
echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
}

if (fk_support($table_status)) {
echo "<h3 id='foreign-keys'>" . lang('Foreign keys') . "</h3>\n";
$foreign_keys = foreign_keys($TABLE);
if ($foreign_keys) {
echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>" . lang('Source') . "<td>" . lang('Target') . "<td>" . lang('ON DELETE') . "<td>" . lang('ON UPDATE') . "<td></thead>\n";
foreach ($foreign_keys as $name => $foreign_key) {
echo "<tr title='" . h($name) . "'>";
echo "<th><i>" . implode("</i>, <i>", array_map('h', $foreign_key["source"])) . "</i>";
echo "<td><a href='" . h($foreign_key["db"] != "" ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), ME) : ($foreign_key["ns"] != "" ? preg_replace('~ns=[^&]*~', "ns=" . urlencode($foreign_key["ns"]), ME) : ME)) . "table=" . urlencode($foreign_key["table"]) . "'>"
. ($foreign_key["db"] != "" ? "<b>" . h($foreign_key["db"]) . "</b>." : "") . ($foreign_key["ns"] != "" ? "<b>" . h($foreign_key["ns"]) . "</b>." : "") . h($foreign_key["table"])
. "</a>"
;
echo "(<i>" . implode("</i>, <i>", array_map('h', $foreign_key["target"])) . "</i>)";
echo "<td>" . h($foreign_key["on_delete"]) . "\n";
echo "<td>" . h($foreign_key["on_update"]) . "\n";
echo '<td><a href="' . h(ME . 'foreign=' . urlencode($TABLE) . '&name=' . urlencode($name)) . '">' . lang('Alter') . '</a>';
}
echo "</table>\n";
}

if (!is_view($table_status)) {
echo "<h3 id='foreign-keys'>" . lang('Foreign keys') . "</h3>\n";
$foreign_keys = foreign_keys($TABLE);
if ($foreign_keys) {
echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>" . lang('Source') . "<td>" . lang('Target') . "<td>" . lang('ON DELETE') . "<td>" . lang('ON UPDATE') . "<td></thead>\n";
foreach ($foreign_keys as $name => $foreign_key) {
echo "<tr title='" . h($name) . "'>";
echo "<th><i>" . implode("</i>, <i>", array_map('h', $foreign_key["source"])) . "</i>";
echo "<td><a href='" . h($foreign_key["db"] != "" ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), ME) : ($foreign_key["ns"] != "" ? preg_replace('~ns=[^&]*~', "ns=" . urlencode($foreign_key["ns"]), ME) : ME)) . "table=" . urlencode($foreign_key["table"]) . "'>"
. ($foreign_key["db"] != "" ? "<b>" . h($foreign_key["db"]) . "</b>." : "") . ($foreign_key["ns"] != "" ? "<b>" . h($foreign_key["ns"]) . "</b>." : "") . h($foreign_key["table"])
. "</a>"
;
echo "(<i>" . implode("</i>, <i>", array_map('h', $foreign_key["target"])) . "</i>)";
echo "<td>" . h($foreign_key["on_delete"]) . "\n";
echo "<td>" . h($foreign_key["on_update"]) . "\n";
echo '<td><a href="' . h(ME . 'foreign=' . urlencode($TABLE) . '&name=' . urlencode($name)) . '">' . lang('Alter') . '</a>';
}
echo '<p class="links"><a href="' . h(ME) . 'foreign=' . urlencode($TABLE) . '">' . lang('Add foreign key') . "</a>\n";
echo "</table>\n";
}
echo '<p class="links"><a href="' . h(ME) . 'foreign=' . urlencode($TABLE) . '">' . lang('Add foreign key') . "</a>\n";
}


if (support(is_view($table_status) ? "view_trigger" : "trigger")) {
echo "<h3 id='triggers'>" . lang('Triggers') . "</h3>\n";
$triggers = triggers($TABLE);
Expand Down
9 changes: 9 additions & 0 deletions plugins/drivers/clickhouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ function is_view($table_status) {
return false;
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return !is_view($table_status);
}

function fk_support($table_status) {
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions plugins/drivers/firebird.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ function is_view($table_status) {
return false;
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return !is_view($table_status);
}

function fk_support($table_status) {
return preg_match('~InnoDB|IBMDB2I~i', $table_status["Engine"]);
}
Expand Down
9 changes: 9 additions & 0 deletions plugins/drivers/simpledb.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ function information_schema() {
function is_view($table_status) {
}

/**
* Check if given table support indexes
* @param $table_status
* @return bool
*/
function index_support($table_status) {
return false;
}

function indexes($table, $connection2 = null) {
return array(
array("type" => "PRIMARY", "columns" => array("itemName()")),
Expand Down