From 69ca2501e6f610fc3bf768aa187cd59efcb13671 Mon Sep 17 00:00:00 2001 From: Stas Klinov Date: Tue, 18 Jun 2024 14:39:46 +0200 Subject: [PATCH] fixed missed KNN options for adding attribute at alter table; added case to test 275; fixed #2230 --- src/searchd.cpp | 1 + src/searchdddl.cpp | 27 ++++++++++++++++++++------- src/searchdsql.h | 1 + src/sphinx_alter.cpp | 1 + src/sphinx_alter.h | 1 + test/test_275/model.bin | 9 +++++++-- test/test_275/test.xml | 5 +++++ 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/searchd.cpp b/src/searchd.cpp index ae4b6dd039..536488743d 100644 --- a/src/searchd.cpp +++ b/src/searchd.cpp @@ -16122,6 +16122,7 @@ static void AddAttrToIndex ( const SqlStmt_t & tStmt, CSphIndex * pIdx, CSphStri tCtx.m_iBits = tStmt.m_iBits; tCtx.m_uFlags = tStmt.m_uAttrFlags; tCtx.m_eEngine = tStmt.m_eEngine; + tCtx.m_tKNN = tStmt.m_tAlterKNN; if ( bIndexed || bStored ) { diff --git a/src/searchdddl.cpp b/src/searchdddl.cpp index 606a23d98b..5b665b8dc8 100644 --- a/src/searchdddl.cpp +++ b/src/searchdddl.cpp @@ -42,6 +42,7 @@ class DdlParser_c : public SqlParserTraits_c void Reset() { *this = ItemOptions_t(); } DWORD ToFlags() const; + knn::IndexSettings_t ToKNN() const; }; DdlParser_c ( CSphVector& dStmt, const char* szQuery, CSphString* pError ); @@ -127,6 +128,19 @@ DWORD DdlParser_c::ItemOptions_t::ToFlags() const return uFlags; } +knn::IndexSettings_t DdlParser_c::ItemOptions_t::ToKNN() const +{ + knn::IndexSettings_t tKNN; + + tKNN.m_iDims = m_iKNNDims; + tKNN.m_eHNSWSimilarity = m_eHNSWSimilarity; + tKNN.m_iHNSWM = m_iHNSWM; + tKNN.m_iHNSWEFConstruction = m_iHNSWEFConstruction; + + return tKNN; + +} + ////////////////////////////////////////////////////////////////////////// DdlParser_c::DdlParser_c ( CSphVector & dStmt, const char* szQuery, CSphString* pError ) @@ -225,7 +239,6 @@ bool DdlParser_c::CheckFieldFlags ( ESphAttr eAttrType, int iFlags, const CSphSt bool DdlParser_c::SetupAlterTable ( const SqlNode_t & tIndex, const SqlNode_t & tAttr, ESphAttr eAttr, int iFieldFlags, int iBits, bool bModify ) { assert( m_pStmt ); - ItemOptions_t tOpts = m_tItemOptions; m_pStmt->m_eStmt = bModify ? STMT_ALTER_MODIFY : STMT_ALTER_ADD; ToString ( m_pStmt->m_sIndex, tIndex ); @@ -235,11 +248,14 @@ bool DdlParser_c::SetupAlterTable ( const SqlNode_t & tIndex, const SqlNode_t & m_pStmt->m_eAlterColType = eAttr; m_pStmt->m_uFieldFlags = ConvertFlags(iFieldFlags); m_pStmt->m_uAttrFlags = m_tItemOptions.ToFlags(); - m_pStmt->m_eEngine = tOpts.m_eEngine; + m_pStmt->m_eEngine = m_tItemOptions.m_eEngine; m_pStmt->m_iBits = iBits; + m_pStmt->m_tAlterKNN = m_tItemOptions.ToKNN(); + + bool bOk = CheckFieldFlags ( m_pStmt->m_eAlterColType, iFieldFlags, m_pStmt->m_sAlterAttr, m_tItemOptions, m_sError ); m_tItemOptions.Reset(); - return CheckFieldFlags ( m_pStmt->m_eAlterColType, iFieldFlags, m_pStmt->m_sAlterAttr, tOpts, m_sError ); + return bOk; } @@ -275,10 +291,7 @@ bool DdlParser_c::AddCreateTableCol ( const SqlNode_t & tName, const SqlNode_t & tAttr.m_bFastFetch = tOpts.m_bFastFetch; tAttr.m_bStringHash = tOpts.m_bStringHash; tAttr.m_bKNN = !tOpts.m_sKNNType.IsEmpty(); - tAttr.m_tKNN.m_iDims = tOpts.m_iKNNDims; - tAttr.m_tKNN.m_eHNSWSimilarity = tOpts.m_eHNSWSimilarity; - tAttr.m_tKNN.m_iHNSWM = tOpts.m_iHNSWM; - tAttr.m_tKNN.m_iHNSWEFConstruction = tOpts.m_iHNSWEFConstruction; + tAttr.m_tKNN = tOpts.ToKNN(); return true; } diff --git a/src/searchdsql.h b/src/searchdsql.h index 851d03f942..67f7d6c97b 100644 --- a/src/searchdsql.h +++ b/src/searchdsql.h @@ -272,6 +272,7 @@ struct SqlStmt_t DWORD m_uFieldFlags = 0; DWORD m_uAttrFlags = 0; int m_iBits = -1; + knn::IndexSettings_t m_tAlterKNN; // CREATE TABLE specific CreateTableSettings_t m_tCreateTable; diff --git a/src/sphinx_alter.cpp b/src/sphinx_alter.cpp index 73a7848d3b..edb10b501d 100644 --- a/src/sphinx_alter.cpp +++ b/src/sphinx_alter.cpp @@ -82,6 +82,7 @@ void AddToSchema ( CSphSchema & tSchema, const AttrAddRemoveCtx_t & tCtx, CSphSt tInfo.m_uAttrFlags = tCtx.m_uFlags; tInfo.m_eEngine = tCtx.m_eEngine; tInfo.m_tLocator.m_iBitCount = tCtx.m_iBits; + tInfo.m_tKNN = tCtx.m_tKNN; auto iIdxExisting = tSchema.GetAttrIndex ( tCtx.m_sName.cstr() ); if ( iIdxExisting >= 0 ) diff --git a/src/sphinx_alter.h b/src/sphinx_alter.h index f633dd3786..2f7354640b 100644 --- a/src/sphinx_alter.h +++ b/src/sphinx_alter.h @@ -43,6 +43,7 @@ struct AttrAddRemoveCtx_t int m_iBits; DWORD m_uFlags; AttrEngine_e m_eEngine; + knn::IndexSettings_t m_tKNN; }; // common add/remove attribute/field code for both RT and plain indexes diff --git a/test/test_275/model.bin b/test/test_275/model.bin index 63f97d3025..91c67d54ba 100644 --- a/test/test_275/model.bin +++ b/test/test_275/model.bin @@ -1,6 +1,11 @@ -a:1:{i:0;a:45:{i:0;a:2:{s:8:"sphinxql";s:11:"show tables";s:10:"total_rows";i:0;}i:1;a:2:{s:8:"sphinxql";s:109:"create table t (title text, tag integer, emp float_vector knn_type='hnsw' knn_dims='8' hnsw_similarity='l2' )";s:14:"total_affected";i:0;}i:2;a:3:{s:8:"sphinxql";s:11:"show tables";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:2:{s:5:"Index";s:1:"t";s:4:"Type";s:2:"rt";}}}i:3;a:3:{s:8:"sphinxql";s:6:"desc t";s:10:"total_rows";i:4;s:4:"rows";a:4:{i:0;a:3:{s:5:"Field";s:2:"id";s:4:"Type";s:6:"bigint";s:10:"Properties";s:0:"";}i:1;a:3:{s:5:"Field";s:5:"title";s:4:"Type";s:4:"text";s:10:"Properties";s:14:"indexed stored";}i:2;a:3:{s:5:"Field";s:3:"tag";s:4:"Type";s:4:"uint";s:10:"Properties";s:0:"";}i:3;a:3:{s:5:"Field";s:3:"emp";s:4:"Type";s:12:"float_vector";s:10:"Properties";s:3:"knn";}}}i:4;a:3:{s:8:"sphinxql";s:19:"show create table t";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:2:{s:5:"Table";s:1:"t";s:12:"Create Table";s:121:"CREATE TABLE t ( +a:1:{i:0;a:47:{i:0;a:2:{s:8:"sphinxql";s:11:"show tables";s:10:"total_rows";i:0;}i:1;a:2:{s:8:"sphinxql";s:109:"create table t (title text, tag integer, emp float_vector knn_type='hnsw' knn_dims='8' hnsw_similarity='l2' )";s:14:"total_affected";i:0;}i:2;a:3:{s:8:"sphinxql";s:11:"show tables";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:2:{s:5:"Index";s:1:"t";s:4:"Type";s:2:"rt";}}}i:3;a:3:{s:8:"sphinxql";s:6:"desc t";s:10:"total_rows";i:4;s:4:"rows";a:4:{i:0;a:3:{s:5:"Field";s:2:"id";s:4:"Type";s:6:"bigint";s:10:"Properties";s:0:"";}i:1;a:3:{s:5:"Field";s:5:"title";s:4:"Type";s:4:"text";s:10:"Properties";s:14:"indexed stored";}i:2;a:3:{s:5:"Field";s:3:"tag";s:4:"Type";s:4:"uint";s:10:"Properties";s:0:"";}i:3;a:3:{s:5:"Field";s:3:"emp";s:4:"Type";s:12:"float_vector";s:10:"Properties";s:3:"knn";}}}i:4;a:3:{s:8:"sphinxql";s:19:"show create table t";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:2:{s:5:"Table";s:1:"t";s:12:"Create Table";s:121:"CREATE TABLE t ( id bigint, title text, tag integer, emp float_vector knn_type='hnsw' knn_dims='8' hnsw_similarity='L2' -)";}}}i:5;a:2:{s:8:"sphinxql";s:203:"insert into t values (1, 'title1', 1, (0.2865696847438812,-0.03181683272123337,0.06668472290039062,0.03292645886540413,-0.008292825892567635,0.16873490810394287,-0.0008463106933049858,-0.36077880859375))";s:14:"total_affected";i:1;}i:6;a:2:{s:8:"sphinxql";s:202:"insert into t values (2, 'title2', 1, (0.33916592597961426,0.3886975646018982,-0.41489771008491516,0.20758016407489777,-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877))";s:14:"total_affected";i:1;}i:7;a:2:{s:8:"sphinxql";s:206:"insert into t values (3, 'title3', 2, (0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303,-0.029800616204738617,0.5721306800842285,-0.051111623644828796,-0.09547730535268784))";s:14:"total_affected";i:1;}i:8;a:2:{s:8:"sphinxql";s:204:"insert into t values (4, 'title4', 2, (0.1097082868218422,-0.059516504406929016,-0.053682904690504074,0.23981636762619019,-0.33325839042663574,0.3685816824436188,0.18456950783729553,-0.05209290236234665))";s:14:"total_affected";i:1;}i:9;a:2:{s:8:"sphinxql";s:202:"insert into t values (5, 'title5', 3, (-0.006129484623670578,0.5033777952194214,-0.5287379026412964,0.5231741070747375,0.022464150562882423,-0.04248378053307533,0.3180341124534607,-0.11792317032814026))";s:14:"total_affected";i:1;}i:10;a:2:{s:8:"sphinxql";s:199:"insert into t values (6, 'title6', 3, (0.07446788251399994,0.24792802333831787,0.20263631641864777,-0.017194697633385658,0.3679729402065277,0.3847752511501312,0.1616753190755844,0.04726771265268326))";s:14:"total_affected";i:1;}i:11;a:2:{s:8:"sphinxql";s:203:"insert into t values (7, 'title7', 4, (-0.03529544919729233,0.44717246294021606,-0.3653179109096527,-0.16520369052886963,-0.28060752153396606,0.024058140814304352,-0.6397897601127625,0.4281712472438812))";s:14:"total_affected";i:1;}i:12;a:2:{s:8:"sphinxql";s:200:"insert into t values (8, 'title8', 4, (-0.1488940566778183,0.7482781410217285,0.09189224243164062,-0.09540678560733795,0.1863720566034317,-0.20858603715896606,-0.226043701171875,-0.06464707106351852))";s:14:"total_affected";i:1;}i:13;a:2:{s:8:"sphinxql";s:199:"insert into t values (9, 'title9', 5, (0.6534488201141357,0.19247837364673615,0.017971690744161606,0.3398212492465973,0.26752832531929016,0.24325883388519287,-0.10399176180362701,0.1764550507068634))";s:14:"total_affected";i:1;}i:14;a:2:{s:8:"sphinxql";s:200:"insert into t values (10, 'title10', 5, (0.4089451730251312,0.0306655615568161,-0.15218715369701385,-0.6105571389198303,-0.29428744316101074,-0.07567915320396423,0.3454975187778473,-0.49481201171875))";s:14:"total_affected";i:1;}i:15;a:3:{s:8:"sphinxql";s:26:"select * from t where id=1";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:4:{s:2:"id";s:1:"1";s:5:"title";s:6:"title1";s:3:"tag";s:1:"1";s:3:"emp";s:91:"0.28656968,-0.03181683,0.06668472,0.03292646,-0.00829283,0.16873491,-0.00084631,-0.36077881";}}}i:16;a:3:{s:8:"sphinxql";s:211:"select id, knn_dist() from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303))";s:10:"total_rows";i:10;s:4:"rows";a:10:{i:0;a:2:{s:2:"id";s:1:"8";s:10:"knn_dist()";s:10:"0.44148445";}i:1;a:2:{s:2:"id";s:1:"5";s:10:"knn_dist()";s:10:"0.63964266";}i:2;a:2:{s:2:"id";s:1:"6";s:10:"knn_dist()";s:10:"0.73040032";}i:3;a:2:{s:2:"id";s:1:"7";s:10:"knn_dist()";s:10:"0.92614752";}i:4;a:2:{s:2:"id";s:1:"2";s:10:"knn_dist()";s:10:"0.95262027";}i:5;a:2:{s:2:"id";s:1:"1";s:10:"knn_dist()";s:10:"1.03401518";}i:6;a:2:{s:2:"id";s:1:"9";s:10:"knn_dist()";s:10:"1.08804023";}i:7;a:2:{s:2:"id";s:1:"4";s:10:"knn_dist()";s:8:"1.151821";}i:8;a:2:{s:2:"id";s:1:"3";s:10:"knn_dist()";s:10:"1.54590726";}i:9;a:2:{s:2:"id";s:2:"10";s:10:"knn_dist()";s:10:"1.71850991";}}}i:17;a:2:{s:8:"sphinxql";s:16:"flush ramchunk t";s:14:"total_affected";i:0;}i:18;a:3:{s:8:"sphinxql";s:211:"select id, knn_dist() from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303))";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:2:{s:2:"id";s:1:"8";s:10:"knn_dist()";s:10:"0.44148445";}i:1;a:2:{s:2:"id";s:1:"5";s:10:"knn_dist()";s:10:"0.63964266";}i:2;a:2:{s:2:"id";s:1:"6";s:10:"knn_dist()";s:10:"0.73040032";}}}i:19;a:3:{s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:2:{s:2:"id";s:1:"8";s:3:"tag";s:1:"4";}i:1;a:2:{s:2:"id";s:1:"5";s:3:"tag";s:1:"3";}i:2;a:2:{s:2:"id";s:1:"6";s:3:"tag";s:1:"3";}}s:8:"sphinxql";s:215:"select id, tag from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303)) facet tag;";}i:20;a:3:{s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:3:"tag";s:1:"4";s:8:"count(*)";s:1:"1";}i:1;a:2:{s:3:"tag";s:1:"3";s:8:"count(*)";s:1:"2";}}s:8:"sphinxql";s:42:" /* result 2 of previous multistatement */";}i:21;a:3:{s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:2:{s:2:"id";s:1:"8";s:3:"tag";s:1:"4";}i:1;a:2:{s:2:"id";s:1:"5";s:3:"tag";s:1:"3";}i:2;a:2:{s:2:"id";s:1:"6";s:3:"tag";s:1:"3";}}s:8:"sphinxql";s:238:"select id, tag from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303)) facet tag order by @knn_dist asc;";}i:22;a:3:{s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:3:"tag";s:1:"4";s:8:"count(*)";s:1:"1";}i:1;a:2:{s:3:"tag";s:1:"3";s:8:"count(*)";s:1:"2";}}s:8:"sphinxql";s:42:" /* result 2 of previous multistatement */";}i:23;a:3:{s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:2:"id";s:1:"8";s:3:"tag";s:1:"4";s:1:"d";s:10:"0.44148445";}i:1;a:3:{s:2:"id";s:1:"5";s:3:"tag";s:1:"3";s:1:"d";s:10:"0.63964266";}i:2;a:3:{s:2:"id";s:1:"6";s:3:"tag";s:1:"3";s:1:"d";s:10:"0.73040032";}}s:8:"sphinxql";s:244:"select id, tag, knn_dist() d from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303)) facet tag order by d asc;";}i:24;a:3:{s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:3:"tag";s:1:"4";s:8:"count(*)";s:1:"1";}i:1;a:2:{s:3:"tag";s:1:"3";s:8:"count(*)";s:1:"2";}}s:8:"sphinxql";s:42:" /* result 2 of previous multistatement */";}i:25;a:2:{s:8:"sphinxql";s:12:"drop table t";s:14:"total_affected";i:0;}i:26;a:2:{s:8:"sphinxql";s:96:"create table t (title text, emp float_vector knn_type='hnsw' knn_dims='8' hnsw_similarity='l2' )";s:14:"total_affected";i:0;}i:27;a:2:{s:8:"sphinxql";s:195:"insert into t values (1, 'title1', (0.4089451730251312,0.0306655615568161,-0.15218715369701385,-0.6105571389198303,-0.29428744316101074,-0.07567915320396423,0.3454975187778473,-0.49481201171875))";s:14:"total_affected";i:1;}i:28;a:3:{s:8:"sphinxql";s:177:"insert into t values (2, 'title2', (0.4089451730251312,0.0306655615568161,-0.15218715369701385,-0.6105571389198303,-0.29428744316101074,-0.07567915320396423,0.3454975187778473))";s:5:"errno";i:1064;s:5:"error";s:56:"KNN error: data has 7 values, index 'emp' needs 8 values";}i:29;a:3:{s:8:"sphinxql";s:38:"insert into t values (3, 'title3', ())";s:5:"errno";i:1064;s:5:"error";s:56:"KNN error: data has 0 values, index 'emp' needs 8 values";}i:30;a:3:{s:8:"sphinxql";s:15:"select * from t";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:3:{s:2:"id";s:1:"1";s:5:"title";s:6:"title1";s:3:"emp";s:90:"0.40894517,0.03066556,-0.15218715,-0.61055714,-0.29428744,-0.07567915,0.34549752,-0.494812";}}}i:31;a:2:{s:8:"sphinxql";s:16:"flush ramchunk t";s:14:"total_affected";i:0;}i:32;a:3:{s:8:"sphinxql";s:15:"select * from t";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:3:{s:2:"id";s:1:"1";s:5:"title";s:6:"title1";s:3:"emp";s:90:"0.40894517,0.03066556,-0.15218715,-0.61055714,-0.29428744,-0.07567915,0.34549752,-0.494812";}}}i:33;a:3:{s:8:"sphinxql";s:28:"select id, knn_dist() from t";s:5:"errno";i:1064;s:5:"error";s:53:"table t: KNN_DIST() is only allowed for KNN() queries";}i:34;a:2:{s:8:"sphinxql";s:12:"drop table t";s:14:"total_affected";i:0;}i:35;a:2:{s:8:"sphinxql";s:109:"create table test ( title text, image_vector float_vector knn_type='hnsw' knn_dims='4' hnsw_similarity='l2' )";s:14:"total_affected";i:0;}i:36;a:2:{s:8:"sphinxql";s:49:"replace into test (id, title) values (1, 'test1')";s:14:"total_affected";i:1;}i:37;a:3:{s:8:"sphinxql";s:18:"select * from test";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:3:{s:2:"id";s:1:"1";s:5:"title";s:5:"test1";s:12:"image_vector";s:35:"0.000000,0.000000,0.000000,0.000000";}}}i:38;a:2:{s:8:"sphinxql";s:15:"drop table test";s:14:"total_affected";i:0;}i:39;a:2:{s:8:"sphinxql";s:113:"create table test ( title text, image_vector float_vector knn_type='hnsw' knn_dims='4' hnsw_similarity='cosine' )";s:14:"total_affected";i:0;}i:40;a:2:{s:8:"sphinxql";s:143:"insert into test values ( 1, 'yellow bag', (0.653448,0.192478,0.017971,0.339821) ), ( 2, 'white bag', (-0.148894,0.748278,0.091892,-0.095406) )";s:14:"total_affected";i:2;}i:41;a:3:{s:8:"sphinxql";s:101:"select id, knn_dist() from test where knn ( image_vector, 5, (0.286569,-0.031816,0.066684,0.032926) )";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:2:"id";s:1:"1";s:10:"knn_dist()";s:10:"0.14651144";}i:1;a:2:{s:2:"id";s:1:"2";s:10:"knn_dist()";s:8:"1.275347";}}}i:42;a:2:{s:8:"sphinxql";s:19:"flush ramchunk test";s:14:"total_affected";i:0;}i:43;a:3:{s:8:"sphinxql";s:101:"select id, knn_dist() from test where knn ( image_vector, 5, (0.286569,-0.031816,0.066684,0.032926) )";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:2:"id";s:1:"1";s:10:"knn_dist()";s:10:"0.14651144";}i:1;a:2:{s:2:"id";s:1:"2";s:10:"knn_dist()";s:8:"1.275347";}}}i:44;a:2:{s:8:"sphinxql";s:15:"drop table test";s:14:"total_affected";i:0;}}} \ No newline at end of file +)";}}}i:5;a:2:{s:8:"sphinxql";s:203:"insert into t values (1, 'title1', 1, (0.2865696847438812,-0.03181683272123337,0.06668472290039062,0.03292645886540413,-0.008292825892567635,0.16873490810394287,-0.0008463106933049858,-0.36077880859375))";s:14:"total_affected";i:1;}i:6;a:2:{s:8:"sphinxql";s:202:"insert into t values (2, 'title2', 1, (0.33916592597961426,0.3886975646018982,-0.41489771008491516,0.20758016407489777,-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877))";s:14:"total_affected";i:1;}i:7;a:2:{s:8:"sphinxql";s:206:"insert into t values (3, 'title3', 2, (0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303,-0.029800616204738617,0.5721306800842285,-0.051111623644828796,-0.09547730535268784))";s:14:"total_affected";i:1;}i:8;a:2:{s:8:"sphinxql";s:204:"insert into t values (4, 'title4', 2, (0.1097082868218422,-0.059516504406929016,-0.053682904690504074,0.23981636762619019,-0.33325839042663574,0.3685816824436188,0.18456950783729553,-0.05209290236234665))";s:14:"total_affected";i:1;}i:9;a:2:{s:8:"sphinxql";s:202:"insert into t values (5, 'title5', 3, (-0.006129484623670578,0.5033777952194214,-0.5287379026412964,0.5231741070747375,0.022464150562882423,-0.04248378053307533,0.3180341124534607,-0.11792317032814026))";s:14:"total_affected";i:1;}i:10;a:2:{s:8:"sphinxql";s:199:"insert into t values (6, 'title6', 3, (0.07446788251399994,0.24792802333831787,0.20263631641864777,-0.017194697633385658,0.3679729402065277,0.3847752511501312,0.1616753190755844,0.04726771265268326))";s:14:"total_affected";i:1;}i:11;a:2:{s:8:"sphinxql";s:203:"insert into t values (7, 'title7', 4, (-0.03529544919729233,0.44717246294021606,-0.3653179109096527,-0.16520369052886963,-0.28060752153396606,0.024058140814304352,-0.6397897601127625,0.4281712472438812))";s:14:"total_affected";i:1;}i:12;a:2:{s:8:"sphinxql";s:200:"insert into t values (8, 'title8', 4, (-0.1488940566778183,0.7482781410217285,0.09189224243164062,-0.09540678560733795,0.1863720566034317,-0.20858603715896606,-0.226043701171875,-0.06464707106351852))";s:14:"total_affected";i:1;}i:13;a:2:{s:8:"sphinxql";s:199:"insert into t values (9, 'title9', 5, (0.6534488201141357,0.19247837364673615,0.017971690744161606,0.3398212492465973,0.26752832531929016,0.24325883388519287,-0.10399176180362701,0.1764550507068634))";s:14:"total_affected";i:1;}i:14;a:2:{s:8:"sphinxql";s:200:"insert into t values (10, 'title10', 5, (0.4089451730251312,0.0306655615568161,-0.15218715369701385,-0.6105571389198303,-0.29428744316101074,-0.07567915320396423,0.3454975187778473,-0.49481201171875))";s:14:"total_affected";i:1;}i:15;a:3:{s:8:"sphinxql";s:26:"select * from t where id=1";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:4:{s:2:"id";s:1:"1";s:5:"title";s:6:"title1";s:3:"tag";s:1:"1";s:3:"emp";s:91:"0.28656968,-0.03181683,0.06668472,0.03292646,-0.00829283,0.16873491,-0.00084631,-0.36077881";}}}i:16;a:3:{s:8:"sphinxql";s:211:"select id, knn_dist() from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303))";s:10:"total_rows";i:10;s:4:"rows";a:10:{i:0;a:2:{s:2:"id";s:1:"8";s:10:"knn_dist()";s:10:"0.44148445";}i:1;a:2:{s:2:"id";s:1:"5";s:10:"knn_dist()";s:10:"0.63964266";}i:2;a:2:{s:2:"id";s:1:"6";s:10:"knn_dist()";s:10:"0.73040032";}i:3;a:2:{s:2:"id";s:1:"7";s:10:"knn_dist()";s:10:"0.92614752";}i:4;a:2:{s:2:"id";s:1:"2";s:10:"knn_dist()";s:10:"0.95262027";}i:5;a:2:{s:2:"id";s:1:"1";s:10:"knn_dist()";s:10:"1.03401518";}i:6;a:2:{s:2:"id";s:1:"9";s:10:"knn_dist()";s:10:"1.08804023";}i:7;a:2:{s:2:"id";s:1:"4";s:10:"knn_dist()";s:8:"1.151821";}i:8;a:2:{s:2:"id";s:1:"3";s:10:"knn_dist()";s:10:"1.54590726";}i:9;a:2:{s:2:"id";s:2:"10";s:10:"knn_dist()";s:10:"1.71850991";}}}i:17;a:2:{s:8:"sphinxql";s:16:"flush ramchunk t";s:14:"total_affected";i:0;}i:18;a:3:{s:8:"sphinxql";s:211:"select id, knn_dist() from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303))";s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:2:{s:2:"id";s:1:"8";s:10:"knn_dist()";s:10:"0.44148445";}i:1;a:2:{s:2:"id";s:1:"5";s:10:"knn_dist()";s:10:"0.63964266";}i:2;a:2:{s:2:"id";s:1:"6";s:10:"knn_dist()";s:10:"0.73040032";}}}i:19;a:3:{s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:2:{s:2:"id";s:1:"8";s:3:"tag";s:1:"4";}i:1;a:2:{s:2:"id";s:1:"5";s:3:"tag";s:1:"3";}i:2;a:2:{s:2:"id";s:1:"6";s:3:"tag";s:1:"3";}}s:8:"sphinxql";s:215:"select id, tag from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303)) facet tag;";}i:20;a:3:{s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:3:"tag";s:1:"4";s:8:"count(*)";s:1:"1";}i:1;a:2:{s:3:"tag";s:1:"3";s:8:"count(*)";s:1:"2";}}s:8:"sphinxql";s:42:" /* result 2 of previous multistatement */";}i:21;a:3:{s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:2:{s:2:"id";s:1:"8";s:3:"tag";s:1:"4";}i:1;a:2:{s:2:"id";s:1:"5";s:3:"tag";s:1:"3";}i:2;a:2:{s:2:"id";s:1:"6";s:3:"tag";s:1:"3";}}s:8:"sphinxql";s:238:"select id, tag from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303)) facet tag order by @knn_dist asc;";}i:22;a:3:{s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:3:"tag";s:1:"4";s:8:"count(*)";s:1:"1";}i:1;a:2:{s:3:"tag";s:1:"3";s:8:"count(*)";s:1:"2";}}s:8:"sphinxql";s:42:" /* result 2 of previous multistatement */";}i:23;a:3:{s:10:"total_rows";i:3;s:4:"rows";a:3:{i:0;a:3:{s:2:"id";s:1:"8";s:3:"tag";s:1:"4";s:1:"d";s:10:"0.44148445";}i:1;a:3:{s:2:"id";s:1:"5";s:3:"tag";s:1:"3";s:1:"d";s:10:"0.63964266";}i:2;a:3:{s:2:"id";s:1:"6";s:3:"tag";s:1:"3";s:1:"d";s:10:"0.73040032";}}s:8:"sphinxql";s:244:"select id, tag, knn_dist() d from t where knn(emp,3,(-0.11468425393104553,0.3873162567615509,-0.26252424716949463,0.007096240296959877,0.24166066944599152,-0.24653761088848114,0.060873936861753464,0.23045268654823303)) facet tag order by d asc;";}i:24;a:3:{s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:3:"tag";s:1:"4";s:8:"count(*)";s:1:"1";}i:1;a:2:{s:3:"tag";s:1:"3";s:8:"count(*)";s:1:"2";}}s:8:"sphinxql";s:42:" /* result 2 of previous multistatement */";}i:25;a:2:{s:8:"sphinxql";s:12:"drop table t";s:14:"total_affected";i:0;}i:26;a:2:{s:8:"sphinxql";s:96:"create table t (title text, emp float_vector knn_type='hnsw' knn_dims='8' hnsw_similarity='l2' )";s:14:"total_affected";i:0;}i:27;a:2:{s:8:"sphinxql";s:195:"insert into t values (1, 'title1', (0.4089451730251312,0.0306655615568161,-0.15218715369701385,-0.6105571389198303,-0.29428744316101074,-0.07567915320396423,0.3454975187778473,-0.49481201171875))";s:14:"total_affected";i:1;}i:28;a:3:{s:8:"sphinxql";s:177:"insert into t values (2, 'title2', (0.4089451730251312,0.0306655615568161,-0.15218715369701385,-0.6105571389198303,-0.29428744316101074,-0.07567915320396423,0.3454975187778473))";s:5:"errno";i:1064;s:5:"error";s:56:"KNN error: data has 7 values, index 'emp' needs 8 values";}i:29;a:3:{s:8:"sphinxql";s:38:"insert into t values (3, 'title3', ())";s:5:"errno";i:1064;s:5:"error";s:56:"KNN error: data has 0 values, index 'emp' needs 8 values";}i:30;a:3:{s:8:"sphinxql";s:15:"select * from t";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:3:{s:2:"id";s:1:"1";s:5:"title";s:6:"title1";s:3:"emp";s:90:"0.40894517,0.03066556,-0.15218715,-0.61055714,-0.29428744,-0.07567915,0.34549752,-0.494812";}}}i:31;a:2:{s:8:"sphinxql";s:16:"flush ramchunk t";s:14:"total_affected";i:0;}i:32;a:3:{s:8:"sphinxql";s:15:"select * from t";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:3:{s:2:"id";s:1:"1";s:5:"title";s:6:"title1";s:3:"emp";s:90:"0.40894517,0.03066556,-0.15218715,-0.61055714,-0.29428744,-0.07567915,0.34549752,-0.494812";}}}i:33;a:3:{s:8:"sphinxql";s:28:"select id, knn_dist() from t";s:5:"errno";i:1064;s:5:"error";s:53:"table t: KNN_DIST() is only allowed for KNN() queries";}i:34;a:2:{s:8:"sphinxql";s:12:"drop table t";s:14:"total_affected";i:0;}i:35;a:2:{s:8:"sphinxql";s:109:"create table test ( title text, image_vector float_vector knn_type='hnsw' knn_dims='4' hnsw_similarity='l2' )";s:14:"total_affected";i:0;}i:36;a:2:{s:8:"sphinxql";s:49:"replace into test (id, title) values (1, 'test1')";s:14:"total_affected";i:1;}i:37;a:3:{s:8:"sphinxql";s:18:"select * from test";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:3:{s:2:"id";s:1:"1";s:5:"title";s:5:"test1";s:12:"image_vector";s:35:"0.000000,0.000000,0.000000,0.000000";}}}i:38;a:2:{s:8:"sphinxql";s:15:"drop table test";s:14:"total_affected";i:0;}i:39;a:2:{s:8:"sphinxql";s:113:"create table test ( title text, image_vector float_vector knn_type='hnsw' knn_dims='4' hnsw_similarity='cosine' )";s:14:"total_affected";i:0;}i:40;a:2:{s:8:"sphinxql";s:143:"insert into test values ( 1, 'yellow bag', (0.653448,0.192478,0.017971,0.339821) ), ( 2, 'white bag', (-0.148894,0.748278,0.091892,-0.095406) )";s:14:"total_affected";i:2;}i:41;a:3:{s:8:"sphinxql";s:101:"select id, knn_dist() from test where knn ( image_vector, 5, (0.286569,-0.031816,0.066684,0.032926) )";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:2:"id";s:1:"1";s:10:"knn_dist()";s:10:"0.14651144";}i:1;a:2:{s:2:"id";s:1:"2";s:10:"knn_dist()";s:8:"1.275347";}}}i:42;a:2:{s:8:"sphinxql";s:19:"flush ramchunk test";s:14:"total_affected";i:0;}i:43;a:3:{s:8:"sphinxql";s:101:"select id, knn_dist() from test where knn ( image_vector, 5, (0.286569,-0.031816,0.066684,0.032926) )";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:2:{s:2:"id";s:1:"1";s:10:"knn_dist()";s:10:"0.14651144";}i:1;a:2:{s:2:"id";s:1:"2";s:10:"knn_dist()";s:8:"1.275347";}}}i:44;a:2:{s:8:"sphinxql";s:103:"alter table test add column image_vecto2 float_vector knn_type='hnsw' knn_dims='7' hnsw_similarity='l2'";s:14:"total_affected";i:0;}i:45;a:3:{s:8:"sphinxql";s:22:"show create table test";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:2:{s:5:"Table";s:4:"test";s:12:"Create Table";s:201:"CREATE TABLE test ( +id bigint, +title text, +image_vector float_vector knn_type='hnsw' knn_dims='4' hnsw_similarity='COSINE', +image_vecto2 float_vector knn_type='hnsw' knn_dims='7' hnsw_similarity='L2' +)";}}}i:46;a:2:{s:8:"sphinxql";s:15:"drop table test";s:14:"total_affected";i:0;}}} \ No newline at end of file diff --git a/test/test_275/test.xml b/test/test_275/test.xml index 7fcd3e0fa0..bc00ef3c15 100644 --- a/test/test_275/test.xml +++ b/test/test_275/test.xml @@ -65,6 +65,11 @@ searchd select id, knn_dist() from test where knn ( image_vector, 5, (0.286569,-0.031816,0.066684,0.032926) ); flush ramchunk test; select id, knn_dist() from test where knn ( image_vector, 5, (0.286569,-0.031816,0.066684,0.032926) ); + + + alter table test add column image_vecto2 float_vector knn_type='hnsw' knn_dims='7' hnsw_similarity='l2'; + show create table test; + drop table test;