From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Shcherbatov Subject: [PATCH v1 1/1] vinyl: fix invalid tuple in surrogate delete Date: Tue, 2 Apr 2019 13:59:11 +0300 Message-Id: <18ddbffc8d63755281e4d4a8366adcded58da720.1554202702.git.kshcherbatov@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov List-ID: If the map contains non-string keys that cannot be used in the JSON index, an incorrect tuple is created in vy_stmt_new_surrogate_delete_raw during the construction of the surrogate tuple. This occurs because the number of items that the map contains has already been copied, while such invalid key-value pairs are not copied. The poblem is resolved through the creation of dummy nil:nil pairs in such cases. --- https://github.com/tarantool/tarantool/tree/kshch/surrogate-delete-raw-fixup src/box/vy_stmt.c | 3 +++ test/engine/json.result | 22 ++++++++++++++++++++++ test/engine/json.test.lua | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c index 5d1e10f07..add86622b 100644 --- a/src/box/vy_stmt.c +++ b/src/box/vy_stmt.c @@ -464,6 +464,8 @@ vy_stmt_new_surrogate_delete_raw(struct tuple_format *format, if (mp_typeof(*src_pos) != MP_STR) { mp_next(&src_pos); mp_next(&src_pos); + pos = mp_encode_nil(pos); + pos = mp_encode_nil(pos); continue; } token.type = JSON_TOKEN_STR; @@ -514,6 +516,7 @@ finish: memcpy(stmt_data, data, bsize); memcpy(stmt_field_map_begin, field_map_begin, format->field_map_size); vy_stmt_set_type(stmt, IPROTO_DELETE); + mp_tuple_assert(stmt_data, stmt_data + bsize); out: region_truncate(region, region_svp); return stmt; diff --git a/test/engine/json.result b/test/engine/json.result index a790cdfbc..09c704963 100644 --- a/test/engine/json.result +++ b/test/engine/json.result @@ -683,6 +683,28 @@ town:select() s:drop() --- ... +-- Check replace with tuple with map having numeric keys that +-- cannot be included in JSON index. +s = box.schema.space.create('withdata', {engine='vinyl'}) +--- +... +pk = s:create_index('pk', {parts={{1, 'int'}}}) +--- +... +idx0 = s:create_index('idx0', {parts = {{2, 'str', path = 'name'}, {3, "str"}}}) +--- +... +s:insert({4, {"d", name='D'}, "test"}) +--- +- [4, {1: 'd', 'name': 'D'}, 'test'] +... +s:replace({4, {"d1", name='D1'}, "test"}) +--- +- [4, {1: 'd1', 'name': 'D1'}, 'test'] +... +s:drop() +--- +... -- -- gh-1260: Multikey indexes -- diff --git a/test/engine/json.test.lua b/test/engine/json.test.lua index f9a7180b1..5c235e1ba 100644 --- a/test/engine/json.test.lua +++ b/test/engine/json.test.lua @@ -193,6 +193,15 @@ name:drop() town:select() s:drop() +-- Check replace with tuple with map having numeric keys that +-- cannot be included in JSON index. +s = box.schema.space.create('withdata', {engine='vinyl'}) +pk = s:create_index('pk', {parts={{1, 'int'}}}) +idx0 = s:create_index('idx0', {parts = {{2, 'str', path = 'name'}, {3, "str"}}}) +s:insert({4, {"d", name='D'}, "test"}) +s:replace({4, {"d1", name='D1'}, "test"}) +s:drop() + -- -- gh-1260: Multikey indexes -- -- 2.21.0