Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-35309 - ALTER performs vector truncation without WARN_DATA_TRUNCATED or similar warnings/errors #3722

Open
wants to merge 1 commit into
base: 11.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions mysql-test/main/vector2.result
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,20 @@ vec_totext(v)
[7]
[6]
drop table t;
#
# 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;
12 changes: 12 additions & 0 deletions mysql-test/main/vector2.test
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,15 @@ create table t (v vector(1) not null, vector(v));
insert into t select vec_fromtext(concat('[',seq,']')) FROM seq_1_to_10;
select vec_totext(v) from t order by vec_distance_euclidean(v,vec_fromtext('[0]')) desc limit 5;
drop table t;

--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;
15 changes: 15 additions & 0 deletions sql/sql_type_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,22 @@ static void do_copy_vec(const Copy_field *copy)
int2store(copy->to_ptr, to_length);

if (from_length > 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
{
memcpy(to, from, from_length);
Expand Down