From a48c7f126f5b99d45a09c2202ef6a8c0c4a1d9e2 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Thu, 19 Apr 2018 10:50:11 +0900 Subject: [PATCH] Fix a crash bug when some complex condition in ORDER BY --- ha_mroonga.cpp | 2 +- .../not_optimized/r/complex_order_by.result | 27 ++++++++++ .../not_optimized/t/complex_order_by.test | 49 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 mysql-test/mroonga/storage/optimization/order_limit/not_optimized/r/complex_order_by.result create mode 100644 mysql-test/mroonga/storage/optimization/order_limit/not_optimized/t/complex_order_by.test diff --git a/ha_mroonga.cpp b/ha_mroonga.cpp index 63b81af05..e507d0f00 100644 --- a/ha_mroonga.cpp +++ b/ha_mroonga.cpp @@ -10827,7 +10827,7 @@ void ha_mroonga::check_fast_order_limit(grn_table_sort_key **sort_keys, mrn_fast_order_limit++; } else { for (int j = 0; j < i; ++j) { - grn_obj_unlink(ctx, sort_keys[j]->key); + grn_obj_unlink(ctx, (*sort_keys)[j].key); } my_free(*sort_keys); *sort_keys = NULL; diff --git a/mysql-test/mroonga/storage/optimization/order_limit/not_optimized/r/complex_order_by.result b/mysql-test/mroonga/storage/optimization/order_limit/not_optimized/r/complex_order_by.result new file mode 100644 index 000000000..029dc465c --- /dev/null +++ b/mysql-test/mroonga/storage/optimization/order_limit/not_optimized/r/complex_order_by.result @@ -0,0 +1,27 @@ +DROP TABLE IF EXISTS memos; +FLUSH STATUS; +SET NAMES UTF8; +CREATE TABLE memos ( +id INT UNSIGNED, +content TEXT, +FULLTEXT INDEX(content) +) DEFAULT CHARSET UTF8; +INSERT INTO memos VALUES(1, 'Groonga is fast.'); +INSERT INTO memos VALUES(2, 'Mroonga is based on Groonga.'); +INSERT INTO memos VALUES(3, 'Groonga is embeddable full text search engine.'); +INSERT INTO memos VALUES(4, 'Mroonga is fast too.'); +SELECT * +FROM memos +WHERE MATCH(content) AGAINST('*D+ Groonga OR Mroonga' IN BOOLEAN MODE) +ORDER BY 1 + 1, +id, +content +LIMIT 3; +id content +1 Groonga is fast. +2 Mroonga is based on Groonga. +3 Groonga is embeddable full text search engine. +SHOW STATUS LIKE 'mroonga_fast_order_limit'; +Variable_name Value +Mroonga_fast_order_limit 0 +DROP TABLE memos; diff --git a/mysql-test/mroonga/storage/optimization/order_limit/not_optimized/t/complex_order_by.test b/mysql-test/mroonga/storage/optimization/order_limit/not_optimized/t/complex_order_by.test new file mode 100644 index 000000000..fc5106ce2 --- /dev/null +++ b/mysql-test/mroonga/storage/optimization/order_limit/not_optimized/t/complex_order_by.test @@ -0,0 +1,49 @@ +# Copyright(C) 2018 Kouhei Sutou +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +--source ../../../../../include/mroonga/have_mroonga.inc + +--disable_warnings +DROP TABLE IF EXISTS memos; +--enable_warnings + +FLUSH STATUS; + +SET NAMES UTF8; +CREATE TABLE memos ( + id INT UNSIGNED, + content TEXT, + FULLTEXT INDEX(content) +) DEFAULT CHARSET UTF8; + +INSERT INTO memos VALUES(1, 'Groonga is fast.'); +INSERT INTO memos VALUES(2, 'Mroonga is based on Groonga.'); +INSERT INTO memos VALUES(3, 'Groonga is embeddable full text search engine.'); +INSERT INTO memos VALUES(4, 'Mroonga is fast too.'); + +SELECT * + FROM memos + WHERE MATCH(content) AGAINST('*D+ Groonga OR Mroonga' IN BOOLEAN MODE) + ORDER BY 1 + 1, + id, + content + LIMIT 3; + +SHOW STATUS LIKE 'mroonga_fast_order_limit'; + +DROP TABLE memos; + +--source ../../../../../include/mroonga/have_mroonga_deinit.inc