Skip to content

Commit

Permalink
[Wasm] Add support for RecursiveModelIndex in IndexScan
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmaltry authored and lucagretscher committed Oct 31, 2024
1 parent 2816aac commit 80cbdbd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/backend/V8Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,12 @@ void V8Engine::execute(const m::MatchBase &plan)
CREATE_TEMPLATES(idx::ArrayIndex, float, v8::Number, array, f);
CREATE_TEMPLATES(idx::ArrayIndex, double, v8::Number, array, d);
CREATE_TEMPLATES(idx::ArrayIndex, const char*, v8::String, array, p);
CREATE_TEMPLATES(idx::RecursiveModelIndex, int8_t, v8::Int32, rmi, i1);
CREATE_TEMPLATES(idx::RecursiveModelIndex, int16_t, v8::Int32, rmi, i2);
CREATE_TEMPLATES(idx::RecursiveModelIndex, int32_t, v8::Int32, rmi, i4);
CREATE_TEMPLATES(idx::RecursiveModelIndex, int64_t, v8::BigInt, rmi, i8);
CREATE_TEMPLATES(idx::RecursiveModelIndex, float, v8::Number, rmi, f);
CREATE_TEMPLATES(idx::RecursiveModelIndex, double, v8::Number, rmi, d);
#undef CREATE_TEMPLATES

v8::Local<v8::Context> context = v8::Context::New(isolate_, /* extensions= */ nullptr, global);
Expand Down Expand Up @@ -1126,6 +1132,12 @@ v8::Local<v8::Object> m::wasm::detail::create_env(v8::Isolate &isolate, const m:
EMIT_FUNC_IMPORTS(float, array, f);
EMIT_FUNC_IMPORTS(double, array, d);
EMIT_FUNC_IMPORTS(const char*, array, p);
EMIT_FUNC_IMPORTS(int8_t, rmi, i1);
EMIT_FUNC_IMPORTS(int16_t, rmi, i2);
EMIT_FUNC_IMPORTS(int32_t, rmi, i4);
EMIT_FUNC_IMPORTS(int64_t, rmi, i8);
EMIT_FUNC_IMPORTS(float, rmi, f);
EMIT_FUNC_IMPORTS(double, rmi, d);
#undef EMIT_FUNC_IMPORTS

#define ADD_FUNC(FUNC, NAME) { \
Expand All @@ -1152,6 +1164,12 @@ v8::Local<v8::Object> m::wasm::detail::create_env(v8::Isolate &isolate, const m:
ADD_FUNCS(idx::ArrayIndex, float, v8::Number, array, f);
ADD_FUNCS(idx::ArrayIndex, double, v8::Number, array, d);
ADD_FUNCS(idx::ArrayIndex, const char*, v8::String, array, p);
ADD_FUNCS(idx::RecursiveModelIndex, int8_t, v8::Int32, rmi, i1);
ADD_FUNCS(idx::RecursiveModelIndex, int16_t, v8::Int32, rmi, i2);
ADD_FUNCS(idx::RecursiveModelIndex, int32_t, v8::Int32, rmi, i4);
ADD_FUNCS(idx::RecursiveModelIndex, int64_t, v8::BigInt, rmi, i8);
ADD_FUNCS(idx::RecursiveModelIndex, float, v8::Number, rmi, f);
ADD_FUNCS(idx::RecursiveModelIndex, double, v8::Number, rmi, d);
#undef ADD_FUNCS
#undef ADD_FUNC_
#undef ADD_FUNC
Expand Down
15 changes: 14 additions & 1 deletion src/backend/WasmOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,10 @@ void m::register_wasm_operators(PhysicalOptimizer &phys_opt)
if (options::simd)
phys_opt.register_operator<Scan<true>>();
}
if (bool(options::scan_implementations bitand option_configs::ScanImplementation::INDEX_SCAN))
if (bool(options::scan_implementations bitand option_configs::ScanImplementation::INDEX_SCAN)) {
phys_opt.register_operator<IndexScan<idx::IndexMethod::Array>>();
phys_opt.register_operator<IndexScan<idx::IndexMethod::Rmi>>();
}
if (bool(options::filter_selection_strategy bitand option_configs::SelectionStrategy::BRANCHING))
phys_opt.register_operator<Filter<false>>();
if (bool(options::filter_selection_strategy bitand option_configs::SelectionStrategy::PREDICATED))
Expand Down Expand Up @@ -1477,6 +1479,8 @@ void index_scan_codegen_compilation(const Index &index, const index_scan_bounds_
}
if constexpr(is_specialization<Index, idx::ArrayIndex>) {
RESOLVE_KEYTYPE(array)
} else if constexpr(is_specialization<Index, idx::RecursiveModelIndex>) {
RESOLVE_KEYTYPE(rmi)
} else {
M_unreachable("unknown index type");
}
Expand Down Expand Up @@ -1712,6 +1716,8 @@ void index_scan_codegen_hybrid(const Index &index, const index_scan_bounds_t &bo
}
if constexpr(is_specialization<Index, idx::ArrayIndex>) {
RESOLVE_KEYTYPE(array)
} else if constexpr(is_specialization<Index, idx::RecursiveModelIndex>) {
RESOLVE_KEYTYPE(rmi)
} else {
M_unreachable("unknown index type");
}
Expand Down Expand Up @@ -1877,6 +1883,11 @@ void index_scan_resolve_index_method(const index_scan_bounds_t &bounds, const Ma
index_scan_resolve_strategy<IndexMethod, const idx::ArrayIndex<AttrT>, SqlT>(
index, bounds, M, std::move(setup), std::move(pipeline), std::move(teardown)
);
} else if constexpr(IndexMethod == idx::IndexMethod::Rmi and requires { typename idx::RecursiveModelIndex<AttrT>; }) {
auto &index = as<const idx::RecursiveModelIndex<AttrT>>(index_base);
index_scan_resolve_strategy<IndexMethod, const idx::RecursiveModelIndex<AttrT>, SqlT>(
index, bounds, M, std::move(setup), std::move(pipeline), std::move(teardown)
);
} else {
M_unreachable("invalid index method");
}
Expand Down Expand Up @@ -6046,6 +6057,8 @@ void Match<m::wasm::IndexScan<IndexMethod>>::print(std::ostream &out, unsigned l
{
if (IndexMethod == idx::IndexMethod::Array)
indent(out, level) << "wasm::ArrayIndexScan(";
else if (IndexMethod == idx::IndexMethod::Rmi)
indent(out, level) << "wasm::RecursiveModelIndexScan(";
else
M_unreachable("unknown index");

Expand Down
2 changes: 2 additions & 0 deletions src/backend/WasmOperator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ namespace m {
X(Scan<false>) \
X(Scan<true>) \
X(IndexScan<m::idx::IndexMethod::Array>) \
X(IndexScan<m::idx::IndexMethod::Rmi>) \
X(Filter<false>) \
X(Filter<true>) \
X(Quicksort<false>) \
Expand Down Expand Up @@ -281,6 +282,7 @@ namespace m {
X(m::Match<m::wasm::Scan<false>>) \
X(m::Match<m::wasm::Scan<true>>) \
X(m::Match<m::wasm::IndexScan<m::idx::IndexMethod::Array>>) \
X(m::Match<m::wasm::IndexScan<m::idx::IndexMethod::Rmi>>) \
X(m::Match<m::wasm::Filter<false>>) \
X(m::Match<m::wasm::Filter<true>>) \
X(m::Match<m::wasm::Quicksort<false>>) \
Expand Down

0 comments on commit 80cbdbd

Please sign in to comment.