From a07b6e21b7bebdf14b56531b6af8d069e8ed090a Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Thu, 27 Jun 2013 16:51:25 +0400 Subject: [PATCH] Add tests for multipart HASH indexes. Derive some tests for multipart HASH indexes from the original implementation by A. Demakov before dropping the branch. --- test/big/hash_multipart.result | 73 ++++++++++++++++++++++++++++++++++ test/big/hash_multipart.test | 53 ++++++++++++++++++++++++ test/big/tarantool.cfg | 19 +++++++++ 3 files changed, 145 insertions(+) create mode 100644 test/big/hash_multipart.result create mode 100644 test/big/hash_multipart.test diff --git a/test/big/hash_multipart.result b/test/big/hash_multipart.result new file mode 100644 index 0000000000..9c2a07d05c --- /dev/null +++ b/test/big/hash_multipart.result @@ -0,0 +1,73 @@ +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 +... diff --git a/test/big/hash_multipart.test b/test/big/hash_multipart.test new file mode 100644 index 0000000000..8d4f7347a5 --- /dev/null +++ b/test/big/hash_multipart.test @@ -0,0 +1,53 @@ +# 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()" diff --git a/test/big/tarantool.cfg b/test/big/tarantool.cfg index 73973d4782..58def14511 100644 --- a/test/big/tarantool.cfg +++ b/test/big/tarantool.cfg @@ -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 -- GitLab