/*------------------------------------------------------------------------------* * Architecture & Implementation of DBMS * *------------------------------------------------------------------------------* * Copyright 2022 Databases and Information Systems Group TU Dortmund * * Visit us at * * http://dbis.cs.tu-dortmund.de/cms/en/home/ * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * * OTHER DEALINGS IN THE SOFTWARE. * * * * Authors: * * Maximilian Berens * * Roland Kühn * * Jan Mühlig * *------------------------------------------------------------------------------* */ #pragma once #include "operator_interface.h" #include "tuple_buffer.h" #include #include #include #include #include #include #include
#include
#include #include namespace beedb::execution { /** * Key (range) that have to be looked up in the. * May be a range or a single key. */ class KeyRange { public: explicit KeyRange(const std::int64_t single_key) : _from(single_key), _to(std::numeric_limits::max()) { } KeyRange(const std::int64_t from, const std::int64_t to) : _from(from), _to(to) { } ~KeyRange() = default; [[nodiscard]] bool is_single_key() const { return _to == std::numeric_limits::max(); } [[nodiscard]] std::int64_t single_key() const { return _from; } [[nodiscard]] std::int64_t from() const { return _from; } [[nodiscard]] std::int64_t to() const { return _to; } bool operator<(const KeyRange &other) const { return _from < other._from; } bool operator==(const KeyRange &other) const { return _from == other._from && _to == other._to; } private: const std::int64_t _from; const std::int64_t _to; }; } // namespace beedb::execution namespace std { template <> struct hash { public: std::size_t operator()(const beedb::execution::KeyRange &range) const { return std::hash()(range.from()) ^ std::hash()(range.to()); } }; } // namespace std namespace beedb::execution { /** * Takes an index and keys to be looked up in the index * and scans only over pages found in the index instead * of scanning all pages from the table. */ class IndexScanOperator final : public OperatorInterface { public: IndexScanOperator(concurrency::Transaction *transaction, const std::uint32_t scan_page_limit, const table::Schema &schema, buffer::Manager &buffer_manager, table::TableDiskManager &table_disk_manager, std::unordered_set &&key_ranges, std::shared_ptr index); ~IndexScanOperator() override = default; void open() override; util::optional next() override; void close() override; [[nodiscard]] const table::Schema &schema() const override { return _schema; } private: const std::uint32_t _scan_page_limit; const table::Schema _schema; buffer::Manager &_buffer_manager; table::TableDiskManager &_table_disk_manager; std::unordered_set _key_ranges; std::shared_ptr _index; std::queue _pages_to_scan; std::vector _pinned_pages; TupleBuffer _buffer; }; } // namespace beedb::execution