ClickHouse/src/Dictionaries/ICacheDictionaryStorage.h

111 lines
3.1 KiB
C++
Raw Normal View History

2021-02-16 21:33:02 +00:00
#pragma once
#include <Common/PODArray.h>
#include <Common/HashTable/HashMap.h>
#include <Columns/IColumn.h>
#include <Dictionaries/DictionaryHelpers.h>
namespace DB
{
struct KeyState
{
enum State
{
found,
expired,
not_found
};
KeyState(State state_, size_t fetched_column_index_)
: state(state_)
, fetched_column_index(fetched_column_index_)
{}
KeyState(State state_)
: state(state_)
{}
inline bool isFound() const { return state == State::found; }
inline bool isExpired() const { return state == State::expired; }
inline bool isNotFound() const { return state == State::not_found; }
State state = not_found;
size_t fetched_column_index = 0;
};
2021-02-17 11:48:06 +00:00
/// Result of fetch from CacheDictionaryStorage
2021-02-16 21:33:02 +00:00
template <typename KeyType>
struct KeysStorageFetchResult
{
2021-02-17 11:48:06 +00:00
/// Fetched column values
2021-02-16 21:33:02 +00:00
MutableColumns fetched_columns;
PaddedPODArray<KeyState> key_index_to_state;
2021-02-16 21:33:02 +00:00
size_t expired_keys_size = 0;
2021-02-16 21:33:02 +00:00
size_t found_keys_size = 0;
2021-02-16 21:33:02 +00:00
size_t not_found_keys_size = 0;
2021-02-16 21:33:02 +00:00
};
using SimpleKeysStorageFetchResult = KeysStorageFetchResult<UInt64>;
using ComplexKeysStorageFetchResult = KeysStorageFetchResult<StringRef>;
class ICacheDictionaryStorage
{
public:
virtual ~ICacheDictionaryStorage() = default;
2021-02-17 11:48:06 +00:00
/// Necessary if all keys are found we can return result to client without additional aggregation
virtual bool returnsFetchedColumnsInOrderOfRequestedKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Name of storage
virtual String getName() const = 0;
2021-02-17 11:48:06 +00:00
/// Does storage support simple keys
2021-02-16 21:33:02 +00:00
virtual bool supportsSimpleKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual SimpleKeysStorageFetchResult fetchColumnsForKeys(
const PaddedPODArray<UInt64> & keys,
2021-02-17 11:48:06 +00:00
const DictionaryStorageFetchRequest & fetch_request) = 0;
2021-02-16 21:33:02 +00:00
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual void insertColumnsForKeys(const PaddedPODArray<UInt64> & keys, Columns columns) = 0;
2021-02-17 11:48:06 +00:00
/// Return cached simple keys
2021-02-16 21:33:02 +00:00
virtual PaddedPODArray<UInt64> getCachedSimpleKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Does storage support complex keys
2021-02-16 21:33:02 +00:00
virtual bool supportsComplexKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual ComplexKeysStorageFetchResult fetchColumnsForKeys(
const PaddedPODArray<StringRef> & keys,
2021-02-17 11:48:06 +00:00
const DictionaryStorageFetchRequest & column_fetch_requests) = 0;
2021-02-16 21:33:02 +00:00
2021-02-17 11:48:06 +00:00
/// Fetch columns for keys, this method is not write thread safe
2021-02-16 21:33:02 +00:00
virtual void insertColumnsForKeys(const PaddedPODArray<StringRef> & keys, Columns columns) = 0;
2021-02-17 11:48:06 +00:00
/// Return cached simple keys
2021-02-16 21:33:02 +00:00
virtual PaddedPODArray<StringRef> getCachedComplexKeys() const = 0;
2021-02-17 11:48:06 +00:00
/// Return size of keys in storage
2021-02-16 21:33:02 +00:00
virtual size_t getSize() const = 0;
/// Return maximum size of keys in storage
virtual size_t getMaxSize() const = 0;
2021-02-17 11:48:06 +00:00
/// Return bytes allocated in storage
2021-02-16 21:33:02 +00:00
virtual size_t getBytesAllocated() const = 0;
};
using CacheDictionaryStoragePtr = std::shared_ptr<ICacheDictionaryStorage>;
}