[Groonga-mysql-commit] mroonga/mroonga [master] storage: support search ENUM values by index

Back to archive index

null+****@clear***** null+****@clear*****
2012年 4月 18日 (水) 23:53:01 JST


Kouhei Sutou	2012-04-18 23:53:01 +0900 (Wed, 18 Apr 2012)

  New Revision: 18be3420626b235b52db265337ccccca5fbde2d0

  Log:
    storage: support search ENUM values by index
    
    fixes #1336
    
    Suggested by @104yuki_n. Thanks!!!

  Added files:
    test/sql/suite/mroonga_storage/r/column_enum_with_index.result
    test/sql/suite/mroonga_storage/t/column_enum_with_index.test
  Modified files:
    ha_mroonga.cpp
    ha_mroonga.hpp

  Modified: ha_mroonga.cpp (+19 -1)
===================================================================
--- ha_mroonga.cpp    2012-04-17 14:11:39 +0900 (0312afa)
+++ ha_mroonga.cpp    2012-04-18 23:53:01 +0900 (090fe21)
@@ -8719,6 +8719,22 @@ int ha_mroonga::storage_encode_key_time2(Field *field, const uchar *key,
 }
 #endif
 
+int ha_mroonga::storage_encode_key_enum(Field *field, const uchar *key,
+                                        uchar *buf, uint *size)
+{
+  MRN_DBUG_ENTER_METHOD();
+  int error = 0;
+  uint16 value;
+  if (field->pack_length() == 1) {
+    value = static_cast<uint16>(key[0]);
+  } else {
+    shortget(value, key);
+  }
+  memcpy(buf, &value, 2);
+  *size = 2;
+  DBUG_RETURN(error);
+}
+
 int ha_mroonga::storage_encode_key(Field *field, const uchar *key,
                                    uchar *buf, uint *size)
 {
@@ -8736,7 +8752,6 @@ int ha_mroonga::storage_encode_key(Field *field, const uchar *key,
 
   switch (field->real_type()) {
   case MYSQL_TYPE_BIT:
-  case MYSQL_TYPE_ENUM:
   case MYSQL_TYPE_SET:
   case MYSQL_TYPE_TINY:
     {
@@ -8826,6 +8841,9 @@ int ha_mroonga::storage_encode_key(Field *field, const uchar *key,
       *size = len;
       break;
     }
+  case MYSQL_TYPE_ENUM:
+    storage_encode_key_enum(field, ptr, buf, size);
+    break;
   default:
     error = HA_ERR_UNSUPPORTED;
     break;

  Modified: ha_mroonga.hpp (+2 -0)
===================================================================
--- ha_mroonga.hpp    2012-04-17 14:11:39 +0900 (e7b9762)
+++ ha_mroonga.hpp    2012-04-18 23:53:01 +0900 (6243f9b)
@@ -542,6 +542,8 @@ private:
   int storage_encode_key_time2(Field *field, const uchar *key,
                                uchar *buf, uint *size);
 #endif
+  int storage_encode_key_enum(Field *field, const uchar *key,
+                              uchar *buf, uint *size);
   int storage_encode_key(Field *field, const uchar *key, uchar *buf, uint *size);
   void storage_encode_multiple_column_key_float(float value,
                                                 uint data_size,

  Added: test/sql/suite/mroonga_storage/r/column_enum_with_index.result (+28 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/column_enum_with_index.result    2012-04-18 23:53:01 +0900 (73fa304)
@@ -0,0 +1,28 @@
+DROP TABLE IF EXISTS items;
+CREATE TABLE items (
+name VARCHAR(255),
+size ENUM("small", "medium", "large"),
+INDEX (size)
+) ENGINE=mroonga DEFAULT CHARSET=utf8;
+SHOW CREATE TABLE items;
+Table	Create Table
+items	CREATE TABLE `items` (
+  `name` varchar(255) DEFAULT NULL,
+  `size` enum('small','medium','large') DEFAULT NULL,
+  KEY `size` (`size`)
+) ENGINE=mroonga DEFAULT CHARSET=utf8
+INSERT INTO items VALUES ("t-shart for child", "small");
+INSERT INTO items VALUES ("leadies' coat", "medium");
+INSERT INTO items VALUES ("parka", "large");
+INSERT INTO items VALUES ("hat", "medium");
+SELECT * FROM items;
+name	size
+t-shart for child	small
+leadies' coat	medium
+parka	large
+hat	medium
+SELECT * FROM items WHERE size = "medium";
+name	size
+leadies' coat	medium
+hat	medium
+DROP TABLE items;

  Added: test/sql/suite/mroonga_storage/t/column_enum_with_index.test (+41 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/column_enum_with_index.test    2012-04-18 23:53:01 +0900 (90ad79b)
@@ -0,0 +1,41 @@
+# 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 items;
+--enable_warnings
+
+CREATE TABLE items (
+  name VARCHAR(255),
+  size ENUM("small", "medium", "large"),
+  INDEX (size)
+) ENGINE=mroonga DEFAULT CHARSET=utf8;
+SHOW CREATE TABLE items;
+
+INSERT INTO items VALUES ("t-shart for child", "small");
+INSERT INTO items VALUES ("leadies' coat", "medium");
+INSERT INTO items VALUES ("parka", "large");
+INSERT INTO items VALUES ("hat", "medium");
+
+SELECT * FROM items;
+
+SELECT * FROM items WHERE size = "medium";
+
+DROP TABLE items;
+
+--source include/have_mroonga_deinit.inc




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