null+****@clear*****
null+****@clear*****
2011年 9月 24日 (土) 01:14:31 JST
Kouhei Sutou 2011-09-23 16:14:31 +0000 (Fri, 23 Sep 2011)
New Revision: 1074f6f3df9eb2d5bfe60db9820ba713aa46f998
Log:
[storage] show warning for unsupported update for multiple column primary key.
fixes #455
Added files:
test/sql/groonga_storage/r/multiple_column_primary_key_update.result
test/sql/groonga_storage/t/multiple_column_primary_key_update.test
Modified files:
ha_mroonga.cc
mrn_sys.h
Modified: ha_mroonga.cc (+31 -2)
===================================================================
--- ha_mroonga.cc 2011-09-23 15:36:41 +0000 (826a9f1)
+++ ha_mroonga.cc 2011-09-23 16:14:31 +0000 (3d15106)
@@ -3463,6 +3463,10 @@ int ha_mroonga::storage_update_row(const uchar *old_data, uchar *new_data)
}
}
+ KEY *pkey_info = NULL;
+ if (table->s->primary_key != MAX_INDEXES) {
+ pkey_info = &(table->key_info[table->s->primary_key]);
+ }
GRN_VOID_INIT(&colbuf);
for (i = 0; i < n_columns; i++) {
Field *field = table->field[i];
@@ -3478,7 +3482,7 @@ int ha_mroonga::storage_update_row(const uchar *old_data, uchar *new_data)
if (strncmp(MRN_COLUMN_NAME_ID, column_name, column_name_size) == 0) {
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
- "data truncated for _id column");
+ "data truncated for _id column");
#ifndef DBUG_OFF
dbug_tmp_restore_column_map(table->read_set, tmp_map);
#endif
@@ -3487,13 +3491,34 @@ int ha_mroonga::storage_update_row(const uchar *old_data, uchar *new_data)
if (strncmp(MRN_COLUMN_NAME_SCORE, column_name, column_name_size) == 0) {
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
- "data truncated for _score column");
+ "data truncated for _score column");
#ifndef DBUG_OFF
dbug_tmp_restore_column_map(table->read_set, tmp_map);
#endif
continue;
}
+ if (pkey_info) {
+ bool have_pkey = false;
+ for (int j = 0; j < pkey_info->key_parts; j++) {
+ Field *pkey_field = pkey_info->key_part[j].field;
+ if (strcmp(pkey_field->field_name, column_name) == 0) {
+ char message[MRN_BUFFER_SIZE];
+ snprintf(message, MRN_BUFFER_SIZE,
+ "data truncated for primary key column: <%s>", column_name);
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
+ message);
+ have_pkey = true;
+ }
+ }
+ if (have_pkey) {
+#ifndef DBUG_OFF
+ dbug_tmp_restore_column_map(table->read_set, tmp_map);
+#endif
+ continue;
+ }
+ }
+
mrn_set_buf(ctx, field, &colbuf, &col_size);
grn_obj_set_value(ctx, grn_columns[i], record_id, &colbuf, GRN_OBJ_SET);
if (ctx->rc) {
@@ -3535,6 +3560,10 @@ int ha_mroonga::storage_update_row_index(const uchar *old_data, uchar *new_data)
uint i;
uint n_keys = table->s->keys;
for (i = 0; i < n_keys; i++) {
+ if (i == table->s->primary_key) {
+ continue;
+ }
+
KEY key_info = table->key_info[i];
if (key_info.key_parts == 1) {
Modified: mrn_sys.h (+1 -0)
===================================================================
--- mrn_sys.h 2011-09-23 15:36:41 +0000 (2f4dad0)
+++ mrn_sys.h 2011-09-23 16:14:31 +0000 (468c867)
@@ -25,6 +25,7 @@
/* constants */
#define MRN_PACKAGE_STRING "groonga-storage-engine"
+#define MRN_BUFFER_SIZE 1024
#define MRN_MAX_KEY_SIZE 1024
#define MRN_MAX_PATH_SIZE 256
#define MRN_MAX_EXPRS 32
Added: test/sql/groonga_storage/r/multiple_column_primary_key_update.result (+32 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/r/multiple_column_primary_key_update.result 2011-09-23 16:14:31 +0000 (8e6b57c)
@@ -0,0 +1,32 @@
+drop table if exists listing;
+set names utf8;
+create table scores (
+name char(30) not null,
+score int not null,
+primary key (name, score)
+) default charset utf8;
+show create table scores;
+Table Create Table
+scores CREATE TABLE `scores` (
+ `name` char(30) NOT NULL,
+ `score` int(11) NOT NULL,
+ PRIMARY KEY (`name`,`score`)
+) ENGINE=groonga DEFAULT CHARSET=utf8
+insert into scores (name, score) values("Taro Yamada", 29);
+insert into scores (name, score) values("Taro Yamada", -12);
+insert into scores (name, score) values("Jiro Yamada", 27);
+insert into scores (name, score) values("Taro Yamada", 10);
+select * from scores;
+name score
+Jiro Yamada 27
+Taro Yamada -12
+Taro Yamada 10
+Taro Yamada 29
+update scores set name = "Taro Yamada" where name = "Jiro Yamada" and score = 27;
+Warnings:
+Warning 1265 data truncated for primary key column: <name>
+select * from scores where name = "Taro Yamada" and (score >= -12 and score < 29);
+name score
+Taro Yamada -12
+Taro Yamada 10
+drop table scores;
Added: test/sql/groonga_storage/t/multiple_column_primary_key_update.test (+39 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/groonga_storage/t/multiple_column_primary_key_update.test 2011-09-23 16:14:31 +0000 (758569a)
@@ -0,0 +1,39 @@
+# Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+#
+# 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_init.inc
+
+--disable_warnings
+drop table if exists listing;
+--enable_warnings
+
+set names utf8;
+create table scores (
+ name char(30) not null,
+ score int not null,
+ primary key (name, score)
+) default charset utf8;
+show create table scores;
+insert into scores (name, score) values("Taro Yamada", 29);
+insert into scores (name, score) values("Taro Yamada", -12);
+insert into scores (name, score) values("Jiro Yamada", 27);
+insert into scores (name, score) values("Taro Yamada", 10);
+select * from scores;
+update scores set name = "Taro Yamada" where name = "Jiro Yamada" and score = 27;
+select * from scores where name = "Taro Yamada" and (score >= -12 and score < 29);
+drop table scores;
+
+--source suite/groonga_include/groonga_deinit.inc