From 2475b5509e9638fa2e9863256348c5415f362b72 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 24 Aug 2016 12:33:38 -0700 Subject: [PATCH] CRM-15601, CRM-19027 - Fix MyISAM DB check 3fa9688a5 introduced a subtle break in how it skips temp tables: * (Old) `strpos($dao->Name, '_temp') !== FALSE` * (New) `TABLE_NAME NOT LIKE '%temp'` This is relevant when the table name is appended with a randomized suffix. I don't the performance issue being addressed by CRM-19027. If there's an issue with this hurting indexes, then maybe the check should be done in PHP again? Alternatively, maybe we should patch all the code which makes temp tables to enforce `ENGINE=InnoDB`? --- CRM/Core/DAO.php | 4 ++-- tests/phpunit/CRM/Core/DAOTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index a66c1ca63a..dec40a3d07 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -777,7 +777,7 @@ LIKE %1 WHERE TABLE_SCHEMA = '" . CRM_Core_DAO::getDatabaseName() . "' AND TABLE_NAME LIKE 'civicrm_%' AND TABLE_NAME NOT LIKE 'civicrm_import_job_%' - AND TABLE_NAME NOT LIKE '%temp' + AND TABLE_NAME NOT LIKE '%_temp%' "); while ($dao->fetch()) { @@ -800,7 +800,7 @@ LIKE %1 AND TABLE_SCHEMA = '" . CRM_Core_DAO::getDatabaseName() . "' AND TABLE_NAME LIKE 'civicrm_%' AND TABLE_NAME NOT LIKE 'civicrm_import_job_%' - AND TABLE_NAME NOT LIKE '%temp' + AND TABLE_NAME NOT LIKE '%_temp%' "); } diff --git a/tests/phpunit/CRM/Core/DAOTest.php b/tests/phpunit/CRM/Core/DAOTest.php index be89d34efc..a80eecc7ba 100644 --- a/tests/phpunit/CRM/Core/DAOTest.php +++ b/tests/phpunit/CRM/Core/DAOTest.php @@ -253,10 +253,28 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { * Test the function designed to find myIsam tables. */ public function testMyISAMCheck() { + // Cleanup previous, failed tests. + CRM_Core_DAO::executeQuery('DROP TABLE IF EXISTS civicrm_my_isam'); + + // A manually created MyISAM table should raise a redflag. $this->assertEquals(0, CRM_Core_DAO::isDBMyISAM()); CRM_Core_DAO::executeQuery('CREATE TABLE civicrm_my_isam (`id` int(10) unsigned NOT NULL) ENGINE = MyISAM'); $this->assertEquals(1, CRM_Core_DAO::isDBMyISAM()); CRM_Core_DAO::executeQuery('DROP TABLE civicrm_my_isam'); + + // A temp table should not raise flag (static naming). + $tempName = CRM_Core_DAO::createTempTableName('civicrm', FALSE); + $this->assertEquals(0, CRM_Core_DAO::isDBMyISAM()); + CRM_Core_DAO::executeQuery("CREATE TABLE $tempName (`id` int(10) unsigned NOT NULL) ENGINE = MyISAM"); + $this->assertEquals(0, CRM_Core_DAO::isDBMyISAM()); // Ignore temp tables + CRM_Core_DAO::executeQuery("DROP TABLE $tempName"); + + // A temp table should not raise flag (randomized naming). + $tempName = CRM_Core_DAO::createTempTableName('civicrm', TRUE); + $this->assertEquals(0, CRM_Core_DAO::isDBMyISAM()); + CRM_Core_DAO::executeQuery("CREATE TABLE $tempName (`id` int(10) unsigned NOT NULL) ENGINE = MyISAM"); + $this->assertEquals(0, CRM_Core_DAO::isDBMyISAM()); // Ignore temp tables + CRM_Core_DAO::executeQuery("DROP TABLE $tempName"); } } -- 2.25.1