From 152000963ec889934db5a0c1ea9e9a40bce58530 Mon Sep 17 00:00:00 2001
From: Roman Tsisyk <roman@tsisyk.com>
Date: Thu, 30 Apr 2015 15:14:41 +0300
Subject: [PATCH] Review fixes for gh-817-index-count

---
 src/box/lua/index.cc       | 12 ++++++++++++
 src/box/lua/schema.lua     |  6 ++++--
 src/box/schema.cc          |  1 -
 test/big/sql.result        |  4 ++--
 test/box/rtree_misc.result |  4 ++--
 5 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/box/lua/index.cc b/src/box/lua/index.cc
index 6463ccfb6e..fb4c692d52 100644
--- a/src/box/lua/index.cc
+++ b/src/box/lua/index.cc
@@ -106,6 +106,12 @@ boxffi_index_min(uint32_t space_id, uint32_t index_id, const char *key)
 {
 	try {
 		Index *index = check_index(space_id, index_id);
+		if (index->key_def->type != TREE) {
+			/* Show nice error messages in Lua */
+			tnt_raise(ClientError, ER_UNSUPPORTED,
+				  index_type_strs[index->key_def->type],
+				  "min()");
+		}
 		uint32_t part_count = key ? mp_decode_array(&key) : 0;
 		key_validate(index->key_def, ITER_GE, key, part_count);
 		struct tuple *tuple = index->min(key, part_count);
@@ -123,6 +129,12 @@ boxffi_index_max(uint32_t space_id, uint32_t index_id, const char *key)
 {
 	try {
 		Index *index = check_index(space_id, index_id);
+		if (index->key_def->type != TREE) {
+			/* Show nice error messages in Lua */
+			tnt_raise(ClientError, ER_UNSUPPORTED,
+				  index_type_strs[index->key_def->type],
+				  "max()");
+		}
 		uint32_t part_count = key ? mp_decode_array(&key) : 0;
 		key_validate(index->key_def, ITER_LE, key, part_count);
 		struct tuple *tuple = index->max(key, part_count);
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index 2f23994ead..3eff82c775 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -588,8 +588,7 @@ local function space_object_check(space)
 end
 
 local function check_iterator_type(opts, key_is_nil)
-    -- Use ALL for {} and nil keys and EQ for other keys
-    local itype = key_is_nil and box.index.ALL or box.index.EQ
+    local itype
     if opts and opts.iterator then
         if type(opts.iterator) == "number" then
             itype = opts.iterator
@@ -601,6 +600,9 @@ local function check_iterator_type(opts, key_is_nil)
         else
             box.error(box.error.ITERATOR_TYPE, tostring(opts.iterator))
         end
+    else
+        -- Use ALL for {} and nil keys and EQ for other keys
+        itype = key_is_nil and box.index.ALL or box.index.EQ
     end
     return itype
 end
diff --git a/src/box/schema.cc b/src/box/schema.cc
index 139e9ab34c..ed5f072838 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -374,7 +374,6 @@ schema_find_grants(const char *type, uint32_t id)
 	struct iterator *it = index->position();
 	char key[10 + BOX_NAME_MAX];
 	mp_encode_uint(mp_encode_str(key, type, strlen(type)), id);
-			make_scoped_guard([=] { iterator_close(it); });
 	index->initIterator(it, ITER_EQ, key, 2);
 	IteratorGuard it_guard(it);
 	return it->next(it);
diff --git a/test/big/sql.result b/test/big/sql.result
index 5818fd8400..a0d2e7690a 100644
--- a/test/big/sql.result
+++ b/test/big/sql.result
@@ -564,11 +564,11 @@ s.index[1]:select{}
 ...
 s.index[0]:min()
 ---
-- error: Invalid key part count in an exact match (expected 1, got 0)
+- error: HASH does not support min()
 ...
 s.index[0]:max()
 ---
-- error: Invalid key part count in an exact match (expected 1, got 0)
+- error: HASH does not support max()
 ...
 s.index[1]:min()
 ---
diff --git a/test/box/rtree_misc.result b/test/box/rtree_misc.result
index 1c22622488..1cf45eed8e 100644
--- a/test/box/rtree_misc.result
+++ b/test/box/rtree_misc.result
@@ -187,11 +187,11 @@ s.index.spatial:count()
 ...
 s.index.spatial:min()
 ---
-- error: Invalid key part count (expected [0..4], got 0)
+- error: RTREE does not support min()
 ...
 s.index.spatial:max()
 ---
-- error: Invalid key part count (expected [0..4], got 0)
+- error: RTREE does not support max()
 ...
 -- seems that drop can't fail
 s.index.spatial:drop()
-- 
GitLab