diff --git a/src/box/key_def.cc b/src/box/key_def.cc index 0c94c934c2f3628ff0cda9ec61d7230ad4e01548..c74a0ab76141b2297754612dd3d5d2f93e3772c9 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 000f4aa31bdc5ab246895ac5450e35cd3f1afeec..cac72d9737dd7ca2a2c8667c6c7e08b88c893868 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 cac688d499e0a9bd9566cdfb874e21f563a1c8e9..1cfc48d39846237f2788e2f11c7467f92473619d 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()