From: Jakub Vrana Date: Sat, 10 Mar 2018 16:16:07 +0000 (+0100) Subject: PostgreSQL: Fix slow query X-Git-Tag: v4.6.3~31 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=19034c35fee457a745a5b05f414de4e6962fee70;p=adminer.git PostgreSQL: Fix slow query --- diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 39a1a6b6..5b4085ed 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -6,7 +6,7 @@ if (isset($_GET["pgsql"])) { define("DRIVER", "pgsql"); if (extension_loaded("pgsql")) { class Min_DB { - var $extension = "PgSQL", $_link, $_result, $_string, $_database = true, $server_info, $affected_rows, $error; + var $extension = "PgSQL", $_link, $_result, $_string, $_database = true, $server_info, $affected_rows, $error, $timeout; function _error($errno, $error) { if (ini_bool("html_errors")) { @@ -69,12 +69,18 @@ if (isset($_GET["pgsql"])) { $this->error = ""; if (!$result) { $this->error = pg_last_error($this->_link); - return false; + $return = false; } elseif (!pg_num_fields($result)) { $this->affected_rows = pg_affected_rows($result); - return true; + $return = true; + } else { + $return = new Min_Result($result); + } + if ($this->timeout) { + $this->timeout = 0; + $this->query("RESET statement_timeout"); } - return new Min_Result($result); + return $return; } function multi_query($query) { @@ -139,7 +145,7 @@ if (isset($_GET["pgsql"])) { } elseif (extension_loaded("pdo_pgsql")) { class Min_DB extends Min_PDO { - var $extension = "PDO_PgSQL"; + var $extension = "PDO_PgSQL", $timeout; function connect($server, $username, $password) { global $adminer; @@ -159,6 +165,15 @@ if (isset($_GET["pgsql"])) { return q($s); } + function query($query, $unbuffered = false) { + $return = parent::query($query, $unbuffered); + if ($this->timeout) { + $this->timeout = 0; + parent::query("RESET statement_timeout"); + } + return $return; + } + function warnings() { return ''; // not implemented in PDO_PgSQL as of PHP 7.2.1 } @@ -194,8 +209,9 @@ if (isset($_GET["pgsql"])) { } function slowQuery($query, $timeout) { - // BEGIN, COMMIT - automatically wrapped into a transaction by pg_query but not by PDO - return "BEGIN; SET LOCAL statement_timeout = " . (1000 * $timeout) . "; $query; COMMIT"; + $this->_conn->query("SET statement_timeout = " . (1000 * $timeout)); + $this->_conn->timeout = 1000 * $timeout; + return $query; } function convertSearch($idf, $val, $field) {