null+****@clear*****
null+****@clear*****
2012年 2月 10日 (金) 10:58:20 JST
Kouhei Sutou 2012-02-10 10:58:20 +0900 (Fri, 10 Feb 2012)
New Revision: c611ea8061e97b88ab839316bb9b7a447ffdc802
Log:
add mroonga_enable_optimization thread variable to on/off optimizations.
Added files:
test/sql/suite/mroonga_storage/r/fulltext_order_limit_disabled.result
test/sql/suite/mroonga_storage/r/optimization_skip_count_disabled.result
test/sql/suite/mroonga_storage/t/fulltext_order_limit_disabled.test
test/sql/suite/mroonga_storage/t/optimization_skip_count_disabled.test
Modified files:
ha_mroonga.cc
ha_mroonga.h
Modified: ha_mroonga.cc (+31 -0)
===================================================================
--- ha_mroonga.cc 2012-02-06 14:38:39 +0900 (8f77ec1)
+++ ha_mroonga.cc 2012-02-10 10:58:20 +0900 (a5fb935)
@@ -762,6 +762,15 @@ static bool mrn_dry_write(THD *thd)
DBUG_RETURN(dry_write_p);
}
+static MYSQL_THDVAR_BOOL(
+ enable_optimization, /* name */
+ PLUGIN_VAR_OPCMDARG, /* options */
+ "If enable_optimization is true, some optimizations will be applied.", /* comment */
+ NULL, /* check */
+ NULL, /* update */
+ true /* default */
+);
+
static MYSQL_SYSVAR_STR(default_wrapper_engine, mrn_default_wrapper_engine,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
"The default engine for wrapper mode",
@@ -789,6 +798,7 @@ static struct st_mysql_sys_var *mrn_system_variables[] =
MYSQL_SYSVAR(log_file),
MYSQL_SYSVAR(default_parser),
MYSQL_SYSVAR(dry_write),
+ MYSQL_SYSVAR(enable_optimization),
MYSQL_SYSVAR(default_wrapper_engine),
MYSQL_SYSVAR(libgroonga_version),
MYSQL_SYSVAR(version),
@@ -6866,10 +6876,24 @@ int ha_mroonga::generic_geo_open_cursor(const uchar *key,
DBUG_RETURN(error);
}
+bool ha_mroonga::is_enable_optimization()
+{
+ MRN_DBUG_ENTER_FUNCTION();
+ bool enable_optimization_p = THDVAR(ha_thd(), enable_optimization);
+ DBUG_RETURN(enable_optimization_p);
+}
+
void ha_mroonga::check_count_skip(key_part_map start_key_part_map,
key_part_map end_key_part_map, bool fulltext)
{
MRN_DBUG_ENTER_METHOD();
+
+ if (!is_enable_optimization()) {
+ DBUG_PRINT("info", ("mroonga: count skip: optimization is disabled"));
+ count_skip = false;
+ DBUG_VOID_RETURN;
+ }
+
st_select_lex *select_lex = table->pos_in_table_list->select_lex;
if (
@@ -7044,6 +7068,13 @@ void ha_mroonga::check_fast_order_limit(grn_table_sort_key **sort_keys,
grn_obj *score_column)
{
MRN_DBUG_ENTER_METHOD();
+
+ if (!is_enable_optimization()) {
+ DBUG_PRINT("info", ("mroonga: fast order limit: optimization is disabled"));
+ fast_order_limit = false;
+ DBUG_VOID_RETURN;
+ }
+
TABLE_LIST *table_list = table->pos_in_table_list;
st_select_lex *select_lex = table_list->select_lex;
SELECT_LEX_UNIT *unit = table_list->derived;
Modified: ha_mroonga.h (+1 -0)
===================================================================
--- ha_mroonga.h 2012-02-06 14:38:39 +0900 (b385666)
+++ ha_mroonga.h 2012-02-10 10:58:20 +0900 (9e512c3)
@@ -410,6 +410,7 @@ private:
#ifdef MRN_HANDLER_HAVE_HA_CLOSE
int close();
#endif
+ bool is_enable_optimization();
void check_count_skip(key_part_map start_key_part_map,
key_part_map end_key_part_map, bool fulltext);
bool is_groonga_layer_condition(const Item *item,
Added: test/sql/suite/mroonga_storage/r/fulltext_order_limit_disabled.result (+46 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/fulltext_order_limit_disabled.result 2012-02-10 10:58:20 +0900 (1178bab)
@@ -0,0 +1,46 @@
+DROP TABLE IF EXISTS diaries;
+SET NAMES UTF8;
+CREATE TABLE diaries (
+id INT UNSIGNED NOT NULL,
+year INT UNSIGNED,
+month INT UNSIGNED,
+day INT UNSIGNED,
+title VARCHAR(255),
+content TEXT,
+FULLTEXT INDEX(content),
+KEY(month),
+KEY(day)
+) DEFAULT CHARSET UTF8 COLLATE UTF8_BIN;
+SHOW CREATE TABLE diaries;
+Table Create Table
+diaries CREATE TABLE `diaries` (
+ `id` int(10) unsigned NOT NULL,
+ `year` int(10) unsigned DEFAULT NULL,
+ `month` int(10) unsigned DEFAULT NULL,
+ `day` int(10) unsigned DEFAULT NULL,
+ `title` varchar(255) COLLATE utf8_bin DEFAULT NULL,
+ `content` text COLLATE utf8_bin,
+ KEY `month` (`month`),
+ KEY `day` (`day`),
+ FULLTEXT KEY `content` (`content`)
+) ENGINE=mroonga DEFAULT CHARSET=utf8 COLLATE=utf8_bin
+INSERT INTO diaries VALUES(1, 2011, 11, 9, "Hello", "今日からはじめました。");
+INSERT INTO diaries VALUES(2, 2011, 11, 10, "天気", "明日の富士山の天気について");
+INSERT INTO diaries VALUES(3, 2011, 11, 11, "富士山", "今日も天気がよくてきれいに見える。");
+INSERT INTO diaries VALUES(4, 2011, 11, 12, "帰り道", "今日は天気がよくてよかった。");
+INSERT INTO diaries VALUES(5, 2011, 11, 13, "はれ", "天気がよいのは今日までみたい。");
+INSERT INTO diaries VALUES(6, 2011, 12, 1, "久しぶり", "天気が悪いからずっと留守番。");
+INSERT INTO diaries VALUES(7, 2011, 12, 2, "初雪", "今日の天気は雪!");
+SET mroonga_enable_optimization=FALSE;
+SELECT * FROM diaries
+WHERE MATCH(content) AGAINST("今日" IN BOOLEAN MODE) AND
+month = 11
+ORDER BY day LIMIT 1,2;
+id year month day title content
+3 2011 11 11 富士山 今日も天気がよくてきれいに見える。
+4 2011 11 12 帰り道 今日は天気がよくてよかった。
+SHOW STATUS LIKE 'mroonga_fast_order_limit';
+Variable_name Value
+mroonga_fast_order_limit 0
+SET mroonga_enable_optimization=TRUE;
+DROP TABLE diaries;
Added: test/sql/suite/mroonga_storage/r/optimization_skip_count_disabled.result (+31 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/optimization_skip_count_disabled.result 2012-02-10 10:58:20 +0900 (a341db5)
@@ -0,0 +1,31 @@
+DROP TABLE IF EXISTS diaries;
+SET NAMES UTF8;
+CREATE TABLE diaries (
+id INT UNSIGNED NOT NULL,
+title VARCHAR(255),
+content TEXT,
+FULLTEXT INDEX(content)
+) DEFAULT CHARSET UTF8 COLLATE UTF8_BIN;
+SHOW CREATE TABLE diaries;
+Table Create Table
+diaries CREATE TABLE `diaries` (
+ `id` int(10) unsigned NOT NULL,
+ `title` varchar(255) COLLATE utf8_bin DEFAULT NULL,
+ `content` text COLLATE utf8_bin,
+ FULLTEXT KEY `content` (`content`)
+) ENGINE=mroonga DEFAULT CHARSET=utf8 COLLATE=utf8_bin
+INSERT INTO diaries VALUES(1, "Hello", "今日からはじめました。");
+INSERT INTO diaries VALUES(2, "天気", "明日の富士山の天気について");
+INSERT INTO diaries VALUES(3, "富士山", "今日も天気がよくてきれいに見える。");
+INSERT INTO diaries VALUES(4, "帰り道", "今日は天気がよくてよかった。");
+INSERT INTO diaries VALUES(5, "はれ", "天気がよいのは今日までみたい。");
+SET mroonga_enable_optimization=FALSE;
+SELECT COUNT(*) FROM diaries
+WHERE MATCH(content) AGAINST("今日" IN BOOLEAN MODE);
+COUNT(*)
+4
+SHOW STATUS LIKE 'mroonga_count_skip';
+Variable_name Value
+mroonga_count_skip 0
+SET mroonga_enable_optimization=TRUE;
+DROP TABLE diaries;
Added: test/sql/suite/mroonga_storage/t/fulltext_order_limit_disabled.test (+58 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/fulltext_order_limit_disabled.test 2012-02-10 10:58:20 +0900 (82daf91)
@@ -0,0 +1,58 @@
+# 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
+
+SET NAMES UTF8;
+CREATE TABLE diaries (
+ id INT UNSIGNED NOT NULL,
+ year INT UNSIGNED,
+ month INT UNSIGNED,
+ day INT UNSIGNED,
+ title VARCHAR(255),
+ content TEXT,
+ FULLTEXT INDEX(content),
+ KEY(month),
+ KEY(day)
+) DEFAULT CHARSET UTF8 COLLATE UTF8_BIN;
+SHOW CREATE TABLE diaries;
+
+INSERT INTO diaries VALUES(1, 2011, 11, 9, "Hello", "今日からはじめました。");
+INSERT INTO diaries VALUES(2, 2011, 11, 10, "天気", "明日の富士山の天気について");
+INSERT INTO diaries VALUES(3, 2011, 11, 11, "富士山", "今日も天気がよくてきれいに見える。");
+INSERT INTO diaries VALUES(4, 2011, 11, 12, "帰り道", "今日は天気がよくてよかった。");
+INSERT INTO diaries VALUES(5, 2011, 11, 13, "はれ", "天気がよいのは今日までみたい。");
+INSERT INTO diaries VALUES(6, 2011, 12, 1, "久しぶり", "天気が悪いからずっと留守番。");
+INSERT INTO diaries VALUES(7, 2011, 12, 2, "初雪", "今日の天気は雪!");
+
+SET mroonga_enable_optimization=FALSE;
+
+SELECT * FROM diaries
+ WHERE MATCH(content) AGAINST("今日" IN BOOLEAN MODE) AND
+ month = 11
+ ORDER BY day LIMIT 1,2;
+
+SHOW STATUS LIKE 'mroonga_fast_order_limit';
+
+SET mroonga_enable_optimization=TRUE;
+
+DROP TABLE diaries;
+
+--source include/have_mroonga_deinit.inc
Added: test/sql/suite/mroonga_storage/t/optimization_skip_count_disabled.test (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/optimization_skip_count_disabled.test 2012-02-10 10:58:20 +0900 (3843728)
@@ -0,0 +1,49 @@
+# 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
+
+SET NAMES UTF8;
+CREATE TABLE diaries (
+ id INT UNSIGNED NOT NULL,
+ title VARCHAR(255),
+ content TEXT,
+ FULLTEXT INDEX(content)
+) DEFAULT CHARSET UTF8 COLLATE UTF8_BIN;
+SHOW CREATE TABLE diaries;
+
+INSERT INTO diaries VALUES(1, "Hello", "今日からはじめました。");
+INSERT INTO diaries VALUES(2, "天気", "明日の富士山の天気について");
+INSERT INTO diaries VALUES(3, "富士山", "今日も天気がよくてきれいに見える。");
+INSERT INTO diaries VALUES(4, "帰り道", "今日は天気がよくてよかった。");
+INSERT INTO diaries VALUES(5, "はれ", "天気がよいのは今日までみたい。");
+
+SET mroonga_enable_optimization=FALSE;
+
+SELECT COUNT(*) FROM diaries
+ WHERE MATCH(content) AGAINST("今日" IN BOOLEAN MODE);
+
+SHOW STATUS LIKE 'mroonga_count_skip';
+
+SET mroonga_enable_optimization=TRUE;
+
+DROP TABLE diaries;
+
+--source include/have_mroonga_deinit.inc