Skip to content
Snippets Groups Projects
Commit a07b6e21 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Add tests for multipart HASH indexes.

Derive some tests for multipart HASH indexes
from the original implementation by A. Demakov
before dropping the branch.
parent e9b4c19a
No related branches found
No related tags found
No related merge requests found
insert into t27 values (0, 'foo', 0, '', 1)
Insert OK, 1 row affected
insert into t27 values (0, 'foo', 1, '', 1)
Insert OK, 1 row affected
insert into t27 values (1, 'foo', 0, '', 2)
Insert OK, 1 row affected
insert into t27 values (1, 'foo', 1, '', 2)
Insert OK, 1 row affected
insert into t27 values (0, 'bar', 0, '', 3)
Insert OK, 1 row affected
insert into t27 values (0, 'bar', 1, '', 3)
Insert OK, 1 row affected
insert into t27 values (1, 'bar', 0, '', 4)
Insert OK, 1 row affected
insert into t27 values (1, 'bar', 1, '', 4)
Insert OK, 1 row affected
insert into t27 values (1, 'bar', 1, '', 5)
An error occurred: ER_TUPLE_FOUND, 'Duplicate key exists in unique index 0'
lua function box.select_all(space) space = tonumber(space) local result = {} for k, v in box.space[space]:pairs() do table.insert(result, v) end return unpack(result) end
---
...
call box.select_all('27')
Found 8 tuples:
[0, 'bar', 0, '', 3]
[0, 'bar', 1, '', 3]
[0, 'foo', 0, '', 1]
[0, 'foo', 1, '', 1]
[1, 'bar', 0, '', 4]
[1, 'bar', 1, '', 4]
[1, 'foo', 0, '', 2]
[1, 'foo', 1, '', 2]
lua box.select(27, 0, 1, 'foo', 0)
---
- 1: {'foo', 0, '', 2}
...
lua box.select(27, 0, 1, 'bar', 0)
---
- 1: {'bar', 0, '', 4}
...
lua box.select(27, 0, 1, 'foo')
---
error: 'Invalid key part count in an exact match (expected 3, got 2)'
...
lua box.select(27, 0, 1, 'foo', 0, 0)
---
error: 'Invalid key part count (expected [0..3], got 4)'
...
lua box.select(27, 0, 1, 'foo', 'baz')
---
error: 'Supplied key field type does not match index type: expected u32'
...
lua box.select(27, 1, 1, 4)
---
- 1: {'bar', 1, '', 4}
...
lua box.select(27, 1, 1, 5)
---
...
lua box.select(27, 1, 1)
---
error: 'Invalid key part count in an exact match (expected 2, got 1)'
...
lua box.select(27, 1, 1, 'baz')
---
error: 'Supplied key field type does not match index type: expected u32'
...
lua box.space[27]:truncate()
---
...
lua box.space[27]:len()
---
- 0
...
# encoding: tarantool
#
# insert rows
exec sql "insert into t27 values (0, 'foo', 0, '', 1)"
exec sql "insert into t27 values (0, 'foo', 1, '', 1)"
exec sql "insert into t27 values (1, 'foo', 0, '', 2)"
exec sql "insert into t27 values (1, 'foo', 1, '', 2)"
exec sql "insert into t27 values (0, 'bar', 0, '', 3)"
exec sql "insert into t27 values (0, 'bar', 1, '', 3)"
exec sql "insert into t27 values (1, 'bar', 0, '', 4)"
exec sql "insert into t27 values (1, 'bar', 1, '', 4)"
# try to insert a row with a duplicate key
exec sql "insert into t27 values (1, 'bar', 1, '', 5)"
# output all rows
lua_code = """
function box.select_all(space)
space = tonumber(space)
local result = {}
for k, v in box.space[space]:pairs() do
table.insert(result, v)
end
return unpack(result)
end
"""
exec admin "lua " + lua_code.replace('\n', ' ')
sql.sort = True
exec sql "call box.select_all('27')"
sql.sort = False
# primary index select
exec admin "lua box.select(27, 0, 1, 'foo', 0)"
exec admin "lua box.select(27, 0, 1, 'bar', 0)"
# primary index slect with missing part
exec admin "lua box.select(27, 0, 1, 'foo')"
# primary index slect with extra part
exec admin "lua box.select(27, 0, 1, 'foo', 0, 0)"
# primary index select with wrong type
exec admin "lua box.select(27, 0, 1, 'foo', 'baz')"
# secondary index select
exec admin "lua box.select(27, 1, 1, 4)"
# secondary index select with no such key
exec admin "lua box.select(27, 1, 1, 5)"
# secondary index select with missing part
exec admin "lua box.select(27, 1, 1)"
# secondary index select with wrong type
exec admin "lua box.select(27, 1, 1, 'baz')"
# cleanup
exec admin "lua box.space[27]:truncate()"
exec admin "lua box.space[27]:len()"
......@@ -375,3 +375,22 @@ space[26].index[1].type = "HASH"
space[26].index[1].unique = true
space[26].index[1].key_field[0].fieldno = 0
space[26].index[1].key_field[0].type = "NUM"
# Multi-part hash
space[27].enabled = 1
space[27].index[0].type = HASH
space[27].index[0].unique = 1
space[27].index[0].key_field[0].fieldno = 0
space[27].index[0].key_field[0].type = NUM
space[27].index[0].key_field[1].fieldno = 1
space[27].index[0].key_field[1].type = STR
space[27].index[0].key_field[2].fieldno = 2
space[27].index[0].key_field[2].type = NUM
space[27].index[1].type = HASH
space[27].index[1].unique = 1
space[27].index[1].key_field[0].fieldno = 2
space[27].index[1].key_field[0].type = NUM
space[27].index[1].key_field[1].fieldno = 4
space[27].index[1].key_field[1].type = NUM
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