Permalink
Browse files

fixed #20 daemon crash on multi-query with bad query; added regressio…

…ns to test 315; added MultiQuery method to QLClient at ubertest
  • Loading branch information...
tomatolog authored and klirichek committed May 30, 2017
1 parent 9ccf254 commit 72395d91f232e2dc3cabcb1328cfa4154d7b6f04
Showing with 165 additions and 3 deletions.
  1. +4 −3 src/sphinxrt.cpp
  2. +33 −0 test/helpers.inc
  3. +27 −0 test/test_315/model.bin
  4. +101 −0 test/test_315/test.xml
@@ -7518,8 +7518,8 @@ bool RtIndex_t::MultiQuery ( const CSphQuery * pQuery, CSphQueryResult * pResult
if ( tCtx.m_uPackedFactorFlags & SPH_FACTOR_ENABLE )
{
pRanker->ExtraData ( EXTRA_SET_MATCHPUSHED, (void**)&(ppSorters[iSorter]->m_iJustPushed) );
pRanker->ExtraData ( EXTRA_SET_MATCHPOPPED, (void**)&(ppSorters[iSorter]->m_dJustPopped) );
pRanker->ExtraData ( EXTRA_SET_MATCHPUSHED, (void**)&(dSorters[iSorter]->m_iJustPushed) );
pRanker->ExtraData ( EXTRA_SET_MATCHPOPPED, (void**)&(dSorters[iSorter]->m_dJustPopped) );
}
}
@@ -7562,7 +7562,8 @@ bool RtIndex_t::MultiQuery ( const CSphQuery * pQuery, CSphQueryResult * pResult
for ( int iSorter = 0; iSorter<iSorters; iSorter++ )
{
ISphMatchSorter * pTop = ppSorters[iSorter];
pTop->Finalize ( tFinal, false );
if ( pTop )
pTop->Finalize ( tFinal, false );
}
}
}
@@ -751,6 +751,39 @@ class QLClient
$res .= "$n rows";
return $res;
}
function MultiQuery($q)
{
if ($this->_conn===false)
return "NOT CONNECTED";
$r = @mysqli_multi_query($this->_conn, $q);
if (!$r)
return "ERROR: ".mysqli_error($this->_conn);
$res = "";
do
{
if ($result = mysqli_store_result($this->_conn))
{
$n = 0;
while ($row = mysqli_fetch_row($result))
{
$res .= join(" | ", $row) . "\n";
$n++;
}
$res .= "$n rows";
mysqli_free_result($result);
} else
{
$res .= "ERROR: " . mysqli_error($this->_conn);
}
if (!mysqli_more_results($this->_conn))
break;
} while (mysqli_next_result($this->_conn));
return $res;
}
}
class APIClient extends SphinxClient
@@ -0,0 +1,27 @@
a:1:{i:0;a:1:{i:0;a:10:{i:0;s:7:"
insert";i:1;s:3:"
OK";i:2;s:8:"
rt scan";i:3;s:63:"
1 | 1 | 1 | 1
2 | 2 | 1 | 2
3 | 3 | 2 | 3
4 | 4 | 2 | 4
4 rows";i:4;s:9:"
rt match";i:5;s:1407:"
1 | 1 | 1 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
2 | 2 | 1 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
3 | 3 | 2 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
4 | 4 | 2 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
4 rows";i:6;s:11:"
plain scan";i:7;s:63:"
1 | 1 | 1 | 1
2 | 2 | 1 | 2
3 | 3 | 2 | 3
4 | 4 | 2 | 4
4 rows";i:8;s:12:"
plain match";i:9;s:1407:"
1 | 1 | 1 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
2 | 2 | 1 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
3 | 3 | 2 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
4 | 4 | 2 | bm25=304, bm25a=0.168710, field_mask=1, doc_word_count=1, field0=(lcs=1, hit_count=1, word_count=1, tf_idf=-0.430677, min_idf=-0.430677, max_idf=-0.430677, sum_idf=-0.430677, min_hit_pos=2, min_best_span_pos=2, exact_hit=0, max_window_hits=1, min_gaps=0, exact_order=1, lccs=1, wlccs=-0.430677, atc=0.000000), word0=(tf=1, idf=-0.430677)
4 rows";}}}
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<test>
<name>catching errors in multiqueries v2</name>
<config>
indexer
{
mem_limit = 16M
}
searchd
{
<searchd_settings/>
}
source srctest
{
type = mysql
<sql_settings/>
sql_query = SELECT id, best_seller, attributes_id, text FROM test_table
sql_attr_uint = best_seller
sql_attr_uint = attributes_id
}
index products
{
source = srctest
path = <data_path/>/test
}
index rt_products
{
type = rt
path = <data_path/>/rt_test
rt_field = title
rt_attr_uint = best_seller
rt_attr_uint = attributes_id
dict = keywords
}
</config>
<db_create>
CREATE TABLE test_table
(
id integer primary key not null auto_increment,
best_seller int not null default 0,
attributes_id int not null default 0,
text varchar(256)
);
</db_create>
<db_drop>
DROP TABLE IF EXISTS test_table;
</db_drop>
<db_insert>
INSERT INTO test_table (best_seller, attributes_id, text) VALUES
( 1, 1, 'text1 text' ),
( 2, 1, 'text2 text' ),
( 3, 2, 'text3 text' ),
( 4, 2, 'text4 text' );
</db_insert>
<!--
<sphqueries>
<sphinxql>REPLACE INTO rt_products (id, best_seller, attributes_id, title) VALUES (1, 1, 1, 'text1 text'),(2, 2, 1, 'text2 text'), (3, 3, 2, 'text3 text'), (4, 4, 2, 'text4 text')</sphinxql>
<sphinxql>select *, to_string(id) i from rt_products order by best_seller asc; select *, to_string(id) i from rt_products order by best_seller1 asc; select *, to_string(id) i from rt_products order by attributes_id asc</sphinxql>
<sphinxql>select *, packedfactors() i from rt_products where match ('text') order by best_seller asc option ranker=expr('1'); select *, packedfactors() i from rt_products where match ('text') order by best_seller1 asc option ranker=expr('1'); select *, packedfactors() i from rt_products where match ('text') order by attributes_id asc option ranker=expr('1')</sphinxql>
<sphinxql>select *, to_string(id) i from products order by best_seller asc; select *, to_string(id) i from products order by best_seller1 asc; select *, to_string(id) i from products order by attributes_id asc</sphinxql>
<sphinxql>select *, packedfactors() i from products where match ('text') order by best_seller asc option ranker=expr('1'); select *, packedfactors() i from products where match ('text') order by best_seller1 asc option ranker=expr('1'); select *, packedfactors() i from products where match ('text') order by attributes_id asc option ranker=expr('1')</sphinxql>
</sphqueries>
-->
<custom_test><![CDATA[
// invalid sorter at multi-query
$results = array();
$ql->Reconnect();
$results[] = "\n" . 'insert';
$results[] = "\n" . $ql->Query ( "INSERT INTO rt_products (id, best_seller, attributes_id, title) VALUES (1, 1, 1, 'text1 text'),(2, 2, 1, 'text2 text'), (3, 3, 2, 'text3 text'), (4, 4, 2, 'text4 text')" );
$results[] = "\n" . 'rt scan';
$results[] = "\n" . $ql->MultiQuery ( "select *, to_string(id) i from rt_products order by best_seller asc; select *, to_string(id) i from rt_products order by best_seller1 asc; select *, to_string(id) i from rt_products order by attributes_id asc" );
$results[] = "\n" . 'rt match';
$results[] = "\n" . $ql->MultiQuery ( "select *, packedfactors() i from rt_products where match ('text') order by best_seller asc option ranker=expr('1'); select *, packedfactors() i from rt_products where match ('text') order by best_seller1 asc option ranker=expr('1'); select *, packedfactors() i from rt_products where match ('text') order by attributes_id asc option ranker=expr('1')" );
$results[] = "\n" . 'plain scan';
$results[] = "\n" . $ql->MultiQuery ( "select *, to_string(id) i from products order by best_seller asc; select *, to_string(id) i from products order by best_seller1 asc; select *, to_string(id) i from products order by attributes_id asc" );
$results[] = "\n" . 'plain match';
$results[] = "\n" . $ql->MultiQuery ( "select *, packedfactors() i from products where match ('text') order by best_seller asc option ranker=expr('1'); select *, packedfactors() i from products where match ('text') order by best_seller1 asc option ranker=expr('1'); select *, packedfactors() i from products where match ('text') order by attributes_id asc option ranker=expr('1')" );
]]></custom_test>
</test>

0 comments on commit 72395d9

Please sign in to comment.