# -*- mode: sql; sql-product: mysql -*-
#
# Copyright(C) 2022 Sutou Kouhei <kou@clear-code.com>
#
# 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_mysql.inc
--source ../../include/mroonga/not_embedded.inc
--source ../../include/mroonga/have_mroonga.inc

--disable_warnings
DROP TABLE IF EXISTS diaries;
--enable_warnings

SET NAMES utf8mb4;
CREATE TABLE diaries(
  title TEXT
) DEFAULT CHARSET=utf8mb4;

# Adding multiple lines in order to work MAX_EXECUTION_TIME(1) in MYSQL 5.7.
INSERT INTO diaries VALUES ('Hello');
INSERT INTO diaries VALUES ('World');

# sleep(1) in SELECT is for working MAX_EXECUTION_TIME(1) in MYSQL 5.7.
# sleep(1) in WHERE is for working MAX_EXECUTION_TIME(1) in MYSQL 8.0.
# "OR title IS NOT NULL" is for getting records of diaries. The result of sleep(1) is false.
--error ER_QUERY_TIMEOUT
SELECT /*+ MAX_EXECUTION_TIME(1) */ sleep(1), title FROM diaries WHERE sleep(1) OR title IS NOT NULL;
SELECT sleep(1), title FROM diaries WHERE sleep(1) OR title IS NOT NULL;
SELECT /*+ MAX_EXECUTION_TIME(10000) */ sleep(1), title FROM diaries WHERE sleep(1) OR title IS NOT NULL;

DROP TABLE diaries;

--source ../../include/mroonga/have_mroonga_deinit.inc
