Skip to content

Commit

Permalink
fixed wrong enabled secondary indexes for JSON attribute fields affec…
Browse files Browse the repository at this point in the history
…ted by update
  • Loading branch information
tomatolog committed Dec 23, 2024
1 parent edadc69 commit 3ff21a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions secondary/blockreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ void ColumnInfo_t::Load ( util::FileReader_c & tReader )
m_sName = tReader.Read_string();
m_eType = (AttrType_e)tReader.Unpack_uint32();
m_uCountDistinct = tReader.Unpack_uint32();

auto iJsonFieldPos = m_sName.find ( "['" );
if ( iJsonFieldPos!=std::string::npos )
m_sJsonParentName = m_sName.substr ( 0, iJsonFieldPos );
}


Expand Down
1 change: 1 addition & 0 deletions secondary/blockreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct ColumnInfo_t
{
common::AttrType_e m_eType = common::AttrType_e::NONE;
std::string m_sName;
std::string m_sJsonParentName;
uint32_t m_uCountDistinct = 0;
bool m_bEnabled = true;

Expand Down
19 changes: 16 additions & 3 deletions secondary/secondary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ bool SecondaryIndex_c::Setup ( const std::string & sFile, std::string & sError )
}

m_hAttrs.insert ( { tCol.m_sName, i } );
if ( !tCol.m_sJsonParentName.empty() )
m_hAttrs.emplace ( tCol.m_sJsonParentName, i );
}

m_iBlocksBase = m_tReader.GetPos();
Expand Down Expand Up @@ -276,13 +278,24 @@ bool SecondaryIndex_c::SaveMeta ( std::string & sError )

void SecondaryIndex_c::ColumnUpdated ( const char * sName )
{
auto tIt = m_hAttrs.find ( sName );
if ( tIt==m_hAttrs.end() )
int iAttr = GetColumnId ( sName );
if ( iAttr==-1 )
return;

ColumnInfo_t & tCol = m_dAttrs[tIt->second];
ColumnInfo_t & tCol = m_dAttrs[iAttr];
m_bUpdated |= tCol.m_bEnabled; // already disabled indexes should not cause flush
bool bWasUpdated = tCol.m_bEnabled;
tCol.m_bEnabled = false;

// need to disable all fields at this JSON attribute
if ( bWasUpdated && !tCol.m_sJsonParentName.empty() )
{
for ( auto & tSibling : m_dAttrs )
{
if ( tSibling.m_sJsonParentName==tCol.m_sJsonParentName )
tSibling.m_bEnabled = false;
}
}
}


Expand Down

0 comments on commit 3ff21a8

Please sign in to comment.