Mariadb.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Db\Schema; |
| 10 | |
| 11 | /** |
| 12 | * Mariadb schema |
| 13 | */ |
| 14 | class Mariadb extends \Piwik\Db\Schema\Mysql |
| 15 | { |
| 16 | /** |
| 17 | * Adds a max_statement_time hint into a SELECT query if $limit is bigger than 0 |
| 18 | * |
| 19 | * @param string $sql query to add hint to |
| 20 | * @param float $limit time limit in seconds |
| 21 | * @return string |
| 22 | */ |
| 23 | public function addMaxExecutionTimeHintToQuery(string $sql, float $limit) : string |
| 24 | { |
| 25 | if ($limit <= 0) { |
| 26 | return $sql; |
| 27 | } |
| 28 | $sql = trim($sql); |
| 29 | $pos = stripos($sql, 'SELECT'); |
| 30 | $isMaxExecutionTimeoutAlreadyPresent = stripos($sql, 'max_statement_time=') !== \false; |
| 31 | if ($pos !== \false && !$isMaxExecutionTimeoutAlreadyPresent) { |
| 32 | $maxExecutionTimeHint = 'SET STATEMENT max_statement_time=' . ceil($limit) . ' FOR '; |
| 33 | $sql = substr_replace($sql, $maxExecutionTimeHint . 'SELECT', $pos, strlen('SELECT')); |
| 34 | } |
| 35 | return $sql; |
| 36 | } |
| 37 | public function isOptimizeInnoDBSupported() : bool |
| 38 | { |
| 39 | $version = strtolower($this->getVersion()); |
| 40 | $semanticVersion = strstr($version, '-', $beforeNeedle = \true); |
| 41 | return version_compare($semanticVersion, '10.1.1', '>='); |
| 42 | } |
| 43 | } |
| 44 |