[PATCH 4/7] Make tuple_bloom support multikey indexes
Vladimir Davydov
vdavydov.dev at gmail.com
Wed May 8 20:22:36 MSK 2019
Just like in case of tuple_extract_key, simply pass multikey_idx to
tuple_bloom_builder_add and tuple_bloom_maybe_has. For now, we always
pass -1, but the following patches will pass offset in multikey array
if the key definition is multikey.
---
src/box/key_def.h | 3 ++-
src/box/tuple_bloom.c | 16 +++++++++++-----
src/box/tuple_bloom.h | 9 ++++++---
src/box/tuple_hash.cc | 4 ++--
src/box/vy_stmt.c | 4 ++--
5 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/src/box/key_def.h b/src/box/key_def.h
index 8b94b3b6..f4a1a8fd 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -675,13 +675,14 @@ tuple_hash_field(uint32_t *ph1, uint32_t *pcarry, const char **field,
* @param pcarry - pointer to carry
* @param tuple - tuple to hash
* @param part - key part
+ * @param multikey_idx - multikey index hint
* @return size of processed data
*
* This function updates @ph1 and @pcarry.
*/
uint32_t
tuple_hash_key_part(uint32_t *ph1, uint32_t *pcarry, struct tuple *tuple,
- struct key_part *part);
+ struct key_part *part, int multikey_idx);
/**
* Calculates a common hash value for a tuple
diff --git a/src/box/tuple_bloom.c b/src/box/tuple_bloom.c
index 935df798..99f19a2e 100644
--- a/src/box/tuple_bloom.c
+++ b/src/box/tuple_bloom.c
@@ -105,9 +105,11 @@ tuple_hash_array_add(struct tuple_hash_array *hash_arr, uint32_t hash)
int
tuple_bloom_builder_add(struct tuple_bloom_builder *builder,
- struct tuple *tuple, struct key_def *key_def)
+ struct tuple *tuple, struct key_def *key_def,
+ int multikey_idx)
{
assert(builder->part_count == key_def->part_count);
+ assert(!key_def_is_multikey(key_def) || multikey_idx >= 0);
uint32_t h = HASH_SEED;
uint32_t carry = 0;
@@ -115,7 +117,8 @@ tuple_bloom_builder_add(struct tuple_bloom_builder *builder,
for (uint32_t i = 0; i < key_def->part_count; i++) {
total_size += tuple_hash_key_part(&h, &carry, tuple,
- &key_def->parts[i]);
+ &key_def->parts[i],
+ multikey_idx);
uint32_t hash = PMurHash32_Result(h, carry, total_size);
if (tuple_hash_array_add(&builder->parts[i], hash) != 0)
return -1;
@@ -198,9 +201,11 @@ tuple_bloom_delete(struct tuple_bloom *bloom)
}
bool
-tuple_bloom_maybe_has(const struct tuple_bloom *bloom,
- struct tuple *tuple, struct key_def *key_def)
+tuple_bloom_maybe_has(const struct tuple_bloom *bloom, struct tuple *tuple,
+ struct key_def *key_def, int multikey_idx)
{
+ assert(!key_def_is_multikey(key_def) || multikey_idx >= 0);
+
if (bloom->is_legacy) {
return bloom_maybe_has(&bloom->parts[0],
tuple_hash(tuple, key_def));
@@ -214,7 +219,8 @@ tuple_bloom_maybe_has(const struct tuple_bloom *bloom,
for (uint32_t i = 0; i < key_def->part_count; i++) {
total_size += tuple_hash_key_part(&h, &carry, tuple,
- &key_def->parts[i]);
+ &key_def->parts[i],
+ multikey_idx);
uint32_t hash = PMurHash32_Result(h, carry, total_size);
if (!bloom_maybe_has(&bloom->parts[i], hash))
return false;
diff --git a/src/box/tuple_bloom.h b/src/box/tuple_bloom.h
index 5a630a49..1b7e4ac4 100644
--- a/src/box/tuple_bloom.h
+++ b/src/box/tuple_bloom.h
@@ -129,11 +129,13 @@ tuple_bloom_builder_delete(struct tuple_bloom_builder *builder);
* @param builder - bloom filter builder
* @param tuple - tuple to add
* @param key_def - key definition
+ * @param multikey_idx - multikey index hint
* @return 0 on success, -1 on OOM
*/
int
tuple_bloom_builder_add(struct tuple_bloom_builder *builder,
- struct tuple *tuple, struct key_def *key_def);
+ struct tuple *tuple, struct key_def *key_def,
+ int multikey_idx);
/**
* Add a key hash to a tuple bloom filter builder.
@@ -169,12 +171,13 @@ tuple_bloom_delete(struct tuple_bloom *bloom);
* @param bloom - bloom filter
* @param tuple - tuple to check
* @param key_def - key definition
+ * @param multikey_idx - multikey index hint
* @return true if the tuple may have been stored in the bloom,
* false if the tuple is definitely not in the bloom
*/
bool
-tuple_bloom_maybe_has(const struct tuple_bloom *bloom,
- struct tuple *tuple, struct key_def *key_def);
+tuple_bloom_maybe_has(const struct tuple_bloom *bloom, struct tuple *tuple,
+ struct key_def *key_def, int multikey_idx);
/**
* Check if a tuple matching a key was stored in a tuple bloom filter.
diff --git a/src/box/tuple_hash.cc b/src/box/tuple_hash.cc
index 63de2bae..f90e1671 100644
--- a/src/box/tuple_hash.cc
+++ b/src/box/tuple_hash.cc
@@ -348,9 +348,9 @@ tuple_hash_null(uint32_t *ph1, uint32_t *pcarry)
uint32_t
tuple_hash_key_part(uint32_t *ph1, uint32_t *pcarry, struct tuple *tuple,
- struct key_part *part)
+ struct key_part *part, int multikey_idx)
{
- const char *field = tuple_field_by_part(tuple, part, -1);
+ const char *field = tuple_field_by_part(tuple, part, multikey_idx);
if (field == NULL)
return tuple_hash_null(ph1, pcarry);
return tuple_hash_field(ph1, pcarry, &field, part->coll);
diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c
index 847b6196..ddad26f5 100644
--- a/src/box/vy_stmt.c
+++ b/src/box/vy_stmt.c
@@ -534,7 +534,7 @@ vy_stmt_bloom_builder_add(struct tuple_bloom_builder *builder,
return tuple_bloom_builder_add_key(builder, data,
part_count, key_def);
} else {
- return tuple_bloom_builder_add(builder, stmt, key_def);
+ return tuple_bloom_builder_add(builder, stmt, key_def, -1);
}
}
@@ -548,7 +548,7 @@ vy_stmt_bloom_maybe_has(const struct tuple_bloom *bloom,
return tuple_bloom_maybe_has_key(bloom, data,
part_count, key_def);
} else {
- return tuple_bloom_maybe_has(bloom, stmt, key_def);
+ return tuple_bloom_maybe_has(bloom, stmt, key_def, -1);
}
}
--
2.11.0
More information about the Tarantool-patches
mailing list