Skip to content
Snippets Groups Projects
Commit 366c96a0 authored by Dmitry Simonenko's avatar Dmitry Simonenko
Browse files

fix for #1005: upsert can update primary key

I've added default tuple fields check against primary index key.
Primary key can yet be updated, but an old key will be
silently used anyway (copy used from update object).

Added tests.

ps. maybe it is better to validate upsert ops on execute?
parent a5cc637f
No related branches found
No related tags found
No related merge requests found
......@@ -190,9 +190,21 @@ SophiaSpace::executeUpsert(struct txn *txn, struct space *space,
struct request *request)
{
SophiaIndex *index = (SophiaIndex *)index_find(space, request->index_id);
/* validate upsert key */
const char *key = request->key;
uint32_t part_count = mp_decode_array(&key);
primary_key_validate(index->key_def, key, part_count);
/* validate default tuple */
space_validate_tuple_raw(space, request->tuple);
tuple_field_count_validate(space->format, request->tuple);
int size = request->tuple_end - request->tuple;
key = tuple_field_raw(request->tuple, size,
index->key_def->parts[0].fieldno);
primary_key_validate(index->key_def, key, index->key_def->part_count);
index->upsert(key,
request->ops,
request->ops_end,
......
......@@ -1045,3 +1045,34 @@ t
space:drop()
---
...
-- upsert default tuple constraint
space = box.schema.space.create('test', { engine = 'sophia' })
---
...
index = space:create_index('primary', { type = 'tree', parts = {1, 'num', 2, 'num'} })
---
...
space:upsert({0, 0}, {{'+', 3, 1}}, {0, 'key', 0})
---
- error: 'Supplied key type of part 1 does not match index part type: expected NUM'
...
space:drop()
---
...
-- upsert primary key modify (skipped)
space = box.schema.space.create('test', { engine = 'sophia' })
---
...
index = space:create_index('primary', { type = 'tree', parts = {1, 'num'} })
---
...
space:upsert({0}, {{'+', 1, 1}, {'+', 2, 1}}, {0, 0})
---
...
space:get({0})
---
- [0, 1]
...
space:drop()
---
...
......@@ -54,3 +54,18 @@ t = {}
for key = 1, 100 do table.insert(t, space:get({key, key})) end
t
space:drop()
-- upsert default tuple constraint
space = box.schema.space.create('test', { engine = 'sophia' })
index = space:create_index('primary', { type = 'tree', parts = {1, 'num', 2, 'num'} })
space:upsert({0, 0}, {{'+', 3, 1}}, {0, 'key', 0})
space:drop()
-- upsert primary key modify (skipped)
space = box.schema.space.create('test', { engine = 'sophia' })
index = space:create_index('primary', { type = 'tree', parts = {1, 'num'} })
space:upsert({0}, {{'+', 1, 1}, {'+', 2, 1}}, {0, 0})
space:get({0})
space:drop()
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