From 5576c5524b48e43e4d6070c28de7c3c66582ed97 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Wed, 1 May 2024 16:05:07 -0400 Subject: Query optimizations --- include/query/knn.h | 4 ++-- include/query/rangecount.h | 42 ++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 24 deletions(-) (limited to 'include') diff --git a/include/query/knn.h b/include/query/knn.h index c856a74..a227293 100644 --- a/include/query/knn.h +++ b/include/query/knn.h @@ -111,7 +111,7 @@ public: pq.pop(); } - return results; + return std::move(results); } static std::vector merge(std::vector>> &results, void *parms, std::vector &output) { @@ -141,7 +141,7 @@ public: pq.pop(); } - return output; + return std::move(output); } static void delete_query_state(void *state) { diff --git a/include/query/rangecount.h b/include/query/rangecount.h index c20feaa..5a18ed4 100644 --- a/include/query/rangecount.h +++ b/include/query/rangecount.h @@ -42,13 +42,7 @@ public: constexpr static bool SKIP_DELETE_FILTER=true; static void *get_query_state(S *shard, void *parms) { - auto res = new State(); - auto p = (Parms *) parms; - - res->start_idx = shard->get_lower_bound(p->lower_bound); - res->stop_idx = shard->get_record_count(); - - return res; + return nullptr; } static void* get_buffer_query_state(BufferView *buffer, void *parms) { @@ -74,37 +68,43 @@ public: res.rec.value = 0; // tombstones records.emplace_back(res); + + auto start_idx = shard->get_lower_bound(p->lower_bound); + auto stop_idx = shard->get_lower_bound(p->upper_bound); + /* * if the returned index is one past the end of the * records for the PGM, then there are not records * in the index falling into the specified range. */ - if (s->start_idx == shard->get_record_count()) { + if (start_idx == shard->get_record_count()) { return records; } - auto ptr = shard->get_record_at(s->start_idx); /* * roll the pointer forward to the first record that is * greater than or equal to the lower bound. */ - while(ptr < shard->get_data() + s->stop_idx && ptr->rec.key < p->lower_bound) { - ptr++; + auto recs = shard->get_data(); + while(start_idx < stop_idx && recs[start_idx].rec.key < p->lower_bound) { + start_idx++; } - while (ptr < shard->get_data() + s->stop_idx && ptr->rec.key <= p->upper_bound) { - if (!ptr->is_deleted()) { - if (ptr->is_tombstone()) { - records[0].rec.value++; - } else { - records[0].rec.key++; - } - } + while (stop_idx < shard->get_record_count() && recs[stop_idx].rec.key <= p->upper_bound) { + stop_idx++; + } + size_t idx = start_idx; + size_t ts_cnt = 0; - ptr++; + while (idx < stop_idx) { + ts_cnt += recs[idx].is_tombstone() * 2 + recs[idx].is_deleted(); + idx++; } + records[0].rec.key = idx - start_idx; + records[0].rec.value = ts_cnt; + return records; } @@ -150,8 +150,6 @@ public: } static void delete_query_state(void *state) { - auto s = (State *) state; - delete s; } static void delete_buffer_query_state(void *state) { -- cgit v1.2.3