MDEV-35309 ALTER performs vector truncation without WARN_DATA_TRUNCATED or similar warnings/errors
Let ALTER TABLE issue a warning/error when VECTOR data is truncated, but only if tail has meaningful (non-zero) values. Closes #3722
This commit is contained in:
parent
e5574d8b94
commit
313b8c293a
@ -436,3 +436,21 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||||||
1 SIMPLE t ALL NULL NULL NULL NULL 2 Using filesort
|
1 SIMPLE t ALL NULL NULL NULL NULL 2 Using filesort
|
||||||
drop table t;
|
drop table t;
|
||||||
# End of 11.7 tests
|
# End of 11.7 tests
|
||||||
|
#
|
||||||
|
# MDEV-35309 - ALTER performs vector truncation without WARN_DATA_TRUNCATED or similar warnings/errors
|
||||||
|
#
|
||||||
|
create table t (v vector(2));
|
||||||
|
insert into t values (0x3131313132323232);
|
||||||
|
select * from t;
|
||||||
|
v
|
||||||
|
11112222
|
||||||
|
alter table t modify v vector(1);
|
||||||
|
ERROR 01000: Data truncated for column 'v' at row 1
|
||||||
|
set statement sql_mode='' for alter table t modify v vector(1);
|
||||||
|
Warnings:
|
||||||
|
Warning 1265 Data truncated for column 'v' at row 1
|
||||||
|
select * from t;
|
||||||
|
v
|
||||||
|
1111
|
||||||
|
drop table t;
|
||||||
|
# End of 11.8 tests
|
||||||
|
@ -318,3 +318,17 @@ insert into t values (0x00000000),(0x00000000);
|
|||||||
explain select vec_totext(a) from t order by vec_distance_euclidean(a,0x00000000) limit 1;
|
explain select vec_totext(a) from t order by vec_distance_euclidean(a,0x00000000) limit 1;
|
||||||
drop table t;
|
drop table t;
|
||||||
--echo # End of 11.7 tests
|
--echo # End of 11.7 tests
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-35309 - ALTER performs vector truncation without WARN_DATA_TRUNCATED or similar warnings/errors
|
||||||
|
--echo #
|
||||||
|
create table t (v vector(2));
|
||||||
|
insert into t values (0x3131313132323232);
|
||||||
|
select * from t;
|
||||||
|
--error WARN_DATA_TRUNCATED
|
||||||
|
alter table t modify v vector(1);
|
||||||
|
set statement sql_mode='' for alter table t modify v vector(1);
|
||||||
|
select * from t;
|
||||||
|
drop table t;
|
||||||
|
|
||||||
|
--echo # End of 11.8 tests
|
||||||
|
@ -256,7 +256,22 @@ static void do_copy_vec(const Copy_field *copy)
|
|||||||
int2store(copy->to_ptr, to_length);
|
int2store(copy->to_ptr, to_length);
|
||||||
|
|
||||||
if (from_length > to_length)
|
if (from_length > to_length)
|
||||||
|
{
|
||||||
memcpy(to, from, to_length);
|
memcpy(to, from, to_length);
|
||||||
|
if (copy->from_field->table->in_use->count_cuted_fields >
|
||||||
|
CHECK_FIELD_EXPRESSION)
|
||||||
|
{
|
||||||
|
for (uint i= to_length; i < from_length; i++)
|
||||||
|
{
|
||||||
|
if (from[i] != 0)
|
||||||
|
{
|
||||||
|
copy->to_field->set_warning(Sql_condition::WARN_LEVEL_WARN,
|
||||||
|
WARN_DATA_TRUNCATED, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(to, from, from_length);
|
memcpy(to, from, from_length);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user