mirror of
https://github.com/MariaDB/server.git
synced 2025-12-28 08:10:14 +00:00
MDEV-33407 Parser support for vector indexes The syntax is create table t1 (... vector index (v) ...); limitation: * v is a binary string and NOT NULL * only one vector index per table * temporary tables are not supported MDEV-33404 Engine-independent indexes: subtable method added support for so-called "high level indexes", they are not visible to the storage engine, implemented on the sql level. For every such an index in a table, say, t1, the server implicitly creates a second table named, like, t1#i#05 (where "05" is the index number in t1). This table has a fixed structure, no frm, not accessible directly, doesn't go into the table cache, needs no MDLs. MDEV-33406 basic optimizer support for k-NN searches for a query like SELECT ... ORDER BY func() optimizer will use item_func->part_of_sortkey() to decide what keys can be used to resolve ORDER BY.
56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
/* Copyright (c) 2023, MariaDB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
|
|
|
|
|
/**
|
|
@file
|
|
|
|
@brief
|
|
This file defines all vector functions
|
|
*/
|
|
|
|
#include <my_global.h>
|
|
#include "item.h"
|
|
|
|
key_map Item_func_vec_distance::part_of_sortkey() const
|
|
{
|
|
key_map map(0);
|
|
if (Item_field *item= get_field_arg())
|
|
{
|
|
Field *f= item->field;
|
|
for (uint i= f->table->s->keys; i < f->table->s->total_keys; i++)
|
|
if (f->table->s->key_info[i].algorithm == HA_KEY_ALG_VECTOR &&
|
|
f->key_start.is_set(i))
|
|
map.set_bit(i);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
double Item_func_vec_distance::val_real()
|
|
{
|
|
String *r1= args[0]->val_str();
|
|
String *r2= args[1]->val_str();
|
|
null_value= !r1 || !r2 || r1->length() != r2->length() ||
|
|
r1->length() % sizeof(float);
|
|
if (null_value)
|
|
return 0;
|
|
float *v1= (float*)r1->ptr();
|
|
float *v2= (float*)r2->ptr();
|
|
double d= 0;
|
|
for (uint i=0; i < r1->length() / sizeof(float); i++)
|
|
d+= (v1[i] - v2[i])*(v1[i] - v2[i]);
|
|
return sqrt(d);
|
|
}
|