alter: fix modification of primary key definition
If pk_def passed to index_def_new() is not NULL, the function will merge it with the given key_def to create index cmp_def, no matter if the index is primary or secondary. When an index is altered, we call index_def_new() to create the new definition, passing the primary key definition of the altered space for pk_def. If it is the primary index that is altered, we will pass the definition of the old primary index and index_def_new() will happily merge it with the new index definition, resulting in invalid index_def::cmp_def. This doesn't affect memtx, as memtx doesn't use cmp_def for unique indexes, but it does affect vinyl in a peculiar way: tarantool> _ = box.schema.space.create('test', {engine = 'vinyl'}) --- ... tarantool> _ = box.space.test:create_index('pk') --- ... tarantool> _ = box.space.test.index.pk:alter{parts = {2, 'unsigned'}} --- ... tarantool> _ = box.space.test:replace{1, 1} --- ... tarantool> _ = box.space.test:replace{2, 1} --- ... tarantool> box.space.test:select() --- - - [1, 1] - [2, 1] ... (expected: [2, 1]) Fix this by making index_def_new() merge key_def with pk_def only for secondary indexes. Closes #3508
Please register or sign in to comment