[PATCH 2/3] vinyl: use point lookup explicitly where appropriate
Vladimir Davydov
vdavydov.dev at gmail.com
Wed Mar 7 12:05:10 MSK 2018
We never use vy_point_lookup directly, instead we open vy_read_iterator,
which automatically falls back on vy_point_lookup if looking for exact
match (EQ + full key). Due to this we can't add a new point lookup
specific argument (we would have to propagate it through the read
iterator, which is ugly). Let's call vy_point_lookup directly when we
know that vy_read_iterator will fall back on it anyway.
---
src/box/vinyl.c | 24 +++++++++++-------------
src/box/vy_read_iterator.c | 18 ------------------
2 files changed, 11 insertions(+), 31 deletions(-)
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 3ffe2fdb..32781ad2 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -40,6 +40,7 @@
#include "vy_upsert.h"
#include "vy_write_iterator.h"
#include "vy_read_iterator.h"
+#include "vy_point_lookup.h"
#include "vy_quota.h"
#include "vy_scheduler.h"
#include "vy_stat.h"
@@ -1346,6 +1347,9 @@ vy_index_get(struct vy_index *index, struct vy_tx *tx,
*/
assert(tx == NULL || tx->state == VINYL_TX_READY);
+ if (tuple_field_count(key) >= index->cmp_def->part_count)
+ return vy_point_lookup(index, tx, rv, key, result);
+
struct vy_read_iterator itr;
vy_read_iterator_open(&itr, index, tx, ITER_EQ, key, rv);
int rc = vy_read_iterator_next(&itr, result);
@@ -1686,7 +1690,7 @@ vy_index_full_by_key(struct vy_index *index, struct vy_tx *tx,
*result = found;
return 0;
}
- rc = vy_index_get(index->pk, tx, rv, found, result);
+ rc = vy_point_lookup(index->pk, tx, rv, found, result);
tuple_unref(found);
return rc;
}
@@ -3565,19 +3569,13 @@ vy_squash_process(struct vy_squash *squash)
/* Upserts enabled only in the primary index. */
assert(index->id == 0);
- struct vy_read_iterator itr;
/*
* Use the committed read view to avoid squashing
* prepared, but not committed statements.
*/
- vy_read_iterator_open(&itr, index, NULL, ITER_EQ, squash->stmt,
- &env->xm->p_committed_read_view);
struct tuple *result;
- int rc = vy_read_iterator_next(&itr, &result);
- if (rc == 0 && result != NULL)
- tuple_ref(result);
- vy_read_iterator_close(&itr);
- if (rc != 0)
+ if (vy_point_lookup(index, NULL, &env->xm->p_committed_read_view,
+ squash->stmt, &result) != 0)
return -1;
if (result == NULL)
return 0;
@@ -3714,7 +3712,7 @@ vy_squash_process(struct vy_squash *squash)
*/
size_t mem_used_before = lsregion_used(&env->mem_env.allocator);
const struct tuple *region_stmt = NULL;
- rc = vy_index_set(index, mem, result, ®ion_stmt);
+ int rc = vy_index_set(index, mem, result, ®ion_stmt);
tuple_unref(result);
size_t mem_used_after = lsregion_used(&env->mem_env.allocator);
assert(mem_used_after >= mem_used_before);
@@ -3889,9 +3887,9 @@ vinyl_iterator_next(struct iterator *base, struct tuple **ret)
}
#endif
/* Get the full tuple from the primary index. */
- if (vy_index_get(it->index->pk, it->tx,
- vy_tx_read_view(it->tx),
- tuple, &tuple) != 0)
+ if (vy_point_lookup(it->index->pk, it->tx,
+ vy_tx_read_view(it->tx),
+ tuple, &tuple) != 0)
goto fail;
} else {
tuple_ref(tuple);
diff --git a/src/box/vy_read_iterator.c b/src/box/vy_read_iterator.c
index 1ba33ffe..a265f587 100644
--- a/src/box/vy_read_iterator.c
+++ b/src/box/vy_read_iterator.c
@@ -37,7 +37,6 @@
#include "vy_upsert.h"
#include "vy_index.h"
#include "vy_stat.h"
-#include "vy_point_lookup.h"
/**
* Merge source, support structure for vy_read_iterator.
@@ -947,23 +946,6 @@ vy_read_iterator_next(struct vy_read_iterator *itr, struct tuple **result)
{
ev_tstamp start_time = ev_monotonic_now(loop());
- /* The key might be set to NULL during previous call, that means
- * that there's no more data */
- if (itr->key == NULL) {
- *result = NULL;
- return 0;
- }
-
- /* Run a special iterator for a special case */
- if ((itr->iterator_type == ITER_EQ || itr->iterator_type == ITER_REQ) &&
- tuple_field_count(itr->key) >= itr->index->cmp_def->part_count) {
- int rc = vy_point_lookup(itr->index, itr->tx, itr->read_view,
- itr->key, &itr->last_stmt);
- *result = itr->last_stmt;
- itr->key = NULL;
- return rc;
- }
-
*result = NULL;
if (!itr->search_started) {
--
2.11.0
More information about the Tarantool-patches
mailing list