1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-09 16:17:48 +02:00

PostgreSQL: Fix slow query

This commit is contained in:
Jakub Vrana
2018-03-10 17:16:07 +01:00
parent 88438cd607
commit 19034c35fe

View File

@@ -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);
}
return new Min_Result($result);
if ($this->timeout) {
$this->timeout = 0;
$this->query("RESET statement_timeout");
}
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) {