From 4c10b711446996c3448a853e909267c016f94159 Mon Sep 17 00:00:00 2001 From: Alexandr Lyapunov <aleks@tarantool.org> Date: Thu, 26 Oct 2017 19:12:59 +0300 Subject: [PATCH] Reject attempts to create non-string index part with collation Collation was simply ignored for non-string parts, that could confuse potential user. Generate a readable error in this case. Fix #2862 part 2 --- src/box/key_def.cc | 8 ++++++++ test/box/misc.result | 26 ++++++++++++++++++++++++++ test/box/misc.test.lua | 7 +++++++ 3 files changed, 41 insertions(+) diff --git a/src/box/key_def.cc b/src/box/key_def.cc index 0c94c934c2..c74a0ab761 100644 --- a/src/box/key_def.cc +++ b/src/box/key_def.cc @@ -394,6 +394,14 @@ key_def_decode_parts(struct key_def *key_def, const char **data, } struct coll *coll = NULL; if (part.coll_id != UINT32_MAX) { + if (part.type != FIELD_TYPE_STRING && + part.type != FIELD_TYPE_SCALAR) { + diag_set(ClientError, ER_WRONG_INDEX_OPTIONS, + i + 1, + "collation is reasonable only for " + "string and scalar parts"); + return -1; + } coll = coll_cache_find(part.coll_id); if (coll == NULL) { diag_set(ClientError, ER_WRONG_INDEX_OPTIONS, diff --git a/test/box/misc.result b/test/box/misc.result index 000f4aa31b..cac72d9737 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -1070,3 +1070,29 @@ s:select{'еж'} s:drop() --- ... +s = box.schema.space.create('test') +--- +... +not not s:create_index('test1', {parts = {{1, 'number', collation = 'unicode_s1'}}}) +--- +- error: 'Wrong index options (field 1): collation is reasonable only for string and + scalar parts' +... +not not s:create_index('test2', {parts = {{2, 'unsigned', collation = 'unicode_s1'}}}) +--- +- error: 'Wrong index options (field 1): collation is reasonable only for string and + scalar parts' +... +not not s:create_index('test3', {parts = {{3, 'integer', collation = 'unicode_s1'}}}) +--- +- error: 'Wrong index options (field 1): collation is reasonable only for string and + scalar parts' +... +not not s:create_index('test4', {parts = {{4, 'boolean', collation = 'unicode_s1'}}}) +--- +- error: 'Wrong index options (field 1): collation is reasonable only for string and + scalar parts' +... +s:drop() +--- +... diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua index cac688d499..1cfc48d398 100644 --- a/test/box/misc.test.lua +++ b/test/box/misc.test.lua @@ -290,3 +290,10 @@ s:replace{'drop'} s:replace{'table'} s:replace{'users'} s:select{} s:select{'еж'} s:drop() + +s = box.schema.space.create('test') +not not s:create_index('test1', {parts = {{1, 'number', collation = 'unicode_s1'}}}) +not not s:create_index('test2', {parts = {{2, 'unsigned', collation = 'unicode_s1'}}}) +not not s:create_index('test3', {parts = {{3, 'integer', collation = 'unicode_s1'}}}) +not not s:create_index('test4', {parts = {{4, 'boolean', collation = 'unicode_s1'}}}) +s:drop() -- GitLab