Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 5/6] sql: don't add string of 'CREATE INDEX ...' to index opts
Date: Mon, 10 Dec 2018 00:30:25 +0300	[thread overview]
Message-ID: <988bd992af26db529d76e259d2498a7e04f958b1.1544387419.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1544387419.git.korablev@tarantool.org>
In-Reply-To: <cover.1544387419.git.korablev@tarantool.org>

Part of #2647
---
 src/box/sql.c       | 22 +++-------------------
 src/box/sql/build.c | 35 +++--------------------------------
 2 files changed, 6 insertions(+), 51 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index e79265823..45c539ec7 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -744,24 +744,6 @@ sql_rename_table(uint32_t space_id, const char *new_name)
 	return 0;
 }
 
-/**
- * Encode index options @opts into message pack with @stream.
- * @param stream Message Pack Stream to use on encode.
- * @param opts Index options to encode.
- */
-static void
-mpstream_encode_index_opts(struct mpstream *stream,
-			   const struct index_opts *opts)
-{
-	mpstream_encode_map(stream, 2);
-	mpstream_encode_str(stream, "unique");
-	mpstream_encode_bool(stream, opts->is_unique);
-	mpstream_encode_str(stream, "sql");
-	mpstream_encode_strn(stream, opts->sql,
-			     opts->sql != NULL ? strlen(opts->sql) : 0);
-}
-
-
 int
 tarantoolSqlite3IdxKeyCompare(struct BtCursor *cursor,
 			      struct UnpackedRecord *unpacked)
@@ -1214,7 +1196,9 @@ sql_encode_index_opts(struct region *region, const struct index_opts *opts,
 	bool is_error = false;
 	mpstream_init(&stream, region, region_reserve_cb, region_alloc_cb,
 		      set_encode_error, &is_error);
-	mpstream_encode_index_opts(&stream, opts);
+	mpstream_encode_map(&stream, 1);
+	mpstream_encode_str(&stream, "unique");
+	mpstream_encode_bool(&stream, opts->is_unique);;
 	mpstream_flush(&stream);
 	if (is_error) {
 		diag_set(OutOfMemory, stream.pos - stream.buf, "mpstream_flush",
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index fd1666c6d..ab2a56420 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -947,12 +947,6 @@ vdbe_emit_create_index(struct Parse *parse, struct space_def *def,
 			  SQL_SUBTYPE_MSGPACK, index_parts, P4_STATIC);
 	sqlite3VdbeAddOp3(v, OP_MakeRecord, entry_reg, 6, tuple_reg);
 	sqlite3VdbeAddOp3(v, OP_SInsert, BOX_INDEX_ID, 0, tuple_reg);
-	/*
-	 * Non-NULL value means that index has been created via
-	 * separate CREATE INDEX statement.
-	 */
-	if (idx_def->opts.sql != NULL)
-		sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE);
 	save_record(parse, BOX_INDEX_ID, entry_reg, 2, v->nOp - 1);
 	return;
 error:
@@ -2138,12 +2132,11 @@ static int
 index_fill_def(struct Parse *parse, struct index *index,
 	       struct space_def *space_def, uint32_t iid, const char *name,
 	       uint32_t name_len, struct ExprList *expr_list,
-	       enum sql_index_type idx_type, char *sql_stmt)
+	       enum sql_index_type idx_type)
 {
 	struct index_opts opts;
 	index_opts_create(&opts);
 	opts.is_unique = idx_type != SQL_INDEX_TYPE_NON_UNIQUE;
-	opts.sql = sql_stmt;
 	index->def = NULL;
 	int rc = -1;
 
@@ -2400,25 +2393,13 @@ sql_create_index(struct Parse *parse, struct Token *token,
 	 * TODO: Issue a warning if the table primary key is used
 	 * as part of the index key.
 	 */
-	char *sql_stmt = NULL;
-	if (tbl_name != NULL) {
-		int n = (int) (parse->sLastToken.z - token->z) +
-			parse->sLastToken.n;
-		if (token->z[n - 1] == ';')
-			n--;
-		sql_stmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
-			   		  idx_type == SQL_INDEX_TYPE_NON_UNIQUE ?
-					  "" : " UNIQUE", n, token->z);
-		if (sql_stmt == NULL)
-			goto exit_create_index;
-	}
 	uint32_t iid;
 	if (idx_type != SQL_INDEX_TYPE_CONSTRAINT_PK)
 		iid = space->index_id_max + 1;
 	else
 		iid = 0;
 	if (index_fill_def(parse, index, def, iid, name, strlen(name),
-			   col_list, idx_type, sql_stmt) != 0)
+			   col_list, idx_type) != 0)
 		goto exit_create_index;
 	/*
 	 * Remove all redundant columns from the PRIMARY KEY.
@@ -2546,6 +2527,7 @@ sql_create_index(struct Parse *parse, struct Token *token,
 		sqlite3VdbeAddOp1(vdbe, OP_Close, cursor);
 		vdbe_emit_create_index(parse, def, index->def,
 				       def->id, index_id);
+		sqlite3VdbeChangeP5(vdbe, OPFLAG_NCHANGE);
 		sqlite3VdbeAddOp0(vdbe, OP_Expire);
 	}
 
@@ -2598,17 +2580,6 @@ sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_list,
 	}
 	struct index *index = space_index(space, index_id);
 	assert(index != NULL);
-	/*
-	 * If index has been created by user, it has its SQL
-	 * statement. Otherwise (i.e. PK and UNIQUE indexes,
-	 * which are created alongside with table) it is NULL.
-	 */
-	if (index->def->opts.sql == NULL) {
-		sqlite3ErrorMsg(parse_context, "index associated with UNIQUE "
-				"or PRIMARY KEY constraint cannot be dropped",
-				0);
-		goto exit_drop_index;
-	}
 
 	/*
 	 * Generate code to remove entry from _index space
-- 
2.15.1

  parent reply	other threads:[~2018-12-09 21:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-09 21:30 [tarantool-patches] [PATCH 0/6] Remove string of SQL statement from opts Nikita Pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 1/6] sql: avoid calling sql_encode_table_opts() during trigger creation Nikita Pettik
2018-12-10 14:17   ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29     ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 2/6] sql: don't update SQL string during renaming Nikita Pettik
2018-12-10 14:16   ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29     ` n.pettik
2018-12-12 12:36       ` Vladislav Shpilevoy
2018-12-13 12:42         ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 3/6] test: fix sqltester methods to drop all tables/views Nikita Pettik
2018-12-10 14:16   ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29     ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 4/6] sql: don't add string of 'CREATE TABLE...' to space opts Nikita Pettik
2018-12-10 14:17   ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29     ` n.pettik
2018-12-09 21:30 ` Nikita Pettik [this message]
2018-12-10 14:18   ` [tarantool-patches] Re: [PATCH 5/6] sql: don't add string of 'CREATE INDEX ...' to index opts Vladislav Shpilevoy
2018-12-11 18:29     ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 6/6] Remove SQL string from " Nikita Pettik
2018-12-25 13:45 ` [tarantool-patches] Re: [PATCH 0/6] Remove string of SQL statement from opts Kirill Yukhin

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=988bd992af26db529d76e259d2498a7e04f958b1.1544387419.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 5/6] sql: don'\''t add string of '\''CREATE INDEX ...'\'' to index opts' \
    /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