diff --git a/src/box/memtx_index.cc b/src/box/memtx_index.cc index 8c0da8c48deddd1d0a301151af4265bb30406c98..a6170392a74921723081a87ada3d5690866c4106 100644 --- a/src/box/memtx_index.cc +++ b/src/box/memtx_index.cc @@ -75,7 +75,7 @@ size_t MemtxIndex::count(enum iterator_type type, const char *key, uint32_t part_count) const { - if (type == ITER_ALL && key == NULL) + if (type == ITER_ALL) return size(); /* optimization */ struct iterator *it = position(); initIterator(it, type, key, part_count); diff --git a/test/box/misc.result b/test/box/misc.result index b360a5403aaac00761697116d08bbaa01e5b1892..2947862f88c7ccf3810335dbd29efda133e3006f 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -673,3 +673,46 @@ box.space.test:select{} box.space.test:drop() --- ... +-- https://github.com/tarantool/tarantool/issues/1323 +-- index:count() work too long +fiber = require('fiber') +--- +... +s = box.schema.create_space('test') +--- +... +i1 = s:create_index('test', {parts = {1, 'num'}}) +--- +... +for i = 1,10000 do s:insert{i} end +--- +... +count = 0 +--- +... +done = false +--- +... +function test1() for i = 1,100 do count = count + i1:count() end end +--- +... +function test2() for j = 1,100 do test1() fiber.sleep(0) end done = true end +--- +... +fib = fiber.create(test2) +--- +... +for i = 1,10 do if done then break end fiber.sleep(0.1) end +--- +... +done and "count calculated fast enough" or "count is calculating too long" +--- +- count calculated fast enough +... +count +--- +- 100000000 +... +box.space.test:drop() +--- +... diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua index f1ca900b8e0eab3137448860cc3ee2390af27a2a..59313b60958d37622f702c1c5e6a611e7ca7a1e9 100644 --- a/test/box/misc.test.lua +++ b/test/box/misc.test.lua @@ -195,3 +195,18 @@ test_run:cmd("restart server default") box.space.test:select{} box.space.test:drop() +-- https://github.com/tarantool/tarantool/issues/1323 +-- index:count() works too long +fiber = require('fiber') +s = box.schema.create_space('test') +i1 = s:create_index('test', {parts = {1, 'num'}}) +for i = 1,10000 do s:insert{i} end +count = 0 +done = false +function test1() for i = 1,100 do count = count + i1:count() end end +function test2() for j = 1,100 do test1() fiber.sleep(0) end done = true end +fib = fiber.create(test2) +for i = 1,10 do if done then break end fiber.sleep(0.1) end +done and "count calculated fast enough" or "count is calculating too long" +count +box.space.test:drop()