From 689cf818ff3a446fceaf9e3d6422d3571a0010d4 Mon Sep 17 00:00:00 2001 From: Abhishek Bansal Date: Mon, 2 Mar 2026 14:43:59 +0530 Subject: [PATCH] MDEV-35211: Make VEC_FromText return VECTOR type instead of VARBINARY VEC_FROMTEXT() was incorrectly inheriting its type handler from Item_str_func, causing it to be identified as VARBINARY. This led to incorrect column types (VARBINARY instead of VECTOR) when using CREATE TABLE ... AS SELECT. This change: - Overrides type_handler() in Item_func_vec_fromtext to return type_handler_vector. - Overrides create_field_for_create_select() to ensure the field is created correctly using the vector type handler during table creation. - Adds a regression test in vector_funcs.test to verify that CREATE TABLE ... AS SELECT now correctly creates a column of type VECTOR. --- mysql-test/main/vector_funcs.result | 10 ++++++++++ mysql-test/main/vector_funcs.test | 7 +++++++ sql/item_vectorfunc.h | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/mysql-test/main/vector_funcs.result b/mysql-test/main/vector_funcs.result index 171bb6c7433..6aba9df0b05 100644 --- a/mysql-test/main/vector_funcs.result +++ b/mysql-test/main/vector_funcs.result @@ -265,4 +265,14 @@ drop table t; # select vec_distance(value(key_cache_name), 0x30303030) from information_schema.key_caches; ERROR HY000: Cannot determine distance type for VEC_DISTANCE, index is not found +# +# MDEV-35211: VEC_FromText does not return vector type but varbinary +# +create table t as select vec_fromtext('[1,2,3]') as v; +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `v` vector(3) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +drop table t; # End of 11.8 tests diff --git a/mysql-test/main/vector_funcs.test b/mysql-test/main/vector_funcs.test index 54f931d706e..b0ada0fa61f 100644 --- a/mysql-test/main/vector_funcs.test +++ b/mysql-test/main/vector_funcs.test @@ -153,4 +153,11 @@ drop table t; --error ER_VEC_DISTANCE_TYPE select vec_distance(value(key_cache_name), 0x30303030) from information_schema.key_caches; +--echo # +--echo # MDEV-35211: VEC_FromText does not return vector type but varbinary +--echo # +create table t as select vec_fromtext('[1,2,3]') as v; +show create table t; +drop table t; + --echo # End of 11.8 tests diff --git a/sql/item_vectorfunc.h b/sql/item_vectorfunc.h index 7677123bf5d..babf6347041 100644 --- a/sql/item_vectorfunc.h +++ b/sql/item_vectorfunc.h @@ -21,6 +21,7 @@ #include "item.h" #include "lex_string.h" #include "item_func.h" +#include "sql_type_vector.h" class Item_func_vec_distance: public Item_real_func { @@ -94,6 +95,10 @@ public: bool fix_length_and_dec(THD *thd) override; Item_func_vec_fromtext(THD *thd, Item *a); String *val_str(String *buf) override; + const Type_handler *type_handler() const override + { return &type_handler_vector; } + Field *create_field_for_create_select(MEM_ROOT *root, TABLE *table) override + { return create_table_field_from_handler(root, table); } LEX_CSTRING func_name_cstring() const override { static LEX_CSTRING name= { STRING_WITH_LEN("VEC_FromText") };