[Groonga-mysql-commit] mroonga/mroonga [master] fix a bug that date/time related types can't be used as primary key.

Back to archive index

null+****@clear***** null+****@clear*****
2012年 2月 14日 (火) 19:08:04 JST


Kouhei Sutou	2012-02-14 19:08:04 +0900 (Tue, 14 Feb 2012)

  New Revision: e0e32beb6adadea62a5a1e05079212ebda35c849

  Log:
    fix a bug that date/time related types can't be used as primary key.
    
    We should not set GRN_OBJ_KEY_NORMALIZE no GRN_DB_TEXT family types.

  Added files:
    test/sql/suite/mroonga_storage/r/primary_key_date.result
    test/sql/suite/mroonga_storage/t/primary_key_date.test
  Modified files:
    ha_mroonga.cc

  Modified: ha_mroonga.cc (+15 -8)
===================================================================
--- ha_mroonga.cc    2012-02-14 17:45:26 +0900 (d67be81)
+++ ha_mroonga.cc    2012-02-14 19:08:04 +0900 (ac5edb7)
@@ -6940,15 +6940,22 @@ bool ha_mroonga::is_need_normalize(Field *field) const
              ("mroonga: charset->csname = %s", field->charset()->csname));
   DBUG_PRINT("info",
              ("mroonga: charset->state = %u", field->charset()->state));
-  if (
-    field->result_type() == STRING_RESULT &&
-    !(field->charset()->state & (MY_CS_BINSORT | MY_CS_CSSORT))
-  ) {
-    DBUG_PRINT("info", ("mroonga: TRUE"));
-    DBUG_RETURN(TRUE);
+  bool need_normalize_p = false;
+  if (field->charset()->state & (MY_CS_BINSORT | MY_CS_CSSORT)) {
+    need_normalize_p = false;
+    DBUG_PRINT("info", ("mroonga: is_need_normalize: false: sort is required"));
+  } else {
+    grn_builtin_type grn_type;
+    grn_type = mrn_grn_type_from_field(ctx, field, true);
+    if (GRN_DB_SHORT_TEXT <= grn_type && grn_type <= GRN_DB_LONG_TEXT) {
+      need_normalize_p = true;
+      DBUG_PRINT("info", ("mroonga: is_need_normalize: true: text type"));
+    } else {
+      need_normalize_p = false;
+      DBUG_PRINT("info", ("mroonga: is_need_normalize: false: no text type"));
+    }
   }
-  DBUG_PRINT("info", ("mroonga: FALSE"));
-  DBUG_RETURN(FALSE);
+  DBUG_RETURN(need_normalize_p);
 }
 
 void ha_mroonga::check_count_skip(key_part_map start_key_part_map,

  Added: test/sql/suite/mroonga_storage/r/primary_key_date.result (+28 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/primary_key_date.result    2012-02-14 19:08:04 +0900 (b6ce60e)
@@ -0,0 +1,28 @@
+DROP TABLE IF EXISTS diaries;
+CREATE TABLE diaries (
+day DATE PRIMARY KEY,
+title TEXT
+) DEFAULT CHARSET UTF8;
+SHOW CREATE TABLE diaries;
+Table	Create Table
+diaries	CREATE TABLE `diaries` (
+  `day` date NOT NULL,
+  `title` text,
+  PRIMARY KEY (`day`)
+) ENGINE=mroonga DEFAULT CHARSET=utf8
+INSERT INTO diaries (day, title) VALUES ("2012-01-29", "clear day");
+INSERT INTO diaries (day, title) VALUES ("2012-01-30", "rainy day");
+INSERT INTO diaries (day, title) VALUES ("2012-01-31", "cloudy day");
+INSERT INTO diaries (day, title) VALUES ("2012-01-31", "duplicated day");
+ERROR 23000: Duplicate entry '2012-01-31' for key 'PRIMARY'
+SELECT * FROM diaries;
+day	title
+2012-01-29	clear day
+2012-01-30	rainy day
+2012-01-31	cloudy day
+SELECT * FROM diaries
+WHERE day BETWEEN "2012-01-29" AND "2012-01-30";
+day	title
+2012-01-29	clear day
+2012-01-30	rainy day
+DROP TABLE diaries;

  Added: test/sql/suite/mroonga_storage/t/primary_key_date.test (+42 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/primary_key_date.test    2012-02-14 19:08:04 +0900 (2a181d4)
@@ -0,0 +1,42 @@
+# Copyright(C) 2012 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 include/have_mroonga.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS diaries;
+--enable_warnings
+
+CREATE TABLE diaries (
+  day DATE PRIMARY KEY,
+  title TEXT
+) DEFAULT CHARSET UTF8;
+SHOW CREATE TABLE diaries;
+
+INSERT INTO diaries (day, title) VALUES ("2012-01-29", "clear day");
+INSERT INTO diaries (day, title) VALUES ("2012-01-30", "rainy day");
+INSERT INTO diaries (day, title) VALUES ("2012-01-31", "cloudy day");
+--error 1062
+INSERT INTO diaries (day, title) VALUES ("2012-01-31", "duplicated day");
+
+SELECT * FROM diaries;
+
+SELECT * FROM diaries
+         WHERE day BETWEEN "2012-01-29" AND "2012-01-30";
+
+DROP TABLE diaries;
+
+--source include/have_mroonga_deinit.inc




Groonga-mysql-commit メーリングリストの案内
Back to archive index