@@ -55,6 +55,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
55
55
const DDL_CREATE = 2 ;
56
56
const DDL_INDEX = 3 ;
57
57
const DDL_FOREIGN_KEY = 4 ;
58
+ const DDL_EXISTS = 5 ;
58
59
const DDL_CACHE_PREFIX = 'DB_PDO_MYSQL_DDL ' ;
59
60
const DDL_CACHE_TAG = 'DB_PDO_MYSQL_DDL ' ;
60
61
@@ -1630,7 +1631,7 @@ public function resetDdlCache($tableName = null, $schemaName = null)
1630
1631
} else {
1631
1632
$ cacheKey = $ this ->_getTableName ($ tableName , $ schemaName );
1632
1633
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 ];
1634
1635
foreach ($ ddlTypes as $ ddlType ) {
1635
1636
unset($ this ->_ddlCache [$ ddlType ][$ cacheKey ]);
1636
1637
}
@@ -2657,7 +2658,29 @@ public function truncateTable($tableName, $schemaName = null)
2657
2658
*/
2658
2659
public function isTableExists ($ tableName , $ schemaName = null )
2659
2660
{
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 ;
2661
2684
}
2662
2685
2663
2686
/**
0 commit comments