null+****@clear*****
null+****@clear*****
2010年 11月 24日 (水) 00:56:05 JST
Kentoku SHIBA 2010-11-23 15:56:05 +0000 (Tue, 23 Nov 2010)
New Revision: 7c6ec608c66e937394f42eda7e3afeed0c7b7631
Log:
#446 インデックスによるrange searchの実装 #702 条件に一致しても最初の1行しか返さない
Modified files:
ha_mroonga.cc
ha_mroonga.h
test/sql/r/order_limit_performance.result
test/sql/r/select_secondary_key.result
test/sql/t/order_limit_performance.test
test/sql/t/select_secondary_key.test
Modified: ha_mroonga.cc (+48 -6)
===================================================================
--- ha_mroonga.cc 2010-11-23 15:14:17 +0000 (39a7d67)
+++ ha_mroonga.cc 2010-11-23 15:56:05 +0000 (76fd6bb)
@@ -762,6 +762,7 @@ ha_mroonga::ha_mroonga(handlerton *hton, TABLE_SHARE *share)
ctx = grn_ctx_open(0);
grn_ctx_use(ctx, mrn_db);
cur = NULL;
+ cur0 = NULL;
res = NULL;
res0 = NULL;
sort_keys = NULL;
@@ -1312,6 +1313,10 @@ int ha_mroonga::rnd_end()
grn_table_cursor_close(ctx, cur);
cur = NULL;
}
+ if (cur0) {
+ grn_table_cursor_close(ctx, cur0);
+ cur0 = NULL;
+ }
DBUG_RETURN(0);
}
@@ -1598,13 +1603,16 @@ ha_rows ha_mroonga::records_in_range(uint keynr, key_range *range_min, key_range
} else { // normal index
uint table_size = grn_table_size(ctx, tbl);
uint cardinality = grn_table_size(ctx, idx_tbl[keynr]);
- grn_table_cursor *cur_t =
+ grn_table_cursor *cur_t0 =
grn_table_cursor_open(ctx, idx_tbl[keynr], val_min, size_min, val_max, size_max, 0, -1, flags);
+ grn_table_cursor *cur_t =
+ grn_index_cursor_open(ctx, cur_t0, idx_col[keynr], 0, GRN_ID_MAX, 0);
grn_id gid;
while ((gid = grn_table_cursor_next(ctx, cur_t)) != GRN_ID_NIL) {
row_count++;
}
grn_table_cursor_close(ctx, cur_t);
+ grn_table_cursor_close(ctx, cur_t0);
row_count = (int) ((double) table_size * ((double) row_count / (double) cardinality));
}
DBUG_RETURN(row_count);
@@ -1625,6 +1633,10 @@ int ha_mroonga::index_end()
grn_table_cursor_close(ctx, cur);
cur = NULL;
}
+ if (cur0) {
+ grn_table_cursor_close(ctx, cur0);
+ cur0 = NULL;
+ }
DBUG_RETURN(0);
}
@@ -1649,6 +1661,10 @@ int ha_mroonga::index_read_map(uchar * buf, const uchar * key,
grn_table_cursor_close(ctx, cur);
cur = NULL;
}
+ if (cur0) {
+ grn_table_cursor_close(ctx, cur0);
+ cur0 = NULL;
+ }
if (find_flag == HA_READ_KEY_EXACT) {
mrn_set_key_buf(ctx, field, key, key_min[keynr], &size_min);
@@ -1698,9 +1714,11 @@ int ha_mroonga::index_read_map(uchar * buf, const uchar * key,
0, -1, flags);
} else { // normal index
DBUG_PRINT("info",("mroonga use key%u", keynr));
- cur =
+ cur0 =
grn_table_cursor_open(ctx, idx_tbl[keynr], val_min, size_min,
val_max, size_max, 0, -1, flags);
+ cur =
+ grn_index_cursor_open(ctx, cur0, idx_col[keynr], 0, GRN_ID_MAX, 0);
}
if (ctx->rc) {
my_message(ER_ERROR_ON_READ, ctx->errbuf, MYF(0));
@@ -1741,6 +1759,10 @@ int ha_mroonga::index_read_last_map(uchar *buf, const uchar *key,
grn_table_cursor_close(ctx, cur);
cur = NULL;
}
+ if (cur0) {
+ grn_table_cursor_close(ctx, cur0);
+ cur0 = NULL;
+ }
mrn_set_key_buf(ctx, field, key, key_min[keynr], &size_min);
val_min = key_min[keynr];
@@ -1756,9 +1778,11 @@ int ha_mroonga::index_read_last_map(uchar *buf, const uchar *key,
0, -1, flags);
} else { // normal index
DBUG_PRINT("info",("mroonga use key%u", keynr));
- cur =
+ cur0 =
grn_table_cursor_open(ctx, idx_tbl[keynr], val_min, size_min,
val_max, size_max, 0, -1, flags);
+ cur =
+ grn_index_cursor_open(ctx, cur0, idx_col[keynr], 0, GRN_ID_MAX, 0);
}
if (ctx->rc) {
my_message(ER_ERROR_ON_READ, ctx->errbuf, MYF(0));
@@ -1831,6 +1855,10 @@ int ha_mroonga::index_first(uchar *buf)
grn_table_cursor_close(ctx, cur);
cur = NULL;
}
+ if (cur0) {
+ grn_table_cursor_close(ctx, cur0);
+ cur0 = NULL;
+ }
uint pkeynr = table->s->primary_key;
if (active_index == pkeynr) { // primary index
DBUG_PRINT("info",("mroonga use primary key"));
@@ -1839,9 +1867,11 @@ int ha_mroonga::index_first(uchar *buf)
0, -1, 0);
} else { // normal index
DBUG_PRINT("info",("mroonga use key%u", active_index));
- cur =
+ cur0 =
grn_table_cursor_open(ctx, idx_tbl[active_index], NULL, 0,
NULL, 0, 0, -1, 0);
+ cur =
+ grn_index_cursor_open(ctx, cur0, idx_col[active_index], 0, GRN_ID_MAX, 0);
}
if (ctx->rc) {
my_message(ER_ERROR_ON_READ, ctx->errbuf, MYF(0));
@@ -1872,6 +1902,10 @@ int ha_mroonga::index_last(uchar *buf)
grn_table_cursor_close(ctx, cur);
cur = NULL;
}
+ if (cur0) {
+ grn_table_cursor_close(ctx, cur0);
+ cur0 = NULL;
+ }
int flags = GRN_CURSOR_DESCENDING;
uint pkeynr = table->s->primary_key;
if (active_index == pkeynr) { // primary index
@@ -1881,9 +1915,11 @@ int ha_mroonga::index_last(uchar *buf)
0, -1, flags);
} else { // normal index
DBUG_PRINT("info",("mroonga use key%u", active_index));
- cur =
+ cur0 =
grn_table_cursor_open(ctx, idx_tbl[active_index], NULL, 0,
NULL, 0, 0, -1, flags);
+ cur =
+ grn_index_cursor_open(ctx, cur0, idx_col[active_index], 0, GRN_ID_MAX, 0);
}
if (ctx->rc) {
my_message(ER_ERROR_ON_READ, ctx->errbuf, MYF(0));
@@ -1953,6 +1989,10 @@ int ha_mroonga::read_range_first(const key_range *start_key,
grn_table_cursor_close(ctx, cur);
cur = NULL;
}
+ if (cur0) {
+ grn_table_cursor_close(ctx, cur0);
+ cur0 = NULL;
+ }
if (start_key != NULL) {
mrn_set_key_buf(ctx, field, start_key->key, key_min[active_index],
@@ -1997,9 +2037,11 @@ int ha_mroonga::read_range_first(const key_range *start_key,
0, -1, flags);
} else { // normal index
DBUG_PRINT("info",("mroonga use key%u", active_index));
- cur =
+ cur0 =
grn_table_cursor_open(ctx, idx_tbl[active_index], val_min, size_min,
val_max, size_max, 0, -1, flags);
+ cur =
+ grn_index_cursor_open(ctx, cur0, idx_col[active_index], 0, GRN_ID_MAX, 0);
}
if (ctx->rc) {
my_message(ER_ERROR_ON_READ, ctx->errbuf, MYF(0));
Modified: ha_mroonga.h (+1 -0)
===================================================================
--- ha_mroonga.h 2010-11-23 15:14:17 +0000 (7e33d73)
+++ ha_mroonga.h 2010-11-23 15:56:05 +0000 (737e3b9)
@@ -80,6 +80,7 @@ class ha_mroonga: public handler
grn_obj *res;
grn_obj *res0;
grn_table_cursor *cur;
+ grn_table_cursor *cur0;
grn_id row_id;
grn_obj *_score;
Modified: test/sql/r/order_limit_performance.result (+0 -3)
===================================================================
--- test/sql/r/order_limit_performance.result 2010-11-23 15:14:17 +0000 (db2c01e)
+++ test/sql/r/order_limit_performance.result 2010-11-23 15:56:05 +0000 (5c3a14c)
@@ -1,5 +1,3 @@
-install plugin groonga soname 'ha_groonga.so';
-set storage_engine=groonga;
drop table if exists t1;
create table t1 (c1 int primary key, c2 int, c3 text, _id int, _score float, key idx1(c2), fulltext index ft(c3));
insert into t1 values(1,10,"aa ii uu ee oo",null,null);
@@ -123,4 +121,3 @@ show status like 'groonga_fast_order_limit';
Variable_name Value
groonga_fast_order_limit 8
drop table t1;
-uninstall plugin groonga;
Modified: test/sql/r/select_secondary_key.result (+14 -1)
===================================================================
--- test/sql/r/select_secondary_key.result 2010-11-23 15:14:17 +0000 (4c7832f)
+++ test/sql/r/select_secondary_key.result 2010-11-23 15:56:05 +0000 (cd435ac)
@@ -1,5 +1,5 @@
drop table if exists t1, t2, t3;
-create table t1 (c1 int primary key, c2 int, c3 text, key idx1(c2), fulltext index ft(c3))engine=groonga;
+create table t1 (c1 int primary key, c2 int, c3 text, key idx1(c2), fulltext index ft(c3));
insert into t1 values(1,10,"aa ii uu ee oo");
insert into t1 values(2,20,"ka ki ku ke ko");
insert into t1 values(3,30,"sa si su se so");
@@ -18,6 +18,19 @@ c1 c2 c3
select * from t1 force index(idx1) where c2 = 20;
c1 c2 c3
2 20 ka ki ku ke ko
+insert into t1 values(6,30,"aa bb cc dd ee");
+select * from t1;
+c1 c2 c3
+1 10 aa ii uu ee oo
+2 20 ka ki ku ke ko
+3 30 sa si su se so
+4 40 ta ti tu te to
+5 50 aa ii uu ee oo
+6 30 aa bb cc dd ee
+select * from t1 force index(idx1) where c2 = 30;
+c1 c2 c3
+3 30 sa si su se so
+6 30 aa bb cc dd ee
drop table t1;
create table t1 (c1 varchar(5) primary key, c2 varchar(5), c3 text, key idx1(c2), fulltext index ft(c3))engine=groonga;
insert into t1 values('ab','ijk',"aa ii uu ee oo");
Modified: test/sql/t/order_limit_performance.test (+2 -6)
===================================================================
--- test/sql/t/order_limit_performance.test 2010-11-23 15:14:17 +0000 (117275b)
+++ test/sql/t/order_limit_performance.test 2010-11-23 15:56:05 +0000 (57cd1c1)
@@ -14,9 +14,9 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+--source suite/groonga/include/groonga.inc
+
--disable_warnings
-install plugin groonga soname 'ha_groonga.so';
-set storage_engine=groonga;
drop table if exists t1;
--enable_warnings
@@ -60,7 +60,3 @@ show status like 'groonga_fast_order_limit';
select c3, _id from t1 where match(c3) against("ii") order by _id limit 1;
show status like 'groonga_fast_order_limit';
drop table t1;
-
---disable_warnings
-uninstall plugin groonga;
---enable_warnings
Modified: test/sql/t/select_secondary_key.test (+49 -44)
===================================================================
--- test/sql/t/select_secondary_key.test 2010-11-23 15:14:17 +0000 (aa6f979)
+++ test/sql/t/select_secondary_key.test 2010-11-23 15:56:05 +0000 (74ec231)
@@ -1,44 +1,49 @@
-# Copyright(C) 2010 Kentoku SHIBA
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
---source suite/groonga/include/groonga.inc
-
---disable_warnings
-drop table if exists t1, t2, t3;
---enable_warnings
-
-create table t1 (c1 int primary key, c2 int, c3 text, key idx1(c2), fulltext index ft(c3))engine=groonga;
-insert into t1 values(1,10,"aa ii uu ee oo");
-insert into t1 values(2,20,"ka ki ku ke ko");
-insert into t1 values(3,30,"sa si su se so");
-insert into t1 values(4,40,"ta ti tu te to");
-insert into t1 values(5,50,"aa ii uu ee oo");
-
-select * from t1;
-select * from t1 force index(idx1) where c2 = 30;
-select * from t1 force index(idx1) where c2 = 20;
-drop table t1;
-
-create table t1 (c1 varchar(5) primary key, c2 varchar(5), c3 text, key idx1(c2), fulltext index ft(c3))engine=groonga;
-insert into t1 values('ab','ijk',"aa ii uu ee oo");
-insert into t1 values('bc','ghi',"ka ki ku ke ko");
-insert into t1 values('cd','efg',"sa si su se so");
-insert into t1 values('de','cde',"ta ti tu te to");
-insert into t1 values('ef','abc',"aa ii uu ee oo");
-select * from t1 force index(idx1) where c2 < 'e';
-select * from t1 force index(idx1) where c2 > 'e';
-select * from t1 force index(idx1) where c2 between 'c' and 'h';
-drop table t1;
+# Copyright(C) 2010 Kentoku SHIBA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+--source suite/groonga/include/groonga.inc
+
+--disable_warnings
+drop table if exists t1, t2, t3;
+--enable_warnings
+
+create table t1 (c1 int primary key, c2 int, c3 text, key idx1(c2), fulltext index ft(c3));
+insert into t1 values(1,10,"aa ii uu ee oo");
+insert into t1 values(2,20,"ka ki ku ke ko");
+insert into t1 values(3,30,"sa si su se so");
+insert into t1 values(4,40,"ta ti tu te to");
+insert into t1 values(5,50,"aa ii uu ee oo");
+
+select * from t1;
+select * from t1 force index(idx1) where c2 = 30;
+select * from t1 force index(idx1) where c2 = 20;
+
+insert into t1 values(6,30,"aa bb cc dd ee");
+select * from t1;
+select * from t1 force index(idx1) where c2 = 30;
+
+drop table t1;
+
+create table t1 (c1 varchar(5) primary key, c2 varchar(5), c3 text, key idx1(c2), fulltext index ft(c3))engine=groonga;
+insert into t1 values('ab','ijk',"aa ii uu ee oo");
+insert into t1 values('bc','ghi',"ka ki ku ke ko");
+insert into t1 values('cd','efg',"sa si su se so");
+insert into t1 values('de','cde',"ta ti tu te to");
+insert into t1 values('ef','abc',"aa ii uu ee oo");
+select * from t1 force index(idx1) where c2 < 'e';
+select * from t1 force index(idx1) where c2 > 'e';
+select * from t1 force index(idx1) where c2 between 'c' and 'h';
+drop table t1;