OmniSciDB  cde582ebc3
 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 candidate_table_keys =
36  query_resultset_cache_->getMappedQueryPlanDagsWithTableKey(table_key);
37  if (candidate_table_keys.has_value()) {
38  query_resultset_cache_->markCachedItemAsDirty(
39  table_key,
40  *candidate_table_keys,
43 
44  chunk_metadata_cache_->markCachedItemAsDirty(
45  table_key,
46  *candidate_table_keys,
49  }
50  }
51 
52  const ResultSetPtr getCachedQueryResultSet(const size_t key);
53 
54  std::optional<std::vector<TargetMetaInfo>> getOutputMetaInfo(QueryPlanHash key);
55 
56  bool hasCachedQueryResultSet(const size_t key);
57 
59  const size_t key,
60  const std::unordered_set<size_t>& input_table_keys,
61  const ResultSetPtr query_result,
62  size_t resultset_size,
63  std::vector<std::shared_ptr<Analyzer::Expr>>& target_exprs);
64 
65  std::optional<ChunkMetadataMap> getCachedChunkMetadata(const size_t key);
66 
67  void putChunkMetadataToCache(const size_t key,
68  const std::unordered_set<size_t>& input_table_keys,
69  const ChunkMetadataMap& chunk_metadata);
70 
72 
74  return chunk_metadata_cache_.get();
75  }
76 
77  std::vector<std::shared_ptr<Analyzer::Expr>>& getTargetExprs(QueryPlanHash key) const;
78 
79  private:
80  static std::unique_ptr<ResultSetRecycler> query_resultset_cache_;
81  // let's manage chunk_metadata cache with resultset recycler together b/c
82  // the only usage currently allowed accessing chunk_metadata_cache is
83  // synthetizing chunk metadata for "resultset"
84  static std::unique_ptr<ChunkMetadataRecycler> chunk_metadata_cache_;
85 };
static std::unique_ptr< ResultSetRecycler > query_resultset_cache_
std::shared_ptr< ResultSet > ResultSetPtr
const ResultSetPtr getCachedQueryResultSet(const size_t key)
ResultSetRecycler * getResultSetRecycler()
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)
size_t QueryPlanHash
#define CHECK(condition)
Definition: Logger.h:222
std::optional< ChunkMetadataMap > getCachedChunkMetadata(const size_t key)
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)
ChunkMetadataRecycler * getChunkMetadataRecycler()