Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH] Use MULTIKEY_NONE instead of -1
Date: Mon, 13 May 2019 19:34:57 +0300	[thread overview]
Message-ID: <361e218b360dc6bec021325f6ad9d2c751b280ae.1557765186.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1557334828.git.vdavydov.dev@gmail.com>

Solely to improve code readability. No functional changes.
Suggested by @kostja.
---
 src/box/field_map.h          | 21 ++++++++++++++-------
 src/box/index.cc             |  3 ++-
 src/box/lua/key_def.c        |  2 +-
 src/box/memtx_bitset.c       |  2 +-
 src/box/memtx_rtree.c        |  2 +-
 src/box/memtx_space.c        |  3 ++-
 src/box/request.c            |  7 ++++---
 src/box/space.c              |  3 ++-
 src/box/sql.c                | 20 ++++++++++----------
 src/box/tuple.c              |  8 +++++---
 src/box/tuple.h              |  2 +-
 src/box/tuple_bloom.c        |  4 ++--
 src/box/tuple_compare.cc     | 21 ++++++++++++++-------
 src/box/tuple_extract_key.cc | 13 ++++++++-----
 src/box/tuple_format.c       |  2 +-
 src/box/tuple_hash.cc        | 11 +++++++----
 src/box/vinyl.c              |  9 ++++++---
 src/box/vy_run.c             |  3 ++-
 src/box/vy_stmt.c            |  3 ++-
 src/box/vy_stmt.h            |  4 ++--
 20 files changed, 87 insertions(+), 56 deletions(-)

diff --git a/src/box/field_map.h b/src/box/field_map.h
index 0fd35c3e..b0dfeb4e 100644
--- a/src/box/field_map.h
+++ b/src/box/field_map.h
@@ -38,6 +38,12 @@ struct region;
 struct field_map_builder_slot;
 
 /**
+ * A special value of multikey index that means that the key
+ * definition is not multikey and no indirection is expected.
+ */
+enum { MULTIKEY_NONE = -1 };
+
+/**
  * A field map is a special area is reserved before tuple's
  * MessagePack data. It is a sequence of the 32-bit unsigned
  * offsets of tuple's indexed fields.
@@ -146,7 +152,7 @@ field_map_get_offset(const uint32_t *field_map, int32_t offset_slot,
 		     int multikey_idx)
 {
 	uint32_t offset;
-	if (multikey_idx >= 0 && field_map[offset_slot] > 0) {
+	if (multikey_idx != MULTIKEY_NONE && field_map[offset_slot] > 0) {
 		assert((int32_t)field_map[offset_slot] < 0);
 		/**
 		 * The field_map extent has the following
@@ -192,10 +198,10 @@ field_map_builder_slot_extent_new(struct field_map_builder *builder,
 /**
  * Set data offset for a field identified by unique offset_slot.
  *
- * When multikey_idx > 0 this routine initialize corresponding
- * field_map_builder_slot_extent is identified by multikey_idx
- * and multikey_count. Performs allocation on region when
- * required.
+ * When multikey_idx != MULTIKEY_NONE this routine initializes
+ * corresponding field_map_builder_slot_extent identified by
+ * multikey_idx and multikey_count. Performs allocation on region
+ * when required.
  *
  * The offset_slot argument must be negative and offset must be
  * positive (by definition).
@@ -209,10 +215,11 @@ field_map_builder_set_slot(struct field_map_builder *builder,
 	assert(offset_slot < 0);
 	assert((uint32_t)-offset_slot <= builder->slot_count);
 	assert(offset > 0);
-	assert(multikey_idx < (int32_t)multikey_count);
-	if (multikey_idx == -1) {
+	if (multikey_idx == MULTIKEY_NONE) {
 		builder->slots[offset_slot].offset = offset;
 	} else {
+		assert(multikey_idx >= 0);
+		assert(multikey_idx < (int32_t)multikey_count);
 		struct field_map_builder_slot_extent *extent;
 		if (builder->slots[offset_slot].has_extent) {
 			extent = builder->slots[offset_slot].extent;
diff --git a/src/box/index.cc b/src/box/index.cc
index 39b0ee46..4a444e5d 100644
--- a/src/box/index.cc
+++ b/src/box/index.cc
@@ -156,7 +156,8 @@ box_tuple_extract_key(box_tuple_t *tuple, uint32_t space_id, uint32_t index_id,
 	struct index *index = index_find(space, index_id);
 	if (index == NULL)
 		return NULL;
-	return tuple_extract_key(tuple, index->def->key_def, -1, key_size);
+	return tuple_extract_key(tuple, index->def->key_def,
+				 MULTIKEY_NONE, key_size);
 }
 
 static inline int
diff --git a/src/box/lua/key_def.c b/src/box/lua/key_def.c
index 28d40478..dfcc8944 100644
--- a/src/box/lua/key_def.c
+++ b/src/box/lua/key_def.c
@@ -265,7 +265,7 @@ lbox_key_def_extract_key(struct lua_State *L)
 	struct region *region = &fiber()->gc;
 	size_t region_svp = region_used(region);
 	uint32_t key_size;
-	char *key = tuple_extract_key(tuple, key_def, -1, &key_size);
+	char *key = tuple_extract_key(tuple, key_def, MULTIKEY_NONE, &key_size);
 	tuple_unref(tuple);
 	if (key == NULL)
 		return luaT_error(L);
diff --git a/src/box/memtx_bitset.c b/src/box/memtx_bitset.c
index 275e736d..8c626684 100644
--- a/src/box/memtx_bitset.c
+++ b/src/box/memtx_bitset.c
@@ -302,7 +302,7 @@ memtx_bitset_index_replace(struct index *base, struct tuple *old_tuple,
 
 	if (new_tuple != NULL) {
 		const char *field = tuple_field_by_part(new_tuple,
-					base->def->key_def->parts, -1);
+				base->def->key_def->parts, MULTIKEY_NONE);
 		uint32_t key_len;
 		const void *key = make_key(field, &key_len);
 #ifndef OLD_GOOD_BITSET
diff --git a/src/box/memtx_rtree.c b/src/box/memtx_rtree.c
index 19cb69a1..45e8fb8e 100644
--- a/src/box/memtx_rtree.c
+++ b/src/box/memtx_rtree.c
@@ -122,7 +122,7 @@ extract_rectangle(struct rtree_rect *rect, struct tuple *tuple,
 	assert(index_def->key_def->part_count == 1);
 	assert(!key_def_is_multikey(index_def->key_def));
 	const char *elems = tuple_field_by_part(tuple,
-				index_def->key_def->parts, -1);
+				index_def->key_def->parts, MULTIKEY_NONE);
 	unsigned dimension = index_def->opts.dimension;
 	uint32_t count = mp_decode_array(&elems);
 	return mp_decode_rect(rect, dimension, elems, count, "Field");
diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index 265bf923..5ddb4f7e 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -445,7 +445,8 @@ memtx_space_execute_upsert(struct space *space, struct txn *txn,
 	/* Extract the primary key from tuple. */
 	const char *key = tuple_extract_key_raw(request->tuple,
 						request->tuple_end,
-						index->def->key_def, -1, NULL);
+						index->def->key_def,
+						MULTIKEY_NONE, NULL);
 	if (key == NULL)
 		return -1;
 	/* Cut array header */
diff --git a/src/box/request.c b/src/box/request.c
index 8b84260a..44a43ee1 100644
--- a/src/box/request.c
+++ b/src/box/request.c
@@ -92,7 +92,8 @@ request_create_from_tuple(struct request *request, struct space *space,
 		uint32_t size, key_size;
 		const char *data = tuple_data_range(old_tuple, &size);
 		request->key = tuple_extract_key_raw(data, data + size,
-				space->index[0]->def->key_def, -1, &key_size);
+				space->index[0]->def->key_def, MULTIKEY_NONE,
+				&key_size);
 		if (request->key == NULL)
 			return -1;
 		request->key_end = request->key + key_size;
@@ -125,8 +126,8 @@ request_rebind_to_primary_key(struct request *request, struct space *space,
 	struct index *pk = space_index(space, 0);
 	assert(pk != NULL);
 	uint32_t key_len;
-	char *key = tuple_extract_key(found_tuple, pk->def->key_def, -1,
-				      &key_len);
+	char *key = tuple_extract_key(found_tuple, pk->def->key_def,
+				      MULTIKEY_NONE, &key_len);
 	assert(key != NULL);
 	request->key = key;
 	request->key_end = key + key_len;
diff --git a/src/box/space.c b/src/box/space.c
index 9a266604..243e7da2 100644
--- a/src/box/space.c
+++ b/src/box/space.c
@@ -320,7 +320,8 @@ space_before_replace(struct space *space, struct txn *txn,
 			break;
 		index = pk;
 		key = tuple_extract_key_raw(request->tuple, request->tuple_end,
-					    index->def->key_def, -1, NULL);
+					    index->def->key_def, MULTIKEY_NONE,
+					    NULL);
 		if (key == NULL)
 			return -1;
 		part_count = mp_decode_array(&key);
diff --git a/src/box/sql.c b/src/box/sql.c
index c3f404ee..fbfa5999 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -480,8 +480,8 @@ int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 	char *key;
 	uint32_t key_size;
 	key = tuple_extract_key(pCur->last_tuple,
-				pCur->iter->index->def->key_def, -1,
-				&key_size);
+				pCur->iter->index->def->key_def,
+				MULTIKEY_NONE, &key_size);
 	if (key == NULL)
 		return SQL_TARANTOOL_DELETE_FAIL;
 
@@ -506,8 +506,8 @@ int tarantoolsqlDelete(BtCursor *pCur, u8 flags)
 	int rc;
 
 	key = tuple_extract_key(pCur->last_tuple,
-				pCur->iter->index->def->key_def, -1,
-				&key_size);
+				pCur->iter->index->def->key_def,
+				MULTIKEY_NONE, &key_size);
 	if (key == NULL)
 		return SQL_TARANTOOL_DELETE_FAIL;
 	rc = sql_delete_by_key(pCur->space, pCur->index->def->iid, key,
@@ -561,8 +561,8 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 	uint32_t  key_size;
 
 	while (iterator_next(it, &tuple) == 0 && tuple != NULL) {
-		key = tuple_extract_key(tuple, it->index->def->key_def, -1,
-					&key_size);
+		key = tuple_extract_key(tuple, it->index->def->key_def,
+					MULTIKEY_NONE, &key_size);
 		if (space_ephemeral_delete(pCur->space, key) != 0) {
 			iterator_delete(it);
 			return SQL_TARANTOOL_DELETE_FAIL;
@@ -594,8 +594,8 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count)
 	if (iter == NULL)
 		return SQL_TARANTOOL_ITERATOR_FAIL;
 	while (iterator_next(iter, &tuple) == 0 && tuple != NULL) {
-		request.key = tuple_extract_key(tuple, pk->def->key_def, -1,
-						&key_size);
+		request.key = tuple_extract_key(tuple, pk->def->key_def,
+						MULTIKEY_NONE, &key_size);
 		request.key_end = request.key + key_size;
 		rc = box_process_rw(&request, space, &unused);
 		if (rc != 0) {
@@ -783,7 +783,7 @@ tarantoolsqlIdxKeyCompare(struct BtCursor *cursor,
 				uint32_t field_offset =
 					field_map_get_offset(field_map,
 							     field->offset_slot,
-							     -1);
+							     MULTIKEY_NONE);
 				p = base + field_offset;
 			}
 		}
@@ -801,7 +801,7 @@ out:
 #ifndef NDEBUG
 	/* Sanity check. */
 	original_size = region_used(&fiber()->gc);
-	key = tuple_extract_key(tuple, key_def, -1, &key_size);
+	key = tuple_extract_key(tuple, key_def, MULTIKEY_NONE, &key_size);
 	if (key != NULL) {
 		int new_rc = sqlVdbeRecordCompareMsgpack(key, unpacked);
 		region_truncate(&fiber()->gc, original_size);
diff --git a/src/box/tuple.c b/src/box/tuple.c
index fe815a64..45c6727a 100644
--- a/src/box/tuple.c
+++ b/src/box/tuple.c
@@ -462,7 +462,7 @@ tuple_go_to_path(const char **data, const char *path, uint32_t path_len,
 	while ((rc = json_lexer_next_token(&lexer, &token)) == 0) {
 		switch (token.type) {
 		case JSON_TOKEN_ANY:
-			if (multikey_idx < 0)
+			if (multikey_idx == MULTIKEY_NONE)
 				return -1;
 			token.num = multikey_idx;
 			FALLTHROUGH;
@@ -535,7 +535,8 @@ tuple_field_raw_by_full_path(struct tuple_format *format, const char *tuple,
 	}
 	return tuple_field_raw_by_path(format, tuple, field_map, fieldno,
 				       path + lexer.offset,
-				       path_len - lexer.offset, NULL, -1);
+				       path_len - lexer.offset,
+				       NULL, MULTIKEY_NONE);
 }
 
 uint32_t
@@ -548,7 +549,8 @@ tuple_raw_multikey_count(struct tuple_format *format, const char *data,
 		tuple_field_raw_by_path(format, data, field_map,
 					key_def->multikey_fieldno,
 					key_def->multikey_path,
-					key_def->multikey_path_len, NULL, -1);
+					key_def->multikey_path_len,
+					NULL, MULTIKEY_NONE);
 	if (array_raw == NULL)
 		return 0;
 	assert(mp_typeof(*array_raw) == MP_ARRAY);
diff --git a/src/box/tuple.h b/src/box/tuple.h
index 2a46f371..4acda789 100644
--- a/src/box/tuple.h
+++ b/src/box/tuple.h
@@ -604,7 +604,7 @@ tuple_field_raw(struct tuple_format *format, const char *tuple,
 		const uint32_t *field_map, uint32_t field_no)
 {
 	return tuple_field_raw_by_path(format, tuple, field_map, field_no,
-				       NULL, 0, NULL, -1);
+				       NULL, 0, NULL, MULTIKEY_NONE);
 }
 
 /**
diff --git a/src/box/tuple_bloom.c b/src/box/tuple_bloom.c
index 99f19a2e..8b74da22 100644
--- a/src/box/tuple_bloom.c
+++ b/src/box/tuple_bloom.c
@@ -109,7 +109,7 @@ tuple_bloom_builder_add(struct tuple_bloom_builder *builder,
 			int multikey_idx)
 {
 	assert(builder->part_count == key_def->part_count);
-	assert(!key_def_is_multikey(key_def) || multikey_idx >= 0);
+	assert(!key_def_is_multikey(key_def) || multikey_idx != MULTIKEY_NONE);
 
 	uint32_t h = HASH_SEED;
 	uint32_t carry = 0;
@@ -204,7 +204,7 @@ bool
 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);
+	assert(!key_def_is_multikey(key_def) || multikey_idx != MULTIKEY_NONE);
 
 	if (bloom->is_legacy) {
 		return bloom_maybe_has(&bloom->parts[0],
diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc
index 0aa032af..c1a70a08 100644
--- a/src/box/tuple_compare.cc
+++ b/src/box/tuple_compare.cc
@@ -512,9 +512,11 @@ tuple_compare_slowpath(struct tuple *tuple_a, hint_t tuple_a_hint,
 							  (int)tuple_b_hint);
 		} else if (has_json_paths) {
 			field_a = tuple_field_raw_by_part(format_a, tuple_a_raw,
-							  field_map_a, part, -1);
+							  field_map_a, part,
+							  MULTIKEY_NONE);
 			field_b = tuple_field_raw_by_part(format_b, tuple_b_raw,
-							  field_map_b, part, -1);
+							  field_map_b, part,
+							  MULTIKEY_NONE);
 		} else {
 			field_a = tuple_field_raw(format_a, tuple_a_raw,
 						  field_map_a, part->fieldno);
@@ -576,9 +578,11 @@ tuple_compare_slowpath(struct tuple *tuple_a, hint_t tuple_a_hint,
 							  (int)tuple_b_hint);
 		} else if (has_json_paths) {
 			field_a = tuple_field_raw_by_part(format_a, tuple_a_raw,
-							  field_map_a, part, -1);
+							  field_map_a, part,
+							  MULTIKEY_NONE);
 			field_b = tuple_field_raw_by_part(format_b, tuple_b_raw,
-							  field_map_b, part, -1);
+							  field_map_b, part,
+							  MULTIKEY_NONE);
 		} else {
 			field_a = tuple_field_raw(format_a, tuple_a_raw,
 						  field_map_a, part->fieldno);
@@ -630,7 +634,8 @@ tuple_compare_with_key_slowpath(struct tuple *tuple, hint_t tuple_hint,
 							(int)tuple_hint);
 		} else if (has_json_paths) {
 			field = tuple_field_raw_by_part(format, tuple_raw,
-							field_map, part, -1);
+							field_map, part,
+							MULTIKEY_NONE);
 		} else {
 			field = tuple_field_raw(format, tuple_raw, field_map,
 						part->fieldno);
@@ -664,7 +669,8 @@ tuple_compare_with_key_slowpath(struct tuple *tuple, hint_t tuple_hint,
 							(int)tuple_hint);
 		} else if (has_json_paths) {
 			field = tuple_field_raw_by_part(format, tuple_raw,
-							field_map, part, -1);
+							field_map, part,
+							MULTIKEY_NONE);
 		} else {
 			field = tuple_field_raw(format, tuple_raw, field_map,
 						part->fieldno);
@@ -1564,7 +1570,8 @@ static hint_t
 tuple_hint(struct tuple *tuple, struct key_def *key_def)
 {
 	assert(!key_def_is_multikey(key_def));
-	const char *field = tuple_field_by_part(tuple, key_def->parts, -1);
+	const char *field = tuple_field_by_part(tuple, key_def->parts,
+						MULTIKEY_NONE);
 	if (is_nullable && field == NULL)
 		return hint_nil();
 	return field_hint<type, is_nullable>(field, key_def->parts->coll);
diff --git a/src/box/tuple_extract_key.cc b/src/box/tuple_extract_key.cc
index 15e43aae..3bd3cde7 100644
--- a/src/box/tuple_extract_key.cc
+++ b/src/box/tuple_extract_key.cc
@@ -119,7 +119,7 @@ tuple_extract_key_slowpath(struct tuple *tuple, struct key_def *key_def,
 	assert(contains_sequential_parts ==
 	       key_def_contains_sequential_parts(key_def));
 	assert(is_multikey == key_def_is_multikey(key_def));
-	assert(!key_def_is_multikey(key_def) || multikey_idx >= 0);
+	assert(!key_def_is_multikey(key_def) || multikey_idx != MULTIKEY_NONE);
 	assert(mp_sizeof_nil() == 1);
 	const char *data = tuple_data(tuple);
 	uint32_t part_count = key_def->part_count;
@@ -136,7 +136,8 @@ tuple_extract_key_slowpath(struct tuple *tuple, struct key_def *key_def,
 						key_def->parts[i].fieldno);
 		} else if (!is_multikey) {
 			field = tuple_field_raw_by_part(format, data, field_map,
-							&key_def->parts[i], -1);
+							&key_def->parts[i],
+							MULTIKEY_NONE);
 		} else {
 			field = tuple_field_raw_by_part(format, data, field_map,
 							&key_def->parts[i],
@@ -187,7 +188,8 @@ tuple_extract_key_slowpath(struct tuple *tuple, struct key_def *key_def,
 						key_def->parts[i].fieldno);
 		} else if (!is_multikey) {
 			field = tuple_field_raw_by_part(format, data, field_map,
-							&key_def->parts[i], -1);
+							&key_def->parts[i],
+							MULTIKEY_NONE);
 		} else {
 			field = tuple_field_raw_by_part(format, data, field_map,
 							&key_def->parts[i],
@@ -248,7 +250,7 @@ tuple_extract_key_slowpath_raw(const char *data, const char *data_end,
 	assert(has_json_paths == key_def->has_json_paths);
 	assert(!has_optional_parts || key_def->is_nullable);
 	assert(has_optional_parts == key_def->has_optional_parts);
-	assert(!key_def_is_multikey(key_def) || multikey_idx >= 0);
+	assert(!key_def_is_multikey(key_def) || multikey_idx != MULTIKEY_NONE);
 	assert(mp_sizeof_nil() == 1);
 	/* allocate buffer with maximal possible size */
 	char *key = (char *) region_alloc(&fiber()->gc, data_end - data);
@@ -453,7 +455,8 @@ tuple_validate_key_parts(struct key_def *key_def, struct tuple *tuple)
 	assert(!key_def_is_multikey(key_def));
 	for (uint32_t idx = 0; idx < key_def->part_count; idx++) {
 		struct key_part *part = &key_def->parts[idx];
-		const char *field = tuple_field_by_part(tuple, part, -1);
+		const char *field = tuple_field_by_part(tuple, part,
+							MULTIKEY_NONE);
 		if (field == NULL) {
 			if (key_part_is_nullable(part))
 				continue;
diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c
index 31f0515e..cee03f0a 100644
--- a/src/box/tuple_format.c
+++ b/src/box/tuple_format.c
@@ -1144,7 +1144,7 @@ tuple_format_iterator_next(struct tuple_format_iterator *it,
 		entry->multikey_idx = it->multikey_frame->idx;
 	} else {
 		entry->multikey_count = 0;
-		entry->multikey_idx = -1;
+		entry->multikey_idx = MULTIKEY_NONE;
 	}
 	if (field == NULL || (it->flags & TUPLE_FORMAT_ITERATOR_VALIDATE) == 0)
 		return 0;
diff --git a/src/box/tuple_hash.cc b/src/box/tuple_hash.cc
index f90e1671..223c5f6f 100644
--- a/src/box/tuple_hash.cc
+++ b/src/box/tuple_hash.cc
@@ -160,7 +160,8 @@ struct TupleHash
 		uint32_t carry = 0;
 		uint32_t total_size = 0;
 		const char *field = tuple_field_by_part(tuple,
-						key_def->parts, -1);
+						key_def->parts,
+						MULTIKEY_NONE);
 		TupleFieldHash<TYPE, MORE_TYPES...>::
 			hash(&field, &h, &carry, &total_size);
 		return PMurHash32_Result(h, carry, total_size);
@@ -173,7 +174,8 @@ struct TupleHash<FIELD_TYPE_UNSIGNED> {
 	{
 		assert(!key_def_is_multikey(key_def));
 		const char *field = tuple_field_by_part(tuple,
-						key_def->parts, -1);
+						key_def->parts,
+						MULTIKEY_NONE);
 		uint64_t val = mp_decode_uint(&field);
 		if (likely(val <= UINT32_MAX))
 			return val;
@@ -373,7 +375,7 @@ tuple_hash_slowpath(struct tuple *tuple, struct key_def *key_def)
 	const char *field;
 	if (has_json_paths) {
 		field = tuple_field_raw_by_part(format, tuple_raw, field_map,
-						key_def->parts, -1);
+						key_def->parts, MULTIKEY_NONE);
 	} else {
 		field = tuple_field_raw(format, tuple_raw, field_map,
 					prev_fieldno);
@@ -394,7 +396,8 @@ tuple_hash_slowpath(struct tuple *tuple, struct key_def *key_def)
 			struct key_part *part = &key_def->parts[part_id];
 			if (has_json_paths) {
 				field = tuple_field_raw_by_part(format, tuple_raw,
-								field_map, part, -1);
+								field_map, part,
+								MULTIKEY_NONE);
 			} else {
 				field = tuple_field_raw(format, tuple_raw, field_map,
 						    part->fieldno);
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 5be10d59..d4929a37 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -1339,7 +1339,8 @@ vy_get_by_secondary_tuple(struct vy_lsm *lsm, struct vy_tx *tx,
 	struct vy_entry key;
 	if (vy_stmt_is_key(entry.stmt)) {
 		key.stmt = vy_stmt_extract_key(entry.stmt, lsm->pk_in_cmp_def,
-					       lsm->env->key_format, -1);
+					       lsm->env->key_format,
+					       MULTIKEY_NONE);
 		if (key.stmt == NULL)
 			return -1;
 	} else {
@@ -1644,7 +1645,8 @@ vy_check_is_unique_secondary(struct vy_tx *tx, const struct vy_read_view **rv,
 		return 0;
 	if (!key_def_is_multikey(lsm->cmp_def)) {
 		return vy_check_is_unique_secondary_one(tx, rv,
-				space_name, index_name, lsm, stmt, -1);
+				space_name, index_name, lsm, stmt,
+				MULTIKEY_NONE);
 	}
 	int count = tuple_multikey_count(stmt, lsm->cmp_def);
 	for (int i = 0; i < count; ++i) {
@@ -2167,7 +2169,8 @@ vy_upsert(struct vy_env *env, struct vy_tx *tx, struct txn_stmt *stmt,
 	 */
 	/* Find the old tuple using the primary key. */
 	struct tuple *key = vy_stmt_extract_key_raw(tuple, tuple_end,
-					pk->key_def, pk->env->key_format, -1);
+					pk->key_def, pk->env->key_format,
+					MULTIKEY_NONE);
 	if (key == NULL)
 		return -1;
 	int rc = vy_get(pk, tx, vy_tx_read_view(tx), key, &stmt->old_tuple);
diff --git a/src/box/vy_run.c b/src/box/vy_run.c
index 0b9950f6..3b38aac6 100644
--- a/src/box/vy_run.c
+++ b/src/box/vy_run.c
@@ -2437,7 +2437,8 @@ vy_run_rebuild_index(struct vy_run *run, const char *dir,
 				}
 			}
 			key = vy_stmt_is_key(tuple) ? tuple_data(tuple) :
-			      tuple_extract_key(tuple, cmp_def, -1, NULL);
+			      tuple_extract_key(tuple, cmp_def,
+						MULTIKEY_NONE, NULL);
 			if (prev_tuple != NULL)
 				tuple_unref(prev_tuple);
 			prev_tuple = tuple;
diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c
index 8ce785a5..9e20b6bf 100644
--- a/src/box/vy_stmt.c
+++ b/src/box/vy_stmt.c
@@ -629,7 +629,8 @@ vy_stmt_encode_primary(struct tuple *value, struct key_def *key_def,
 	case IPROTO_DELETE:
 		extracted = vy_stmt_is_key(value) ?
 			    tuple_data_range(value, &size) :
-			    tuple_extract_key(value, key_def, -1, &size);
+			    tuple_extract_key(value, key_def,
+					      MULTIKEY_NONE, &size);
 		if (extracted == NULL)
 			return -1;
 		request.key = extracted;
diff --git a/src/box/vy_stmt.h b/src/box/vy_stmt.h
index 0026d614..a80456ad 100644
--- a/src/box/vy_stmt.h
+++ b/src/box/vy_stmt.h
@@ -691,13 +691,13 @@ vy_stmt_str(struct tuple *stmt);
 
 /**
  * Extract a multikey index hint from a statement entry.
- * Returns -1 if the key definition isn't multikey.
+ * Returns MULTIKEY_NONE if the key definition isn't multikey.
  */
 static inline int
 vy_entry_multikey_idx(struct vy_entry entry, struct key_def *key_def)
 {
 	if (!key_def_is_multikey(key_def) || vy_stmt_is_key(entry.stmt))
-		return -1;
+		return MULTIKEY_NONE;
 	assert(entry.hint != HINT_NONE);
 	return (int)entry.hint;
 }
-- 
2.11.0

  parent reply	other threads:[~2019-05-13 16:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 17:22 [PATCH 0/7] Support multikey indexes in Vinyl Vladimir Davydov
2019-05-08 17:22 ` [PATCH 1/7] Make tuple comparison hints mandatory Vladimir Davydov
2019-05-09  5:58   ` [tarantool-patches] " Konstantin Osipov
2019-05-08 17:22 ` [PATCH 2/7] Get rid of tuple_field_by_part_multikey Vladimir Davydov
2019-05-08 17:22 ` [PATCH 3/7] Make tuple_extract_key support multikey indexes Vladimir Davydov
2019-05-08 17:22 ` [PATCH 4/7] Make tuple_bloom " Vladimir Davydov
2019-05-08 17:22 ` [PATCH 5/7] vinyl: use field_map_builder for constructing stmt field map Vladimir Davydov
2019-05-08 17:22 ` [PATCH 6/7] vinyl: use multikey hints while writing runs Vladimir Davydov
2019-05-08 17:22 ` [PATCH 7/7] vinyl: implement multikey index support Vladimir Davydov
2019-05-13 16:34 ` Vladimir Davydov [this message]
2019-05-13 19:26 ` [PATCH 0/7] Support multikey indexes in Vinyl Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=361e218b360dc6bec021325f6ad9d2c751b280ae.1557765186.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH] Use MULTIKEY_NONE instead of -1' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox