Skip to content

Commit

Permalink
fixed filter-by-id; added test
Browse files Browse the repository at this point in the history
  • Loading branch information
glookka committed May 25, 2019
1 parent 230c321 commit 5802b85
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/secondaryindex.cpp
Expand Up @@ -1047,7 +1047,7 @@ void SelectIterators ( const CSphVector<CSphFilterSettings> & dFilters, const CS
} }




RowidIterator_i * CreateFilteredIterator ( CSphVector<CSphFilterSettings> & dFilters, const CSphVector<FilterTreeItem_t> & dFilterTree, const CSphVector<IndexHint_t> & dHints, const HistogramContainer_c & tHistograms, const BYTE * pDocidLookup ) RowidIterator_i * CreateFilteredIterator ( const CSphVector<CSphFilterSettings> & dFilters, CSphVector<CSphFilterSettings> & dModifiedFilters, const CSphVector<FilterTreeItem_t> & dFilterTree, const CSphVector<IndexHint_t> & dHints, const HistogramContainer_c & tHistograms, const BYTE * pDocidLookup )
{ {
// no iterators with OR queries // no iterators with OR queries
if ( dFilterTree.GetLength() ) if ( dFilterTree.GetLength() )
Expand All @@ -1065,8 +1065,11 @@ RowidIterator_i * CreateFilteredIterator ( CSphVector<CSphFilterSettings> & dFil
} }


dEnabledIndexes.Sort ( bind ( &SecondaryIndexInfo_t::m_iFilterId ) ); dEnabledIndexes.Sort ( bind ( &SecondaryIndexInfo_t::m_iFilterId ) );
for ( int i = dEnabledIndexes.GetLength()-1; i>=0; i-- ) ARRAY_FOREACH ( i, dFilters )
dFilters.Remove ( dEnabledIndexes[i].m_iFilterId ); {
if ( !dEnabledIndexes.FindFirst ( [i] ( const SecondaryIndexInfo_t & tInfo ) { return tInfo.m_iFilterId==i; } ) )
dModifiedFilters.Add ( dFilters[i] );
}


int nIterators = dIterators.GetLength(); int nIterators = dIterators.GetLength();
if ( nIterators==1 ) if ( nIterators==1 )
Expand Down
2 changes: 1 addition & 1 deletion src/secondaryindex.h
Expand Up @@ -85,7 +85,7 @@ struct SecondaryIndexInfo_t
int m_iFilterId {-1}; int m_iFilterId {-1};
}; };


RowidIterator_i * CreateFilteredIterator ( CSphVector<CSphFilterSettings> & dFilters, const CSphVector<FilterTreeItem_t> & dFilterTree, const CSphVector<IndexHint_t> & dHints, const HistogramContainer_c & tHistograms, const BYTE * pDocidLookup ); RowidIterator_i * CreateFilteredIterator ( const CSphVector<CSphFilterSettings> & dFilters, CSphVector<CSphFilterSettings> & dModifiedFilters, const CSphVector<FilterTreeItem_t> & dFilterTree, const CSphVector<IndexHint_t> & dHints, const HistogramContainer_c & tHistograms, const BYTE * pDocidLookup );


////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////


Expand Down
6 changes: 4 additions & 2 deletions src/sphinx.cpp
Expand Up @@ -13864,15 +13864,17 @@ bool CSphIndex_VLN::MultiScan ( const CSphQuery * pQuery, CSphQueryResult * pRes
bool bReverse = pQuery->m_bReverseScan; // shortcut bool bReverse = pQuery->m_bReverseScan; // shortcut
int iCutoff = ( pQuery->m_iCutoff<=0 ) ? -1 : pQuery->m_iCutoff; int iCutoff = ( pQuery->m_iCutoff<=0 ) ? -1 : pQuery->m_iCutoff;


CSphVector<CSphFilterSettings> dFilters = pQuery->m_dFilters; // we don't modify the original filters because iterators may use some data from them (to avoid copying)
CSphVector<CSphFilterSettings> dModifiedFilters;
RowidIterator_i * pIterator = nullptr; RowidIterator_i * pIterator = nullptr;
if ( m_pHistograms ) if ( m_pHistograms )
pIterator = CreateFilteredIterator ( dFilters, pQuery->m_dFilterTree, pQuery->m_dIndexHints, *m_pHistograms, m_tDocidLookup.GetWritePtr() ); pIterator = CreateFilteredIterator ( pQuery->m_dFilters, dModifiedFilters, pQuery->m_dFilterTree, pQuery->m_dIndexHints, *m_pHistograms, m_tDocidLookup.GetWritePtr() );


if ( pIterator ) if ( pIterator )
{ {
// one or several filters got replaced by an iterator, need to re-create the remaining filters // one or several filters got replaced by an iterator, need to re-create the remaining filters
SafeDelete ( tCtx.m_pFilter ); SafeDelete ( tCtx.m_pFilter );
tFlx.m_pFilters = &dModifiedFilters;
tCtx.CreateFilters ( tFlx, pResult->m_sError, pResult->m_sWarning ); tCtx.CreateFilters ( tFlx, pResult->m_sError, pResult->m_sWarning );


bool bStop; bool bStop;
Expand Down
1 change: 1 addition & 0 deletions test/test_379/model.bin
@@ -0,0 +1 @@
a:1:{i:0;a:3:{i:0;a:3:{s:8:"sphinxql";s:58:"select id from test1 where id in (1,13) and gid not in (1)";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:1:{s:2:"id";s:1:"1";}i:1;a:1:{s:2:"id";s:2:"13";}}}i:1;a:3:{s:8:"sphinxql";s:74:"select id from test1 where id in (1,13) and gid not in (1) force index(id)";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:1:{s:2:"id";s:1:"1";}i:1;a:1:{s:2:"id";s:2:"13";}}}i:2;a:3:{s:8:"sphinxql";s:75:"select id from test1 where id in (1,13) and gid not in (1) ignore index(id)";s:10:"total_rows";i:2;s:4:"rows";a:2:{i:0;a:1:{s:2:"id";s:1:"1";}i:1;a:1:{s:2:"id";s:2:"13";}}}}}
59 changes: 59 additions & 0 deletions test/test_379/test.xml
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<test>

<name>id attr index</name>

<config>
indexer
{
mem_limit = 16M
}

searchd
{
<searchd_settings/>
}

source test1
{
type = mysql
<sql_settings/>
sql_query = select id, gid, title from test_table
sql_attr_uint = gid
sql_field_string = title
}

index test1
{
source = test1
path = <data_path/>/test1
}
</config>

<db_create>
create table test_table
(
id int not null,
gid int not null,
title varchar(255) not null
);
</db_create>
<db_drop>drop table if exists test_table;</db_drop>

<db_insert>
insert into test_table values
( 1, 11, 'test' ),
( 2, 12, 'test' ),
( 3, 13, 'test' ),
( 11, 21,'test' ),
( 12, 22, 'test' ),
( 13, 23, 'test' )
</db_insert>

<sphqueries>
<sphinxql>select id from test1 where id in (1,13) and gid not in (1)</sphinxql>
<sphinxql>select id from test1 where id in (1,13) and gid not in (1) force index(id)</sphinxql>
<sphinxql>select id from test1 where id in (1,13) and gid not in (1) ignore index(id)</sphinxql>
</sphqueries>

</test>

0 comments on commit 5802b85

Please sign in to comment.