Skip to content
Snippets Groups Projects
Commit 512f9d11 authored by Alexandr Lyapunov's avatar Alexandr Lyapunov
Browse files

*) Fixed gh-836 : Restored GE iterator for HASH

*) Additionally added GT iterator
*) Added  test for that
parent ac674aea
No related branches found
No related tags found
No related merge requests found
......@@ -60,7 +60,7 @@ key_validate(struct key_def *key_def, enum iterator_type type, const char *key,
/*
* Zero key parts are allowed:
* - for TREE index, all iterator types,
* - ITERA_ALL iterator type, all index types
* - ITER_ALL iterator type, all index types
* - ITER_GE iterator in HASH index (legacy)
*/
if (key_def->type == TREE || type == ITER_ALL)
......
......@@ -171,7 +171,23 @@ hash_iterator_ge(struct iterator *ptr)
{
assert(ptr->free == hash_iterator_free);
struct hash_iterator *it = (struct hash_iterator *) ptr;
struct tuple **res = light_index_itr_get_and_next(it->hash_table, &it->hitr);
struct tuple **res = light_index_itr_get_and_next(it->hash_table,
&it->hitr);
return res ? *res : 0;
}
struct tuple *
hash_iterator_gt(struct iterator *ptr)
{
assert(ptr->free == hash_iterator_free);
ptr->next = hash_iterator_ge;
struct hash_iterator *it = (struct hash_iterator *) ptr;
struct tuple **res = light_index_itr_get_and_next(it->hash_table,
&it->hitr);
if (!res)
return 0;
res = light_index_itr_get_and_next(it->hash_table,
&it->hitr);
return res ? *res : 0;
}
......@@ -303,7 +319,7 @@ MemtxHash::replace(struct tuple *old_tuple, struct tuple *new_tuple,
if (old_tuple) {
uint32_t h = tuple_hash(old_tuple, key_def);
int res = light_index_delete_value(hash_table, h, old_tuple);
assert(res == 0);
assert(res == 0); (void)res;
}
return old_tuple;
}
......@@ -337,13 +353,33 @@ MemtxHash::initIterator(struct iterator *ptr, enum iterator_type type,
struct hash_iterator *it = (struct hash_iterator *) ptr;
switch (type) {
case ITER_GE:
if (part_count != 0) {
light_index_itr_key(it->hash_table, &it->hitr,
key_hash(key, key_def), key);
} else {
light_index_itr_begin(it->hash_table, &it->hitr);
}
it->base.next = hash_iterator_ge;
break;
case ITER_GT:
if (part_count != 0) {
light_index_itr_key(it->hash_table, &it->hitr,
key_hash(key, key_def), key);
it->base.next = hash_iterator_gt;
} else {
light_index_itr_begin(it->hash_table, &it->hitr);
it->base.next = hash_iterator_ge;
}
break;
case ITER_ALL:
light_index_itr_begin(it->hash_table, &it->hitr);
it->base.next = hash_iterator_ge;
break;
case ITER_EQ:
assert(part_count > 0);
light_index_itr_key(it->hash_table, &it->hitr, key_hash(key, key_def), key);
light_index_itr_key(it->hash_table, &it->hitr,
key_hash(key, key_def), key);
it->base.next = hash_iterator_eq;
break;
default:
......
......@@ -1054,3 +1054,33 @@ space:select({}, {iterator = 'mistake'})
space:drop()
---
...
-------------------------------------------------------------------------------
-- Restore GE iterator for HASH https://github.com/tarantool/tarantool/issues/836
-------------------------------------------------------------------------------
space = box.schema.space.create('test', {temporary=true})
---
...
idx1 = space:create_index('primary', {type='hash',unique=true})
---
...
for i = 0,4 do space:insert{i} end
---
...
space:select(2)
---
- - [2]
...
space:select(2, {iterator="GE"})
---
- - [2]
- [3]
- [4]
...
space:select(2, {iterator="GT"})
---
- - [3]
- [4]
...
space:drop()
---
...
......@@ -229,3 +229,17 @@ space:select({}, {iterator = 'mistake'})
space:drop()
-------------------------------------------------------------------------------
-- Restore GE iterator for HASH https://github.com/tarantool/tarantool/issues/836
-------------------------------------------------------------------------------
space = box.schema.space.create('test', {temporary=true})
idx1 = space:create_index('primary', {type='hash',unique=true})
for i = 0,4 do space:insert{i} end
space:select(2)
space:select(2, {iterator="GE"})
space:select(2, {iterator="GT"})
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