Skip to content

Commit 999b669

Browse files
MDEV-40486 [fixup] Clamp max_length at MAX_FIELD_VARCHARLENGTH in Item_func_vec_fromtext::fix_length_and_dec
This allows create table t1 (v vector(64) not null); insert into t1 select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64; which was banned in the previous fix bb0ac43, though this also introduces the inconsistency(?) where create table t1 as select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64; still fails ER_TRUNCATED_WRONG_VALUE see updated tests TODO: - Changes in vector_utf16.result does not look right - the following tests crashes: CREATE TABLE t1 (v VECTOR(2)); --error ER_TOO_BIG_FIELDLENGTH INSERT INTO t1 VALUES (VEC_FROMTEXT(CONCAT('[1.', REPEAT('0',70000), ',2]'))); DROP TABLE t1; SELECT VEC_FROMTEXT('😀😀😀');
1 parent d26f9ab commit 999b669

4 files changed

Lines changed: 19 additions & 18 deletions

File tree

mysql-test/main/vector2.result

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ drop table t;
160160
# MDEV-35141 Server crashes in Field_vector::report_wrong_value upon statistic collection
161161
#
162162
create table t1 (v vector(64) not null);
163-
insert into t1 select vec_fromtext(cast(concat('[',group_concat(1),']') as char(130))) from seq_1_to_64;
163+
insert into t1 select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64;
164164
analyze table t1 persistent for all;
165165
Table Op Msg_type Msg_text
166166
test.t1 analyze status Engine-independent statistics collected
@@ -571,11 +571,11 @@ set sql_mode=@old_sql_mode;
571571
## Original testcase
572572
CREATE TABLE t (a TEXT) AS SELECT '[1]' AS a;
573573
CREATE TABLE tt AS SELECT VEC_FROMTEXT(a) AS f FROM t;
574-
ERROR 42000: Column length too big for column 'f' (max = 16383); use BLOB or TEXT instead
574+
ERROR 22007: Incorrect vector value: '\x00\x00\x80?' for column `test`.`tt`.`f` at row 1
575575
DROP TABLE t;
576576
CREATE TABLE t (a LONGBLOB) AS SELECT '[1]' AS a;
577577
CREATE TABLE tt AS SELECT VEC_FROMTEXT(a) AS f FROM t;
578-
ERROR 42000: Column length too big for column 'f' (max = 16383); use BLOB or TEXT instead
578+
ERROR 22007: Incorrect vector value: '\x00\x00\x80?' for column `test`.`tt`.`f` at row 1
579579
DROP TABLE t;
580580
## Another case, which would have failed with ERROR 1292
581581
## without the fix
@@ -592,7 +592,7 @@ SELECT VEC_FROMTEXT(concat('[1', repeat(',1', 16382), ']')) AS f;
592592
DROP TABLE tt;
593593
CREATE TABLE tt AS
594594
SELECT VEC_FROMTEXT(concat('[1', repeat(',1', 16383), ']')) AS f;
595-
ERROR 42000: Column length too big for column 'f' (max = 16383); use BLOB or TEXT instead
595+
ERROR 22007: Incorrect vector value: '\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00...' for column `test`.`tt`.`f` at row 1
596596
## "Zero-dimensional" argument, no change in behaviour after fix
597597
SELECT VEC_FROMTEXT('[]') as f;
598598
f
@@ -625,9 +625,10 @@ t2 CREATE TABLE `t2` (
625625
DROP TABLE t1, t2;
626626
CREATE TABLE t3 (f VECTOR(0));
627627
ERROR 42000: Incorrect column specifier for column 'f'
628-
## Fails because concat('[',group_concat(1),']') is mediumblob
629628
create view v1 as select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64;
630-
ERROR 42000: Column length too big for column 'vec_fromtext(concat('[',group_concat(1),']'))' (max = 16383); use BLOB or TEXT instead
629+
DROP view v1;
630+
create table t1 as select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64;
631+
ERROR 22007: Incorrect vector value: '\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00\x80?\x00\x00...' for column `test`.`t1`.`vec_fromtext(concat('[',group_concat(1),']'))` at row 65
631632
## NULLs
632633
select vec_fromtext(NULL);
633634
vec_fromtext(NULL)

mysql-test/main/vector2.test

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ drop table t;
125125
--echo # MDEV-35141 Server crashes in Field_vector::report_wrong_value upon statistic collection
126126
--echo #
127127
create table t1 (v vector(64) not null);
128-
insert into t1 select vec_fromtext(cast(concat('[',group_concat(1),']') as char(130))) from seq_1_to_64;
128+
insert into t1 select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64;
129129
analyze table t1 persistent for all;
130130
drop table t1;
131131

@@ -453,12 +453,12 @@ set sql_mode=@old_sql_mode;
453453

454454
--echo ## Original testcase
455455
CREATE TABLE t (a TEXT) AS SELECT '[1]' AS a;
456-
--error ER_TOO_BIG_FIELDLENGTH
456+
--error ER_TRUNCATED_WRONG_VALUE
457457
CREATE TABLE tt AS SELECT VEC_FROMTEXT(a) AS f FROM t;
458458
DROP TABLE t;
459459

460460
CREATE TABLE t (a LONGBLOB) AS SELECT '[1]' AS a;
461-
--error ER_TOO_BIG_FIELDLENGTH
461+
--error ER_TRUNCATED_WRONG_VALUE
462462
CREATE TABLE tt AS SELECT VEC_FROMTEXT(a) AS f FROM t;
463463
DROP TABLE t;
464464

@@ -478,7 +478,7 @@ CREATE TABLE tt AS
478478
SELECT VEC_FROMTEXT(concat('[1', repeat(',1', 16382), ']')) AS f;
479479
DROP TABLE tt;
480480

481-
--error ER_TOO_BIG_FIELDLENGTH
481+
--error ER_TRUNCATED_WRONG_VALUE
482482
CREATE TABLE tt AS
483483
SELECT VEC_FROMTEXT(concat('[1', repeat(',1', 16383), ']')) AS f;
484484

@@ -503,9 +503,11 @@ DROP TABLE t1, t2;
503503
--error ER_WRONG_FIELD_SPEC
504504
CREATE TABLE t3 (f VECTOR(0));
505505

506-
--echo ## Fails because concat('[',group_concat(1),']') is mediumblob
507-
--error ER_TOO_BIG_FIELDLENGTH
508506
create view v1 as select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64;
507+
DROP view v1;
508+
509+
--error ER_TRUNCATED_WRONG_VALUE
510+
create table t1 as select vec_fromtext(concat('[',group_concat(1),']')) from seq_1_to_64;
509511

510512
--echo ## NULLs
511513
select vec_fromtext(NULL);
-44 Bytes
Binary file not shown.

sql/item_vectorfunc.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,7 @@ bool Item_func_vec_fromtext::fix_length_and_dec(THD *thd)
196196
else
197197
maxlen= (maxlen - 1) * 2;
198198
fix_length_and_charset(maxlen, &my_charset_bin);
199-
if (max_length > MAX_FIELD_VARCHARLENGTH)
200-
{
201-
my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), name.str,
202-
static_cast<ulong>(MAX_FIELD_VARCHARLENGTH / sizeof(float)));
203-
return true;
204-
}
199+
set_if_smaller(max_length, MAX_FIELD_VARCHARLENGTH);
205200
set_maybe_null();
206201
return false;
207202
}
@@ -215,6 +210,9 @@ String *Item_func_vec_fromtext::val_str(String *buf)
215210
if ((null_value= !value))
216211
return nullptr;
217212

213+
if (value->length() > max_length)
214+
return nullptr;
215+
218216
buf->length(0);
219217
buf->set_charset(&my_charset_bin);
220218
CHARSET_INFO *cs= value->charset();

0 commit comments

Comments
 (0)