summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2021-09-20 17:51:33 +0300
committerSergei Petrunia <psergey@askmonty.org>2021-09-20 17:51:33 +0300
commite44074feb2bd482d9d28cbf04829770dc33db27d (patch)
tree72cb2acc5b99728f0170b1baa6153aad0c6d342c
parent4ea73d61e36f7d4b9553f718675e00e6a9be82d0 (diff)
downloadmariadb-git-e44074feb2bd482d9d28cbf04829770dc33db27d.tar.gz
MDEV-26589: Assertion failure upon DECODE_HISTOGRAM with NULLs
Item_func_decode_histogram::val_str should correctly set null_value when "decoding" JSON histogram.
-rw-r--r--mysql-test/main/statistics_json.result30
-rw-r--r--mysql-test/main/statistics_json.test12
-rw-r--r--sql/item_strfunc.cc1
3 files changed, 43 insertions, 0 deletions
diff --git a/mysql-test/main/statistics_json.result b/mysql-test/main/statistics_json.result
index dba562aadc9..1d2ee77461f 100644
--- a/mysql-test/main/statistics_json.result
+++ b/mysql-test/main/statistics_json.result
@@ -7460,3 +7460,33 @@ b a
1 foo
2 bar
drop table t1;
+#
+# MDEV-26589: Assertion failure upon DECODE_HISTOGRAM with NULLs in first column
+# (Just the testcase)
+#
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (NULL,1), (NULL,2);
+SET histogram_type = JSON_HB;
+ANALYZE TABLE t1 PERSISTENT FOR ALL;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+SELECT DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats;
+DECODE_HISTOGRAM(hist_type, histogram)
+NULL
+{
+ "histogram_hb_v2": [
+ {
+ "start": "1",
+ "size": 0.5,
+ "ndv": 1
+ },
+ {
+ "start": "2",
+ "end": "2",
+ "size": 0.5,
+ "ndv": 1
+ }
+ ]
+}
+drop table t1;
diff --git a/mysql-test/main/statistics_json.test b/mysql-test/main/statistics_json.test
index c5bac951f21..ab061ed9f4e 100644
--- a/mysql-test/main/statistics_json.test
+++ b/mysql-test/main/statistics_json.test
@@ -182,3 +182,15 @@ SET histogram_type= JSON_HB;
ANALYZE TABLE t1 PERSISTENT FOR ALL;
SELECT * FROM t1;
drop table t1;
+
+--echo #
+--echo # MDEV-26589: Assertion failure upon DECODE_HISTOGRAM with NULLs in first column
+--echo # (Just the testcase)
+--echo #
+
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (NULL,1), (NULL,2);
+SET histogram_type = JSON_HB;
+ANALYZE TABLE t1 PERSISTENT FOR ALL;
+SELECT DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats;
+drop table t1;
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 9f406a7a1cf..06fb6fc5c51 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -530,6 +530,7 @@ String *Item_func_decode_histogram::val_str(String *str)
if (type == JSON_HB)
{
// It's a JSON histogram. Return it as-is.
+ null_value= 0;
return res;
}