#550124 by c960657, catch, and Crell: Remove prepared statement caching, which was a nice idea, but uses up tons of memory without any tangible performance benefits.

merge-requests/26/head
Angie Byron 2010-02-12 06:58:43 +00:00
parent 8bd39cd981
commit 9ce1c6339f
3 changed files with 9 additions and 34 deletions

View File

@ -201,16 +201,6 @@ abstract class DatabaseConnection extends PDO {
*/
protected $logger = NULL;
/**
* Cache of prepared statements.
*
* This cache only lasts as long as the current page request, so it's not
* as useful as it could be, but every little bit helps.
*
* @var Array
*/
protected $preparedStatements = array();
/**
* Track the number of "layers" of transactions currently active.
*
@ -446,26 +436,14 @@ abstract class DatabaseConnection extends PDO {
* @param $query
* The query string as SQL, with curly-braces surrounding the
* table names.
* @param $cache
* Whether or not to cache the prepared statement for later reuse in this
* same request. Usually we want to, but queries that require preprocessing
* cannot be safely cached.
* @return DatabaseStatementInterface
* A PDO prepared statement ready for its execute() method.
*/
public function prepareQuery($query, $cache = TRUE) {
public function prepareQuery($query) {
$query = $this->prefixTables($query);
if (isset($this->preparedStatements[$query])) {
$stmt = $this->preparedStatements[$query];
}
else {
// Call PDO::prepare.
$stmt = parent::prepare($query);
if ($cache) {
$this->preparedStatements[$query] = $stmt;
}
}
return $stmt;
// Call PDO::prepare.
return parent::prepare($query);
}
/**
@ -581,8 +559,8 @@ abstract class DatabaseConnection extends PDO {
$stmt->execute(NULL, $options);
}
else {
$modified = $this->expandArguments($query, $args);
$stmt = $this->prepareQuery($query, !$modified);
$this->expandArguments($query, $args);
$stmt = $this->prepareQuery($query);
$stmt->execute($args, $options);
}

View File

@ -69,8 +69,8 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
$stmt->execute(NULL, $options);
}
else {
$modified = $this->expandArguments($query, $args);
$stmt = $this->prepareQuery($query, !$modified);
$this->expandArguments($query, $args);
$stmt = $this->prepareQuery($query);
$stmt->execute($args, $options);
}

View File

@ -161,10 +161,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
return isset($specials[$operator]) ? $specials[$operator] : NULL;
}
public function prepareQuery($query, $cache = TRUE) {
// It makes no sense to use the static prepared statement cache here,
// because all the work in our implementation is done in
// DatabaseStatement_sqlite::execute() and cannot be cached.
public function prepareQuery($query) {
return $this->prepare($this->prefixTables($query));
}