[tarantool-patches] [PATCH 3/4] sql: disallow creation of index on space without format

Nikita Pettik korablev at tarantool.org
Fri Mar 29 21:24:23 MSK 2019


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





More information about the Tarantool-patches mailing list