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 3/4] sql: disallow creation of index on space without format
Date: Fri, 29 Mar 2019 21:24:23 +0300	[thread overview]
Message-ID: <4b28e5463aa0c4d3ee61d94b8db48c8a30f69aef.1553883575.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1553883575.git.korablev@tarantool.org>
In-Reply-To: <cover.1553883575.git.korablev@tarantool.org>

During index creation from SQL we should resolve columns names, which in
turn impossible for spaces without format. Now it leads to crash. Let's
fix it by raising corresponding diag error.
---
 src/box/sql/build.c              | 16 ++++++++++++++++
 src/box/sql/delete.c             |  4 +---
 src/box/sql/sqlInt.h             | 12 ++++++++++++
 test/sql-tap/lua-tables.test.lua | 17 ++++++++++++++++-
 4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 5b1e933c7..73ce5b7bf 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -1996,6 +1996,18 @@ table_add_index(struct space *space, struct index *index)
 	space->index_id_max =  MAX(space->index_id_max, index->def->iid);;
 }
 
+int
+sql_space_def_check_format(const struct space_def *space_def)
+{
+	assert(space_def != NULL);
+	if (space_def->field_count == 0) {
+		diag_set(ClientError, ER_UNSUPPORTED, "SQL",
+			 "space without format");
+		return -1;
+	}
+	return 0;
+}
+
 /**
  * Create and set index_def in the given Index.
  *
@@ -2160,6 +2172,10 @@ sql_create_index(struct Parse *parse, struct Token *token,
 		parse->is_aborted = true;
 		goto exit_create_index;
 	}
+	if (sql_space_def_check_format(def) != 0) {
+		parse->is_aborted = true;
+		goto exit_create_index;
+	}
 	/*
 	 * Find the name of the index.  Make sure there is not
 	 * already another index with the same name.
diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index 5a3d7cfad..8d6e848bb 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -47,9 +47,7 @@ sql_lookup_space(struct Parse *parse, struct SrcList_item *space_name)
 		return NULL;
 	}
 	assert(space != NULL);
-	if (space->def->field_count == 0) {
-		diag_set(ClientError, ER_UNSUPPORTED, "SQL",
-			 "space without format");
+	if (sql_space_def_check_format(space->def) != 0) {
 		parse->is_aborted = true;
 		return NULL;
 	}
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 72bd4ee0f..22d21f74b 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -4401,6 +4401,18 @@ void
 sql_drop_foreign_key(struct Parse *parse_context, struct SrcList *table,
 		     struct Token *constraint);
 
+/**
+ * Now our SQL implementation can't operate on spaces which
+ * lack format: it is reasonable since for instance we can't
+ * resolve column names, their types etc. In case of format
+ * absence, diag error is raised.
+ *
+ * @retval 0 in case space features format.
+ * @retval -1 if space doesn't have format.
+ */
+int
+sql_space_def_check_format(const struct space_def *space_def);
+
 /**
  * Counts the trail bytes for a UTF-8 lead byte of a valid UTF-8
  * sequence.
diff --git a/test/sql-tap/lua-tables.test.lua b/test/sql-tap/lua-tables.test.lua
index aa10c7066..7ba1d7ac5 100755
--- a/test/sql-tap/lua-tables.test.lua
+++ b/test/sql-tap/lua-tables.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(12)
+test:plan(14)
 
 test:do_test(
     "lua-tables-prepare-1",
@@ -160,4 +160,19 @@ test:do_eqp_test(
         {0, 0, 0, 'SEARCH TABLE TEST USING COVERING INDEX secondary (A=?)'}
     })
 
+-- Make sure that without format it is impossible to create
+-- an index: format is required to resolve column names.
+test:do_test(
+    "no-format-create-index-prep",
+    function()
+        s = box.schema.create_space('T')
+    end, {})
+
+test:do_catchsql_test(
+    "no-format-create-index",
+    [[
+        CREATE INDEX i1 ON t(id);
+    ]],
+        {1, "SQL does not support space without format"})
+
 test:finish_test()
-- 
2.15.1

  parent reply	other threads:[~2019-03-29 18:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-29 18:24 [tarantool-patches] [PATCH 0/4] Fixes in SQL involving no-pk or no-format spaces Nikita Pettik
2019-03-29 18:24 ` [tarantool-patches] [PATCH 1/4] Drop foreign keys before indexes in space:drop() Nikita Pettik
2019-03-29 18:24 ` [tarantool-patches] [PATCH 2/4] Fix creation of FK constraint in case of no child's PK Nikita Pettik
2019-04-01 13:41   ` [tarantool-patches] " Vladislav Shpilevoy
2019-03-29 18:24 ` Nikita Pettik [this message]
2019-03-29 18:24 ` [tarantool-patches] [PATCH 4/4] sql: disallow creation of FK referencing space without PK Nikita Pettik

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=4b28e5463aa0c4d3ee61d94b8db48c8a30f69aef.1553883575.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 3/4] sql: disallow creation of index on space without format' \
    /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