Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [PATCH v5 01/12] box: refactor key_def_find routine
Date: Mon, 29 Oct 2018 09:56:30 +0300	[thread overview]
Message-ID: <4f2acb62de31f7ec7efc0246ae98c89b38d0291a.1540795996.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1540795996.git.kshcherbatov@tarantool.org>
In-Reply-To: <cover.1540795996.git.kshcherbatov@tarantool.org>

Refactored key_def_find routine to use key_part as a second
argument. Introduced key_def_find_by_fieldno helper to use in
scenarios where no key_part exists.
New API is more convenient for complex key_part that will appear
with JSON paths introduction.

Need for #1012
---
 src/box/alter.cc     |  7 ++++---
 src/box/key_def.c    | 19 ++++++++++++++-----
 src/box/key_def.h    |  9 ++++++++-
 src/box/sql/build.c  |  2 +-
 src/box/sql/pragma.c |  2 +-
 5 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index a6bb5a0..fc4d44e 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -3952,9 +3952,10 @@ on_replace_dd_fk_constraint(struct trigger * /* trigger*/, void *event)
 				continue;
 			uint32_t j;
 			for (j = 0; j < fk_def->field_count; ++j) {
-				if (key_def_find(idx->def->key_def,
-						 fk_def->links[j].parent_field)
-				    == NULL)
+				if (key_def_find_by_fieldno(idx->def->key_def,
+							    fk_def->links[j].
+							    parent_field) ==
+							    NULL)
 					break;
 			}
 			if (j != fk_def->field_count)
diff --git a/src/box/key_def.c b/src/box/key_def.c
index 3a560bb..2119ca3 100644
--- a/src/box/key_def.c
+++ b/src/box/key_def.c
@@ -519,12 +519,21 @@ key_def_decode_parts(struct key_part_def *parts, uint32_t part_count,
 }
 
 const struct key_part *
-key_def_find(const struct key_def *key_def, uint32_t fieldno)
+key_def_find_by_fieldno(const struct key_def *key_def, uint32_t fieldno)
+{
+	struct key_part part;
+	memset(&part, 0, sizeof(struct key_part));
+	part.fieldno = fieldno;
+	return key_def_find(key_def, &part);
+}
+
+const struct key_part *
+key_def_find(const struct key_def *key_def, const struct key_part *to_find)
 {
 	const struct key_part *part = key_def->parts;
 	const struct key_part *end = part + key_def->part_count;
 	for (; part != end; part++) {
-		if (part->fieldno == fieldno)
+		if (part->fieldno == to_find->fieldno)
 			return part;
 	}
 	return NULL;
@@ -536,7 +545,7 @@ key_def_contains(const struct key_def *first, const struct key_def *second)
 	const struct key_part *part = second->parts;
 	const struct key_part *end = part + second->part_count;
 	for (; part != end; part++) {
-		if (key_def_find(first, part->fieldno) == NULL)
+		if (key_def_find(first, part) == NULL)
 			return false;
 	}
 	return true;
@@ -553,7 +562,7 @@ key_def_merge(const struct key_def *first, const struct key_def *second)
 	const struct key_part *part = second->parts;
 	const struct key_part *end = part + second->part_count;
 	for (; part != end; part++) {
-		if (key_def_find(first, part->fieldno))
+		if (key_def_find(first, part) != NULL)
 			--new_part_count;
 	}
 
@@ -584,7 +593,7 @@ key_def_merge(const struct key_def *first, const struct key_def *second)
 	part = second->parts;
 	end = part + second->part_count;
 	for (; part != end; part++) {
-		if (key_def_find(first, part->fieldno))
+		if (key_def_find(first, part) != NULL)
 			continue;
 		key_def_set_part(new_def, pos++, part->fieldno, part->type,
 				 part->nullable_action, part->coll,
diff --git a/src/box/key_def.h b/src/box/key_def.h
index 20e79f9..cfed3f1 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -320,7 +320,14 @@ key_def_decode_parts(struct key_part_def *parts, uint32_t part_count,
  * If fieldno is not in index_def->parts returns NULL.
  */
 const struct key_part *
-key_def_find(const struct key_def *key_def, uint32_t fieldno);
+key_def_find_by_fieldno(const struct key_def *key_def, uint32_t fieldno);
+
+/**
+ * Returns the part in index_def->parts for the specified key part.
+ * If to_find is not in index_def->parts returns NULL.
+ */
+const struct key_part *
+key_def_find(const struct key_def *key_def, const struct key_part *to_find);
 
 /**
  * Check if key definition @a first contains all parts of
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index fb5d61c..7556a78 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -145,7 +145,7 @@ sql_space_column_is_in_pk(struct space *space, uint32_t column)
 	if (column < 63)
 		return (pk_mask & (((uint64_t) 1) << column)) != 0;
 	else if ((pk_mask & (((uint64_t) 1) << 63)) != 0)
-		return key_def_find(key_def, column) != NULL;
+		return key_def_find_by_fieldno(key_def, column) != NULL;
 	return false;
 }
 
diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 9ece82a..cc99eb1 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -273,7 +273,7 @@ sql_pragma_table_info(struct Parse *parse, const char *tbl_name)
 			k = 1;
 		} else {
 			struct key_def *kdef = pk->def->key_def;
-			k = key_def_find(kdef, i) - kdef->parts + 1;
+			k = key_def_find_by_fieldno(kdef, i) - kdef->parts + 1;
 		}
 		sqlite3VdbeMultiLoad(v, 1, "issisi", i, field->name,
 				     field_type_strs[field->type],
-- 
2.7.4

  reply	other threads:[~2018-10-29  6:56 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29  6:56 [PATCH v5 00/12] box: indexes by JSON path Kirill Shcherbatov
2018-10-29  6:56 ` Kirill Shcherbatov [this message]
2018-11-19 17:48   ` [PATCH v5 01/12] box: refactor key_def_find routine Vladimir Davydov
2018-10-29  6:56 ` [PATCH v5 10/12] box: tune tuple_field_raw_by_path for indexed data Kirill Shcherbatov
2018-10-29  6:56 ` [PATCH v5 11/12] box: introduce offset slot cache in key_part Kirill Shcherbatov
2018-11-01 13:32   ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:15     ` [tarantool-patches] " Kirill Shcherbatov
2018-10-29  6:56 ` [PATCH v5 12/12] box: specify indexes in user-friendly form Kirill Shcherbatov
2018-11-01 13:34   ` [tarantool-patches] " Konstantin Osipov
2018-11-01 14:18   ` Konstantin Osipov
2018-11-06 12:15     ` [tarantool-patches] " Kirill Shcherbatov
2018-10-29  6:56 ` [PATCH v5 02/12] box: introduce key_def_parts_are_sequential Kirill Shcherbatov
2018-11-01 14:23   ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:14     ` [tarantool-patches] " Kirill Shcherbatov
2018-11-19 17:48   ` Vladimir Davydov
2018-10-29  6:56 ` [PATCH v5 03/12] box: introduce tuple_field_go_to_path Kirill Shcherbatov
2018-11-19 17:48   ` Vladimir Davydov
2018-10-29  6:56 ` [PATCH v5 04/12] box: introduce tuple_format_add_key_part Kirill Shcherbatov
2018-11-01 14:38   ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:15     ` [tarantool-patches] " Kirill Shcherbatov
2018-11-19 17:50   ` Vladimir Davydov
2018-10-29  6:56 ` [PATCH v5 05/12] lib: implement JSON tree class for json library Kirill Shcherbatov
2018-11-01 15:08   ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:15     ` [tarantool-patches] " Kirill Shcherbatov
2018-11-19 17:53       ` Vladimir Davydov
2018-11-20 16:43   ` Vladimir Davydov
2018-11-21 10:37     ` [tarantool-patches] " Kirill Shcherbatov
2018-11-26 10:50     ` Kirill Shcherbatov
2018-10-29  6:56 ` [PATCH v5 06/12] box: manage format fields with JSON tree class Kirill Shcherbatov
2018-10-29  6:56 ` [PATCH v5 07/12] lib: introduce json_path_normalize routine Kirill Shcherbatov
2018-11-01 15:22   ` [tarantool-patches] " Konstantin Osipov
2018-11-01 15:27     ` [tarantool-patches] " Kirill Shcherbatov
2018-11-20 15:13       ` Vladimir Davydov
2018-11-26 10:50         ` Kirill Shcherbatov
2018-11-20 15:14   ` Vladimir Davydov
2018-10-29  6:56 ` [PATCH v5 08/12] box: introduce JSON indexes Kirill Shcherbatov
2018-11-20 16:52   ` Vladimir Davydov
2018-11-26 10:50     ` [tarantool-patches] " Kirill Shcherbatov
2018-10-29  6:56 ` [tarantool-patches] [PATCH v5 09/12] box: introduce has_json_paths flag in templates Kirill Shcherbatov

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=4f2acb62de31f7ec7efc0246ae98c89b38d0291a.1540795996.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v5 01/12] box: refactor key_def_find routine' \
    /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