From 1be3cad6e3004b875d85341cb3cf1edac637d2a2 Mon Sep 17 00:00:00 2001 From: "Fawzi E. Abdulfattah" Date: Fri, 22 Jul 2022 19:26:02 +0200 Subject: Supporting the compressed option for MariaDB Ref: #14956 Signed-off-by: Fawzi E. Abdulfattah --- libraries/classes/Types.php | 11 ++++++++++- libraries/classes/Util.php | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'libraries') diff --git a/libraries/classes/Types.php b/libraries/classes/Types.php index 12f7a7e4cf..e2deae064d 100644 --- a/libraries/classes/Types.php +++ b/libraries/classes/Types.php @@ -713,13 +713,22 @@ class Types */ public function getAttributes() { - return [ + $isMariaDB = $this->dbi->isMariaDB(); + $serverVersion = $this->dbi->getVersion(); + + $attributes = [ '', 'BINARY', 'UNSIGNED', 'UNSIGNED ZEROFILL', 'on update CURRENT_TIMESTAMP', ]; + + if ($isMariaDB && $serverVersion >= 100100) { + $attributes[] = 'COMPRESSED=zlib'; + } + + return $attributes; } /** diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 8338d8e003..0d39ca8bae 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1373,6 +1373,7 @@ class Util $binary = false; $unsigned = false; $zerofill = false; + $compressed = false; } else { $enumSetValues = []; @@ -1394,6 +1395,8 @@ class Util $zerofill = ($zerofillCount > 0); $printType = (string) preg_replace('@unsigned@', '', $printType, -1, $unsignedCount); $unsigned = ($unsignedCount > 0); + $printType = (string) preg_replace('@\/\*!100301 compressed\*\/@', '', $printType, -1, $compressedCount); + $compressed = ($compressedCount > 0); $printType = trim($printType); } @@ -1410,6 +1413,10 @@ class Util $attribute = 'UNSIGNED ZEROFILL'; } + if ($compressed) { + $attribute = 'COMPRESSED=zlib'; + } + $canContainCollation = false; if (! $binary && preg_match('@^(char|varchar|text|tinytext|mediumtext|longtext|set|enum)@', $type)) { $canContainCollation = true; -- cgit v1.2.3 From 70a067ad09d5ac55b55cda67728307236ae3b35f Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 30 Sep 2022 23:26:54 +0200 Subject: Move compatibility logic into the Compatibility class Signed-off-by: William Desportes --- libraries/classes/Query/Compatibility.php | 14 ++++++++++++++ libraries/classes/Types.php | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'libraries') diff --git a/libraries/classes/Query/Compatibility.php b/libraries/classes/Query/Compatibility.php index aa1ab6829f..5f995951f6 100644 --- a/libraries/classes/Query/Compatibility.php +++ b/libraries/classes/Query/Compatibility.php @@ -213,6 +213,20 @@ class Compatibility return false; } + /** + * Returns whether the database server supports compressed columns + */ + public static function supportsCompressedColumns(int $serverVersion): bool + { + // @see https://mariadb.com/kb/en/innodb-page-compression/#comment_1992 + // Comment: Page compression is only available in MariaDB >= 10.1. [...] + if (self::isMariaDb()) { + return $serverVersion >= 100100; + } + + return false; + } + /** * @see https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-6.html#mysqld-5-7-6-account-management * @see https://mariadb.com/kb/en/mariadb-1042-release-notes/#notable-changes diff --git a/libraries/classes/Types.php b/libraries/classes/Types.php index e2deae064d..02b9efc14a 100644 --- a/libraries/classes/Types.php +++ b/libraries/classes/Types.php @@ -7,6 +7,8 @@ declare(strict_types=1); namespace PhpMyAdmin; +use PhpMyAdmin\Query\Compatibility; + use function __; use function _pgettext; use function array_diff; @@ -724,7 +726,7 @@ class Types 'on update CURRENT_TIMESTAMP', ]; - if ($isMariaDB && $serverVersion >= 100100) { + if (Compatibility::supportsCompressedColumns($serverVersion)) { $attributes[] = 'COMPRESSED=zlib'; } -- cgit v1.2.3 From 49b4951cbb3df1a8b76da4a3e0290af96c6f8674 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 30 Sep 2022 23:39:50 +0200 Subject: Document why zlib is the only value for a compressed column Signed-off-by: William Desportes --- libraries/classes/Util.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libraries') diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 0d39ca8bae..2e5a88159b 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1414,6 +1414,10 @@ class Util } if ($compressed) { + // With InnoDB page compression, multiple compression algorithms are supported. + // In contrast, with InnoDB's COMPRESSED row format, zlib is the only supported compression algorithm. + // This means that the COMPRESSED row format has less compression options than InnoDB page compression does. + // @see https://mariadb.com/kb/en/innodb-page-compression/#comparison-with-the-compressed-row-format $attribute = 'COMPRESSED=zlib'; } -- cgit v1.2.3