null+****@clear*****
null+****@clear*****
2010年 11月 21日 (日) 11:23:27 JST
Tetsuro IKEDA 2010-11-21 02:23:27 +0000 (Sun, 21 Nov 2010)
New Revision: ef7a71b346fd3c444d5366b261665d36081e78fb
Log:
added _id support w/hash index for UPDATE and DELETE.
Modified files:
ha_mroonga.cc
test/sql/r/delete.result
test/sql/r/update.result
test/sql/t/delete.test
test/sql/t/update.test
Modified: ha_mroonga.cc (+37 -10)
===================================================================
--- ha_mroonga.cc 2010-11-21 00:53:41 +0000 (25595bc)
+++ ha_mroonga.cc 2010-11-21 02:23:27 +0000 (e06ad88)
@@ -1413,16 +1413,17 @@ int ha_mroonga::update_row(const uchar *old_data, uchar *new_data)
const char *col_name = field->field_name;
int col_name_size = strlen(col_name);
- if (field->is_null()) continue;
-
- if (strncmp(MRN_ID_COL_NAME, col_name, col_name_size) == 0) {
- my_message(ER_DATA_TOO_LONG, "cannot update value to _id column", MYF(0));
- DBUG_RETURN(ER_DATA_TOO_LONG);
- }
- if (strncmp(MRN_SCORE_COL_NAME, col_name, col_name_size) == 0) {
- my_message(ER_DATA_TOO_LONG, "cannot update value to _score column", MYF(0));
- DBUG_RETURN(ER_DATA_TOO_LONG);
- }
+ if (bitmap_is_set(table->write_set, field->field_index)) {
+ if (field->is_null()) continue;
+ if (strncmp(MRN_ID_COL_NAME, col_name, col_name_size) == 0) {
+ my_message(ER_DATA_TOO_LONG, "cannot update value to _id column", MYF(0));
+ DBUG_RETURN(ER_DATA_TOO_LONG);
+ }
+ if (strncmp(MRN_SCORE_COL_NAME, col_name, col_name_size) == 0) {
+ my_message(ER_DATA_TOO_LONG, "cannot update value to _score column", MYF(0));
+ DBUG_RETURN(ER_DATA_TOO_LONG);
+ }
+ }
}
}
@@ -1596,6 +1597,7 @@ int ha_mroonga::index_read_map(uchar * buf, const uchar * key,
store_fields_from_primary_table(buf, rid);
table->status = 0;
cur = NULL;
+ row_id = rid;
DBUG_RETURN(0);
} else {
table->status = STATUS_NOT_FOUND;
@@ -1878,6 +1880,8 @@ int ha_mroonga::read_range_first(const key_range *start_key,
KEY key_info = table->s->key_info[active_index];
KEY_PART_INFO key_part = key_info.key_part[0];
Field *field = key_part.field;
+ const char *col_name = field->field_name;
+ int col_name_size = strlen(col_name);
if (cur) {
grn_table_cursor_close(ctx, cur);
@@ -1890,6 +1894,24 @@ int ha_mroonga::read_range_first(const key_range *start_key,
val_min = key_min[active_index];
if (start_key->flag == HA_READ_AFTER_KEY) {
flags |= GRN_CURSOR_GT;
+ } else if (start_key->flag == HA_READ_KEY_EXACT) {
+ // for _id
+ if (strncmp(MRN_ID_COL_NAME, col_name, col_name_size) == 0) {
+ grn_id rid = *(grn_id*) key_min[active_index];
+ if (grn_table_at(ctx, tbl, rid) != GRN_ID_NIL) { // found
+ store_fields_from_primary_table(table->record[0], rid);
+ table->status = 0;
+ cur = NULL;
+ row_id = rid;
+ DBUG_RETURN(0);
+ } else {
+ table->status = STATUS_NOT_FOUND;
+ cur = NULL;
+ row_id = GRN_ID_NIL;
+ DBUG_RETURN(HA_ERR_END_OF_FILE);
+ }
+ }
+
}
}
if (end_key != NULL) {
@@ -1937,6 +1959,11 @@ int ha_mroonga::read_range_first(const key_range *start_key,
int ha_mroonga::read_range_next() {
DBUG_ENTER("ha_mroonga::read_range_next");
+
+ if (cur == NULL) {
+ DBUG_RETURN(HA_ERR_END_OF_FILE);
+ }
+
row_id = grn_table_cursor_next(ctx, cur);
if (ctx->rc) {
my_message(ER_ERROR_ON_READ, ctx->errbuf, MYF(0));
Modified: test/sql/r/delete.result (+36 -0)
===================================================================
--- test/sql/r/delete.result 2010-11-21 00:53:41 +0000 (5a74d2c)
+++ test/sql/r/delete.result 2010-11-21 02:23:27 +0000 (e3092d6)
@@ -52,3 +52,39 @@ c1 c2
select * from t1 where match(c2) against("ki");
c1 c2
drop table t1;
+create table t1 (_id int, c1 int, unique key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+_id c1
+1 100
+2 100
+3 100
+4 100
+delete from t1 where _id = 2;
+select * from t1;
+_id c1
+1 100
+3 100
+4 100
+drop table t1;
+create table t1 (_id int, c1 int, key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+_id c1
+1 100
+2 100
+3 100
+4 100
+delete from t1 where _id = 2;
+select * from t1;
+_id c1
+1 100
+3 100
+4 100
+drop table t1;
Modified: test/sql/r/update.result (+38 -0)
===================================================================
--- test/sql/r/update.result 2010-11-21 00:53:41 +0000 (541a8f3)
+++ test/sql/r/update.result 2010-11-21 02:23:27 +0000 (7472cfb)
@@ -99,3 +99,41 @@ c1 _id _score
2 2 0
3 3 0
drop table t1;
+create table t1 (_id int, c1 int, unique key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+_id c1
+1 100
+2 100
+3 100
+4 100
+update t1 set c1 = 200 where _id = 2;
+select * from t1;
+_id c1
+1 100
+2 200
+3 100
+4 100
+drop table t1;
+create table t1 (_id int, c1 int, key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+_id c1
+1 100
+2 100
+3 100
+4 100
+update t1 set c1 = 200 where _id = 2;
+select * from t1;
+_id c1
+1 100
+2 200
+3 100
+4 100
+drop table t1;
Modified: test/sql/t/delete.test (+21 -0)
===================================================================
--- test/sql/t/delete.test 2010-11-21 00:53:41 +0000 (0b5ff47)
+++ test/sql/t/delete.test 2010-11-21 02:23:27 +0000 (9fce4b4)
@@ -53,3 +53,24 @@ select * from t1;
select * from t1 where match(c2) against("ki");
drop table t1;
+
+# _id and hash index
+create table t1 (_id int, c1 int, unique key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+delete from t1 where _id = 2;
+select * from t1;
+drop table t1;
+
+create table t1 (_id int, c1 int, key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+delete from t1 where _id = 2;
+select * from t1;
+drop table t1;
Modified: test/sql/t/update.test (+21 -0)
===================================================================
--- test/sql/t/update.test 2010-11-21 00:53:41 +0000 (dc87b89)
+++ test/sql/t/update.test 2010-11-21 02:23:27 +0000 (f676950)
@@ -77,3 +77,24 @@ update t1 set _score = 22 where c1 = 2;
update t1 set _id = 11, _score = 22 where c1 = 3;
select * from t1;
drop table t1;
+
+# _id and hash index
+create table t1 (_id int, c1 int, unique key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+update t1 set c1 = 200 where _id = 2;
+select * from t1;
+drop table t1;
+
+create table t1 (_id int, c1 int, key (_id) using hash);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+insert into t1 values(null, 100);
+select * from t1;
+update t1 set c1 = 200 where _id = 2;
+select * from t1;
+drop table t1;