Skip to content

backport showTableStatus from Magento2 #1712

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions lib/Varien/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ class Varien_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql implements V
* @var array|null
*/
protected $_queryHook = null;

/**
* Save if mysql engine is 8 or not.
*
* @var bool
*/
private $isMysql8Engine;


/**
* Begin new DB transaction for connection
Expand Down Expand Up @@ -1057,6 +1065,22 @@ public function modifyColumn($tableName, $columnName, $definition, $flushData =

return $this;
}

/**
* Checks if the engine is mysql 8
*
* @return bool
*/
private function isMysql8EngineUsed(): bool
{
if (!$this->isMysql8Engine) {
$version = $this->fetchPairs("SHOW variables LIKE 'version'")['version'];
$this->isMysql8Engine = (bool) preg_match('/^(8\.)/', $version);
}

return $this->isMysql8Engine;
}


/**
* Show table status
Expand All @@ -1071,9 +1095,18 @@ public function showTableStatus($tableName, $schemaName = null)
if ($schemaName !== null) {
$fromDbName = ' FROM ' . $this->quoteIdentifier($schemaName);
}
$query = sprintf('SHOW TABLE STATUS%s LIKE %s', $fromDbName, $this->quote($tableName));
$query = sprintf('SHOW TABLE STATUS%s LIKE %s', $fromDbName, $this->quote($tableName));
//checks which slq engine used
if (!$this->isMysql8EngineUsed()) {
//if it's not MySQl-8 we just fetch results
return $this->rawFetchRow($query);
}
// Run show table status query in different connection because DDL queries do it in transaction,
// and we don't have actual table statistic in this case
$connection = $this->_transactionLevel ? $this->createConnection() : $this;
$connection->query(sprintf('ANALYZE TABLE %s', $this->quoteIdentifier($tableName)));

return $this->raw_fetchRow($query);
return $connection->query($query)->fetch(\PDO::FETCH_ASSOC);
}

/**
Expand Down