Skip to content

Commit b56ca29

Browse files
committed
MDEV-35105 Assertion `tab->join->order' fails upon vector search with DISTINCT
don't apply distinct optimization to order by a vector index
1 parent 9ddb94f commit b56ca29

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

mysql-test/main/vector2.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,12 @@ t CREATE TABLE `t` (
9595
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
9696
drop table t;
9797
set mhnsw_distance_function= default;
98+
#
99+
# MDEV-35105 Assertion `tab->join->order' fails upon vector search with DISTINCT
100+
#
101+
create table t (a int, v blob not null, vector(v));
102+
insert into t values(1,x'00000000'),(2,x'00000000');
103+
select distinct a from t order by vec_distance_euclidean(v,vec_fromtext('[1]')) limit 1;
104+
a
105+
#
106+
drop table t;

mysql-test/main/vector2.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@ execute stmt;
8282
show create table t;
8383
drop table t;
8484
set mhnsw_distance_function= default;
85+
86+
--echo #
87+
--echo # MDEV-35105 Assertion `tab->join->order' fails upon vector search with DISTINCT
88+
--echo #
89+
create table t (a int, v blob not null, vector(v));
90+
insert into t values(1,x'00000000'),(2,x'00000000');
91+
--replace_column 1 #
92+
select distinct a from t order by vec_distance_euclidean(v,vec_fromtext('[1]')) limit 1;
93+
drop table t;

sql/sql_select.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4402,7 +4402,8 @@ JOIN::optimize_distinct()
44024402
}
44034403

44044404
/* Optimize "select distinct b from t1 order by key_part_1 limit #" */
4405-
if (order && skip_sort_order && !unit->lim.is_with_ties())
4405+
if (order && skip_sort_order && !unit->lim.is_with_ties()
4406+
&& (*order->item)->type() == Item::FIELD_ITEM)
44064407
{
44074408
/* Should already have been optimized away */
44084409
DBUG_ASSERT(ordered_index_usage == ordered_index_order_by);

0 commit comments

Comments
 (0)