
From 142cd10e454ed24d5e67bf8619e1b781c15c1237 Mon Sep 17 00:00:00 2001
From: Daniel Black <daniel@mariadb.org>
Date: Sun, 19 Jun 2022 22:42:22 +0300
Subject: [PATCH] MDEV-28866: mariadb-upgrade to 10.8 mysql.column_stats
 hist_type + histogram errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The incorrect type of mysql.column_stats caused the server during the
upgrade of every other table to complain:

[ERROR] Incorrect definition of table mysql.column_stats: expected column 'hist_type' at position 9
and expected column 'histogram' at position 10 to have type longblob.

To prevent these verbose server errors, we upgrade the
mysql.column_stats table first.

Consequently limit "Incorrect definition of table mysql.*" to the appropriate
set of limited test cases.

The rpl_gtid_errorhandling.result changes the GTID number by one
because of the added early suppression (adding a table row).

Reviewer: Vicențiu Ciorbaru

Fixes MariaDB/mariadb-docker#438
---
 mysql-test/include/mtr_warnings.sql           |  1 -
 mysql-test/main/events_1.result               |  1 +
 mysql-test/main/events_1.test                 |  1 +
 mysql-test/main/events_restart.result         |  1 +
 mysql-test/main/events_restart.test           |  1 +
 mysql-test/main/mysql_upgrade.result          |  1 +
 mysql-test/main/mysql_upgrade.test            |  1 +
 mysql-test/main/statistics_upgrade.result     |  4 ++++
 mysql-test/main/statistics_upgrade.test       | 10 ++++++++
 .../suite/rpl/r/rpl_gtid_errorhandling.result |  9 +++----
 .../suite/rpl/t/rpl_gtid_errorhandling.test   |  1 +
 scripts/mysql_system_tables_fix.sql           | 24 +++++++++----------
 12 files changed, 38 insertions(+), 17 deletions(-)

Index: mariadb-10.6.15/mysql-test/include/mtr_warnings.sql
===================================================================
--- mariadb-10.6.15.orig/mysql-test/include/mtr_warnings.sql
+++ mariadb-10.6.15/mysql-test/include/mtr_warnings.sql
@@ -105,7 +105,6 @@ INSERT INTO global_suppressions VALUES
  */
 
  ("Got error [0-9]* when reading table"),
- ("Incorrect definition of table"),
  ("Incorrect information in file"),
  ("InnoDB: Warning: we did not need to do crash recovery"),
  /*("Invalid \\(old\\?\\) table or database name"),*/
Index: mariadb-10.6.15/scripts/mysql_system_tables_fix.sql
===================================================================
--- mariadb-10.6.15.orig/scripts/mysql_system_tables_fix.sql
+++ mariadb-10.6.15/scripts/mysql_system_tables_fix.sql
@@ -30,6 +30,18 @@ set enforce_storage_engine=NULL;
 set alter_algorithm='DEFAULT';
 set use_stat_tables='NEVER';
 
+
+--
+-- Upgrade mysql.column_stats table early because its quite noisy otherwise
+--
+
+ALTER TABLE column_stats
+  modify min_value varbinary(255) DEFAULT NULL,
+  modify max_value varbinary(255) DEFAULT NULL,
+  modify hist_type enum('SINGLE_PREC_HB','DOUBLE_PREC_HB','JSON_HB'),
+  modify histogram longblob,
+  ENGINE=Aria transactional=0;
+
 set @have_innodb= (select count(engine) from information_schema.engines where engine='INNODB' and support != 'NO');
 
 # MDEV-21873: 10.2 to 10.3 upgrade doesn't remove semi-sync reference from
@@ -67,7 +79,6 @@ ALTER TABLE help_category ENGINE=Aria tr
 ALTER TABLE help_relation ENGINE=Aria transactional=0;
 ALTER TABLE help_keyword ENGINE=Aria transactional=0;
 ALTER TABLE table_stats ENGINE=Aria transactional=0;
-ALTER TABLE column_stats ENGINE=Aria transactional=0;
 ALTER TABLE index_stats ENGINE=Aria transactional=0;
 
 ALTER TABLE user add File_priv enum('N','Y') COLLATE utf8mb3_general_ci DEFAULT 'N' NOT NULL;
@@ -783,9 +794,6 @@ flush privileges;
 ALTER TABLE help_category MODIFY url TEXT NOT NULL;
 ALTER TABLE help_topic MODIFY url TEXT NOT NULL;
 
-# MDEV-7383 - varbinary on mix/max of column_stats
-alter table column_stats modify min_value varbinary(255) DEFAULT NULL, modify max_value varbinary(255) DEFAULT NULL;
-
 DELIMITER //
 IF 'BASE TABLE' = (select table_type from information_schema.tables where table_schema=database() and table_name='user') THEN
   CREATE TABLE IF NOT EXISTS global_priv (Host char(255) binary DEFAULT '', User char(128) binary DEFAULT '', Priv JSON NOT NULL DEFAULT '{}' CHECK(JSON_VALID(Priv)), PRIMARY KEY Host (Host,User)) engine=Aria transactional=1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment='Users and global privileges'
