OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ResultSetRecyclerHolder.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
21 
23  public:
24  static auto invalidateCache() {
26  query_resultset_cache_->clearCache();
27 
29  chunk_metadata_cache_->clearCache();
30  }
31 
32  static auto markCachedItemAsDirty(size_t table_key) {
35  auto resultset_cache_tbl_key =
36  query_resultset_cache_->getMappedQueryPlanDagsWithTableKey(table_key);
37  if (resultset_cache_tbl_key.has_value()) {
38  query_resultset_cache_->markCachedItemAsDirty(
39  table_key,
40  *resultset_cache_tbl_key,
43  }
44  auto chunk_metadata_cache_tbl_key =
45  chunk_metadata_cache_->getMappedQueryPlanDagsWithTableKey(table_key);
46  if (chunk_metadata_cache_tbl_key.has_value()) {
47  chunk_metadata_cache_->markCachedItemAsDirty(
48  table_key,
49  *chunk_metadata_cache_tbl_key,
52  }
53  }
54 
56  return query_resultset_cache_.get();
57  }
58 
60  return chunk_metadata_cache_.get();
61  }
62 
63  const ResultSetPtr getCachedQueryResultSet(const size_t key);
64 
65  std::optional<std::vector<TargetMetaInfo>> getOutputMetaInfo(QueryPlanHash key);
66 
67  bool hasCachedQueryResultSet(const size_t key);
68 
70  const size_t key,
71  const std::unordered_set<size_t>& input_table_keys,
72  const ResultSetPtr query_result,
73  size_t resultset_size,
74  std::vector<std::shared_ptr<Analyzer::Expr>>& target_exprs);
75 
76  std::optional<ChunkMetadataMap> getCachedChunkMetadata(const size_t key);
77 
78  void putChunkMetadataToCache(const size_t key,
79  const std::unordered_set<size_t>& input_table_keys,
80  const ChunkMetadataMap& chunk_metadata);
81 
82  std::vector<std::shared_ptr<Analyzer::Expr>>& getTargetExprs(QueryPlanHash key) const;
83 
84  private:
85  static std::unique_ptr<ResultSetRecycler> query_resultset_cache_;
86  // let's manage chunk_metadata cache with resultset recycler together b/c
87  // the only usage currently allowed accessing chunk_metadata_cache is
88  // synthetizing chunk metadata for "resultset"
89  static std::unique_ptr<ChunkMetadataRecycler> chunk_metadata_cache_;
90 };
static std::unique_ptr< ResultSetRecycler > query_resultset_cache_
std::shared_ptr< ResultSet > ResultSetPtr
const ResultSetPtr getCachedQueryResultSet(const size_t key)
std::map< int, std::shared_ptr< ChunkMetadata >> ChunkMetadataMap
static std::unique_ptr< ChunkMetadataRecycler > chunk_metadata_cache_
bool hasCachedQueryResultSet(const size_t key)
void putChunkMetadataToCache(const size_t key, const std::unordered_set< size_t > &input_table_keys, const ChunkMetadataMap &chunk_metadata)
std::vector< std::shared_ptr< Analyzer::Expr > > & getTargetExprs(QueryPlanHash key) const
std::optional< std::vector< TargetMetaInfo > > getOutputMetaInfo(QueryPlanHash key)
static ChunkMetadataRecycler * getChunkMetadataRecycler()
size_t QueryPlanHash
#define CHECK(condition)
Definition: Logger.h:291
std::optional< ChunkMetadataMap > getCachedChunkMetadata(const size_t key)
static ResultSetRecycler * getResultSetRecycler()
static auto markCachedItemAsDirty(size_t table_key)
static constexpr DeviceIdentifier CPU_DEVICE_IDENTIFIER
Definition: DataRecycler.h:136
void putQueryResultSetToCache(const size_t key, const std::unordered_set< size_t > &input_table_keys, const ResultSetPtr query_result, size_t resultset_size, std::vector< std::shared_ptr< Analyzer::Expr >> &target_exprs)