From 80cbdbd280e8f085f9a433cd17e897d95f2b1569 Mon Sep 17 00:00:00 2001 From: Marcel Maltry Date: Thu, 4 Apr 2024 13:22:20 +0200 Subject: [PATCH] [Wasm] Add support for `RecursiveModelIndex` in `IndexScan` --- src/backend/V8Engine.cpp | 18 ++++++++++++++++++ src/backend/WasmOperator.cpp | 15 ++++++++++++++- src/backend/WasmOperator.hpp | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/backend/V8Engine.cpp b/src/backend/V8Engine.cpp index 1025d437..3c7b9029 100644 --- a/src/backend/V8Engine.cpp +++ b/src/backend/V8Engine.cpp @@ -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 context = v8::Context::New(isolate_, /* extensions= */ nullptr, global); @@ -1126,6 +1132,12 @@ v8::Local 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) { \ @@ -1152,6 +1164,12 @@ v8::Local 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 diff --git a/src/backend/WasmOperator.cpp b/src/backend/WasmOperator.cpp index 0d0a2ece..0153b3be 100644 --- a/src/backend/WasmOperator.cpp +++ b/src/backend/WasmOperator.cpp @@ -533,8 +533,10 @@ void m::register_wasm_operators(PhysicalOptimizer &phys_opt) if (options::simd) phys_opt.register_operator>(); } - 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>(); + phys_opt.register_operator>(); + } if (bool(options::filter_selection_strategy bitand option_configs::SelectionStrategy::BRANCHING)) phys_opt.register_operator>(); if (bool(options::filter_selection_strategy bitand option_configs::SelectionStrategy::PREDICATED)) @@ -1477,6 +1479,8 @@ void index_scan_codegen_compilation(const Index &index, const index_scan_bounds_ } if constexpr(is_specialization) { RESOLVE_KEYTYPE(array) + } else if constexpr(is_specialization) { + RESOLVE_KEYTYPE(rmi) } else { M_unreachable("unknown index type"); } @@ -1712,6 +1716,8 @@ void index_scan_codegen_hybrid(const Index &index, const index_scan_bounds_t &bo } if constexpr(is_specialization) { RESOLVE_KEYTYPE(array) + } else if constexpr(is_specialization) { + RESOLVE_KEYTYPE(rmi) } else { M_unreachable("unknown index type"); } @@ -1877,6 +1883,11 @@ void index_scan_resolve_index_method(const index_scan_bounds_t &bounds, const Ma index_scan_resolve_strategy, 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; }) { + auto &index = as>(index_base); + index_scan_resolve_strategy, SqlT>( + index, bounds, M, std::move(setup), std::move(pipeline), std::move(teardown) + ); } else { M_unreachable("invalid index method"); } @@ -6046,6 +6057,8 @@ void Match>::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"); diff --git a/src/backend/WasmOperator.hpp b/src/backend/WasmOperator.hpp index a3372f3d..facd68e6 100644 --- a/src/backend/WasmOperator.hpp +++ b/src/backend/WasmOperator.hpp @@ -240,6 +240,7 @@ namespace m { X(Scan) \ X(Scan) \ X(IndexScan) \ + X(IndexScan) \ X(Filter) \ X(Filter) \ X(Quicksort) \ @@ -281,6 +282,7 @@ namespace m { X(m::Match>) \ X(m::Match>) \ X(m::Match>) \ + X(m::Match>) \ X(m::Match>) \ X(m::Match>) \ X(m::Match>) \