Skip to content

Instantly share code, notes, and snippets.

@y-ken
Last active December 16, 2015 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-ken/5506785 to your computer and use it in GitHub Desktop.
Save y-ken/5506785 to your computer and use it in GitHub Desktop.
mroonga-3.03では、FULLTEXT INDEXに対するノーマライザーの指定がCOMMENTを用いて出来るようになりました。 しかし、インデックスコメント以外にも作用している挙動が見受けられます。 https://github.com/mroonga/mroonga/commit/7165b02b8e2bbab12995e3710c68d994f9308442#ha_mroonga.cpp

mysql-mroonga-3.02 での挙動

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 359
Server version: 5.6.10-log MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> CREATE TABLE hoge_table (
    ->   id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'PK',
    ->   contents TEXT COMMENT 'contents',
    ->   FULLTEXT INDEX (contents)
    -> ) ENGINE = mroonga DEFAULT CHARSET utf8;
Query OK, 0 rows affected, 1 warning (0.23 sec)

mysql> CREATE TABLE hoge_table2 (
    ->   id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'PK',
    ->   contents TEXT COMMENT 'コンテンツ',
    ->   FULLTEXT INDEX (contents)
    -> ) ENGINE = mroonga DEFAULT CHARSET utf8;
Query OK, 0 rows affected, 1 warning (0.19 sec)

mysql> CREATE TABLE hoge_table3 (
    ->   id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'プライマリキー',
    ->   contents TEXT COMMENT 'コンテンツ',
    ->   FULLTEXT INDEX (contents)
    -> ) ENGINE = mroonga DEFAULT CHARSET utf8;
Query OK, 0 rows affected, 1 warning (0.18 sec)

mysql> show warnings \G
*************************** 1. row ***************************
  Level: Warning
   Code: 138
Message: NormalizerMySQLGeneralCI normalizer isn't found for utf8_general_ci. Install groonga-normalizer-mysql normalizer. NormalizerAuto is used as fallback.
1 row in set (0.00 sec)

mysql> CREATE TABLE hoge_table4 (
    ->    id INT PRIMARY KEY AUTO_INCREMENT,
    ->    contents TEXT,
    ->    FULLTEXT INDEX (contents)
    ->  ) ENGINE = mroonga DEFAULT CHARSET utf8;
Query OK, 0 rows affected, 1 warning (0.21 sec)

mysql> show warnings \G
*************************** 1. row ***************************
  Level: Warning
   Code: 138
Message: NormalizerMySQLGeneralCI normalizer isn't found for utf8_general_ci. Install groonga-normalizer-mysql normalizer. NormalizerAuto is used as fallback.
1 row in set (0.00 sec)

※ groonga-normalizer-mysqlを入れていません

mysql-mroonga-3.03 での挙動

COMMENTを含むとThe table parameter '***' is invalid`というエラーが発生します。 parser指定以外の場合には、無視するようにして頂きたいです。

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.6.11-log MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> CREATE TABLE hoge_table (
    ->   id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'PK',
    ->   contents TEXT COMMENT 'contents',
    ->   FULLTEXT INDEX (contents)
    -> ) ENGINE = mroonga DEFAULT CHARSET utf8;
ERROR 16501 (HY000): The table parameter 'PK' is invalid

mysql> CREATE TABLE hoge_table2 (
    ->   id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'PK',
    ->   contents TEXT COMMENT 'コンテンツ',
    ->   FULLTEXT INDEX (contents)
    -> ) ENGINE = mroonga DEFAULT CHARSET utf8;
ERROR 16501 (HY000): The table parameter 'コンテンツ' is invalid

mysql> CREATE TABLE hoge_table3 (
    ->   id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'プライマリキー',
    ->   contents TEXT COMMENT 'コンテンツ',
    ->   FULLTEXT INDEX (contents)
    -> ) ENGINE = mroonga DEFAULT CHARSET utf8;
ERROR 16501 (HY000): The table parameter 'プライマリキー' is invalid

mysql> CREATE TABLE hoge_table4 (
    ->    id INT PRIMARY KEY AUTO_INCREMENT,
    ->    contents TEXT,
    ->    FULLTEXT INDEX (contents)
    ->  ) ENGINE = mroonga DEFAULT CHARSET utf8;
Query OK, 0 rows affected (0.01 sec)

また、ALTER TABLE構文でCOMMENTを付与するとテーブルが壊れます。

mysql> CREATE TABLE table_with_comment (
    ->    id INT PRIMARY KEY AUTO_INCREMENT,
    ->    contents TEXT ,
    ->    FULLTEXT INDEX (contents)
    ->  ) ENGINE = mroonga DEFAULT CHARSET utf8;
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER TABLE table_with_comment CHANGE contents contents TEXT COMMENT 'foo';
ERROR 16501 (HY000): The table parameter 'foo' is invalid

mysql> show table status \G
*************************** 1. row ***************************
           Name: table_with_comment
         Engine: NULL
        Version: NULL
     Row_format: NULL
           Rows: NULL
 Avg_row_length: NULL
    Data_length: NULL
Max_data_length: NULL
   Index_length: NULL
      Data_free: NULL
 Auto_increment: NULL
    Create_time: NULL
    Update_time: NULL
     Check_time: NULL
      Collation: NULL
       Checksum: NULL
 Create_options: NULL
        Comment: The table parameter 'foo' is invalid
1 row in set, 1 warning (0.00 sec)

mysql> show create table table_with_comment;
ERROR 16501 (HY000): The table parameter 'foo' is invalid

mysql> drop table table_with_comment;
ERROR 16501 (HY000): The table parameter 'foo' is invalid

InnoDB Wrapperモードの場合には、ALTER TABLE構文でCOMMENTを付与するとテーブルが壊れるだけでなく、
手動削除後に同じ名前のテーブルが作成できなくなります。(ibdabta1に管理データがあるため)

mysql> CREATE TABLE table_with_comment_innodb (
    ->   id INT PRIMARY KEY AUTO_INCREMENT,
    ->   contents TEXT ,
    ->   FULLTEXT INDEX (contents)
    -> ) ENGINE = mroonga DEFAULT CHARSET utf8 COMMENT = 'engine "innodb"' ;
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER TABLE table_with_comment_innodb CHANGE contents contents TEXT COMMENT 'foo';
ERROR 16501 (HY000): The table parameter 'foo' is invalid

mysql> show table status \G
*************************** 1. row ***************************
           Name: table_with_comment_innodb
         Engine: NULL
        Version: NULL
     Row_format: NULL
           Rows: NULL
 Avg_row_length: NULL
    Data_length: NULL
Max_data_length: NULL
   Index_length: NULL
      Data_free: NULL
 Auto_increment: NULL
    Create_time: NULL
    Update_time: NULL
     Check_time: NULL
      Collation: NULL
       Checksum: NULL
 Create_options: NULL
        Comment: The table parameter 'foo' is invalid
1 row in set, 1 warning (0.00 sec)

mysql> show table status \G
Empty set (0.00 sec)
$ sudo rm /var/lib/mysql/test/table_with_comment_innodb.*
rm: remove regular file `/var/lib/mysql/test/table_with_comment_innodb.frm'? y
rm: remove regular file `/var/lib/mysql/test/table_with_comment_innodb.ibd'? y

$ sudo rm /var/lib/mysql/test.mrn.00001*
rm: remove regular file `/var/lib/mysql/test.mrn.0000109'? y
rm: remove regular file `/var/lib/mysql/test.mrn.0000113'? y
rm: remove regular file `/var/lib/mysql/test.mrn.0000117'? y
rm: remove regular file `/var/lib/mysql/test.mrn.0000117.c'? y
mysql> show table status \G
Empty set (0.00 sec)

mysql> CREATE TABLE table_with_comment_innodb (   id INT PRIMARY KEY AUTO_INCREMENT,   contents TEXT ,   FULLTEXT INDEX (contents) ) ENGINE = mroonga DEFAULT CHARSET utf8 COMMENT = 'engine "innodb"';
ERROR 16501 (HY000): The table parameter 'foo' is invalid
mysql> show table status;
Empty set (0.00 sec)
$ sudo /etc/init.d/mysql restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL.                                            [  OK  ]
mysql> CREATE TABLE table_with_comment_innodb (   id INT PRIMARY KEY AUTO_INCREMENT,   contents TEXT ,   FULLTEXT INDEX (contents) ) ENGINE = mroonga DEFAULT CHARSET utf8 COMMENT = 'engine "innodb"';
ERROR 1050 (42S01): Table '`test`.`table_with_comment_innodb`' already exists

mysql> show table status;                                                                                                                   Empty set (0.00 sec)

mysql> drop table table_with_comment_innodb;
ERROR 1051 (42S02): Unknown table 'test.table_with_comment_innodb'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment