19double rmi_model_entry_ratio = 0.01;
24static
void add_index_args()
32 "--rmi-model-entry-ratio",
33 "specify the ratio of linear models to index entries for recursive model indexes",
34 [](
double rmi_model_entry_ratio){ options::rmi_model_entry_ratio = rmi_model_entry_ratio; }
42 std::ostringstream oss;
44 for (std::size_t i = 0; i != schema.
num_entries(); ++i) {
45 if (i != 0) oss <<
", ";
46 oss << schema.
at(i).
id;
48 oss <<
" FROM " << table.
name() <<
';';
54 : memory_(
Catalog::Get().
allocator().allocate(ALLOCATION_SIZE)), num_entries_(0), finalized_(false)
66 auto entry = key_schema.
at(0);
69 auto attribute_type = entry.
type;
71 if constexpr(not std::same_as<key_type, TYPE>) \
72 throw invalid_argument("Key type and attribute type do not match."); \
80 case Numeric::N_Decimal:
83 case 8:
CHECK(int8_t);
84 case 16:
CHECK(int16_t);
85 case 32:
CHECK(int32_t);
86 case 64:
CHECK(int64_t);
88 case Numeric::N_Float:
91 case 32:
CHECK(
float);
92 case 64:
CHECK(
double);
104 auto query = build_query(table, key_schema);
115 fn_get = [](
const Tuple &t) {
return static_cast<key_type>(t.
get(0).
as<int64_t>()); };
120 std::size_t tuple_id = 0;
121 auto fn_add = [&](
const Schema&,
const Tuple &tuple) {
122 if (not tuple.is_null(0))
123 this->add(fn_get(tuple), tuple_id);
126 auto consumer = std::make_unique<CallbackOperator>(fn_add);
132 static thread_local std::unique_ptr<Backend> backend;
143 std::exchange(
Catalog::Get().timer(), std::move(old_timer));
146template<
typename Key>
149 if ((num_entries_ + 1) *
sizeof(
entry_type) > memory_.size())
152 if constexpr(std::same_as<key_type, const char*>) {
162template<arithmetic Key>
166 std::sort(base_type::begin(), base_type::end(), base_type::cmp);
169 auto begin = base_type::begin();
170 auto end = base_type::end();
171 std::size_t n_keys = std::distance(begin, end);
172 std::size_t n_models = std::max<std::size_t>(1, n_keys * options::rmi_model_entry_ratio);
173 models_.reserve(n_models + 1);
176 models_.emplace_back(
177 LinearModel::train_linear_spline(
181 static_cast<double>(n_models) / n_keys
186 auto get_segment_id = [&](
entry_type e) {
return std::clamp<double>(models_[0](e.first), 0, n_models - 1); };
187 std::size_t segment_start = 0;
188 std::size_t segment_id = 0;
189 for (std::size_t i = 0; i != n_keys; ++i) {
190 auto pos = begin + i;
191 std::size_t pred_segment_id = get_segment_id(*pos);
192 if (pred_segment_id > segment_id) {
193 models_.emplace_back(
194 LinearModel::train_linear_regression(
195 begin + segment_start,
200 for (std::size_t j = segment_id + 1; j < pred_segment_id; ++j) {
201 models_.emplace_back(
202 LinearModel::train_linear_regression(
209 segment_id = pred_segment_id;
214 models_.emplace_back(
215 LinearModel::train_linear_regression(
216 begin + segment_start,
221 for (std::size_t j = segment_id + 1; j < n_models; ++j) {
222 models_.emplace_back(
223 LinearModel::train_linear_regression(
232 base_type::finalized_ =
true;
236#define INSTANTIATE(CLASS) \
237 template struct CLASS;
#define M_INDEX_LIST_TEMPLATED(X)
__attribute__((constructor(202))) static void register_interpreter()
#define INSTANTIATE(CLASS)
void add(const char *group_name, const char *short_name, const char *long_name, const char *description, Callback &&callback)
Adds a new group option to the ArgParser.
#define M_unreachable(MSG)
std::unique_ptr< ast::Stmt > M_EXPORT statement_from_string(Diagnostic &diag, const std::string &str)
Use lexer, parser, and semantic analysis to create a Stmt from str.
void M_EXPORT execute_query(Diagnostic &diag, const ast::SelectStmt &stmt, std::unique_ptr< Consumer > consumer)
Optimizes and executes the given SelectStmt.
auto visit(Callable &&callable, Base &obj, m::tag< Callable > &&=m::tag< Callable >())
Generic implementation to visit a class hierarchy, with similar syntax as std::visit.
command-line options for the HeuristicSearchPlanEnumerator
The catalog contains all Databases and keeps track of all meta information of the database system.
ThreadSafePooledString pool(const char *str) const
Creates an internalized copy of the string str by adding it to the internal StringPool.
static Catalog & Get()
Return a reference to the single Catalog instance.
std::unique_ptr< Backend > create_backend() const
Returns a new Backend.
m::ArgParser & arg_parser()
The type of character strings, both fixed length and varying length.
The numeric type represents integer and floating-point types of different precision and scale.
static Options & Get()
Return a reference to the single Options instance.
A Schema represents a sequence of identifiers, optionally with a prefix, and their associated types.
std::size_t num_entries() const
Returns the number of entries in this Schema.
entry_type & at(std::size_t idx)
Returns the entry at index idx with in-bounds checking.
A table is a sorted set of attributes.
virtual const ThreadSafePooledString & name() const =0
Returns the name of the Table.
Collect timings of events.
Value & get(std::size_t idx)
Returns a reference to the Value at index idx.
std::conditional_t< std::is_pointer_v< T >, T, T & > as()
Returns a reference to the value interpreted as of type T.
void bulkload(const Table &table, const Schema &key_schema) override
Bulkloads the index from table on the key contained in key_schema by executing a query and adding one...
std::pair< key_type, value_type > entry_type
void add(const key_type key, const value_type value)
Adds a single pair of key and value to the index.
static std::string build_query(const Table &table, const Schema &schema)
Constructs a query string to select all attributes in schema from table.
void finalize() override
Sorts the underlying vector, builds the linear models, and flags the index as finalized.
base_type::entry_type entry_type
Signals that an argument to a function of method was invalid.
Signals a runtime error that mu*t*able is not responsible for and that mu*t*able was not able to reco...