summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2023-01-24 12:24:54 +0300
committerNikita Malyavin <nikitamalyavin@gmail.com>2023-01-24 12:42:18 +0300
commitee92b709ee6ada510ff1fcb5b92757c1bccdd0f7 (patch)
treeea224930a3bb068b5fbd4f0f8d83eb426d829a22
parent2ba6f3d46a4ee0268d82bf5b19f9d117c77fd4f0 (diff)
downloadmariadb-git-bb-10.5-MDEV-30415.tar.gz
MDEV-30415 PERIOD false positive overlap wtih utf8mb4_unicode_nopad_cibb-10.5-MDEV-30415
A wrong UNIQUE violation is caused here by camparing strings 'def' and 'def ' (with space), under utf8mb4_unicode_nopad_ci collation, which means "don't count in paddings when comparing". Field::cmp_prefix uses a comparison through collation, so cmp_binary should be used instead.
-rw-r--r--mysql-test/suite/period/r/overlaps.result15
-rw-r--r--mysql-test/suite/period/t/overlaps.test20
-rw-r--r--sql/table.cc2
3 files changed, 36 insertions, 1 deletions
diff --git a/mysql-test/suite/period/r/overlaps.result b/mysql-test/suite/period/r/overlaps.result
index 3ed8e1a0014..e7aef7564d4 100644
--- a/mysql-test/suite/period/r/overlaps.result
+++ b/mysql-test/suite/period/r/overlaps.result
@@ -351,3 +351,18 @@ primary key(id, p without overlaps)
) engine=heap partition by hash(id);
update t set id = 1;
drop table t, t1;
+# MDEV-30415 PERIOD false positive overlap wtih utf8mb4_unicode_nopad_ci
+create table `t1` (
+datetime_column_name_1 datetime(6) not null,
+datetime_column_name_2 datetime(6) not null,
+text_column_name text collate utf8mb4_unicode_nopad_ci not null,
+period for p (datetime_column_name_1, datetime_column_name_2),
+unique key index_name (text_column_name(191), p without overlaps)
+) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_nopad_ci;
+insert into t1 values ('2000-01-01', '2001-01-01', 'def '),
+('2000-01-01', '2001-01-01', 'def');
+truncate t1;
+insert into t1 values ('2000-01-01', '2001-01-01', 'def'),
+('2000-01-01', '2001-01-01', 'def '),
+('2000-01-01', '2001-01-01', 'def ');
+drop table t1;
diff --git a/mysql-test/suite/period/t/overlaps.test b/mysql-test/suite/period/t/overlaps.test
index 6cd78769d4a..23d95605e5f 100644
--- a/mysql-test/suite/period/t/overlaps.test
+++ b/mysql-test/suite/period/t/overlaps.test
@@ -344,3 +344,23 @@ create or replace table t (id int, s date, e date, period for p(s,e),
update t set id = 1;
drop table t, t1;
+
+
+--echo # MDEV-30415 PERIOD false positive overlap wtih utf8mb4_unicode_nopad_ci
+
+create table `t1` (
+ datetime_column_name_1 datetime(6) not null,
+ datetime_column_name_2 datetime(6) not null,
+ text_column_name text collate utf8mb4_unicode_nopad_ci not null,
+ period for p (datetime_column_name_1, datetime_column_name_2),
+ unique key index_name (text_column_name(191), p without overlaps)
+) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_nopad_ci;
+
+
+insert into t1 values ('2000-01-01', '2001-01-01', 'def '),
+ ('2000-01-01', '2001-01-01', 'def');
+truncate t1;
+insert into t1 values ('2000-01-01', '2001-01-01', 'def'),
+ ('2000-01-01', '2001-01-01', 'def '),
+ ('2000-01-01', '2001-01-01', 'def ');
+drop table t1;
diff --git a/sql/table.cc b/sql/table.cc
index 7334f0143e6..118f6ffed8d 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -9025,7 +9025,7 @@ bool TABLE::check_period_overlaps(const KEY &key,
if (f->is_null_in_record(lhs) || f->is_null_in_record(rhs))
return false;
uint kp_len= key.key_part[part_nr].length;
- if (f->cmp_prefix(f->ptr_in_record(lhs), f->ptr_in_record(rhs),
+ if (f->cmp_binary(f->ptr_in_record(lhs), f->ptr_in_record(rhs),
kp_len) != 0)
return false;
}