diff --git a/src/template_db/transaction.h b/src/template_db/transaction.h index 101092362..01c5b280a 100644 --- a/src/template_db/transaction.h +++ b/src/template_db/transaction.h @@ -97,6 +97,12 @@ inline void Nonsynced_Transaction::flush() } +inline bool ends_with(const std::string& s, const std::string& suffix) +{ + return s.size() >= suffix.size() && s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0; +} + + inline File_Blocks_Index_Base* Nonsynced_Transaction::data_index (const File_Properties* fp) { @@ -108,7 +114,9 @@ inline File_Blocks_Index_Base* Nonsynced_Transaction::data_index File_Blocks_Index_Base* data_index = fp->new_data_index(access_mode, use_shadow, db_dir, file_name_extension); if (data_index != 0) { - if (access_mode == Access_Mode::readonly) + // Statements of a union read the same skeleton and local tag blocks, but look up different + // tags in the global tag index, so its blocks are rarely read again: don't cache them. + if (access_mode == Access_Mode::readonly && !ends_with(fp->get_file_name_trunk(), "_tags_global")) data_index->block_cache = &block_cache_; data_files[fp] = data_index; }