From 4f162cdcc52a54c7faa1ffaa933f2e7f8bf2d919 Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 3 Nov 2023 03:39:29 +0000 Subject: [PATCH] =?UTF-8?q?fix=20json/gis/text/blob=20meta=20response=20in?= =?UTF-8?q?consistent=20with=20mysql5.7=20=EF=BC=88master=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deps/oblib/src/common/ob_field.cpp | 6 +++++- src/observer/mysql/obsm_utils.cpp | 4 ++-- src/sql/ob_result_set.cpp | 3 +++ .../meta_info/r/mysql/meta_build_in_func_test.result | 8 ++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/deps/oblib/src/common/ob_field.cpp b/deps/oblib/src/common/ob_field.cpp index f4d5b2e6dd..3a0dfec8e9 100644 --- a/deps/oblib/src/common/ob_field.cpp +++ b/deps/oblib/src/common/ob_field.cpp @@ -359,7 +359,11 @@ int ObField::get_field_mb_length(const ObObjType type, if (OB_FAIL(common::ObCharset::get_mbmaxlen_by_coll(charsetnr, mbmaxlen))) { LOG_WARN("fail to get mbmaxlen", K(charsetnr), K(ret)); } else { - if (lib::is_mysql_mode() && tc == ObTextTC) { + if (lib::is_mysql_mode() && (type == ObLongTextType || type == ObJsonType || type == ObGeometryType)) { + // issue: 52728955, 52735855, 52731784, 52734963, 52729976 + // compat mysql .net driver 5.7, longblob, json, gis length is max u32 + length = UINT32_MAX; + } else if (lib::is_mysql_mode() && tc == ObTextTC) { // compat mysql-jdbc 8.x for judge text type by length length = static_cast(ObAccuracy::MAX_ACCURACY[type].get_length() - 1); } else { diff --git a/src/observer/mysql/obsm_utils.cpp b/src/observer/mysql/obsm_utils.cpp index c81b7a33d0..87f0a9b263 100644 --- a/src/observer/mysql/obsm_utils.cpp +++ b/src/observer/mysql/obsm_utils.cpp @@ -85,8 +85,8 @@ static const ObMySQLTypeMap type_maps_[ObMaxType] = {EMySQLFieldType::MYSQL_TYPE_OB_NCHAR, 0, 0}, /* ObNCharType */ {EMySQLFieldType::MYSQL_TYPE_OB_UROWID, 0, 0}, {EMySQLFieldType::MYSQL_TYPE_ORA_BLOB, 0, 0}, /* ObLobType */ - {EMySQLFieldType::MYSQL_TYPE_JSON, BLOB_FLAG | NO_DEFAULT_VALUE_FLAG, 0}, /* ObJsonType */ - {EMySQLFieldType::MYSQL_TYPE_GEOMETRY, BLOB_FLAG | NO_DEFAULT_VALUE_FLAG, 0}, /* ObGeometryType */ + {EMySQLFieldType::MYSQL_TYPE_JSON, BLOB_FLAG | BINARY_FLAG, 0}, /* ObJsonType */ + {EMySQLFieldType::MYSQL_TYPE_GEOMETRY, BLOB_FLAG | BINARY_FLAG, 0}, /* ObGeometryType */ {EMySQLFieldType::MYSQL_TYPE_COMPLEX, 0, 0}, /* ObUserDefinedSQLType */ {EMySQLFieldType::MYSQL_TYPE_NEWDECIMAL, 0, 0}, /* ObDecimalIntType */ /* ObMaxType */ diff --git a/src/sql/ob_result_set.cpp b/src/sql/ob_result_set.cpp index 9daa4a84f1..946462cf09 100644 --- a/src/sql/ob_result_set.cpp +++ b/src/sql/ob_result_set.cpp @@ -1724,6 +1724,9 @@ void ObResultSet::replace_lob_type(const ObSQLSessionInfo &session, // for 5.x, always return MYSQL_TYPE_BLOB // for 8.x always return MYSQL_TYPE_BLOB, and do text type judge in mysql-jdbc by length mfield.type_ = obmysql::EMySQLFieldType::MYSQL_TYPE_BLOB; + } else if (mfield.type_ == obmysql::EMySQLFieldType::MYSQL_TYPE_JSON) { + // for mysql 5.x json response as plain text not binary, but the charset always binary + mfield.charsetnr_ = common::CS_TYPE_BINARY; } } } diff --git a/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result b/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result index dcba0dc997..82408240a8 100644 --- a/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result +++ b/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result @@ -265,7 +265,7 @@ def substr(v,1) 253 512 0 Y 0 0 45 ##cast test select substr(cast(date_c as char(1024)), 0) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def substr(cast(date_c as char(1024)), 0) 252 536870910 0 Y 16 0 45 +def substr(cast(date_c as char(1024)), 0) 252 4294967295 0 Y 16 0 45 +---------------------------------------+ | substr(cast(date_c as char(1024)), 0) | +---------------------------------------+ @@ -273,7 +273,7 @@ def substr(cast(date_c as char(1024)), 0) 252 536870910 0 Y 16 0 45 +---------------------------------------+ select substr(cast(date_c as char(1024)), 10) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def substr(cast(date_c as char(1024)), 10) 252 536870910 17 Y 16 0 45 +def substr(cast(date_c as char(1024)), 10) 252 4294967295 17 Y 16 0 45 +----------------------------------------+ | substr(cast(date_c as char(1024)), 10) | +----------------------------------------+ @@ -289,7 +289,7 @@ def substr(cast(1024 as char(1024)), 1, 2) 253 8 2 Y 0 0 45 +----------------------------------------+ select substr(cast(date_c as char(1024)) from 10) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def substr(cast(date_c as char(1024)) from 10) 252 536870910 17 Y 16 0 45 +def substr(cast(date_c as char(1024)) from 10) 252 4294967295 17 Y 16 0 45 +--------------------------------------------+ | substr(cast(date_c as char(1024)) from 10) | +--------------------------------------------+ @@ -2771,7 +2771,7 @@ def unhex('123') 253 2 2 Y 128 0 63 +--------------+ select unhex(cast(repeat('123',5) as char(1024))); Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def unhex(cast(repeat('123',5) as char(1024))) 252 536870910 8 Y 144 0 63 +def unhex(cast(repeat('123',5) as char(1024))) 252 4294967295 8 Y 144 0 63 +--------------------------------------------+ | unhex(cast(repeat('123',5) as char(1024))) | +--------------------------------------------+