Skip to content

Commit 2d67fdd

Browse files
committed
Rewrote Magento\Framework\DB\Adapter\Pdo\Mysql->isTableExists
* Use INFORMATION_SCHEMA.TABLES instead of "SHOW TABLE STATUS" * Extend DDL cache for table existence and use it in isTableExists
1 parent 134ef81 commit 2d67fdd

File tree

1 file changed

+25
-2
lines changed
  • lib/internal/Magento/Framework/DB/Adapter/Pdo

1 file changed

+25
-2
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
5555
const DDL_CREATE = 2;
5656
const DDL_INDEX = 3;
5757
const DDL_FOREIGN_KEY = 4;
58+
const DDL_EXISTS = 5;
5859
const DDL_CACHE_PREFIX = 'DB_PDO_MYSQL_DDL';
5960
const DDL_CACHE_TAG = 'DB_PDO_MYSQL_DDL';
6061

@@ -1630,7 +1631,7 @@ public function resetDdlCache($tableName = null, $schemaName = null)
16301631
} else {
16311632
$cacheKey = $this->_getTableName($tableName, $schemaName);
16321633

1633-
$ddlTypes = [self::DDL_DESCRIBE, self::DDL_CREATE, self::DDL_INDEX, self::DDL_FOREIGN_KEY];
1634+
$ddlTypes = [self::DDL_DESCRIBE, self::DDL_CREATE, self::DDL_INDEX, self::DDL_FOREIGN_KEY, self::DDL_EXISTS];
16341635
foreach ($ddlTypes as $ddlType) {
16351636
unset($this->_ddlCache[$ddlType][$cacheKey]);
16361637
}
@@ -2657,7 +2658,29 @@ public function truncateTable($tableName, $schemaName = null)
26572658
*/
26582659
public function isTableExists($tableName, $schemaName = null)
26592660
{
2660-
return $this->showTableStatus($tableName, $schemaName) !== false;
2661+
$cacheKey = $this->_getTableName($tableName, $schemaName);
2662+
2663+
$ddl = $this->loadDdlCache($cacheKey, self::DDL_EXISTS);
2664+
if ($ddl !== false) {
2665+
return true;
2666+
}
2667+
2668+
$fromDbName = 'DATABASE()';
2669+
if ($schemaName !== null) {
2670+
$fromDbName = $this->quote($schemaName);
2671+
}
2672+
2673+
$sql = sprintf('SELECT COUNT(1) AS tbl_exists FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = %s AND TABLE_SCHEMA = %s',
2674+
$this->quote($tableName),
2675+
$fromDbName
2676+
);
2677+
$ddl = $this->rawFetchRow($sql, 'tbl_exists');
2678+
if ($ddl) {
2679+
$this->saveDdlCache($cacheKey, self::DDL_EXISTS, $ddl);
2680+
return true;
2681+
}
2682+
2683+
return false;
26612684
}
26622685

26632686
/**

0 commit comments

Comments
 (0)