Skip to content

Commit 35d327f

Browse files
committed
MDEV-22599 WITHOUT OVERLAPS does not work with prefix indexes
cmp_max is used instead of cmp to compare key_parts
1 parent 0c595bd commit 35d327f

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

mysql-test/suite/period/r/overlaps.result

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ id u s e
185185
5 6 2003-05-01 2003-07-01
186186
7 8 2003-05-01 2003-07-01
187187
9 10 2003-05-01 2003-07-01
188+
drop sequence seq;
188189
create or replace table t(id int, s date, e date,
189190
period for p(s,e));
190191
insert into t values (1, '2003-01-01', '2003-03-01'),
@@ -281,4 +282,18 @@ Warnings:
281282
Warning 1062 Duplicate entry '1-2020-03-05-2020-03-01' for key 'x'
282283
load data infile 'tmp_t.txt' replace into table t;
283284
ERROR 42000: This version of MariaDB doesn't yet support 'WITHOUT OVERLAPS'
284-
create or replace database test;
285+
# MDEV-22599 WITHOUT OVERLAPS does not work with prefix indexes
286+
create or replace table t1 (a varchar(6), s timestamp, e timestamp,
287+
period for p(s,e),
288+
unique(a(3), p without overlaps));
289+
insert into t1 values ('foo', '2012-01-01', '2015-12-31');
290+
insert into t1 values ('foobar', '2013-01-01', '2014-01-01');
291+
ERROR 23000: Duplicate entry 'foo-2014-01-01 00:00:00-2013-01-01 00:00:00' for key 'a'
292+
insert into t1 values ('bar', '2012-01-01', '2015-12-31'),
293+
('baz', '2013-01-01', '2014-01-01');
294+
select * from t1;
295+
a s e
296+
foo 2012-01-01 00:00:00 2015-12-31 00:00:00
297+
bar 2012-01-01 00:00:00 2015-12-31 00:00:00
298+
baz 2013-01-01 00:00:00 2014-01-01 00:00:00
299+
drop table t, t1;

mysql-test/suite/period/t/overlaps.test

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ update t set id= nextval(seq), u= nextval(seq), s='2003-05-01', e='2003-07-01'
163163

164164
--sorted_result
165165
select * from t;
166+
drop sequence seq;
166167

167168
create or replace table t(id int, s date, e date,
168169
period for p(s,e));
@@ -270,4 +271,18 @@ load data infile 'tmp_t.txt' replace into table t;
270271

271272
remove_file $MYSQLD_DATADIR/test/tmp_t.txt;
272273

273-
create or replace database test;
274+
275+
--echo # MDEV-22599 WITHOUT OVERLAPS does not work with prefix indexes
276+
create or replace table t1 (a varchar(6), s timestamp, e timestamp,
277+
period for p(s,e),
278+
unique(a(3), p without overlaps));
279+
280+
insert into t1 values ('foo', '2012-01-01', '2015-12-31');
281+
--error ER_DUP_ENTRY
282+
insert into t1 values ('foobar', '2013-01-01', '2014-01-01');
283+
284+
insert into t1 values ('bar', '2012-01-01', '2015-12-31'),
285+
('baz', '2013-01-01', '2014-01-01');
286+
select * from t1;
287+
288+
drop table t, t1;

sql/table.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8759,7 +8759,8 @@ bool TABLE::check_period_overlaps(const KEY &key,
87598759
if (key.key_part[part_nr].null_bit)
87608760
if (f->is_null_in_record(lhs) || f->is_null_in_record(rhs))
87618761
return false;
8762-
if (f->cmp(f->ptr_in_record(lhs), f->ptr_in_record(rhs)) != 0)
8762+
uint kp_len= key.key_part[part_nr].length;
8763+
if (f->cmp_max(f->ptr_in_record(lhs), f->ptr_in_record(rhs), kp_len) != 0)
87638764
return false;
87648765
}
87658766

0 commit comments

Comments
 (0)