Skip to content
Permalink
Browse files

fixed filter-by-id; added test

  • Loading branch information...
glookka committed May 25, 2019
1 parent 230c321 commit 5802b85aa93a81caea77073a3381ef912fdd677c
Showing with 71 additions and 6 deletions.
  1. +6 −3 src/secondaryindex.cpp
  2. +1 −1 src/secondaryindex.h
  3. +4 −2 src/sphinx.cpp
  4. +1 −0 test/test_379/model.bin
  5. +59 −0 test/test_379/test.xml
@@ -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
if ( dFilterTree.GetLength() )
@@ -1065,8 +1065,11 @@ RowidIterator_i * CreateFilteredIterator ( CSphVector<CSphFilterSettings> & dFil
}

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

int nIterators = dIterators.GetLength();
if ( nIterators==1 )
@@ -85,7 +85,7 @@ struct SecondaryIndexInfo_t
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 );

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

@@ -13864,15 +13864,17 @@ bool CSphIndex_VLN::MultiScan ( const CSphQuery * pQuery, CSphQueryResult * pRes
bool bReverse = pQuery->m_bReverseScan; // shortcut
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;
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 )
{
// one or several filters got replaced by an iterator, need to re-create the remaining filters
SafeDelete ( tCtx.m_pFilter );
tFlx.m_pFilters = &dModifiedFilters;
tCtx.CreateFilters ( tFlx, pResult->m_sError, pResult->m_sWarning );

bool bStop;
@@ -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";}}}}}
@@ -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.
You can’t perform that action at this time.