From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 9A0D92B522 for ; Fri, 29 Mar 2019 14:24:31 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r-yrSMdZ73_A for ; Fri, 29 Mar 2019 14:24:31 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 554992B515 for ; Fri, 29 Mar 2019 14:24:31 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 3/4] sql: disallow creation of index on space without format Date: Fri, 29 Mar 2019 21:24:23 +0300 Message-Id: <4b28e5463aa0c4d3ee61d94b8db48c8a30f69aef.1553883575.git.korablev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Nikita Pettik 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