Skip to content
Snippets Groups Projects
Commit 7503bac2 authored by Ilya Verbin's avatar Ilya Verbin Committed by Vladimir Davydov
Browse files

box: inherit index collation from the space format

If create_index('...', {parts = {...}}) is called without the `collation`
option, then use collation from the space format.

Closes #5104

@TarantoolBot document
Title: Index options are inherited from the space format
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/create_index/

If `is_nullable` and `collation` options are not set, then they are
inherited from the space format, if applicable for that field type.

(cherry picked from commit f2f40ff7)
parent 1d70774c
No related branches found
No related tags found
No related merge requests found
## bugfix/box
* Fixed a bug in `space_object:create_index()` when `collation` option is not
set. Now it is inherited from the space format (gh-5104).
......@@ -1191,6 +1191,9 @@ local function update_index_parts(format, parts)
box.error(box.error.ILLEGAL_PARAMS,
"options.parts[" .. i .. "]: type (string) is expected")
end
if part.collation == nil and fmt then
part.collation = fmt.collation
end
if part.is_nullable == nil then
if fmt and fmt.is_nullable then
part.is_nullable = true
......
local t = require('luatest')
local g = t.group('gh-5104', {{engine = 'memtx'},
{engine = 'vinyl'}})
g.before_all(function(cg)
local server = require('test.luatest_helpers.server')
cg.server = server:new({alias = 'master'})
cg.server:start()
end)
g.after_all(function(cg)
cg.server:stop()
cg.server = nil
end)
-- Check that index collation is inherited from the space format.
g.test_collation = function(cg)
local engine = cg.params.engine
cg.server:exec(function(engine)
local t = require('luatest')
local s = box.schema.space.create('test', {engine = engine})
s:format({{name = 'a', type = 'string', collation = 'unicode_ci'}})
s:create_index('pk', {parts = {{'a', 'string'}}})
s:insert{'ЕЛь'}
t.assert_equals(s.index.pk.parts[1].collation, 'unicode_ci')
t.assert_error_msg_contains('Duplicate key exists in unique index',
s.insert, s, {'ель'})
end, {engine})
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment