From d6e08e9d8d3ac9b356ac50cee22b41f828160247 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Thu, 27 Jul 2023 18:21:26 -0400 Subject: Expanded query interface Query interface now enables skipping of delete processing and stopping query processing when first match is found. --- include/shard/TrieSpline.h | 48 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'include/shard/TrieSpline.h') diff --git a/include/shard/TrieSpline.h b/include/shard/TrieSpline.h index f06756f..7d1a90d 100644 --- a/include/shard/TrieSpline.h +++ b/include/shard/TrieSpline.h @@ -300,6 +300,9 @@ private: template class TrieSplineRangeQuery { public: + constexpr static bool EARLY_ABORT=false; + constexpr static bool SKIP_DELETE_FILTER=true; + static void *get_query_state(TrieSpline *ts, void *parms) { auto res = new TrieSplineState(); auto p = (ts_range_query_parms *) parms; @@ -317,7 +320,7 @@ public: return res; } - static void process_query_states(void *query_parms, std::vector shard_states, void *buff_state) { + static void process_query_states(void *query_parms, std::vector &shard_states, void *buff_state) { return; } @@ -367,11 +370,25 @@ public: return records; } - static std::vector merge(std::vector> &results, void *parms) { + static std::vector merge(std::vector>> &results, void *parms) { + std::vector>> cursors; + cursors.reserve(results.size()); + + PriorityQueue> pq(results.size()); size_t total = 0; - for (size_t i=0; i 0){ + auto base = results[i].data(); + cursors.emplace_back(Cursor{base, base + results[i].size(), 0, results[i].size()}); + assert(i == cursors.size() - 1); + total += results[i].size(); + pq.push(cursors[i].ptr, tmp_n - i - 1); + } else { + cursors.emplace_back(Cursor>{nullptr, nullptr, 0, 0}); + } if (total == 0) { return std::vector(); @@ -380,11 +397,28 @@ public: std::vector output; output.reserve(total); - for (size_t i=0; i 1 ? pq.peek(1) : queue_record>{nullptr, 0}; + if (!now.data->is_tombstone() && next.data != nullptr && + now.data->rec == next.data->rec && next.data->is_tombstone()) { + + pq.pop(); pq.pop(); + auto& cursor1 = cursors[tmp_n - now.version - 1]; + auto& cursor2 = cursors[tmp_n - next.version - 1]; + if (advance_cursor>(cursor1)) pq.push(cursor1.ptr, now.version); + if (advance_cursor>(cursor2)) pq.push(cursor2.ptr, next.version); + } else { + auto& cursor = cursors[tmp_n - now.version - 1]; + if (!now.data->is_tombstone()) output.push_back(cursor.ptr->rec); + pq.pop(); + + if (advance_cursor>(cursor)) pq.push(cursor.ptr, now.version); + } } return output; + } static void delete_query_state(void *state) { -- cgit v1.2.3