null+****@clear*****
null+****@clear*****
2012年 1月 24日 (火) 22:37:56 JST
Kouhei Sutou 2012-01-24 22:37:56 +0900 (Tue, 24 Jan 2012) New Revision: 973f7d6edfa2a0757ba43300930a48b1df8eabf0 Log: [storage] fix crash by indexed count(*) on view. fixes #1255 Reported by Takahiro Nagai. Thanks!!! Added files: test/sql/suite/mroonga_storage/r/count_skip_view.result test/sql/suite/mroonga_storage/t/count_skip_view.test Modified files: ha_mroonga.cc Modified: ha_mroonga.cc (+2 -0) =================================================================== --- ha_mroonga.cc 2012-01-24 16:15:09 +0900 (dbe24b0) +++ ha_mroonga.cc 2012-01-24 22:37:56 +0900 (0ca700e) @@ -6874,6 +6874,8 @@ void ha_mroonga::check_count_skip(key_part_map start_key_part_map, if (where->type() == Item::FIELD_ITEM) { Field *field = ((Item_field *)where)->field; + if (!field) + break; if (field->table != table) break; uint j; Added: test/sql/suite/mroonga_storage/r/count_skip_view.result (+28 -0) 100644 =================================================================== --- /dev/null +++ test/sql/suite/mroonga_storage/r/count_skip_view.result 2012-01-24 22:37:56 +0900 (407347a) @@ -0,0 +1,28 @@ +DROP TABLE IF EXISTS diaries, users; +CREATE TABLE diaries ( +id INT PRIMARY KEY AUTO_INCREMENT, +user_id INT NOT NULL, +title VARCHAR(45) NOT NULL, +KEY (user_id), +FULLTEXT INDEX title_index (title) +) DEFAULT CHARSET=UTF8; +CREATE TABLE users ( +id INT PRIMARY KEY AUTO_INCREMENT, +name VARCHAR(45) NOT NULL, +INDEX (name) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8; +INSERT INTO users (id, name) VALUES (1, "Alice"), (2, "Bob"); +INSERT INTO diaries (user_id, title) VALUES (1, "survey"); +INSERT INTO diaries (user_id, title) VALUES (2, "groonga (1)"); +INSERT INTO diaries (user_id, title) VALUES (2, "groonga (2)"); +CREATE VIEW articles AS +SELECT diaries.user_id AS user_id, +diaries.title AS title, +users.name AS name +FROM diaries, users +WHERE diaries.user_id = users.id; +SELECT COUNT(*) FROM articles WHERE name = 'Bob'; +COUNT(*) +2 +DROP VIEW articles; +DROP TABLE diaries, users; Added: test/sql/suite/mroonga_storage/t/count_skip_view.test (+55 -0) 100644 =================================================================== --- /dev/null +++ test/sql/suite/mroonga_storage/t/count_skip_view.test 2012-01-24 22:37:56 +0900 (ae2fb70) @@ -0,0 +1,55 @@ +# 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, users; +--enable_warnings + +CREATE TABLE diaries ( + id INT PRIMARY KEY AUTO_INCREMENT, + user_id INT NOT NULL, + title VARCHAR(45) NOT NULL, + KEY (user_id), + FULLTEXT INDEX title_index (title) +) DEFAULT CHARSET=UTF8; + +CREATE TABLE users ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(45) NOT NULL, + INDEX (name) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8; + +INSERT INTO users (id, name) VALUES (1, "Alice"), (2, "Bob"); +INSERT INTO diaries (user_id, title) VALUES (1, "survey"); +INSERT INTO diaries (user_id, title) VALUES (2, "groonga (1)"); +INSERT INTO diaries (user_id, title) VALUES (2, "groonga (2)"); + +CREATE VIEW articles AS + SELECT diaries.user_id AS user_id, + diaries.title AS title, + users.name AS name + FROM diaries, users + WHERE diaries.user_id = users.id; + + +SELECT COUNT(*) FROM articles WHERE name = 'Bob'; + +DROP VIEW articles; +DROP TABLE diaries, users; + +--source include/have_mroonga_deinit.inc