Skip to content

Commit

Permalink
implemented better analyzer rewinding
Browse files Browse the repository at this point in the history
  • Loading branch information
glookka committed Aug 20, 2023
1 parent fea449a commit c6dbbcb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 52 deletions.
11 changes: 11 additions & 0 deletions columnar/accessor/accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@ class MatchingBlocks_c
FORCE_INLINE void Add ( int iBlock ) { m_dBlocks.push_back(iBlock); }
FORCE_INLINE int GetBlock ( int iBlock ) const { return m_dBlocks[iBlock]; }
FORCE_INLINE int GetNumBlocks() const { return (int)m_dBlocks.size(); }
FORCE_INLINE int Find ( int iStartBlock, int iValue );

private:
std::vector<int> m_dBlocks;
};


int MatchingBlocks_c::Find ( int iStartBlock, int iValue )
{
auto tFound = std::lower_bound ( m_dBlocks.begin()+iStartBlock, m_dBlocks.end(), iValue );
if ( tFound==m_dBlocks.end() )
return (int)m_dBlocks.size();

return tFound-m_dBlocks.begin();
}


using SharedBlocks_c = std::shared_ptr<MatchingBlocks_c>;

class Analyzer_i : public common::BlockIterator_i
Expand Down
31 changes: 8 additions & 23 deletions columnar/accessor/accessortraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,32 +198,17 @@ bool Analyzer_T<HAVE_MATCHING_BLOCKS>::MoveToSubblock ( int iSubblock )
template <bool HAVE_MATCHING_BLOCKS>
bool Analyzer_T<HAVE_MATCHING_BLOCKS>::HintRowID ( uint32_t tRowID )
{
int iNextSubblock = m_iCurSubblock;
int iNextSubblock = m_tSubblockCalc.GetSubblockId(tRowID);
if constexpr ( HAVE_MATCHING_BLOCKS )
iNextSubblock = m_pMatchingSubblocks->Find ( m_iCurSubblock, iNextSubblock );

// we assume that we are only advancing forward
while ( iNextSubblock<m_iTotalSubblocks )
{
int iSubblockID;
if ( HAVE_MATCHING_BLOCKS )
iSubblockID = m_pMatchingSubblocks->GetBlock(iNextSubblock);
else
iSubblockID = iNextSubblock;

uint32_t tSubblockStart = m_tSubblockCalc.SubblockId2RowId(iSubblockID);
uint32_t tSubblockEnd = tSubblockStart + m_tSubblockCalc.m_iSubblockSize;

if ( tRowID<tSubblockStart || ( tRowID>=tSubblockStart && tRowID<tSubblockEnd ) )
{
if ( iNextSubblock!=m_iCurSubblock )
return MoveToSubblock(iNextSubblock);

return true;
}
if ( iNextSubblock>=m_iTotalSubblocks )
return false;

iNextSubblock++;
}
if ( iNextSubblock>m_iCurSubblock )
return MoveToSubblock(iNextSubblock);

return false;
return true;
}

template <bool HAVE_MATCHING_BLOCKS>
Expand Down
42 changes: 13 additions & 29 deletions columnar/columnar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class BlockIterator_c : public BlockIterator_i
bool WasCutoffHit() const final { return false; }

private:
static const int MAX_COLLECTED = 128;
static const int MAX_COLLECTED = 1024;

std::shared_ptr<MatchingBlocks_c> m_pMatchingBlocks;
std::array<uint32_t,MAX_COLLECTED> m_dCollected;
Expand All @@ -250,9 +250,10 @@ class BlockIterator_c : public BlockIterator_i
int m_iMinMaxLeafShift = 0;
int m_iNumLevels = 0;

inline bool SetCurBlock ( int iBlock );
FORCE_INLINE int GetNumDocs ( int iBlock ) const;
FORCE_INLINE uint32_t MinMaxBlockId2RowId ( int iBlockId ) const;
FORCE_INLINE bool SetCurBlock ( int iBlock );
FORCE_INLINE int GetNumDocs ( int iBlock ) const;
FORCE_INLINE uint32_t MinMaxBlockId2RowId ( int iBlockId ) const { return iBlockId<<m_iMinMaxLeafShift; }
FORCE_INLINE int RowId2MinMaxBlockId ( uint32_t uRowID ) const { return uRowID>>m_iMinMaxLeafShift; }
};


Expand Down Expand Up @@ -284,35 +285,24 @@ bool BlockIterator_c::Setup ( const std::vector<HeaderWithLocator_t> & dHeaders,
return true;
}


void BlockIterator_c::AddDesc ( std::vector<IteratorDesc_t> & dDesc ) const
{
for ( const auto & i : m_dAttrs )
dDesc.push_back ( { i, "prefilter" } );
}


bool BlockIterator_c::HintRowID ( uint32_t tRowID )
{
int iNextBlock = m_iBlock;
int iNumBlocks = m_pMatchingBlocks->GetNumBlocks();

// we assume that we are only advancing forward
while ( iNextBlock<iNumBlocks )
{
uint32_t tSubblockStart = MinMaxBlockId2RowId ( m_pMatchingBlocks->GetBlock(iNextBlock) );
uint32_t tSubblockEnd = tSubblockStart + m_iDocsPerBlock;

if ( tRowID<tSubblockStart || ( tRowID>=tSubblockStart && tRowID<tSubblockEnd ) )
{
if ( iNextBlock!=m_iBlock )
SetCurBlock(iNextBlock);

return true;
}
int iNextBlock = m_pMatchingBlocks->Find ( m_iBlock, RowId2MinMaxBlockId(tRowID) );
if ( iNextBlock>=m_pMatchingBlocks->GetNumBlocks() )
return false;

iNextBlock++;
}
if ( iNextBlock>m_iBlock )
SetCurBlock(iNextBlock);

return false;
return true;
}


Expand Down Expand Up @@ -377,12 +367,6 @@ int BlockIterator_c::GetNumDocs ( int iBlock ) const
return m_iDocsInLastBlock;
}


uint32_t BlockIterator_c::MinMaxBlockId2RowId ( int iBlockId ) const
{
return iBlockId<<m_iMinMaxLeafShift;
}

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

class Columnar_c final : public Columnar_i
Expand Down

0 comments on commit c6dbbcb

Please sign in to comment.