From 3c5ecd3657286d947cc0a33e88209164f35ab8ab Mon Sep 17 00:00:00 2001 From: tianfengli Date: Mon, 11 Nov 2024 18:58:59 +0800 Subject: [PATCH] accept Json_uint for longlong type in extract_json_dom_value() --- .../r/histogram_update_using_data.result | 13 +++++++++++++ mysql-test/t/histogram_update_using_data.test | 18 ++++++++++++++++++ sql/histograms/histogram.cc | 17 +++++++++++------ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/histogram_update_using_data.result b/mysql-test/r/histogram_update_using_data.result index 24ae109bd6b..d9ea02de4d7 100644 --- a/mysql-test/r/histogram_update_using_data.result +++ b/mysql-test/r/histogram_update_using_data.result @@ -1050,3 +1050,16 @@ ANALYZE TABLE tbl_int UPDATE HISTOGRAM ON col1 USING DATA '{"buckets": [[4, 0.25 Table Op Msg_type Msg_text test.tbl_int histogram status Histogram statistics created for column 'col1'. DROP TABLE tbl_int; +# +# Singleton histogram, INT column. +# +# +CREATE TABLE tbl_bigint(col1 BIGINT); +INSERT INTO tbl_bigint VALUES (100000000000); +ANALYZE TABLE tbl_bigint UPDATE HISTOGRAM ON col1 WITH 4 BUCKETS MANUAL UPDATE; +Table Op Msg_type Msg_text +test.tbl_bigint histogram status Histogram statistics created for column 'col1'. +ANALYZE TABLE tbl_bigint UPDATE HISTOGRAM ON col1 USING DATA '{"buckets": [[100000000000, 1.0]], "data-type": "int", "auto-update": false, "null-values": 0.0, "collation-id": 8, "sampling-rate": 1.0, "histogram-type": "singleton", "number-of-buckets-specified": 4}'; +Table Op Msg_type Msg_text +test.tbl_bigint histogram status Histogram statistics created for column 'col1'. +DROP TABLE tbl_bigint; diff --git a/mysql-test/t/histogram_update_using_data.test b/mysql-test/t/histogram_update_using_data.test index d08c46570d4..7b054a43bef 100644 --- a/mysql-test/t/histogram_update_using_data.test +++ b/mysql-test/t/histogram_update_using_data.test @@ -682,3 +682,21 @@ let $json_data= {"buckets": [[4, 0.25], [12, 0.5], [23, 0.625], [52, 0.75]], "da --source include/store_histogram_and_check.inc DROP TABLE tbl_int; + +--echo # +--echo # Singleton histogram, INT column. +--echo # +--echo # + +--let $tbl_name= tbl_bigint +--let $col_name= col1 +--let $buckets= 4 +--let $comparison_value= 20 +--let $update = MANUAL + +CREATE TABLE tbl_bigint(col1 BIGINT); +INSERT INTO tbl_bigint VALUES (100000000000); +let $json_data= {"buckets": [[100000000000, 1.0]], "data-type": "int", "auto-update": false, "null-values": 0.0, "collation-id": 8, "sampling-rate": 1.0, "histogram-type": "singleton", "number-of-buckets-specified": 4}; +--source include/store_histogram_and_check.inc + +DROP TABLE tbl_bigint; diff --git a/sql/histograms/histogram.cc b/sql/histograms/histogram.cc index a248a5d0c9b..5715cc67148 100644 --- a/sql/histograms/histogram.cc +++ b/sql/histograms/histogram.cc @@ -873,16 +873,21 @@ bool Histogram::extract_json_dom_value(const Json_dom *json_dom, ulonglong *out, template <> bool Histogram::extract_json_dom_value(const Json_dom *json_dom, longlong *out, Error_context *context) { - if (json_dom->json_type() != enum_json_type::J_INT) { - if (json_dom->json_type() == enum_json_type::J_UINT) + if (json_dom->json_type() == enum_json_type::J_INT) + *out = down_cast(json_dom)->value(); + else if (!context->binary() && + json_dom->json_type() == enum_json_type::J_UINT) { + ulonglong val = down_cast(json_dom)->value(); + if (val > LLONG_MAX) { context->report_node(json_dom, Message::JSON_VALUE_OUT_OF_RANGE); - else - context->report_node(json_dom, Message::JSON_WRONG_ATTRIBUTE_TYPE); - + return true; + } + *out = static_cast(val); + } else { + context->report_node(json_dom, Message::JSON_WRONG_ATTRIBUTE_TYPE); return true; } - *out = down_cast(json_dom)->value(); return false; } -- 2.19.1