Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/sphinxexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6931,7 +6931,16 @@ ISphExpr * ExprParser_t::CreateFuncExpr ( int iNode, VecRefPtrs_t<ISphExpr*> & d
case FUNC_SINT: return new Expr_Sint_c ( dArgs[0] );
case FUNC_CRC32: return new Expr_Crc32_c ( dArgs[0] );
case FUNC_FIBONACCI:return new Expr_Fibonacci_c ( dArgs[0] );
case FUNC_KNN_DIST: return new Expr_GetFloat_c ( m_pSchema->GetAttr ( GetKnnDistAttrName() )->m_tLocator, GetKnnDistAttrName() );
case FUNC_KNN_DIST:
{
const CSphColumnInfo * pAttr = m_pSchema->GetAttr ( GetKnnDistAttrName() );
if ( !pAttr )
{
m_sCreateError = "KNN_DIST() attribute not available in this context";
return nullptr;
}
return new Expr_GetFloat_c ( pAttr->m_tLocator, GetKnnDistAttrName() );
}

case FUNC_DAY: return CreateExprDay ( dArgs[0] );
case FUNC_WEEK: return CreateExprWeek ( dArgs[0], dArgs.GetLength()>1 ? dArgs[1] : nullptr );
Expand Down Expand Up @@ -10828,7 +10837,11 @@ static void CheckDescendingNodes ( const CSphVector<ExprNode_t> & dNodes )
ISphExpr * ExprParser_t::Create ( bool * pUsesWeight, CSphString & sError )
{
if ( GetError () )
{
if ( !m_sCreateError.IsEmpty() )
sError = m_sCreateError;
return nullptr;
}

#ifndef NDEBUG
CheckDescendingNodes ( m_dNodes );
Expand Down
30 changes: 30 additions & 0 deletions test/clt-tests/bugs/3602-knn-dist-attribute-error.rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Test for issue #3602: searchd crash on particular SQL query with KNN and MATCH
https://github.com/manticoresoftware/manticoresearch/issues/3602

Bug: Query with knn() function and MATCH() condition using ranker=expr('knn_dist()') crashes searchd.
Expected: Query should return proper error instead of crashing.

––– comment –––
Start Manticore Search daemon
––– block: ../base/start-searchd –––
––– comment –––
Drop table if it exists
––– input –––
mysql -h0 -P9306 -e 'drop table if exists companysearch;'
––– output –––
––– comment –––
Create table with text field and float_vector embeddings field
––– input –––
mysql -h0 -P9306 -e "create table companysearch(f text, embeddings float_vector knn_type='hnsw' knn_dims='2' hnsw_similarity='l2');"
––– output –––
––– comment –––
Insert test data
––– input –––
mysql -h0 -P9306 -e "insert into companysearch values(1, 'web', (0,0));"
––– output –––
––– comment –––
Test query with KNN and MATCH - should return error, not crash
––– input –––
mysql -h0 -P9306 -e "SELECT * FROM companysearch WHERE knn(embeddings, 5, (1,1)) AND MATCH('web') OPTION ranker=expr('knn_dist()');"
––– output –––
ERROR 1064 (42000) at line 1: table companysearch: KNN_DIST() attribute not available in this context