Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBenaka <diosmosis@users.noreply.github.com>2015-03-18 04:10:13 +0300
committerBenaka <diosmosis@users.noreply.github.com>2015-03-18 04:10:13 +0300
commit7e0d617359f0baf167d3f053f3e99a60e3c09a86 (patch)
tree278eaca557d72b77adc0a1b631a273e819a5b952 /core
parent00c394065d518e32cb535b6452bb657dc7672035 (diff)
parent317fdce1c7a7116f6879f46f78ade506c5057f46 (diff)
Merge pull request #7464 from piwik/7462_optimize_tables_mariadb
Fixes #7462, optimize InnoDB tables if MariaDB v10.1.1 or greater is used.
Diffstat (limited to 'core')
-rw-r--r--core/Db.php40
1 files changed, 30 insertions, 10 deletions
diff --git a/core/Db.php b/core/Db.php
index a96786e1e3..8c718ceac5 100644
--- a/core/Db.php
+++ b/core/Db.php
@@ -324,7 +324,7 @@ class Db
$optimize = Config::getInstance()->General['enable_sql_optimize_queries'];
if (empty($optimize)) {
- return;
+ return false;
}
if (empty($tables)) {
@@ -335,22 +335,26 @@ class Db
$tables = array($tables);
}
- // 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'];
+ if (!self::isOptimizeInnoDBSupported()) {
+ // 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($myisamDbTables)) {
+ if (empty($tables)) {
return false;
}
// optimize the tables
- return self::query("OPTIMIZE TABLE " . implode(',', $myisamDbTables));
+ return self::query("OPTIMIZE TABLE " . implode(',', $tables));
}
private static function getTableStatus()
@@ -731,4 +735,20 @@ class Db
{
return self::$logQueries;
}
+
+ public static function isOptimizeInnoDBSupported($version = null)
+ {
+ if (empty($version)) {
+ $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', '>=');
+ }
}