Skip to content

Commit bf76ce1

Browse files
authored
rewrite isTableExists for performance reasons (#1720)
faster implementation of isTableExists withous "showtablestatus"
1 parent 061dbe0 commit bf76ce1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/Varien/Db/Adapter/Pdo/Mysql.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,22 @@ public function truncateTable($tableName, $schemaName = null)
26302630
*/
26312631
public function isTableExists($tableName, $schemaName = null)
26322632
{
2633-
return $this->showTableStatus($tableName, $schemaName) !== false;
2633+
$fromDbName = 'DATABASE()';
2634+
if ($schemaName !== null) {
2635+
$fromDbName = $this->quote($schemaName);
2636+
}
2637+
2638+
$sql = sprintf(
2639+
'SELECT COUNT(1) AS tbl_exists FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = %s AND TABLE_SCHEMA = %s',
2640+
$this->quote($tableName),
2641+
$fromDbName
2642+
);
2643+
$ddl = $this->rawFetchRow($sql, 'tbl_exists');
2644+
if ($ddl) {
2645+
return true;
2646+
}
2647+
2648+
return false;
26342649
}
26352650

26362651
/**

0 commit comments

Comments
 (0)