From b57b315f6f31119ed000533518d9a57f3838d1aa Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 1 Jul 2024 12:10:46 +0200 Subject: [PATCH 1/2] Use methods related to optimizing database tables to schema classes --- CHANGELOG.md | 4 + core/Db.php | 76 +++---------------- core/Db/Schema.php | 26 +++++++ core/Db/Schema/Mariadb.php | 7 ++ core/Db/Schema/Mysql.php | 74 ++++++++++++++++++ core/Db/Schema/Tidb.php | 11 +++ core/Db/SchemaInterface.php | 20 +++++ .../CoreAdminHome/Commands/DeleteLogsData.php | 2 +- .../Commands/OptimizeArchiveTables.php | 2 +- .../Commands/PurgeOldArchiveData.php | 4 +- plugins/CoreAdminHome/Tasks.php | 2 +- plugins/PrivacyManager/LogDataPurger.php | 2 +- plugins/PrivacyManager/ReportsPurger.php | 4 +- .../Integration/Db/Schema/MariadbTest.php | 71 +++++++++++++++++ .../Integration/Db/Schema/MysqlTest.php | 71 +++++++++++++++++ .../Integration/Db/Schema/TiDbTest.php | 46 +++++++++++ tests/PHPUnit/Integration/DbTest.php | 26 ------- tests/PHPUnit/Integration/SqlTest.php | 53 ------------- tests/PHPUnit/Unit/DeprecatedMethodsTest.php | 2 + 19 files changed, 350 insertions(+), 153 deletions(-) create mode 100644 tests/PHPUnit/Integration/Db/Schema/MariadbTest.php create mode 100644 tests/PHPUnit/Integration/Db/Schema/MysqlTest.php create mode 100644 tests/PHPUnit/Integration/Db/Schema/TiDbTest.php delete mode 100644 tests/PHPUnit/Integration/SqlTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b5106e24647..d789953c5fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)* * The dependency `jQuery.dotdotdot` has been removed. Please use pure CSS instead or include the library in your plugin if needed. +## Deprecations + +The methods `Db::isOptimizeInnoDBSupported` and `Db::optimizeTables` have been deprecated. Use `Db\Schema::getInstance()->isOptimizeInnoDBSupported` and `Db\Schema::getInstance()->optimizeTables` instead + ## Matomo 5.1.0 ### Breaking Changes diff --git a/core/Db.php b/core/Db.php index dc7b0a45beb..afa13ab2659 100644 --- a/core/Db.php +++ b/core/Db.php @@ -11,6 +11,7 @@ use Exception; use Piwik\Db\Adapter; +use Piwik\Db\Schema; /** * Contains SQL related helper functions for Piwik's MySQL database. @@ -466,63 +467,13 @@ public static function deleteAllRows($table, $where, $orderBy, $maxRowsPerQuery * Table names must be prefixed (see {@link Piwik\Common::prefixTable()}). * @param bool $force If true, the `OPTIMIZE TABLE` query will be run even if InnoDB tables are being used. * @return bool + * @deprecated will be removed in Matomo 6 + * use Schema::getInstance()->optimizeTables() instead */ public static function optimizeTables($tables, $force = false) { - $optimize = Config::getInstance()->General['enable_sql_optimize_queries']; - - if ( - empty($optimize) - && !$force - ) { - return false; - } - - if (empty($tables)) { - return false; - } - - if (!is_array($tables)) { - $tables = array($tables); - } - - if ( - !self::isOptimizeInnoDBSupported() - && !$force - ) { - // filter out all InnoDB tables - $myisamDbTables = array(); - foreach (self::getTableStatus() as $row) { - if ( - strtolower($row['Engine']) == 'myisam' - && in_array($row['Name'], $tables) - ) { - $myisamDbTables[] = $row['Name']; - } - } - - $tables = $myisamDbTables; - } - - if (empty($tables)) { - return false; - } - - // optimize the tables - $success = true; - foreach ($tables as &$t) { - $ok = self::query('OPTIMIZE TABLE ' . $t); - if (!$ok) { - $success = false; - } - } - - return $success; - } - - private static function getTableStatus() - { - return Db::fetchAll("SHOW TABLE STATUS"); + $tables = !is_array($tables) ? [$tables] : $tables; + return Schema::getInstance()->optimizeTables($tables, (bool) $force); } /** @@ -912,19 +863,12 @@ public static function isQueryLogEnabled() return self::$logQueries; } + /** + * @deprecated will be removed with Matomo 6 + * use Schema::getInstance()->isOptimizeInnoDBSupported() instead + */ public static function isOptimizeInnoDBSupported($version = null) { - if ($version === null) { - $version = Db::fetchOne("SELECT VERSION()"); - } - - $version = strtolower($version); - - if (strpos($version, "mariadb") === false) { - return false; - } - - $semanticVersion = strstr($version, '-', $beforeNeedle = true); - return version_compare($semanticVersion, '10.1.1', '>='); + return Db\Schema::getInstance()->isOptimizeInnoDBSupported(); } } diff --git a/core/Db/Schema.php b/core/Db/Schema.php index 7211a1be468..49d3e927a9f 100644 --- a/core/Db/Schema.php +++ b/core/Db/Schema.php @@ -254,4 +254,30 @@ public function supportsComplexColumnUpdates(): bool { return $this->getSchema()->supportsComplexColumnUpdates(); } + + /** + * Returns if the schema supports `OPTIMIZE TABLE` statements for innodb tables + * + * @return bool + */ + public function isOptimizeInnoDBSupported(): bool + { + return $this->getSchema()->isOptimizeInnoDBSupported(); + } + + /** + * Runs an `OPTIMIZE TABLE` query on the supplied table or tables. + * + * Tables will only be optimized if the `[General] enable_sql_optimize_queries` INI config option is + * set to **1**. + * + * @param string|array $tables The name of the table to optimize or an array of tables to optimize. + * Table names must be prefixed (see {@link Piwik\Common::prefixTable()}). + * @param bool $force If true, the `OPTIMIZE TABLE` query will be run even if InnoDB tables are being used. + * @return bool + */ + public function optimizeTables(array $tables, bool $force = false): bool + { + return $this->getSchema()->optimizeTables($tables, $force); + } } diff --git a/core/Db/Schema/Mariadb.php b/core/Db/Schema/Mariadb.php index 0c93c667843..f5b99fc6d67 100644 --- a/core/Db/Schema/Mariadb.php +++ b/core/Db/Schema/Mariadb.php @@ -37,4 +37,11 @@ public function addMaxExecutionTimeHintToQuery(string $sql, float $limit): strin return $sql; } + + public function isOptimizeInnoDBSupported(): bool + { + $version = strtolower($this->getVersion()); + $semanticVersion = strstr($version, '-', $beforeNeedle = true); + return version_compare($semanticVersion, '10.1.1', '>='); + } } diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php index 6cfab7e90d2..ba720ea5df2 100644 --- a/core/Db/Schema/Mysql.php +++ b/core/Db/Schema/Mysql.php @@ -12,6 +12,7 @@ use Exception; use Piwik\Common; use Piwik\Concurrency\Lock; +use Piwik\Config; use Piwik\Date; use Piwik\Db\SchemaInterface; use Piwik\Db; @@ -688,6 +689,69 @@ public function getTableCreateOptions(): string return $options; } + public function optimizeTables(array $tables, bool $force = false): bool + { + $optimize = Config::getInstance()->General['enable_sql_optimize_queries']; + + if ( + empty($optimize) + && !$force + ) { + return false; + } + + if (empty($tables)) { + return false; + } + + if ( + !$this->isOptimizeInnoDBSupported() + && !$force + ) { + // filter out all InnoDB tables + $myisamDbTables = array(); + foreach ($this->getTableStatus() as $row) { + if ( + strtolower($row['Engine']) == 'myisam' + && in_array($row['Name'], $tables) + ) { + $myisamDbTables[] = $row['Name']; + } + } + + $tables = $myisamDbTables; + } + + if (empty($tables)) { + return false; + } + + // optimize the tables + $success = true; + foreach ($tables as &$t) { + $ok = Db::query('OPTIMIZE TABLE ' . $t); + if (!$ok) { + $success = false; + } + } + + return $success; + } + + public function isOptimizeInnoDBSupported(): bool + { + $version = strtolower($this->getVersion()); + + // Note: This check for MariaDb is here on purpose, so it's working correctly for people + // having MySQL still configured, when using MariaDb + if (strpos($version, "mariadb") === false) { + return false; + } + + $semanticVersion = strstr($version, '-', $beforeNeedle = true); + return version_compare($semanticVersion, '10.1.1', '>='); + } + protected function getDatabaseCreateOptions(): string { $charset = DbHelper::getDefaultCharset(); @@ -715,6 +779,16 @@ private function getTablePrefix() return $this->getDbSettings()->getTablePrefix(); } + protected function getVersion(): string + { + return Db::fetchOne("SELECT VERSION()"); + } + + protected function getTableStatus() + { + return Db::fetchAll("SHOW TABLE STATUS"); + } + private function getDb() { return Db::get(); diff --git a/core/Db/Schema/Tidb.php b/core/Db/Schema/Tidb.php index 193750259c7..1b3104d211c 100644 --- a/core/Db/Schema/Tidb.php +++ b/core/Db/Schema/Tidb.php @@ -51,6 +51,17 @@ public function getTableCreateOptions(): string return $options; } + public function isOptimizeInnoDBSupported(): bool + { + return false; + } + + public function optimizeTables(array $tables, bool $force = false): bool + { + // OPTIMIZE TABLE not supported for TiDb + return false; + } + protected function getDatabaseCreateOptions(): string { $charset = DbHelper::getDefaultCharset(); diff --git a/core/Db/SchemaInterface.php b/core/Db/SchemaInterface.php index 3c256bed5bf..2ecc3494044 100644 --- a/core/Db/SchemaInterface.php +++ b/core/Db/SchemaInterface.php @@ -138,4 +138,24 @@ public function getDefaultPort(): int; * @return string */ public function getTableCreateOptions(): string; + + /** + * Returns if performing on `OPTIMIZE TABLE` is supported for InnoDb tables + * + * @return bool + */ + public function isOptimizeInnoDBSupported(): bool; + + /** + * Runs an `OPTIMIZE TABLE` query on the supplied table or tables. + * + * Tables will only be optimized if the `[General] enable_sql_optimize_queries` INI config option is + * set to **1**. + * + * @param array $tables The name of the table to optimize or an array of tables to optimize. + * Table names must be prefixed (see {@link Piwik\Common::prefixTable()}). + * @param bool $force If true, the `OPTIMIZE TABLE` query will be run even if InnoDB tables are being used. + * @return bool + */ + public function optimizeTables(array $tables, bool $force = false): bool; } diff --git a/plugins/CoreAdminHome/Commands/DeleteLogsData.php b/plugins/CoreAdminHome/Commands/DeleteLogsData.php index 9c94f22878d..24d58f7506a 100644 --- a/plugins/CoreAdminHome/Commands/DeleteLogsData.php +++ b/plugins/CoreAdminHome/Commands/DeleteLogsData.php @@ -194,7 +194,7 @@ private function optimizeTables() $prefixedTable = Common::prefixTable($table); - $done = Db::optimizeTables($prefixedTable); + $done = Db\Schema::getInstance()->optimizeTables([$prefixedTable]); if ($done) { $this->getOutput()->writeln("done. " . $timer . ""); diff --git a/plugins/CoreAdminHome/Commands/OptimizeArchiveTables.php b/plugins/CoreAdminHome/Commands/OptimizeArchiveTables.php index d5e6284db68..9e348af18df 100644 --- a/plugins/CoreAdminHome/Commands/OptimizeArchiveTables.php +++ b/plugins/CoreAdminHome/Commands/OptimizeArchiveTables.php @@ -64,7 +64,7 @@ private function optimizeTable($dryRun, $table) if ($dryRun) { $output->write("[dry-run, not optimising table]"); } else { - Db::optimizeTables(Common::prefixTable($table), $force = true); + Db\Schema::getInstance()->optimizeTables([Common::prefixTable($table)], $force = true); } $output->writeln("Done."); diff --git a/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php b/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php index a76d0be8f7d..05ca09bd41f 100644 --- a/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php +++ b/plugins/CoreAdminHome/Commands/PurgeOldArchiveData.php @@ -198,12 +198,12 @@ private function optimizeArchiveTables($dates) foreach ($dates as $date) { $numericTable = ArchiveTableCreator::getNumericTable($date); $this->performTimedPurging("Optimizing table $numericTable...", function () use ($numericTable) { - Db::optimizeTables($numericTable, $force = true); + Db\Schema::getInstance()->optimizeTables([$numericTable], $force = true); }); $blobTable = ArchiveTableCreator::getBlobTable($date); $this->performTimedPurging("Optimizing table $blobTable...", function () use ($blobTable) { - Db::optimizeTables($blobTable, $force = true); + Db\Schema::getInstance()->optimizeTables([$blobTable], $force = true); }); } } diff --git a/plugins/CoreAdminHome/Tasks.php b/plugins/CoreAdminHome/Tasks.php index ef6509d5e9a..2670e3c6eab 100644 --- a/plugins/CoreAdminHome/Tasks.php +++ b/plugins/CoreAdminHome/Tasks.php @@ -315,7 +315,7 @@ public function purgeInvalidatedArchives() public function optimizeArchiveTable() { $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled(); - Db::optimizeTables($archiveTables); + Db\Schema::getInstance()->optimizeTables($archiveTables); } /** diff --git a/plugins/PrivacyManager/LogDataPurger.php b/plugins/PrivacyManager/LogDataPurger.php index 1a869518af7..8b278e699a0 100644 --- a/plugins/PrivacyManager/LogDataPurger.php +++ b/plugins/PrivacyManager/LogDataPurger.php @@ -105,7 +105,7 @@ public function purgeData($deleteLogsOlderThan, $deleteUnusedLogActions) Piwik::postEvent('PrivacyManager.deleteLogsOlderThan', array($dateUpperLimit, $deleteLogsOlderThan)); // optimize table overhead after deletion - Db::optimizeTables($logTables); + Db\Schema::getInstance()->optimizeTables($logTables); } /** diff --git a/plugins/PrivacyManager/ReportsPurger.php b/plugins/PrivacyManager/ReportsPurger.php index 510901b538b..bcac9cc30f1 100644 --- a/plugins/PrivacyManager/ReportsPurger.php +++ b/plugins/PrivacyManager/ReportsPurger.php @@ -123,7 +123,7 @@ public function purgeData($optimize = false) } if ($optimize) { - Db::optimizeTables($oldBlobTables); + Db\Schema::getInstance()->optimizeTables($oldBlobTables); } } @@ -152,7 +152,7 @@ public function purgeData($optimize = false) } if ($optimize) { - Db::optimizeTables($oldNumericTables); + Db\Schema::getInstance()->optimizeTables($oldNumericTables); } } } diff --git a/tests/PHPUnit/Integration/Db/Schema/MariadbTest.php b/tests/PHPUnit/Integration/Db/Schema/MariadbTest.php new file mode 100644 index 00000000000..d5e1fe92a63 --- /dev/null +++ b/tests/PHPUnit/Integration/Db/Schema/MariadbTest.php @@ -0,0 +1,71 @@ +getMockBuilder(Db\Schema\Mariadb::class)->onlyMethods(['getVersion'])->getMock(); + $schema->method('getVersion')->willReturn($version); + $this->assertEquals($expectedResult, $schema->isOptimizeInnoDBSupported()); + } + + public function getIsOptimizeInnoDBTestData() + { + return array( + array("10.0.17-MariaDB-1~trusty", false), + array("10.1.1-MariaDB-1~trusty", true), + array("10.2.0-MariaDB-1~trusty", true), + array("10.6.19-0ubuntu0.14.04.1", true), // we expect true, as the version is high enough + array("8.0.11-TiDB-v8.1.0", false), + array("", false), + array("0", false), + array("slkdf(@*#lkesjfMariaDB", false), + array("slkdfjq3rujlkv", false), + ); + } + + public function testOptimize() + { + if (DatabaseConfig::getConfigValue('schema') !== 'Mariadb') { + self::markTestSkipped('Mariadb is not available'); + } + + // create two myisam tables + Db::exec("CREATE TABLE table1 (a INT) ENGINE=MYISAM"); + Db::exec("CREATE TABLE table2 (b INT) ENGINE=MYISAM"); + + // create two innodb tables + Db::exec("CREATE TABLE table3 (c INT) ENGINE=InnoDB"); + Db::exec("CREATE TABLE table4 (d INT) ENGINE=InnoDB"); + + $schema = Db\Schema::getInstance(); + + // make sure optimizing myisam tables works + $this->assertTrue($schema->optimizeTables(['table1', 'table2'])); + + // make sure optimizing both myisam & innodb results in optimizations + $this->assertTrue($schema->optimizeTables(['table1', 'table2', 'table3', 'table4'])); + + // optimizing innodb should be available for mariadb + $this->assertTrue($schema->optimizeTables(['table3', 'table4']), true); + + // should optimize when forced + $this->assertTrue($schema->optimizeTables(['table3', 'table4'], true), true); + } +} diff --git a/tests/PHPUnit/Integration/Db/Schema/MysqlTest.php b/tests/PHPUnit/Integration/Db/Schema/MysqlTest.php new file mode 100644 index 00000000000..69094eb4386 --- /dev/null +++ b/tests/PHPUnit/Integration/Db/Schema/MysqlTest.php @@ -0,0 +1,71 @@ +getMockBuilder(Db\Schema\Mysql::class)->onlyMethods(['getVersion'])->getMock(); + $schema->method('getVersion')->willReturn($version); + $this->assertEquals($expectedResult, $schema->isOptimizeInnoDBSupported()); + } + + public function getIsOptimizeInnoDBTestData() + { + return array( + array("10.0.17-MariaDB-1~trusty", false), + array("10.1.1-MariaDB-1~trusty", true), + array("10.2.0-MariaDB-1~trusty", true), + array("10.6.19-0ubuntu0.14.04.1", false), + array("8.0.11-TiDB-v8.1.0", false), + array("", false), + array("0", false), + array("slkdf(@*#lkesjfMariaDB", false), + array("slkdfjq3rujlkv", false), + ); + } + + public function testOptimize() + { + if (DatabaseConfig::getConfigValue('schema') !== 'Mysql') { + self::markTestSkipped('Mysql is not available'); + } + + // create two myisam tables + Db::exec("CREATE TABLE table1 (a INT) ENGINE=MYISAM"); + Db::exec("CREATE TABLE table2 (b INT) ENGINE=MYISAM"); + + // create two innodb tables + Db::exec("CREATE TABLE table3 (c INT) ENGINE=InnoDB"); + Db::exec("CREATE TABLE table4 (d INT) ENGINE=InnoDB"); + + $schema = Db\Schema::getInstance(); + + // make sure optimizing myisam tables works + $this->assertTrue($schema->optimizeTables(['table1', 'table2'])); + + // make sure optimizing both myisam & innodb results in optimizations + $this->assertTrue($schema->optimizeTables(['table1', 'table2', 'table3', 'table4'])); + + // innodb should be skipped by default + $this->assertFalse($schema->optimizeTables(['table3', 'table4'])); + + // should optimize when forced + $this->assertTrue($schema->optimizeTables(['table3', 'table4'], true)); + } +} diff --git a/tests/PHPUnit/Integration/Db/Schema/TiDbTest.php b/tests/PHPUnit/Integration/Db/Schema/TiDbTest.php new file mode 100644 index 00000000000..1103a202d92 --- /dev/null +++ b/tests/PHPUnit/Integration/Db/Schema/TiDbTest.php @@ -0,0 +1,46 @@ +assertFalse($schema->isOptimizeInnoDBSupported()); + } + + public function testOptimize() + { + if (DatabaseConfig::getConfigValue('schema') !== 'Tidb') { + self::markTestSkipped('Tidb is not available'); + } + + // create two myisam tables + Db::exec("CREATE TABLE table1 (a INT) ENGINE=MYISAM"); + Db::exec("CREATE TABLE table2 (b INT) ENGINE=MYISAM"); + + // create two innodb tables + Db::exec("CREATE TABLE table3 (c INT) ENGINE=InnoDB"); + Db::exec("CREATE TABLE table4 (d INT) ENGINE=InnoDB"); + + $schema = Db\Schema::getInstance(); + + // optimizing not available for TiDb + $this->assertFalse($schema->optimizeTables(['table1', 'table2'])); + $this->assertFalse($schema->optimizeTables(['table1', 'table2', 'table3', 'table4'])); + $this->assertFalse($schema->optimizeTables(['table3', 'table4'])); + $this->assertFalse($schema->optimizeTables(['table3', 'table4'], true)); + } +} diff --git a/tests/PHPUnit/Integration/DbTest.php b/tests/PHPUnit/Integration/DbTest.php index 600482b1f84..5656d6ab627 100644 --- a/tests/PHPUnit/Integration/DbTest.php +++ b/tests/PHPUnit/Integration/DbTest.php @@ -198,15 +198,6 @@ private function assertColumnNames($tableName, $expectedColumnNames) $this->assertEquals($expectedColumnNames, $colmuns); } - /** - * @dataProvider getIsOptimizeInnoDBTestData - */ - public function testIsOptimizeInnoDBSupportedReturnsCorrectResult($version, $expectedResult) - { - $result = Db::isOptimizeInnoDBSupported($version); - $this->assertEquals($expectedResult, $result); - } - /** * @dataProvider getDbAdapter */ @@ -274,23 +265,6 @@ public function getDbAdapter() ); } - public function getIsOptimizeInnoDBTestData() - { - return array( - array("10.0.17-MariaDB-1~trusty", false), - array("10.1.1-MariaDB-1~trusty", true), - array("10.2.0-MariaDB-1~trusty", true), - array("10.6.19-0ubuntu0.14.04.1", false), - - // for sanity. maybe not ours. - array("", false), - array(0, false), - array(false, false), - array("slkdf(@*#lkesjfMariaDB", false), - array("slkdfjq3rujlkv", false), - ); - } - /** * Forces Db::get() to return a database connection that * will throw "server has gone away" when running a query. diff --git a/tests/PHPUnit/Integration/SqlTest.php b/tests/PHPUnit/Integration/SqlTest.php deleted file mode 100644 index 197a7b202b3..00000000000 --- a/tests/PHPUnit/Integration/SqlTest.php +++ /dev/null @@ -1,53 +0,0 @@ -assertTrue(Db::optimizeTables(array('table1', 'table2')) !== false); - - // make sure optimizing both myisam & innodb results in optimizations - $this->assertTrue(Db::optimizeTables(array('table1', 'table2', 'table3', 'table4')) !== false); - - // make sure innodb tables are skipped - if (Db::isOptimizeInnoDBSupported()) { - $this->assertTrue(Db::optimizeTables(array('table3', 'table4'))); - } else { - $this->assertFalse(Db::optimizeTables(array('table3', 'table4'))); - } - } -} diff --git a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php index d4816625c27..153964f35e2 100644 --- a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php +++ b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php @@ -89,6 +89,8 @@ public function testDeprecations() $this->assertDeprecatedMethodIsRemovedInMatomo6('Piwik\Common', 'getRequestVar'); $this->assertDeprecatedMethodIsRemovedInMatomo6('Piwik\Plugins\Overlay\API', 'getExcludedQueryParameters'); + $this->assertDeprecatedMethodIsRemovedInMatomo6('Piwik\Db', 'isOptimizeInnoDBSupported'); + $this->assertDeprecatedMethodIsRemovedInMatomo6('Piwik\Db', 'optimizeTables'); } From 13ce3819af9dc6202626c60de8e62e4780d04a43 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Fri, 5 Jul 2024 10:26:12 +0200 Subject: [PATCH 2/2] apply review feedback --- core/Db.php | 4 ++++ .../Integration/Db/Schema/{TiDbTest.php => TidbTest.php} | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) rename tests/PHPUnit/Integration/Db/Schema/{TiDbTest.php => TidbTest.php} (97%) diff --git a/core/Db.php b/core/Db.php index afa13ab2659..c0b58bfecd2 100644 --- a/core/Db.php +++ b/core/Db.php @@ -472,6 +472,10 @@ public static function deleteAllRows($table, $where, $orderBy, $maxRowsPerQuery */ public static function optimizeTables($tables, $force = false) { + if (empty($tables)) { + return false; + } + $tables = !is_array($tables) ? [$tables] : $tables; return Schema::getInstance()->optimizeTables($tables, (bool) $force); } diff --git a/tests/PHPUnit/Integration/Db/Schema/TiDbTest.php b/tests/PHPUnit/Integration/Db/Schema/TidbTest.php similarity index 97% rename from tests/PHPUnit/Integration/Db/Schema/TiDbTest.php rename to tests/PHPUnit/Integration/Db/Schema/TidbTest.php index 1103a202d92..87fe17dc382 100644 --- a/tests/PHPUnit/Integration/Db/Schema/TiDbTest.php +++ b/tests/PHPUnit/Integration/Db/Schema/TidbTest.php @@ -13,7 +13,7 @@ use Piwik\Db; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; -class TiDbTest extends IntegrationTestCase +class TidbTest extends IntegrationTestCase { public function testIsOptimizeInnoDBSupportedReturnsCorrectResult() {