OmniSciDB  72c90bc290
 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 
53  return query_resultset_cache_.get();
54  }
55 
57  return chunk_metadata_cache_.get();
58  }
59 
60  const ResultSetPtr getCachedQueryResultSet(const size_t key);
61 
62  std::optional<std::vector<TargetMetaInfo>> getOutputMetaInfo(QueryPlanHash key);
63 
64  bool hasCachedQueryResultSet(const size_t key);
65 
67  const size_t key,
68  const std::unordered_set<size_t>& input_table_keys,
69  const ResultSetPtr query_result,
70  size_t resultset_size,
71  std::vector<std::shared_ptr<Analyzer::Expr>>& target_exprs);
72 
73  std::optional<ChunkMetadataMap> getCachedChunkMetadata(const size_t key);
74 
75  void putChunkMetadataToCache(const size_t key,
76  const std::unordered_set<size_t>& input_table_keys,
77  const ChunkMetadataMap& chunk_metadata);
78 
79  std::vector<std::shared_ptr<Analyzer::Expr>>& getTargetExprs(QueryPlanHash key) const;
80 
81  private:
82  static std::unique_ptr<ResultSetRecycler> query_resultset_cache_;
83  // let's manage chunk_metadata cache with resultset recycler together b/c
84  // the only usage currently allowed accessing chunk_metadata_cache is
85  // synthetizing chunk metadata for "resultset"
86  static std::unique_ptr<ChunkMetadataRecycler> chunk_metadata_cache_;
87 };
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)