summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2021-12-02 20:47:08 +0300
committerSergei Petrunia <psergey@askmonty.org>2022-01-19 18:10:11 +0300
commita0916cf5a2bb67a6bfa85cc2363e11a8f292c366 (patch)
treeca671011ce93709687f7646fa02e3c02c1e8e029
parenta0f93f433aa0a522f4a3311ca83a53677a83bb3b (diff)
downloadmariadb-git-a0916cf5a2bb67a6bfa85cc2363e11a8f292c366.tar.gz
MDEV-26519: Improved histograms: Better error reporting, test coverage
Also report JSON histogram load errors into error log, like it is already done with other histogram/statistics load errors. Add test coverage to see what happens if one upgrades but does NOT run mysql_upgrade.
-rw-r--r--mysql-test/main/statistics_json.result1
-rw-r--r--mysql-test/main/statistics_json.test1
-rw-r--r--mysql-test/main/statistics_upgrade_not_done.result44
-rw-r--r--mysql-test/main/statistics_upgrade_not_done.test57
-rw-r--r--sql/opt_histogram_json.cc4
5 files changed, 107 insertions, 0 deletions
diff --git a/mysql-test/main/statistics_json.result b/mysql-test/main/statistics_json.result
index 43fd61b4203..7ad6827711b 100644
--- a/mysql-test/main/statistics_json.result
+++ b/mysql-test/main/statistics_json.result
@@ -4157,6 +4157,7 @@ set @@global.histogram_size=@save_histogram_size;
drop table if exists t1;
set @save_histogram_type=@@histogram_type;
set @save_histogram_size=@@histogram_size;
+call mtr.add_suppression("Failed to parse histogram for table .*");
create table ten(a int primary key);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
set histogram_size=100;
diff --git a/mysql-test/main/statistics_json.test b/mysql-test/main/statistics_json.test
index e90df83f9c9..21d8ebc3829 100644
--- a/mysql-test/main/statistics_json.test
+++ b/mysql-test/main/statistics_json.test
@@ -16,6 +16,7 @@ drop table if exists t1;
set @save_histogram_type=@@histogram_type;
set @save_histogram_size=@@histogram_size;
+call mtr.add_suppression("Failed to parse histogram for table .*");
create table ten(a int primary key);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
diff --git a/mysql-test/main/statistics_upgrade_not_done.result b/mysql-test/main/statistics_upgrade_not_done.result
new file mode 100644
index 00000000000..902bf25c242
--- /dev/null
+++ b/mysql-test/main/statistics_upgrade_not_done.result
@@ -0,0 +1,44 @@
+# Create the old-version of the table
+call mtr.add_suppression(".*Incorrect definition of table mysql.column_stats:.*");
+alter table mysql.column_stats rename test.t1;
+CREATE TABLE mysql.column_stats (
+`db_name` varchar(64) COLLATE utf8mb3_bin NOT NULL,
+`table_name` varchar(64) COLLATE utf8mb3_bin NOT NULL,
+`column_name` varchar(64) COLLATE utf8mb3_bin NOT NULL,
+`min_value` varbinary(255) DEFAULT NULL,
+`max_value` varbinary(255) DEFAULT NULL,
+`nulls_ratio` decimal(12,4) DEFAULT NULL,
+`avg_length` decimal(12,4) DEFAULT NULL,
+`avg_frequency` decimal(12,4) DEFAULT NULL,
+`hist_size` tinyint(3) unsigned DEFAULT NULL,
+`hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') COLLATE utf8mb3_bin DEFAULT NULL,
+`histogram` varbinary(255) DEFAULT NULL,
+PRIMARY KEY (`db_name`,`table_name`,`column_name`)
+) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns';
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+INSERT INTO mysql.column_stats VALUES
+('test','t0','a','0','9',0.0000,4.0000,1.0000,5,'DOUBLE_PREC_HB', x'5555AAAA00');
+flush tables;
+analyze select * from t0 where a<3;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10.00 100.00 30.00 Using where
+# restart
+select hex(histogram) from mysql.column_stats where table_name='t0' and db_name='test';
+hex(histogram)
+5555AAAA00
+analyze select * from t0 where a<3;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10.00 100.00 30.00 Using where
+create table t2 (a int);
+# This currently just pretends that the histogram was collected.
+analyze table t2 persistent for all;
+Table Op Msg_type Msg_text
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status Table is already up to date
+select * from mysql.column_stats where table_name='t2' and db_name='test';
+db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
+analyze select * from t0 where a<3;
+id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10.00 33.33 30.00 Using where
+drop table t0, t1, t2;
diff --git a/mysql-test/main/statistics_upgrade_not_done.test b/mysql-test/main/statistics_upgrade_not_done.test
new file mode 100644
index 00000000000..a74a5f35d83
--- /dev/null
+++ b/mysql-test/main/statistics_upgrade_not_done.test
@@ -0,0 +1,57 @@
+--source include/not_embedded.inc
+--source include/mysql_upgrade_preparation.inc
+--source include/have_innodb.inc
+
+#
+# This is like the upgrade test in statistics_upgrade.test, except that we also
+# check what happens if one doesn't do the upgrade and attempts to use the new
+# server with the old mysql.column_stats table
+#
+--echo # Create the old-version of the table
+
+call mtr.add_suppression(".*Incorrect definition of table mysql.column_stats:.*");
+
+alter table mysql.column_stats rename test.t1;
+
+CREATE TABLE mysql.column_stats (
+ `db_name` varchar(64) COLLATE utf8mb3_bin NOT NULL,
+ `table_name` varchar(64) COLLATE utf8mb3_bin NOT NULL,
+ `column_name` varchar(64) COLLATE utf8mb3_bin NOT NULL,
+ `min_value` varbinary(255) DEFAULT NULL,
+ `max_value` varbinary(255) DEFAULT NULL,
+ `nulls_ratio` decimal(12,4) DEFAULT NULL,
+ `avg_length` decimal(12,4) DEFAULT NULL,
+ `avg_frequency` decimal(12,4) DEFAULT NULL,
+ `hist_size` tinyint(3) unsigned DEFAULT NULL,
+ `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') COLLATE utf8mb3_bin DEFAULT NULL,
+ `histogram` varbinary(255) DEFAULT NULL,
+ PRIMARY KEY (`db_name`,`table_name`,`column_name`)
+) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Columns';
+
+create table t0(a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+INSERT INTO mysql.column_stats VALUES
+('test','t0','a','0','9',0.0000,4.0000,1.0000,5,'DOUBLE_PREC_HB', x'5555AAAA00');
+
+flush tables;
+analyze select * from t0 where a<3;
+
+# Restart the server
+
+--source include/restart_mysqld.inc
+
+select hex(histogram) from mysql.column_stats where table_name='t0' and db_name='test';
+analyze select * from t0 where a<3;
+
+create table t2 (a int);
+-- echo # This currently just pretends that the histogram was collected.
+analyze table t2 persistent for all;
+select * from mysql.column_stats where table_name='t2' and db_name='test';
+
+--exec $MYSQL_UPGRADE --upgrade-system-tables --force --silent 2>&1
+let $MYSQLD_DATADIR= `select @@datadir`;
+--file_exists $MYSQLD_DATADIR/mysql_upgrade_info
+--remove_file $MYSQLD_DATADIR/mysql_upgrade_info
+
+analyze select * from t0 where a<3;
+drop table t0, t1, t2;
diff --git a/sql/opt_histogram_json.cc b/sql/opt_histogram_json.cc
index 8e04931b71c..faf5ec314ab 100644
--- a/sql/opt_histogram_json.cc
+++ b/sql/opt_histogram_json.cc
@@ -696,6 +696,10 @@ err:
ER_THD(thd, ER_JSON_HISTOGRAM_PARSE_FAILED),
db_name, table_name,
err, (je.s.c_str - (const uchar*)hist_data));
+ sql_print_error(ER_THD(thd, ER_JSON_HISTOGRAM_PARSE_FAILED),
+ db_name, table_name, err,
+ (je.s.c_str - (const uchar*)hist_data));
+
DBUG_RETURN(true);
}