Skip to content

Commit cca243b

Browse files
committed
MDEV-35768 Vector key is not used upon selecting from views / subqueries
1 parent 61806af commit cca243b

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

mysql-test/main/vector2.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,21 @@ vec_totext(v)
369369
[7]
370370
[6]
371371
drop table t;
372+
#
373+
# MDEV-35768 Vector key is not used upon selecting from views / subqueries
374+
#
375+
create table t (b vector(1) not null, vector(b));
376+
insert into t values (0x31313131),(0x32323232);
377+
create view v as select * from t;
378+
explain select * from t order by vec_distance_euclidean(b,0x30303030) limit 1;
379+
id select_type table type possible_keys key key_len ref rows Extra
380+
1 SIMPLE t index NULL b 6 NULL 1
381+
explain select * from v order by vec_distance_euclidean(b,0x30303030) limit 1;
382+
id select_type table type possible_keys key key_len ref rows Extra
383+
1 SIMPLE t index NULL b 6 NULL 1
384+
explain select * from (select * from t) sq order by vec_distance_euclidean(b,0x30303030) limit 1;
385+
id select_type table type possible_keys key key_len ref rows Extra
386+
1 SIMPLE t index NULL b 6 NULL 1
387+
drop view v;
388+
drop table t;
389+
# End of 11.7 tests

mysql-test/main/vector2.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,18 @@ create table t (v vector(1) not null, vector(v));
265265
insert into t select vec_fromtext(concat('[',seq,']')) FROM seq_1_to_10;
266266
select vec_totext(v) from t order by vec_distance_euclidean(v,vec_fromtext('[0]')) desc limit 5;
267267
drop table t;
268+
269+
--echo #
270+
--echo # MDEV-35768 Vector key is not used upon selecting from views / subqueries
271+
--echo #
272+
273+
create table t (b vector(1) not null, vector(b));
274+
insert into t values (0x31313131),(0x32323232);
275+
create view v as select * from t;
276+
explain select * from t order by vec_distance_euclidean(b,0x30303030) limit 1;
277+
explain select * from v order by vec_distance_euclidean(b,0x30303030) limit 1;
278+
explain select * from (select * from t) sq order by vec_distance_euclidean(b,0x30303030) limit 1;
279+
drop view v;
280+
drop table t;
281+
282+
--echo # End of 11.7 tests

sql/item_vectorfunc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class Item_func_vec_distance_common: public Item_real_func
2626
{
2727
Item_field *get_field_arg() const
2828
{
29-
if (args[0]->type() == Item::FIELD_ITEM && args[1]->const_item())
30-
return (Item_field*)(args[0]);
31-
if (args[1]->type() == Item::FIELD_ITEM && args[0]->const_item())
32-
return (Item_field*)(args[1]);
29+
if (args[0]->real_item()->type() == Item::FIELD_ITEM && args[1]->const_item())
30+
return (Item_field*)(args[0]->real_item());
31+
if (args[1]->real_item()->type() == Item::FIELD_ITEM && args[0]->const_item())
32+
return (Item_field*)(args[1])->real_item();
3333
return NULL;
3434
}
3535
bool check_arguments() const override

0 commit comments

Comments
 (0)