From e9d3f56167f2a0601c15aec6c4704aa2178e5bd3 Mon Sep 17 00:00:00 2001 From: nbuxrr Date: Mon, 14 Nov 2022 11:49:31 +0800 Subject: [PATCH] add: RC4 patch --- ...OUNTER-OPTIMIZATION-FOR-MySQL-8.0.25.patch | 235 + ...RC4-CODE-THREADPOOL-FOR-MySQL-8.0.25.patch | 2962 ++++++++ ....RC4-MTR-THREADPOOL-FOR-MySQL-8.0.25.patch | 5954 +++++++++++++++++ 3 files changed, 9151 insertions(+) create mode 100644 KunpengBoostKit22.0.RC4-CODE-THREAD-COUNTER-OPTIMIZATION-FOR-MySQL-8.0.25.patch create mode 100644 KunpengBoostKit22.0.RC4-CODE-THREADPOOL-FOR-MySQL-8.0.25.patch create mode 100644 KunpengBoostKit22.0.RC4-MTR-THREADPOOL-FOR-MySQL-8.0.25.patch diff --git a/KunpengBoostKit22.0.RC4-CODE-THREAD-COUNTER-OPTIMIZATION-FOR-MySQL-8.0.25.patch b/KunpengBoostKit22.0.RC4-CODE-THREAD-COUNTER-OPTIMIZATION-FOR-MySQL-8.0.25.patch new file mode 100644 index 000000000..58c59553f --- /dev/null +++ b/KunpengBoostKit22.0.RC4-CODE-THREAD-COUNTER-OPTIMIZATION-FOR-MySQL-8.0.25.patch @@ -0,0 +1,235 @@ +diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc +index c8a9ec1eb434..e4a491f98cbc 100644 +--- a/sql/event_scheduler.cc ++++ b/sql/event_scheduler.cc +@@ -170,7 +170,6 @@ bool post_init_event_thread(THD *thd) { + + Global_THD_manager *thd_manager = Global_THD_manager::get_instance(); + thd_manager->add_thd(thd); +- thd_manager->inc_thread_running(); + return false; + } + +@@ -190,7 +189,6 @@ void deinit_event_thread(THD *thd) { + DBUG_PRINT("exit", ("Event thread finishing")); + thd->release_resources(); + thd_manager->remove_thd(thd); +- thd_manager->dec_thread_running(); + delete thd; + } + +diff --git a/sql/mysqld_thd_manager.cc b/sql/mysqld_thd_manager.cc +index 902fe2b2c610..56f7aab2610d 100644 +--- a/sql/mysqld_thd_manager.cc ++++ b/sql/mysqld_thd_manager.cc +@@ -315,6 +315,32 @@ THD *Global_THD_manager::find_thd(Find_thd_with_id *func) { + return nullptr; + } + ++/** ++ This class implements callback for do_for_all_thd(). ++ It counts the total number of running threads ++ from global thread list. ++*/ ++class Count_thread_running : public Do_THD_Impl { ++ public: ++ Count_thread_running() : m_count(0) {} ++ ~Count_thread_running() {} ++ virtual void operator()(THD *thd) { ++ if (thd->get_command() != COM_SLEEP) { ++ m_count++; ++ } ++ } ++ int get_count() { return m_count; } ++ ++ private: ++ int m_count; ++}; ++ ++void Global_THD_manager::count_num_thread_running() { ++ Count_thread_running count_thread_running; ++ do_for_all_thd(&count_thread_running); ++ atomic_num_thread_running = count_thread_running.get_count(); ++} ++ + void inc_thread_created() { + Global_THD_manager::get_instance()->inc_thread_created(); + } +diff --git a/sql/mysqld_thd_manager.h b/sql/mysqld_thd_manager.h +index 046997db6852..70dcea1ef8a9 100644 +--- a/sql/mysqld_thd_manager.h ++++ b/sql/mysqld_thd_manager.h +@@ -148,20 +148,15 @@ class Global_THD_manager { + void remove_thd(THD *thd); + + /** +- Retrieves thread running statistic variable. +- @return int Returns the total number of threads currently running ++ Count thread running statistic variable. + */ +- int get_num_thread_running() const { return atomic_num_thread_running; } ++ void count_num_thread_running(); + + /** +- Increments thread running statistic variable. +- */ +- void inc_thread_running() { atomic_num_thread_running++; } +- +- /** +- Decrements thread running statistic variable. ++ Retrieves thread running statistic variable. ++ @return int Returns the total number of threads currently running + */ +- void dec_thread_running() { atomic_num_thread_running--; } ++ int get_num_thread_running() const { return atomic_num_thread_running; } + + /** + Retrieves thread created statistic variable. +diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc +index 52f7f16431eb..e4952a63a206 100644 +--- a/sql/sql_parse.cc ++++ b/sql/sql_parse.cc +@@ -1599,7 +1599,6 @@ bool dispatch_command(THD *thd, const COM_DATA *com_data, + } + thd->set_query_id(next_query_id()); + thd->reset_rewritten_query(); +- thd_manager->inc_thread_running(); + + if (!(server_command_flags[command] & CF_SKIP_QUESTIONS)) + thd->status_var.questions++; +@@ -2265,8 +2264,6 @@ bool dispatch_command(THD *thd, const COM_DATA *com_data, + /* Prevent rewritten query from getting "stuck" in SHOW PROCESSLIST. */ + thd->reset_rewritten_query(); + +- thd_manager->dec_thread_running(); +- + /* Freeing the memroot will leave the THD::work_part_info invalid. */ + thd->work_part_info = nullptr; + +diff --git a/storage/perfschema/pfs_variable.cc b/storage/perfschema/pfs_variable.cc +index d33b1a488899..15a9f41e87da 100644 +--- a/storage/perfschema/pfs_variable.cc ++++ b/storage/perfschema/pfs_variable.cc +@@ -1157,6 +1157,17 @@ int PFS_status_variable_cache::do_materialize_global(void) { + false, /* threads */ + true, /* THDs */ + &visitor); ++ ++ /* ++ Because of the reason described in ++ PFS_status_variable_cache::do_materialize_all(THD *unsafe_thd), ++ PFS_status_variable_cache::do_materialize_session(THD *unsafe_thd) and ++ PFS_status_variable_cache::do_materialize_session(PFS_thread *pfs_thread), ++ count_num_thread_running() cannot put together with ++ get_num_thread_running(), so count_num_thread_running() is put here. ++ */ ++ Global_THD_manager::get_instance()->count_num_thread_running(); ++ + /* + Build the status variable cache using the SHOW_VAR array as a reference. + Use the status totals collected from all threads. +@@ -1200,6 +1211,22 @@ int PFS_status_variable_cache::do_materialize_all(THD *unsafe_thd) { + init_show_var_array(OPT_SESSION, false); + } + ++ /* ++ count_num_thread_running() counts the total number of running threads ++ from global thread list, using LOCK_thd_list to protect sharded ++ global thread list. In lock_order_dependencies.txt, the lock order ++ is that LOCK_thd_list must be locked before LOCK_thd_data. In this ++ function, LOCK_thd_data is already locked in get_THD(), Then manifest() ++ will call get_num_thread_running(). If get_num_thread_running() counts ++ and returns the num, the lock order will be incorrect, which may ++ lead to dead lock. To prevent this situation, get_num_thread_running() ++ is split into two part, one is still called get_num_thread_running() ++ which returns the num, the other is called count_num_thread_running() ++ which counts the num and should be called before get_THD() and ++ get_num_thread_running(). So count_num_thread_running() is put here. ++ */ ++ Global_THD_manager::get_instance()->count_num_thread_running(); ++ + /* Get and lock a validated THD from the thread manager. */ + if ((m_safe_thd = get_THD(unsafe_thd)) != nullptr) { + /* +@@ -1249,6 +1276,22 @@ int PFS_status_variable_cache::do_materialize_session(THD *unsafe_thd) { + init_show_var_array(OPT_SESSION, true); + } + ++ /* ++ count_num_thread_running() counts the total number of running threads ++ from global thread list, using LOCK_thd_list to protect sharded ++ global thread list. In lock_order_dependencies.txt, the lock order ++ is that LOCK_thd_list must be locked before LOCK_thd_data. In this ++ function, LOCK_thd_data is already locked in get_THD(), Then manifest() ++ will call get_num_thread_running(). If get_num_thread_running() counts ++ and returns the num, the lock order will be incorrect, which may ++ lead to dead lock. To prevent this situation, get_num_thread_running() ++ is split into two part, one is still called get_num_thread_running() ++ which returns the num, the other is called count_num_thread_running() ++ which counts the num and should be called before get_THD() and ++ get_num_thread_running(). So count_num_thread_running() is put here. ++ */ ++ Global_THD_manager::get_instance()->count_num_thread_running(); ++ + /* Get and lock a validated THD from the thread manager. */ + if ((m_safe_thd = get_THD(unsafe_thd)) != nullptr) { + /* +@@ -1292,6 +1335,22 @@ int PFS_status_variable_cache::do_materialize_session(PFS_thread *pfs_thread) { + /* The SHOW_VAR array must be initialized externally. */ + assert(m_initialized); + ++ /* ++ count_num_thread_running() counts the total number of running threads ++ from global thread list, using LOCK_thd_list to protect sharded ++ global thread list. In lock_order_dependencies.txt, the lock order ++ is that LOCK_thd_list must be locked before LOCK_thd_data. In this ++ function, LOCK_thd_data is already locked in get_THD(), Then manifest() ++ will call get_num_thread_running(). If get_num_thread_running() counts ++ and returns the num, the lock order will be incorrect, which may ++ lead to dead lock. To prevent this situation, get_num_thread_running() ++ is split into two part, one is still called get_num_thread_running() ++ which returns the num, the other is called count_num_thread_running() ++ which counts the num and should be called before get_THD() and ++ get_num_thread_running(). So count_num_thread_running() is put here. ++ */ ++ Global_THD_manager::get_instance()->count_num_thread_running(); ++ + /* Get and lock a validated THD from the thread manager. */ + if ((m_safe_thd = get_THD(pfs_thread)) != nullptr) { + /* +@@ -1343,6 +1402,16 @@ int PFS_status_variable_cache::do_materialize_client(PFS_client *pfs_client) { + */ + m_sum_client_status(pfs_client, &status_totals); + ++ /* ++ Because of the reason described in ++ PFS_status_variable_cache::do_materialize_all(THD *unsafe_thd), ++ PFS_status_variable_cache::do_materialize_session(THD *unsafe_thd) and ++ PFS_status_variable_cache::do_materialize_session(PFS_thread *pfs_thread), ++ count_num_thread_running() cannot put together with ++ get_num_thread_running(), so count_num_thread_running() is put here. ++ */ ++ Global_THD_manager::get_instance()->count_num_thread_running(); ++ + /* + Build the status variable cache using the SHOW_VAR array as a reference and + the status totals collected from threads associated with this client. +diff --git a/unittest/gunit/thd_manager-t.cc b/unittest/gunit/thd_manager-t.cc +index 1e2efa42011a..4c0aa1bdbafd 100644 +--- a/unittest/gunit/thd_manager-t.cc ++++ b/unittest/gunit/thd_manager-t.cc +@@ -82,14 +82,6 @@ TEST_F(ThreadManagerTest, AddRemoveTHDWithGuard) { + EXPECT_EQ(0U, thd_manager->get_thd_count()); + } + +-TEST_F(ThreadManagerTest, IncDecThreadRunning) { +- EXPECT_EQ(0, thd_manager->get_num_thread_running()); +- thd_manager->inc_thread_running(); +- EXPECT_EQ(1, thd_manager->get_num_thread_running()); +- thd_manager->dec_thread_running(); +- EXPECT_EQ(0, thd_manager->get_num_thread_running()); +-} +- + TEST_F(ThreadManagerTest, IncThreadCreated) { + EXPECT_EQ(0U, thd_manager->get_num_thread_created()); + thd_manager->inc_thread_created(); diff --git a/KunpengBoostKit22.0.RC4-CODE-THREADPOOL-FOR-MySQL-8.0.25.patch b/KunpengBoostKit22.0.RC4-CODE-THREADPOOL-FOR-MySQL-8.0.25.patch new file mode 100644 index 000000000..03541ab2b --- /dev/null +++ b/KunpengBoostKit22.0.RC4-CODE-THREADPOOL-FOR-MySQL-8.0.25.patch @@ -0,0 +1,2962 @@ +diff --git a/plugin/thread_pool/CMakeLists.txt b/plugin/thread_pool/CMakeLists.txt +new file mode 100644 +index 00000000000..35cbdff5140 +--- /dev/null ++++ b/plugin/thread_pool/CMakeLists.txt +@@ -0,0 +1,26 @@ ++# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. ++# Copyright (c) 2022 Huawei Technologies Co., Ltd. ++# ++# This program is free software; you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation; version 2 of the License. ++# ++# This program 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 General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program; if not, write to the Free Software ++# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ++ ++ADD_COMPILE_DEFINITIONS( ++ COMPILE_DEFINITIONS MYSQL_DYNAMIC_PLUGIN) ++ ++MYSQL_ADD_PLUGIN(thread_pool ++ threadpool_common.cc ++ threadpool_unix.cc ++ MODULE_ONLY ++ MODULE_OUTPUT_NAME "thread_pool" ++ ) ++ +diff --git a/plugin/thread_pool/numa_affinity_manager.h b/plugin/thread_pool/numa_affinity_manager.h +new file mode 100644 +index 00000000000..3471d328736 +--- /dev/null ++++ b/plugin/thread_pool/numa_affinity_manager.h +@@ -0,0 +1,117 @@ ++/* Copyright (C) 2012 Monty Program Ab ++ Copyright (C) 2022 Huawei Technologies Co., Ltd ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; version 2 of the License. ++ ++ This program 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 General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program; if not, write to the Free Software ++ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ++#ifndef NUMA_AFFINITY_MANAGER_H_ ++#define NUMA_AFFINITY_MANAGER_H_ ++ ++#include ++#include ++#include ++#include ++#include ++ ++using namespace std; ++ ++class numa_affinity_manager ++{ ++public: ++ numa_affinity_manager(){}; ++ virtual ~numa_affinity_manager(){}; ++ ++ bool init() { ++ initok = false; ++ cpu_count = get_sys_cpu(); ++ numa_count = get_sys_numa(); ++ if (cpu_count <= 0 || numa_count <= 0 || ++ cpu_count % numa_count != 0) { ++ return false; ++ } ++ ++ int cpu_per_numa = cpu_count / numa_count; ++ int start = 0; ++ numa_cpu_map.clear(); ++ auto delete_cpumask = [](bitmask *ptr) { ++ if (ptr != nullptr) { ++ numa_free_cpumask(ptr); ++ } ++ }; ++ for (int i = 0; i < numa_count; i++) { ++ auto msk = numa_allocate_cpumask(); ++ if (msk == nullptr) { ++ return false; ++ } ++ ++ for (int j = 0; j < cpu_per_numa; j++) { ++ numa_bitmask_setbit(msk, start + j); ++ } ++ numa_cpu_map.emplace_back(msk, delete_cpumask); ++ start += cpu_per_numa; ++ } ++ initok = true; ++ return true; ++ } ++ ++ bool bind_numa(int group_id) { ++ if (initok) { ++ pid_t pid = gettid(); ++ return (numa_sched_setaffinity( ++ pid, numa_cpu_map[group_id%numa_cpu_map.size()].get()) == 0); ++ } ++ ++ return false; ++ } ++ ++protected: ++ int get_sys_cpu() { ++ return numa_num_configured_cpus(); ++ } ++ ++ int get_sys_numa() { ++ return numa_num_configured_nodes(); ++ } ++ ++ pid_t gettid() { ++ return static_cast(syscall(SYS_gettid)); ++ } ++ ++public: ++ void print_cpumask(const string &name, bitmask *msk) { ++ cout << name << ": "; ++ for (unsigned int i = 0; i < msk->size; i++) { ++ if (numa_bitmask_isbitset(msk, i)) { ++ cout << i << " "; ++ } ++ } ++ cout << endl; ++ } ++ void dump() { ++ cout << "initok: " << initok << endl; ++ cout << "cpu_count: " << cpu_count << endl; ++ cout << "numa_count: " << numa_count << endl; ++ ++ for (unsigned int i = 0; i < numa_cpu_map.size(); i++) { ++ string name = "numa_cpu_map[" + to_string(i) + "]"; ++ print_cpumask(name, numa_cpu_map[i].get()); ++ } ++ } ++ ++private: ++ bool initok{false}; ++ int cpu_count{0}; ++ int numa_count{0}; ++ vector> numa_cpu_map; ++}; ++ ++#endif // NUMA_AFFINITY_MANAGER_H_ +diff --git a/plugin/thread_pool/threadpool.h b/plugin/thread_pool/threadpool.h +new file mode 100644 +index 00000000000..f4dd68dc8a9 +--- /dev/null ++++ b/plugin/thread_pool/threadpool.h +@@ -0,0 +1,89 @@ ++/* Copyright (C) 2012 Monty Program Ab ++ Copyright (C) 2022 Huawei Technologies Co., Ltd ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; version 2 of the License. ++ ++ This program 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 General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program; if not, write to the Free Software ++ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ++#ifndef THREADPOOL_H_ ++#define THREADPOOL_H_ ++ ++#include "sql/sql_class.h" ++#include "sql/mysqld_thd_manager.h" ++#include "sql/conn_handler/connection_handler_manager.h" ++#include "sql/conn_handler/channel_info.h" ++ ++struct SHOW_VAR; ++ ++#define MAX_THREAD_GROUPS 1024 ++#define MAX_CONNECTIONS 100000 ++ ++ ++enum tp_high_prio_mode_t { ++ TP_HIGH_PRIO_MODE_TRANSACTIONS, ++ TP_HIGH_PRIO_MODE_STATEMENTS, ++ TP_HIGH_PRIO_MODE_NONE ++}; ++ ++/* Threadpool parameters */ ++extern uint threadpool_idle_timeout; /* Shutdown idle worker threads after this timeout */ ++extern bool threadpool_dedicated_listener; /* Control whether listener be dedicated */ ++extern uint threadpool_size; /* Number of parallel executing threads */ ++extern bool threadpool_sched_affinity; /* Control whether thread group scheduling affinity */ ++extern uint threadpool_max_threads; ++extern uint threadpool_stall_limit; /* time interval in 10 ms units for stall checks*/ ++extern uint threadpool_oversubscribe; /* Maximum active threads in group */ ++extern uint threadpool_toobusy; /* Maximum active and waiting threads in group */ ++ ++/* Possible values for thread_pool_high_prio_mode */ ++extern const char *threadpool_high_prio_mode_names[]; ++ ++/* Common thread pool routines, suitable for different implementations */ ++extern void threadpool_remove_connection(THD *thd); ++extern int threadpool_process_request(THD *thd); ++extern int threadpool_add_connection(THD *thd); ++ ++/* ++ Functions used by scheduler. ++ OS-specific implementations are in ++ threadpool_unix.cc or threadpool_win.cc ++*/ ++extern bool tp_init(); ++extern void tp_wait_begin(THD *, int); ++extern void tp_wait_end(THD *); ++extern void tp_post_kill_notification(THD *thd) noexcept; ++extern bool tp_add_connection(Channel_info *); ++extern void tp_end(void); ++extern void tp_fake_end(void); ++extern void threadpool_remove_connection(THD *thd); ++extern bool thread_attach(THD *thd); ++ ++extern THD_event_functions tp_event_functions; ++ ++/* ++ Threadpool statistics ++*/ ++struct TP_STATISTICS { ++ /* Current number of worker thread. */ ++ std::atomic num_worker_threads; ++}; ++ ++extern TP_STATISTICS tp_stats; ++ ++/* Functions to set threadpool parameters */ ++extern void tp_set_threadpool_size(uint val) noexcept; ++extern void tp_set_threadpool_stall_limit(uint val) noexcept; ++ ++extern uint tp_get_thdvar_high_prio_tickets(THD *thd); ++extern uint tp_get_thdvar_high_prio_mode(THD *thd); ++ ++#endif // THREADPOOL_H_ ++ +diff --git a/plugin/thread_pool/threadpool_common.cc b/plugin/thread_pool/threadpool_common.cc +new file mode 100644 +index 00000000000..00595fc4b3f +--- /dev/null ++++ b/plugin/thread_pool/threadpool_common.cc +@@ -0,0 +1,765 @@ ++/* Copyright (C) 2012 Monty Program Ab ++ Copyright (C) 2022 Huawei Technologies Co., Ltd ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; version 2 of the License. ++ ++ This program 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 General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program; if not, write to the Free Software ++ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ++ ++#include "threadpool.h" ++#include "threadpool_unix.h" ++#include "my_thread_local.h" ++#include "my_sys.h" ++#include "mysql/plugin.h" ++#include "mysql/psi/mysql_idle.h" ++#include "mysql/thread_pool_priv.h" ++#include "sql/debug_sync.h" ++#include "sql/mysqld.h" ++#include "sql/sql_class.h" ++#include "sql/sql_connect.h" ++#include "sql/protocol_classic.h" ++#include "sql/sql_parse.h" ++#include "sql/sql_table.h" ++#include "sql/field.h" ++#include "sql/sql_show.h" ++#include "sql/sql_class.h" ++#include ++#include ++ ++#define MYSQL_SERVER 1 ++ ++/* Threadpool parameters */ ++uint threadpool_idle_timeout; ++bool threadpool_dedicated_listener; ++uint threadpool_size; ++bool threadpool_sched_affinity; ++uint threadpool_stall_limit; ++uint threadpool_max_threads; ++uint threadpool_oversubscribe; ++uint threadpool_toobusy; ++ ++/* Stats */ ++TP_STATISTICS tp_stats; ++ ++/* ++ Worker threads contexts, and THD contexts. ++ ========================================= ++ ++ Both worker threads and connections have their sets of thread local variables ++ At the moment it is mysys_var (this has specific data for dbug, my_error and ++ similar goodies), and PSI per-client structure. ++ ++ Whenever query is executed following needs to be done: ++ ++ 1. Save worker thread context. ++ 2. Change TLS variables to connection specific ones using thread_attach(THD*). ++ This function does some additional work. ++ 3. Process query ++ 4. Restore worker thread context. ++ ++ Connection login and termination follows similar schema w.r.t saving and ++ restoring contexts. ++ ++ For both worker thread, and for the connection, mysys variables are created ++ using my_thread_init() and freed with my_thread_end(). ++ ++*/ ++class Worker_thread_context { ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ PSI_thread *const psi_thread; ++#endif ++#ifndef NDEBUG ++ const my_thread_id thread_id; ++#endif ++ public: ++ Worker_thread_context() noexcept ++ : ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ psi_thread(PSI_THREAD_CALL(get_thread)()) ++#endif ++#ifndef NDEBUG ++ , ++ thread_id(my_thread_var_id()) ++#endif ++ { ++ } ++ ++ ~Worker_thread_context() noexcept { ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ PSI_THREAD_CALL(set_thread)(psi_thread); ++#endif ++#ifndef NDEBUG ++ set_my_thread_var_id(thread_id); ++#endif ++ THR_MALLOC = nullptr; ++ } ++}; ++ ++/* ++ Attach/associate the connection with the OS thread, ++*/ ++bool thread_attach(THD *thd) { ++#ifndef NDEBUG ++ set_my_thread_var_id(thd->thread_id()); ++#endif ++ thd->thread_stack = (char *)&thd; ++ thd->store_globals(); ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ PSI_THREAD_CALL(set_thread)(thd->get_psi()); ++#endif ++ mysql_socket_set_thread_owner( ++ thd->get_protocol_classic()->get_vio()->mysql_socket); ++ return 0; ++} ++ ++#ifdef HAVE_PSI_STATEMENT_INTERFACE ++extern PSI_statement_info stmt_info_new_packet; ++#endif ++ ++static void threadpool_net_before_header_psi_noop(NET * /* net */, ++ void * /* user_data */, ++ size_t /* count */) {} ++ ++static void threadpool_init_net_server_extension(THD *thd) { ++#ifdef HAVE_PSI_INTERFACE ++ // socket_connection.cc:init_net_server_extension should have been called ++ // already for us. We only need to overwrite the "before" callback ++ assert(thd->m_net_server_extension.m_user_data == thd); ++ thd->m_net_server_extension.m_before_header = ++ threadpool_net_before_header_psi_noop; ++#else ++ assert(thd->get_protocol_classic()->get_net()->extension == NULL); ++#endif ++} ++ ++int threadpool_add_connection(THD *thd) { ++ int retval = 1; ++ Worker_thread_context worker_context; ++ ++ my_thread_init(); ++ ++ /* Create new PSI thread for use with the THD. */ ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ thd->set_psi(PSI_THREAD_CALL(new_thread)(key_thread_one_connection, thd, ++ thd->thread_id())); ++#endif ++ ++ /* Login. */ ++ thread_attach(thd); ++ thd->start_utime = my_micro_time(); ++ thd->store_globals(); ++ ++ if (thd_prepare_connection(thd)) { ++ goto end; ++ } ++ ++ /* ++ Check if THD is ok, as prepare_new_connection_state() ++ can fail, for example if init command failed. ++ */ ++ if (thd_connection_alive(thd)) { ++ retval = 0; ++ thd_set_net_read_write(thd, 1); ++ MYSQL_SOCKET_SET_STATE(thd->get_protocol_classic()->get_vio()->mysql_socket, ++ PSI_SOCKET_STATE_IDLE); ++ thd->m_server_idle = true; ++ threadpool_init_net_server_extension(thd); ++ } ++ ++end: ++ if (retval) { ++ Connection_handler_manager *handler_manager = ++ Connection_handler_manager::get_instance(); ++ handler_manager->inc_aborted_connects(); ++ } ++ return retval; ++} ++ ++ ++static Connection_handler_functions tp_chf = { ++ 0, ++ tp_add_connection, ++ tp_end ++}; ++ ++THD_event_functions tp_event_functions = { ++ tp_wait_begin, ++ tp_wait_end, ++ tp_post_kill_notification ++}; ++ ++ ++void threadpool_remove_connection(THD *thd) { ++ Worker_thread_context worker_context; ++ ++ thread_attach(thd); ++ thd_set_net_read_write(thd, 0); ++ ++ end_connection(thd); ++ close_connection(thd, 0); ++ ++ thd->release_resources(); ++ ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ PSI_THREAD_CALL(delete_thread)(thd->get_psi()); ++#endif ++ ++ Global_THD_manager::get_instance()->remove_thd(thd); ++ Connection_handler_manager::dec_connection_count(); ++ delete thd; ++} ++ ++/** ++ Process a single client request or a single batch. ++*/ ++int threadpool_process_request(THD *thd) { ++ int retval = 0; ++ Worker_thread_context worker_context; ++ ++ thread_attach(thd); ++ ++ if (thd->killed == THD::KILL_CONNECTION) { ++ /* ++ killed flag was set by timeout handler ++ or KILL command. Return error. ++ */ ++ retval = 1; ++ goto end; ++ } ++ ++ /* ++ In the loop below, the flow is essentially the copy of thead-per-connections ++ logic, see do_handle_one_connection() in sql_connect.c ++ ++ The goal is to execute a single query, thus the loop is normally executed ++ only once. However for SSL connections, it can be executed multiple times ++ (SSL can preread and cache incoming data, and vio->has_data() checks if it ++ was the case). ++ */ ++ for (;;) { ++ Vio *vio; ++ thd_set_net_read_write(thd, 0); ++ ++ if ((retval = do_command(thd)) != 0) goto end; ++ ++ if (!thd_connection_alive(thd)) { ++ retval = 1; ++ goto end; ++ } ++ ++ vio = thd->get_protocol_classic()->get_vio(); ++ if (!vio->has_data(vio)) { ++ /* More info on this debug sync is in sql_parse.cc*/ ++ DEBUG_SYNC(thd, "before_do_command_net_read"); ++ thd_set_net_read_write(thd, 1); ++ goto end; ++ } ++ if (!thd->m_server_idle) { ++ MYSQL_SOCKET_SET_STATE(vio->mysql_socket, PSI_SOCKET_STATE_IDLE); ++ MYSQL_START_IDLE_WAIT(thd->m_idle_psi, &thd->m_idle_state); ++ thd->m_server_idle = true; ++ } ++ } ++ ++end: ++ if (!retval && !thd->m_server_idle) { ++ MYSQL_SOCKET_SET_STATE(thd->get_protocol_classic()->get_vio()->mysql_socket, ++ PSI_SOCKET_STATE_IDLE); ++ MYSQL_START_IDLE_WAIT(thd->m_idle_psi, &thd->m_idle_state); ++ thd->m_server_idle = true; ++ } ++ ++ return retval; ++} ++ ++static void fix_threadpool_size(THD*, ++ struct SYS_VAR *, void*, const void* value) ++{ ++ threadpool_size = *static_cast(value); ++ tp_set_threadpool_size(threadpool_size); ++} ++ ++static void fix_threadpool_stall_limit(THD*, struct SYS_VAR *, void*, const void* value) ++{ ++ threadpool_stall_limit = *static_cast(value); ++ tp_set_threadpool_stall_limit(threadpool_stall_limit); ++} ++ ++static inline int my_getncpus() noexcept { ++#ifdef _SC_NPROCESSORS_ONLN ++ return sysconf(_SC_NPROCESSORS_ONLN); ++#else ++ return 2; /* The value returned by the old my_getncpus implementation */ ++#endif ++} ++ ++static MYSQL_SYSVAR_UINT(idle_timeout, threadpool_idle_timeout, ++ PLUGIN_VAR_RQCMDARG, ++ "Timeout in seconds for an idle thread in the thread pool." ++ "Worker thread will be shut down after timeout", ++ NULL, NULL, 60, 1, UINT_MAX, 1); ++ ++static MYSQL_SYSVAR_UINT(oversubscribe, threadpool_oversubscribe, ++ PLUGIN_VAR_RQCMDARG, ++ "How many additional active worker threads in a group are allowed.", ++ NULL, NULL, 3, 1, 1000, 1); ++ ++static MYSQL_SYSVAR_UINT(toobusy, threadpool_toobusy, ++ PLUGIN_VAR_RQCMDARG, ++ "How many additional active and waiting worker threads in a group are allowed.", ++ NULL, NULL, 13, 1, 1000, 1); ++ ++static MYSQL_SYSVAR_BOOL(dedicated_listener, threadpool_dedicated_listener, ++ PLUGIN_VAR_RQCMDARG, ++ "Control whether listener be dedicated", nullptr, ++ nullptr, false); ++ ++static MYSQL_SYSVAR_UINT(size, threadpool_size, ++ PLUGIN_VAR_RQCMDARG, ++ "Number of thread groups in the pool. " ++ "This parameter is roughly equivalent to maximum number of concurrently " ++ "executing threads (threads in a waiting state do not count as executing).", ++ NULL, fix_threadpool_size, (uint)my_getncpus(), 1, MAX_THREAD_GROUPS, 1); ++ ++static MYSQL_SYSVAR_BOOL(sched_affinity, threadpool_sched_affinity, ++ PLUGIN_VAR_RQCMDARG, ++ "Control whether thread group scheduling affinity.", nullptr, ++ nullptr, false); ++ ++static MYSQL_SYSVAR_UINT(stall_limit, threadpool_stall_limit, ++ PLUGIN_VAR_RQCMDARG, ++ "Maximum query execution time in milliseconds," ++ "before an executing non-yielding thread is considered stalled." ++ "If a worker thread is stalled, additional worker thread " ++ "may be created to handle remaining clients.", ++ NULL, fix_threadpool_stall_limit, 500, 10, UINT_MAX, 1); ++ ++static MYSQL_SYSVAR_UINT(max_threads, threadpool_max_threads, ++ PLUGIN_VAR_RQCMDARG, ++ "Maximum allowed number of worker threads in the thread pool", ++ NULL, NULL, MAX_CONNECTIONS, 1, MAX_CONNECTIONS, 1); ++ ++static int threadpool_plugin_init(void *) ++{ ++ DBUG_ENTER("threadpool_plugin_init"); ++ ++ tp_init(); ++ my_connection_handler_set(&tp_chf, &tp_event_functions); ++ DBUG_RETURN(0); ++} ++ ++static int threadpool_plugin_deinit(void *) ++{ ++ DBUG_ENTER("threadpool_plugin_deinit"); ++ my_connection_handler_reset(); ++ DBUG_RETURN(0); ++} ++ ++static MYSQL_THDVAR_UINT(high_prio_tickets, ++ PLUGIN_VAR_RQCMDARG, ++ "Number of tickets to enter the high priority event queue for each " ++ "transaction.", ++ NULL, NULL, UINT_MAX, 0, UINT_MAX, 1); ++ ++const char *threadpool_high_prio_mode_names[] = {"transactions", "statements", ++ "none", NullS}; ++TYPELIB threadpool_high_prio_mode_typelib = { ++ array_elements(threadpool_high_prio_mode_names) - 1, "", ++ threadpool_high_prio_mode_names, NULL ++}; ++ ++static MYSQL_THDVAR_ENUM(high_prio_mode, ++ PLUGIN_VAR_RQCMDARG, ++ "High priority queue mode: one of 'transactions', 'statements' or 'none'. " ++ "In the 'transactions' mode the thread pool uses both high- and low-priority " ++ "queues depending on whether an event is generated by an already started " ++ "transaction and whether it has any high priority tickets (see " ++ "thread_pool_high_prio_tickets). In the 'statements' mode all events (i.e. " ++ "individual statements) always go to the high priority queue, regardless of " ++ "the current transaction state and high priority tickets. " ++ "'none' is the opposite of 'statements', i.e. disables the high priority queue " ++ "completely.", ++ NULL, NULL, TP_HIGH_PRIO_MODE_TRANSACTIONS, &threadpool_high_prio_mode_typelib); ++ ++static uint &idle_timeout = threadpool_idle_timeout; ++static bool &dedicated_listener = threadpool_dedicated_listener; ++static uint &size = threadpool_size; ++static bool &sched_affinity = threadpool_sched_affinity; ++static uint &stall_limit = threadpool_stall_limit; ++static uint &max_threads = threadpool_max_threads; ++static uint &oversubscribe = threadpool_oversubscribe; ++static uint &toobusy = threadpool_toobusy; ++ ++SYS_VAR *system_variables[] = { ++ MYSQL_SYSVAR(idle_timeout), ++ MYSQL_SYSVAR(dedicated_listener), ++ MYSQL_SYSVAR(size), ++ MYSQL_SYSVAR(sched_affinity), ++ MYSQL_SYSVAR(max_threads), ++ MYSQL_SYSVAR(stall_limit), ++ MYSQL_SYSVAR(oversubscribe), ++ MYSQL_SYSVAR(toobusy), ++ MYSQL_SYSVAR(high_prio_tickets), ++ MYSQL_SYSVAR(high_prio_mode), ++ NULL ++}; ++ ++namespace Show { ++ ++static ST_FIELD_INFO groups_fields_info[] = ++{ ++ {"GROUP_ID", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"CONNECTIONS", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"THREADS", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"ACTIVE_THREADS", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"STANDBY_THREADS", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"QUEUE_LENGTH", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"HAS_LISTENER", 1, MYSQL_TYPE_TINY, 0, 0, 0, 0}, ++ {"IS_STALLED", 1, MYSQL_TYPE_TINY, 0, 0, 0, 0}, ++ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} ++}; ++ ++} // namespace Show ++ ++ ++static int groups_fill_table(THD* thd, TABLE_LIST* tables, Item*) ++{ ++ if (!all_groups) ++ return 0; ++ ++ TABLE* table = tables->table; ++ for (uint i = 0; i < MAX_THREAD_GROUPS && all_groups[i].pollfd != -1; i++) ++ { ++ thread_group_t* group = &all_groups[i]; ++ ++ mysql_mutex_lock(&group->mutex); ++ ++ /* ID */ ++ table->field[0]->store(i, true); ++ /* CONNECTION_COUNT */ ++ table->field[1]->store(group->connection_count, true); ++ /* THREAD_COUNT */ ++ table->field[2]->store(group->thread_count, true); ++ /* ACTIVE_THREAD_COUNT */ ++ table->field[3]->store(group->active_thread_count, true); ++ /* STANDBY_THREAD_COUNT */ ++ table->field[4]->store(group->waiting_thread_count, true); ++ /* QUEUE LENGTH */ ++ uint queue_len = group->high_prio_queue.elements() ++ + group->queue.elements(); ++ table->field[5]->store(queue_len, true); ++ /* HAS_LISTENER */ ++ table->field[6]->store((longlong)(group->listener != 0), true); ++ /* IS_STALLED */ ++ table->field[7]->store(group->stalled, true); ++ ++ mysql_mutex_unlock(&group->mutex); ++ ++ if (schema_table_store_record(thd, table)) ++ return 1; ++ } ++ return 0; ++} ++ ++ ++static int groups_init(void* p) ++{ ++ ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p; ++ schema->fields_info = Show::groups_fields_info; ++ schema->fill_table = groups_fill_table; ++ return 0; ++} ++ ++ ++namespace Show { ++ ++static ST_FIELD_INFO queues_field_info[] = ++{ ++ {"GROUP_ID", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"POSITION", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"PRIORITY", 1, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"CONNECTION_ID", 19, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, 0, 0}, ++ {"QUEUEING_TIME_MICROSECONDS", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} ++}; ++ ++} // namespace Show ++ ++typedef connection_queue_t::Iterator connection_queue_iterator; ++ ++static int queues_fill_table(THD* thd, TABLE_LIST* tables, Item*) ++{ ++ if (!all_groups) ++ return 0; ++ ++ TABLE* table = tables->table; ++ for (uint group_id = 0; ++ group_id < MAX_THREAD_GROUPS && all_groups[group_id].pollfd != -1; ++ group_id++) ++ { ++ thread_group_t* group = &all_groups[group_id]; ++ ++ mysql_mutex_lock(&group->mutex); ++ bool err = false; ++ int pos = 0; ++ ulonglong now = my_microsecond_getsystime(); ++ connection_queue_t queues[NQUEUES] = {group->high_prio_queue, group->queue}; ++ for (uint prio = 0; prio < NQUEUES && !err; prio++) ++ { ++ connection_queue_iterator it(queues[prio]); ++ connection_t* c; ++ while ((c = it++) != nullptr) ++ { ++ /* GROUP_ID */ ++ table->field[0]->store(group_id, true); ++ /* POSITION */ ++ table->field[1]->store(pos++, true); ++ /* PRIORITY */ ++ table->field[2]->store(prio, true); ++ /* CONNECTION_ID */ ++ if (c->thd != nullptr) { ++ table->field[3]->store(c->thd->thread_id(), true); ++ } else { ++ table->field[3]->store(0, true); ++ } ++ /* QUEUEING_TIME */ ++ table->field[4]->store(now - c->enqueue_time, true); ++ ++ err = schema_table_store_record(thd, table); ++ if (err) ++ break; ++ } ++ } ++ mysql_mutex_unlock(&group->mutex); ++ if (err) ++ return 1; ++ } ++ return 0; ++} ++ ++static int queues_init(void* p) ++{ ++ ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p; ++ schema->fields_info = Show::queues_field_info; ++ schema->fill_table = queues_fill_table; ++ return 0; ++} ++ ++namespace Show { ++ ++static ST_FIELD_INFO stats_fields_info[] = ++{ ++ {"GROUP_ID", 6, MYSQL_TYPE_LONG, 0, 0, 0, 0}, ++ {"THREAD_CREATIONS", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"THREAD_CREATIONS_DUE_TO_STALL", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"WAKES", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"WAKES_DUE_TO_STALL", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"THROTTLES", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"STALLS", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"POLLS_BY_LISTENER", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"POLLS_BY_WORKER", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"DEQUEUES_BY_LISTENER", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {"DEQUEUES_BY_WORKER", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} ++}; ++ ++} // namespace Show ++ ++ ++static int stats_fill_table(THD* thd, TABLE_LIST* tables, Item*) ++{ ++ if (!all_groups) ++ return 0; ++ ++ TABLE* table = tables->table; ++ for (uint i = 0; i < MAX_THREAD_GROUPS && all_groups[i].pollfd != -1; i++) ++ { ++ table->field[0]->store(i, true); ++ thread_group_t* group = &all_groups[i]; ++ ++ mysql_mutex_lock(&group->mutex); ++ thread_group_counters_t* counters = &group->counters; ++ table->field[1]->store(counters->thread_creations, true); ++ table->field[2]->store(counters->thread_creations_due_to_stall, true); ++ table->field[3]->store(counters->wakes, true); ++ table->field[4]->store(counters->wakes_due_to_stall, true); ++ table->field[5]->store(counters->throttles, true); ++ table->field[6]->store(counters->stalls, true); ++ table->field[7]->store(counters->polls[LISTENER], true); ++ table->field[8]->store(counters->polls[WORKER], true); ++ table->field[9]->store(counters->dequeues[LISTENER], true); ++ table->field[10]->store(counters->dequeues[WORKER], true); ++ mysql_mutex_unlock(&group->mutex); ++ if (schema_table_store_record(thd, table)) ++ return 1; ++ } ++ return 0; ++} ++ ++static int stats_init(void* p) ++{ ++ ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p; ++ schema->fields_info = Show::stats_fields_info; ++ schema->fill_table = stats_fill_table; ++ return 0; ++} ++ ++ ++namespace Show { ++ ++static ST_FIELD_INFO waits_fields_info[] = ++{ ++ {"REASON", 16, MYSQL_TYPE_STRING, 0, 0, 0, 0}, ++ {"COUNT", 19, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, ++ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} ++}; ++ ++} // namespace Show ++ ++/* See thd_wait_type enum for explanation*/ ++static const LEX_CSTRING wait_reasons[THD_WAIT_LAST] = ++{ ++ {STRING_WITH_LEN("UNKNOWN")}, ++ {STRING_WITH_LEN("SLEEP")}, ++ {STRING_WITH_LEN("DISKIO")}, ++ {STRING_WITH_LEN("ROW_LOCK")}, ++ {STRING_WITH_LEN("GLOBAL_LOCK")}, ++ {STRING_WITH_LEN("META_DATA_LOCK")}, ++ {STRING_WITH_LEN("TABLE_LOCK")}, ++ {STRING_WITH_LEN("USER_LOCK")}, ++ {STRING_WITH_LEN("BINLOG")}, ++ {STRING_WITH_LEN("GROUP_COMMIT")}, ++ {STRING_WITH_LEN("SYNC")} ++}; ++ ++extern std::atomic tp_waits[THD_WAIT_LAST]; ++ ++static int waits_fill_table(THD* thd, TABLE_LIST* tables, Item*) ++{ ++ if (!all_groups) ++ return 0; ++ ++ TABLE* table = tables->table; ++ for (unsigned int i = 0; i < THD_WAIT_LAST; i++) ++ { ++ table->field[0]->store(wait_reasons[i].str, wait_reasons[i].length, system_charset_info); ++ table->field[1]->store(tp_waits[i], true); ++ if (schema_table_store_record(thd, table)) ++ return 1; ++ } ++ return 0; ++} ++ ++static int waits_init(void* p) ++{ ++ ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*)p; ++ schema->fields_info = Show::waits_fields_info; ++ schema->fill_table = waits_fill_table; ++ return 0; ++} ++ ++struct st_mysql_daemon thread_pool_plugin = ++{ MYSQL_DAEMON_INTERFACE_VERSION }; ++ ++static struct st_mysql_information_schema plugin_descriptor = ++{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; ++ ++mysql_declare_plugin(thread_pool) ++{ ++ MYSQL_DAEMON_PLUGIN, ++ &thread_pool_plugin, ++ "thread_pool", ++ "TEST_TEST", ++ "thread pool plugin extracted from percona server", ++ PLUGIN_LICENSE_GPL, ++ threadpool_plugin_init, /* Plugin Init */ ++ nullptr, /* Plugin Check uninstall */ ++ threadpool_plugin_deinit, /* Plugin Deinit */ ++ 0x0100 /* 1.0 */, ++ nullptr, /* status variables */ ++ system_variables, /* system variables */ ++ nullptr, /* config options */ ++ 0, /* flags */ ++}, ++{ ++ MYSQL_INFORMATION_SCHEMA_PLUGIN, ++ &plugin_descriptor, ++ "THREAD_POOL_GROUPS", ++ "Vladislav Vaintroub", ++ "Provides information about threadpool groups.", ++ PLUGIN_LICENSE_GPL, ++ groups_init, ++ nullptr, ++ nullptr, ++ 0x0100, ++ nullptr, ++ nullptr, ++ nullptr, ++ 0, ++}, ++{ ++ MYSQL_INFORMATION_SCHEMA_PLUGIN, ++ &plugin_descriptor, ++ "THREAD_POOL_QUEUES", ++ "Vladislav Vaintroub", ++ "Provides information about threadpool queues.", ++ PLUGIN_LICENSE_GPL, ++ queues_init, ++ nullptr, ++ nullptr, ++ 0x0100, ++ nullptr, ++ nullptr, ++ nullptr, ++ 0, ++}, ++{ ++ MYSQL_INFORMATION_SCHEMA_PLUGIN, ++ &plugin_descriptor, ++ "THREAD_POOL_STATS", ++ "Vladislav Vaintroub", ++ "Provides performance counter information for threadpool.", ++ PLUGIN_LICENSE_GPL, ++ stats_init, ++ nullptr, ++ nullptr, ++ 0x0100, ++ nullptr, ++ nullptr, ++ nullptr, ++ 0, ++}, ++{ ++ MYSQL_INFORMATION_SCHEMA_PLUGIN, ++ &plugin_descriptor, ++ "THREAD_POOL_WAITS", ++ "Vladislav Vaintroub", ++ "Provides wait counters for threadpool.", ++ PLUGIN_LICENSE_GPL, ++ waits_init, ++ nullptr, ++ nullptr, ++ 0x0100, ++ nullptr, ++ nullptr, ++ nullptr, ++ 0, ++} ++mysql_declare_plugin_end; ++ ++uint tp_get_thdvar_high_prio_tickets(THD *thd) { ++ return THDVAR(thd, high_prio_tickets); ++} ++ ++uint tp_get_thdvar_high_prio_mode(THD *thd) { ++ return THDVAR(thd, high_prio_mode); ++} ++ +diff --git a/plugin/thread_pool/threadpool_unix.cc b/plugin/thread_pool/threadpool_unix.cc +new file mode 100644 +index 00000000000..a9fdf3dbfcd +--- /dev/null ++++ b/plugin/thread_pool/threadpool_unix.cc +@@ -0,0 +1,1794 @@ ++/* Copyright (C) 2012 Monty Program Ab ++ Copyright (C) 2022 Huawei Technologies Co., Ltd ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; version 2 of the License. ++ ++ This program 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 General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program; if not, write to the Free Software ++ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ++#include "threadpool_unix.h" ++#include "sql/debug_sync.h" ++#include "sql/log.h" ++#include "sql/protocol_classic.h" ++#include "my_sys.h" ++#include "my_systime.h" ++#include "mysql/thread_pool_priv.h" // thd_is_transaction_active() ++#include "mysql/plugin.h" ++#include "threadpool.h" ++#include ++#include ++ ++#define MYSQL_SERVER 1 ++ ++/** Maximum number of native events a listener can read in one go */ ++#define MAX_EVENTS 1024 ++ ++/** Define if wait_begin() should create threads if necessary without waiting ++for stall detection to kick in */ ++#define THREADPOOL_CREATE_THREADS_ON_WAIT ++ ++/** Indicates that threadpool was initialized*/ ++static bool threadpool_started = false; ++ ++/* ++ Define PSI Keys for performance schema. ++ We have a mutex per group, worker threads, condition per worker thread, ++ and timer thread with its own mutex and condition. ++*/ ++ ++#ifdef HAVE_PSI_INTERFACE ++static PSI_mutex_key key_group_mutex; ++static PSI_mutex_key key_timer_mutex; ++static PSI_mutex_info mutex_list[] = { ++ {&key_group_mutex, "group_mutex", 0, 0, PSI_DOCUMENT_ME}, ++ {&key_timer_mutex, "timer_mutex", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}}; ++ ++static PSI_cond_key key_worker_cond; ++static PSI_cond_key key_timer_cond; ++static PSI_cond_info cond_list[] = { ++ {&key_worker_cond, "worker_cond", 0, 0, PSI_DOCUMENT_ME}, ++ {&key_timer_cond, "timer_cond", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}}; ++ ++static PSI_thread_key key_worker_thread; ++static PSI_thread_key key_timer_thread; ++static PSI_thread_info thread_list[] = { ++ {&key_worker_thread, "worker_thread", 0, 0, PSI_DOCUMENT_ME}, ++ {&key_timer_thread, "timer_thread", PSI_FLAG_SINGLETON, 0, ++ PSI_DOCUMENT_ME}}; ++#endif // HAVE_PSI_INTERFACE ++ ++thread_group_t all_groups[MAX_THREAD_GROUPS]; ++numa_affinity_manager group_affinity; ++ ++static uint group_count; ++ ++/** ++ Used for printing "pool blocked" message, see ++ print_pool_blocked_message(); ++*/ ++static ulonglong pool_block_start; ++ ++/* Global timer for all groups */ ++struct pool_timer_t { ++ mysql_mutex_t mutex; ++ mysql_cond_t cond; ++ std::atomic current_microtime; ++ std::atomic next_timeout_check; ++ int tick_interval; ++ bool shutdown; ++}; ++ ++static pool_timer_t pool_timer; ++ ++static void queue_put(thread_group_t *thread_group, connection_t *connection); ++static int wake_thread(thread_group_t *thread_group, ++ bool due_to_stall) noexcept; ++static void handle_event(connection_t *connection); ++static int wake_or_create_thread(thread_group_t *thread_group, ++ bool due_to_stall = false); ++static int create_worker(thread_group_t *thread_group, bool due_to_stall) noexcept; ++static void *admin_port_worker_main(void *param); ++static void *worker_main(void *param); ++static void *connection_detach_worker(void *param); ++static void check_stall(thread_group_t *thread_group); ++static void connection_abort(connection_t *connection); ++static void set_next_timeout_check(ulonglong abstime); ++static void print_pool_blocked_message(bool) noexcept; ++ ++THD *thd_to_detach = nullptr; ++ ++class ThreadPoolConnSet { ++public: ++ ThreadPoolConnSet() {}; ++ virtual ~ThreadPoolConnSet() {}; ++ ++ bool empty() { ++ bool ret = false; ++ mtx.lock(); ++ ret = conns.empty(); ++ mtx.unlock(); ++ return ret; ++ } ++ ++ void killConns() { ++ mtx.lock(); ++ for (auto &it: conns) { ++ THD *thd = it->thd; ++ if (current_thd != thd && thd->killed != THD::KILL_CONNECTION) { ++ mysql_mutex_lock(&thd->LOCK_thd_data); ++ thd->killed = THD::KILL_CONNECTION; ++ tp_post_kill_notification(thd); ++ mysql_mutex_unlock(&thd->LOCK_thd_data); ++ } else if (current_thd == thd) { ++ thd_to_detach = thd; ++ } ++ } ++ mtx.unlock(); ++ } ++ ++ void insert(connection_t *c) { ++ mtx.lock(); ++ conns.insert(c); ++ mtx.unlock(); ++ } ++ ++ void erase(connection_t *c) { ++ mtx.lock(); ++ conns.erase(c); ++ mtx.unlock(); ++ } ++ ++public: ++ std::set conns; ++ std::mutex mtx; ++}; ++ ++ThreadPoolConnSet threadpool_thds; ++ ++int vio_cancel(Vio *vio, int how) ++{ ++ int r= 0; ++ DBUG_ENTER("vio_cancel"); ++ ++ if (vio->inactive == false) ++ { ++ assert(vio->type == VIO_TYPE_TCPIP || ++ vio->type == VIO_TYPE_SOCKET || ++ vio->type == VIO_TYPE_SSL); ++ ++ assert(mysql_socket_getfd(vio->mysql_socket) >= 0); ++ if (mysql_socket_shutdown(vio->mysql_socket, how)) ++ r= -1; ++ } ++ ++ DBUG_RETURN(r); ++} ++ ++/** ++ Asynchronous network IO. ++ ++ We use native edge-triggered network IO multiplexing facility. ++ This maps to different APIs on different Unixes. ++ ++ Supported are currently Linux with epoll, Solaris with event ports, ++ OSX and BSD with kevent. All those API's are used with one-shot flags ++ (the event is signalled once client has written something into the socket, ++ then socket is removed from the "poll-set" until the command is finished, ++ and we need to re-arm/re-register socket) ++ ++ No implementation for poll/select/AIO is currently provided. ++ ++ The API closely resembles all of the above mentioned platform APIs ++ and consists of following functions. ++ ++ - io_poll_create() ++ Creates an io_poll descriptor ++ On Linux: epoll_create() ++ ++ - io_poll_associate_fd(int poll_fd, int fd, void *data) ++ Associate file descriptor with io poll descriptor ++ On Linux : epoll_ctl(..EPOLL_CTL_ADD)) ++ ++ - io_poll_disassociate_fd(int pollfd, int fd) ++ Associate file descriptor with io poll descriptor ++ On Linux: epoll_ctl(..EPOLL_CTL_DEL) ++ ++ ++ - io_poll_start_read(int poll_fd,int fd, void *data) ++ The same as io_poll_associate_fd(), but cannot be used before ++ io_poll_associate_fd() was called. ++ On Linux : epoll_ctl(..EPOLL_CTL_MOD) ++ ++ - io_poll_wait (int pollfd, native_event *native_events, int maxevents, ++ int timeout_ms) ++ ++ wait until one or more descriptors added with io_poll_associate_fd() ++ or io_poll_start_read() becomes readable. Data associated with ++ descriptors can be retrieved from native_events array, using ++ native_event_get_userdata() function. ++ ++ ++ On Linux: epoll_wait() ++*/ ++ ++#if defined(__linux__) ++#ifndef EPOLLRDHUP ++/* Early 2.6 kernel did not have EPOLLRDHUP */ ++#define EPOLLRDHUP 0 ++#endif ++static int io_poll_create() noexcept { return epoll_create(1); } ++ ++static int io_poll_associate_fd(int pollfd, int fd, void *data) noexcept { ++ struct epoll_event ev; ++ ev.data.u64 = 0; /* Keep valgrind happy */ ++ ev.data.ptr = data; ++ ev.events = EPOLLIN | EPOLLET | EPOLLERR | EPOLLRDHUP | EPOLLONESHOT; ++ return epoll_ctl(pollfd, EPOLL_CTL_ADD, fd, &ev); ++} ++ ++static int io_poll_start_read(int pollfd, int fd, void *data) noexcept { ++ struct epoll_event ev; ++ ev.data.u64 = 0; /* Keep valgrind happy */ ++ ev.data.ptr = data; ++ ev.events = EPOLLIN | EPOLLET | EPOLLERR | EPOLLRDHUP | EPOLLONESHOT; ++ return epoll_ctl(pollfd, EPOLL_CTL_MOD, fd, &ev); ++} ++ ++static int io_poll_disassociate_fd(int pollfd, int fd) noexcept { ++ struct epoll_event ev; ++ return epoll_ctl(pollfd, EPOLL_CTL_DEL, fd, &ev); ++} ++ ++/* ++ Wrapper around epoll_wait. ++ NOTE - in case of EINTR, it restarts with original timeout. Since we use ++ either infinite or 0 timeouts, this is not critical ++*/ ++static int io_poll_wait(int pollfd, native_event *native_events, int maxevents, ++ int timeout_ms) noexcept { ++ int ret; ++ do { ++ ret = epoll_wait(pollfd, native_events, maxevents, timeout_ms); ++ } while (ret == -1 && errno == EINTR); ++ return ret; ++} ++ ++static void *native_event_get_userdata(native_event *event) noexcept { ++ return event->data.ptr; ++} ++ ++#elif defined(__FreeBSD__) || defined(__APPLE__) ++static int io_poll_create() noexcept { return kqueue(); } ++ ++static int io_poll_start_read(int pollfd, int fd, void *data) noexcept { ++ struct kevent ke; ++ EV_SET(&ke, fd, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, data); ++ return kevent(pollfd, &ke, 1, 0, 0, 0); ++} ++ ++static int io_poll_associate_fd(int pollfd, int fd, void *data) noexcept { ++ struct kevent ke; ++ EV_SET(&ke, fd, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, data); ++ return io_poll_start_read(pollfd, fd, data); ++} ++ ++static int io_poll_disassociate_fd(int pollfd, int fd) noexcept { ++ struct kevent ke; ++ EV_SET(&ke, fd, EVFILT_READ, EV_DELETE, 0, 0, nullptr); ++ return kevent(pollfd, &ke, 1, 0, 0, 0); ++} ++ ++static int io_poll_wait(int pollfd, struct kevent *events, int maxevents, ++ int timeout_ms) noexcept { ++ struct timespec ts; ++ int ret; ++ if (timeout_ms >= 0) { ++ ts.tv_sec = timeout_ms / 1000; ++ ts.tv_nsec = (timeout_ms % 1000) * 1000000; ++ } ++ do { ++ ret = kevent(pollfd, 0, 0, events, maxevents, ++ (timeout_ms >= 0) ? &ts : nullptr); ++ } while (ret == -1 && errno == EINTR); ++ return ret; ++} ++ ++static void *native_event_get_userdata(native_event *event) noexcept { ++ return event->udata; ++} ++#else ++#error not ported yet to this OS ++#endif ++ ++namespace { ++ ++/* ++ Prevent too many active threads executing at the same time, if the workload is ++ not CPU bound. ++*/ ++inline bool too_many_active_threads( ++ const thread_group_t &thread_group) noexcept { ++ return (thread_group.active_thread_count >= ++ 1 + (int)threadpool_oversubscribe && ++ !thread_group.stalled); ++} ++ ++/* ++ Limit the number of 'busy' threads by 1 + threadpool_toobusy. A thread ++ is busy if it is in either the active state or the waiting state (i.e. between ++ thd_wait_begin() / thd_wait_end() calls). ++*/ ++inline bool too_many_busy_threads(const thread_group_t &thread_group) noexcept { ++ return (thread_group.active_thread_count + thread_group.waiting_thread_count > ++ 1 + (int)threadpool_toobusy); ++} ++ ++inline bool too_many_connection(const thread_group_t &thread_group) noexcept { ++ return (thread_group.connection_count > (int)threadpool_toobusy - 1); ++} ++ ++/* ++ Checks if a given connection is eligible to enter the high priority queue ++ based on its current thread_pool_high_prio_mode value, available high ++ priority tickets and transactional state and whether any locks are held. ++*/ ++inline bool connection_is_high_prio(const connection_t &c) noexcept { ++ const ulong mode = tp_get_thdvar_high_prio_mode(c.thd); ++ ++ return (mode == TP_HIGH_PRIO_MODE_STATEMENTS) || ++ (mode == TP_HIGH_PRIO_MODE_TRANSACTIONS && c.tickets > 0 && ++ (thd_is_transaction_active(c.thd) || ++ c.thd->variables.option_bits & OPTION_TABLE_LOCK || ++ c.thd->locked_tables_mode != LTM_NONE || ++ c.thd->mdl_context.has_locks() || ++ c.thd->global_read_lock.is_acquired() || ++ c.thd->mdl_context.has_locks(MDL_key::USER_LEVEL_LOCK) || ++ c.thd->mdl_context.has_locks(MDL_key::LOCKING_SERVICE))); ++} ++ ++inline bool connection_is_worker_continue(const connection_t &c) noexcept { ++ if (c.thd->is_admin_connection()) { ++ return true; ++ } ++ ++ if (c.thread_group != &all_groups[c.thd->thread_id() % group_count]) { ++ return false; ++ } ++ ++ if (!too_many_connection(*(c.thread_group))) { ++ return true; ++ } ++ ++ const ulong mode = tp_get_thdvar_high_prio_mode(c.thd); ++ bool ret = (mode == TP_HIGH_PRIO_MODE_TRANSACTIONS && c.tickets > 0 && ++ (thd_is_transaction_active(c.thd) || ++ c.thd->variables.option_bits & OPTION_TABLE_LOCK || ++ c.thd->locked_tables_mode != LTM_NONE || ++ c.thd->mdl_context.has_locks() || ++ c.thd->global_read_lock.is_acquired() || ++ c.thd->mdl_context.has_locks(MDL_key::USER_LEVEL_LOCK) || ++ c.thd->mdl_context.has_locks(MDL_key::LOCKING_SERVICE))); ++ return ret; ++} ++ ++} // namespace ++ ++/* Dequeue element from a workqueue */ ++static connection_t *queue_get(thread_group_t *thread_group) noexcept { ++ DBUG_ENTER("queue_get"); ++ thread_group->queue_event_count++; ++ connection_t *c; ++ ++ if ((c = thread_group->high_prio_queue.front())) { ++ thread_group->high_prio_queue.remove(c); ++ } ++ /* ++ Don't pick events from the low priority queue if there are too many ++ active + waiting threads. ++ */ ++ else if (!too_many_busy_threads(*thread_group) && ++ (c = thread_group->queue.front())) { ++ thread_group->queue.remove(c); ++ } ++ DBUG_RETURN(c); ++} ++ ++static connection_t *queue_get(thread_group_t *group, operation_origin origin) { ++ connection_t *ret = queue_get(group); ++ if (ret != nullptr) { ++ TP_INCREMENT_GROUP_COUNTER(group, dequeues[(int)origin]); ++ } ++ return ret; ++} ++ ++static inline void queue_push(thread_group_t *thread_group, connection_t *connection) ++{ ++ connection->enqueue_time= pool_timer.current_microtime; ++ thread_group->queue.push_back(connection); ++} ++ ++static inline void high_prio_queue_push(thread_group_t *thread_group, connection_t *connection) ++{ ++ connection->enqueue_time= pool_timer.current_microtime; ++ thread_group->high_prio_queue.push_back(connection); ++} ++ ++class Thd_timeout_checker : public Do_THD_Impl { ++ private: ++ pool_timer_t *const m_timer; ++ ++ public: ++ Thd_timeout_checker(pool_timer_t *timer) noexcept : m_timer(timer) {} ++ ++ virtual ~Thd_timeout_checker() {} ++ ++ virtual void operator()(THD *thd) noexcept { ++ if (thd_get_net_read_write(thd) != 1) return; ++ ++ connection_t *connection = (connection_t *)thd->scheduler.data; ++ if (!connection) return; ++ ++ if (connection->abs_wait_timeout < ++ m_timer->current_microtime.load(std::memory_order_relaxed)) { ++ /* Wait timeout exceeded, kill connection. */ ++ mysql_mutex_lock(&thd->LOCK_thd_data); ++ thd->killed = THD::KILL_CONNECTION; ++ tp_post_kill_notification(thd); ++ mysql_mutex_unlock(&thd->LOCK_thd_data); ++ } else { ++ set_next_timeout_check(connection->abs_wait_timeout); ++ } ++ } ++}; ++ ++/* ++ Handle wait timeout : ++ Find connections that have been idle for too long and kill them. ++ Also, recalculate time when next timeout check should run. ++*/ ++static void timeout_check(pool_timer_t *timer) { ++ DBUG_ENTER("timeout_check"); ++ ++ /* Reset next timeout check, it will be recalculated in the loop below */ ++ timer->next_timeout_check.store(ULLONG_MAX, std::memory_order_relaxed); ++ ++ Thd_timeout_checker thd_timeout_checker(timer); ++ Global_THD_manager::get_instance()->do_for_all_thd_copy(&thd_timeout_checker); ++ ++ DBUG_VOID_RETURN; ++} ++ ++/* ++ Timer thread. ++ ++ Periodically, check if one of the thread groups is stalled. Stalls happen if ++ events are not being dequeued from the queue, or from the network, Primary ++ reason for stall can be a lengthy executing non-blocking request. It could ++ also happen that thread is waiting but wait_begin/wait_end is forgotten by ++ storage engine. Timer thread will create a new thread in group in case of ++ a stall. ++ ++ Besides checking for stalls, timer thread is also responsible for terminating ++ clients that have been idle for longer than wait_timeout seconds. ++ ++ TODO: Let the timer sleep for long time if there is no work to be done. ++ Currently it wakes up rather often on and idle server. ++*/ ++static void *timer_thread(void *param) noexcept { ++ my_thread_init(); ++ DBUG_ENTER("timer_thread"); ++ ++ pool_timer_t *timer = (pool_timer_t *)param; ++ timer->next_timeout_check.store(ULLONG_MAX, std::memory_order_relaxed); ++ timer->current_microtime.store(my_microsecond_getsystime(), ++ std::memory_order_relaxed); ++ ++ for (;;) { ++ struct timespec ts; ++ ++ set_timespec_nsec(&ts, timer->tick_interval * 1000000ULL); ++ mysql_mutex_lock(&timer->mutex); ++ int err = mysql_cond_timedwait(&timer->cond, &timer->mutex, &ts); ++ if (timer->shutdown) { ++ mysql_mutex_unlock(&timer->mutex); ++ break; ++ } ++ if (err == ETIMEDOUT) { ++ timer->current_microtime.store(my_microsecond_getsystime(), ++ std::memory_order_relaxed); ++ ++ /* Check stalls in thread groups */ ++ for (size_t i = 0; i < array_elements(all_groups); i++) { ++ if (all_groups[i].connection_count) check_stall(&all_groups[i]); ++ } ++ ++ /* Check if any client exceeded wait_timeout */ ++ if (timer->next_timeout_check.load(std::memory_order_relaxed) <= ++ timer->current_microtime.load(std::memory_order_relaxed)) ++ timeout_check(timer); ++ } ++ mysql_mutex_unlock(&timer->mutex); ++ } ++ ++ mysql_mutex_destroy(&timer->mutex); ++ my_thread_end(); ++ return nullptr; ++} ++ ++/* ++ Check if both the high and low priority queues are empty. ++ ++ NOTE: we also consider the low priority queue empty in case it has events, but ++ they cannot be processed due to the too_many_busy_threads() limit. ++*/ ++static bool queues_are_empty(const thread_group_t &tg) noexcept { ++ return (tg.high_prio_queue.is_empty() && ++ (tg.queue.is_empty() || too_many_busy_threads(tg))); ++} ++ ++static void check_stall(thread_group_t *thread_group) { ++ if (mysql_mutex_trylock(&thread_group->mutex) != 0) { ++ /* Something happens. Don't disturb */ ++ return; ++ } ++ ++ /* ++ Check if listener is present. If not, check whether any IO ++ events were dequeued since last time. If not, this means ++ listener is either in tight loop or thd_wait_begin() ++ was forgotten. Create a new worker(it will make itself listener). ++ */ ++ if (!thread_group->listener && !thread_group->io_event_count) { ++ wake_or_create_thread(thread_group, true); ++ mysql_mutex_unlock(&thread_group->mutex); ++ return; ++ } ++ ++ /* Reset io event count */ ++ thread_group->io_event_count = 0; ++ ++ /* ++ Check whether requests from the workqueues are being dequeued. ++ ++ The stall detection and resolution works as follows: ++ ++ 1. There is a counter thread_group->queue_event_count for the number of ++ events removed from the queues. Timer resets the counter to 0 on each ++ run. ++ 2. Timer determines stall if this counter remains 0 since last check ++ and at least one of the high and low priority queues is not empty. ++ 3. Once timer determined a stall it sets thread_group->stalled flag and ++ wakes and idle worker (or creates a new one, subject to throttling). ++ 4. The stalled flag is reset, when an event is dequeued. ++ ++ Q : Will this handling lead to an unbound growth of threads, if queues ++ stall permanently? ++ A : No. If queues stall permanently, it is an indication for many very long ++ simultaneous queries. The maximum number of simultanoues queries is ++ max_connections, further we have threadpool_max_threads limit, upon which no ++ worker threads are created. So in case there is a flood of very long ++ queries, threadpool would slowly approach thread-per-connection behavior. ++ NOTE: ++ If long queries never wait, creation of the new threads is done by timer, ++ so it is slower than in real thread-per-connection. However if long queries ++ do wait and indicate that via thd_wait_begin/end callbacks, thread creation ++ will be faster. ++ */ ++ if (!thread_group->queue_event_count && !queues_are_empty(*thread_group)) { ++ thread_group->stalled = true; ++ TP_INCREMENT_GROUP_COUNTER(thread_group, stalls); ++ wake_or_create_thread(thread_group, true); ++ } ++ ++ /* Reset queue event count */ ++ thread_group->queue_event_count = 0; ++ ++ mysql_mutex_unlock(&thread_group->mutex); ++} ++ ++static void start_timer(pool_timer_t *timer) noexcept { ++ my_thread_handle thread_id; ++ DBUG_ENTER("start_timer"); ++ mysql_mutex_init(key_timer_mutex, &timer->mutex, nullptr); ++ mysql_cond_init(key_timer_cond, &timer->cond); ++ timer->shutdown = false; ++ mysql_thread_create(key_timer_thread, &thread_id, nullptr, timer_thread, timer); ++ DBUG_VOID_RETURN; ++} ++ ++static void stop_timer(pool_timer_t *timer) noexcept { ++ DBUG_ENTER("stop_timer"); ++ mysql_mutex_lock(&timer->mutex); ++ timer->shutdown = true; ++ mysql_cond_signal(&timer->cond); ++ mysql_mutex_unlock(&timer->mutex); ++ DBUG_VOID_RETURN; ++} ++ ++/** ++ Poll for socket events and distribute them to worker threads ++ In many case current thread will handle single event itself. ++ ++ @return a ready connection, or NULL on shutdown ++*/ ++static connection_t *listener(thread_group_t *thread_group) { ++ DBUG_ENTER("listener"); ++ connection_t *retval = nullptr; ++ ++ for (;;) { ++ if (thread_group->shutdown) break; ++ ++ native_event ev[MAX_EVENTS]; ++ int cnt = io_poll_wait(thread_group->pollfd, ev, MAX_EVENTS, -1); ++ ++ DBUG_EXECUTE_IF("threadpool_io_poll_wait_at_least_2_events", ++ { ++ while (cnt < 2) ++ { ++ int cnt_again = io_poll_wait(thread_group->pollfd, ev + cnt, MAX_EVENTS - cnt, -1); ++ cnt += cnt_again; ++ } ++ } ++ ); ++ ++ TP_INCREMENT_GROUP_COUNTER(thread_group, polls[LISTENER]); ++ if (cnt <= 0) { ++ assert(thread_group->shutdown); ++ break; ++ } ++ ++ mysql_mutex_lock(&thread_group->mutex); ++ ++ if (thread_group->shutdown) { ++ mysql_mutex_unlock(&thread_group->mutex); ++ break; ++ } ++ ++ thread_group->io_event_count += cnt; ++ ++ /* ++ We got some network events and need to make decisions : whether ++ listener hould handle events and whether or not any wake worker ++ threads so they can handle events. ++ ++ Q1 : Should listener handle an event itself, or put all events into ++ queue and let workers handle the events? ++ ++ Solution : ++ Generally, listener that handles events itself is preferable. We do not ++ want listener thread to change its state from waiting to running too ++ often, Since listener has just woken from poll, it better uses its time ++ slice and does some work. Besides, not handling events means they go to ++ the queue, and often to wake another worker must wake up to handle the ++ event. This is not good, as we want to avoid wakeups. ++ ++ The downside of listener that also handles queries is that we can ++ potentially leave thread group for long time not picking the new ++ network events. It is not a major problem, because this stall will be ++ detected sooner or later by the timer thread. Still, relying on timer ++ is not always good, because it may "tick" too slow (large timer_interval) ++ ++ We use following strategy to solve this problem - if queue was not empty ++ we suspect flood of network events and listener stays, Otherwise, it ++ handles a query. ++ ++ ++ Q2: If queue is not empty, how many workers to wake? ++ ++ Solution: ++ We generally try to keep one thread per group active (threads handling ++ queries are considered active, unless they stuck in inside some "wait") ++ Thus, we will wake only one worker, and only if there is not active ++ threads currently,and listener is not going to handle a query. When we ++ don't wake, we hope that currently active threads will finish fast and ++ handle the queue. If this does not happen, timer thread will detect stall ++ and wake a worker. ++ ++ NOTE: Currently nothing is done to detect or prevent long queuing times. ++ A solutionc for the future would be to give up "one active thread per ++ group" principle, if events stay in the queue for too long, and just wake ++ more workers. ++ */ ++ ++ const bool listener_picks_event = threadpool_dedicated_listener? false : ++ (thread_group->high_prio_queue.is_empty() && thread_group->queue.is_empty()); ++ ++ /* ++ If listener_picks_event is set, listener thread will handle first event, ++ and put the rest into the queue. If listener_pick_event is not set, all ++ events go to the queue. ++ */ ++ for (int i = (listener_picks_event) ? 1 : 0; i < cnt; i++) { ++ connection_t *c = (connection_t *)native_event_get_userdata(&ev[i]); ++ if (connection_is_high_prio(*c)) { ++ c->tickets--; ++ thread_group->high_prio_queue.push_back(c); ++ } else { ++ c->tickets = tp_get_thdvar_high_prio_tickets(c->thd); ++ queue_push(thread_group, c); ++ } ++ } ++ ++ if (listener_picks_event) { ++ /* Handle the first event. */ ++ retval = (connection_t *)native_event_get_userdata(&ev[0]); ++ TP_INCREMENT_GROUP_COUNTER(thread_group, dequeues[LISTENER]); ++ mysql_mutex_unlock(&thread_group->mutex); ++ break; ++ } ++ ++ /* The remaining threads can be created at most */ ++ int workers_in_need = (int)threadpool_toobusy - ++ thread_group->active_thread_count - thread_group->waiting_thread_count; ++ ++ /* There are no remaining threads and the thread group is stalled */ ++ if (workers_in_need <= 0 && thread_group->active_thread_count == 0) { ++ workers_in_need = 1; ++ } ++ ++ /* The number of threads that can be created and ++ the number of threads that are really needed, whichever is smaller */ ++ workers_in_need = workers_in_need > cnt ? cnt : workers_in_need; ++ ++ /* Wake up or create the required threads */ ++ for (int i = 0; i < workers_in_need; i++) { ++ /* We added some work items to queue, now wake a worker. */ ++ if (wake_thread(thread_group, false)) { ++ /* ++ Wake failed, hence groups has no idle threads. Now check if there are ++ any threads in the group except listener. ++ In order to achieve the best running performance of the ++ number of threads, the conditions for the wake-up or ++ creation of worker threads are relaxed. ++ The queue is not empty, and listener is not going to handle ++ events. In order to drain the queue, we create a worker here. ++ Alternatively, we could just rely on timer to detect stall, and ++ create thread, but waiting for timer would be an inefficient and ++ pointless delay. ++ */ ++ create_worker(thread_group, false); ++ } ++ } ++ mysql_mutex_unlock(&thread_group->mutex); ++ } ++ DBUG_RETURN(retval); ++} ++ ++/** ++ Adjust thread counters in group or global ++ whenever thread is created or is about to exit ++ ++ @param thread_group ++ @param count - 1, when new thread is created ++ -1, when thread is about to exit ++*/ ++static void add_thread_count(thread_group_t *thread_group, ++ int32 count) noexcept { ++ thread_group->thread_count += count; ++ /* worker starts out and end in "active" state */ ++ thread_group->active_thread_count += count; ++ tp_stats.num_worker_threads.fetch_add(count, std::memory_order_relaxed); ++} ++ ++/** ++ Creates a new worker thread. ++ thread_mutex must be held when calling this function ++ ++ NOTE: in rare cases, the number of threads can exceed ++ threadpool_max_threads, because we need at least 2 threads ++ per group to prevent deadlocks (one listener + one worker) ++*/ ++static int create_worker(thread_group_t *thread_group, ++ bool due_to_stall) noexcept { ++ my_thread_handle thread_id; ++ bool max_threads_reached = false; ++ int err; ++ ++ DBUG_ENTER("create_worker"); ++ if (tp_stats.num_worker_threads.load(std::memory_order_relaxed) >= ++ (int)threadpool_max_threads && ++ thread_group->thread_count >= 2) { ++ err = 1; ++ max_threads_reached = true; ++ goto end; ++ } ++ ++ err = mysql_thread_create(key_worker_thread, &thread_id, ++ thread_group->pthread_attr, worker_main, ++ thread_group); ++ if (!err) { ++ thread_group->last_thread_creation_time = my_microsecond_getsystime(); ++ Global_THD_manager::get_instance()->inc_thread_created(); ++ add_thread_count(thread_group, 1); ++ TP_INCREMENT_GROUP_COUNTER(thread_group, thread_creations); ++ ++ if (due_to_stall) { ++ TP_INCREMENT_GROUP_COUNTER(thread_group, thread_creations_due_to_stall); ++ } ++ } else { ++ set_my_errno(errno); ++ } ++ ++end: ++ if (err) { ++ print_pool_blocked_message(max_threads_reached); ++ } else { ++ pool_block_start = 0; /* Reset pool blocked timer, if it was set */ ++ } ++ ++ DBUG_RETURN(err); ++} ++ ++/** ++ Calculate microseconds throttling delay for thread creation. ++ ++ The value depends on how many threads are already in the group: ++ small number of threads means no delay, the more threads the larger ++ the delay. ++ ++ The actual values were not calculated using any scientific methods. ++ They just look right, and behave well in practice. ++ ++ TODO: Should throttling depend on thread_pool_stall_limit? ++*/ ++static ulonglong microsecond_throttling_interval( ++ const thread_group_t &thread_group) noexcept { ++ const int count = thread_group.thread_count; ++ ++ if (count < 4) return 0; ++ ++ if (count < 8) return 50 * 1000; ++ ++ if (count < 16) return 100 * 1000; ++ ++ return 200 * 1000; ++} ++ ++/** ++ Wakes a worker thread, or creates a new one. ++ ++ Worker creation is throttled, so we avoid too many threads ++ to be created during the short time. ++*/ ++static int wake_or_create_thread(thread_group_t *thread_group, ++ bool due_to_stall) { ++ DBUG_ENTER("wake_or_create_thread"); ++ ++ if (thread_group->shutdown) DBUG_RETURN(0); ++ ++ if (wake_thread(thread_group, due_to_stall) == 0) DBUG_RETURN(0); ++ ++ if (thread_group->thread_count > thread_group->connection_count) ++ DBUG_RETURN(-1); ++ ++ /* In order to achieve the best running performance of the ++ number of threads, the conditions for the wake-up or ++ creation of worker threads are relaxed. */ ++ if (thread_group->active_thread_count < ++ (1 + (int)threadpool_oversubscribe)) { ++ /* ++ We're better off creating a new thread here with no delay, either there ++ are not enough active workers, or they all are all blocking and there was no ++ idle thread to wakeup. Smells like a potential deadlock or very slowly ++ executing requests, e.g sleeps or user locks. ++ */ ++ DBUG_RETURN(create_worker(thread_group, due_to_stall)); ++ } ++ ++ const ulonglong now = my_microsecond_getsystime(); ++ const ulonglong time_since_last_thread_created = ++ (now - thread_group->last_thread_creation_time); ++ ++ /* Throttle thread creation. */ ++ if (time_since_last_thread_created > ++ microsecond_throttling_interval(*thread_group)) { ++ DBUG_RETURN(create_worker(thread_group, due_to_stall)); ++ } ++ ++ TP_INCREMENT_GROUP_COUNTER(thread_group, throttles); ++ DBUG_RETURN(-1); ++} ++ ++static int thread_group_init(thread_group_t *thread_group, ++ pthread_attr_t *thread_attr) noexcept { ++ DBUG_ENTER("thread_group_init"); ++ thread_group->pthread_attr = thread_attr; ++ mysql_mutex_init(key_group_mutex, &thread_group->mutex, nullptr); ++ thread_group->pollfd = -1; ++ thread_group->shutdown_pipe[0] = -1; ++ thread_group->shutdown_pipe[1] = -1; ++ thread_group->thread_count = 0; ++ thread_group->admin_port_thread_count = 0; ++ thread_group->dump_thread_count = 0; ++ thread_group->active_thread_count = 0; ++ thread_group->connection_count = 0; ++ thread_group->waiting_thread_count = 0; ++ thread_group->io_event_count = 0; ++ thread_group->queue_event_count = 0; ++ thread_group->shutdown = false; ++ thread_group->stalled = false; ++ DBUG_RETURN(0); ++} ++ ++static void thread_group_destroy(thread_group_t *thread_group) noexcept { ++ mysql_mutex_destroy(&thread_group->mutex); ++ if (thread_group->pollfd != -1) { ++ close(thread_group->pollfd); ++ thread_group->pollfd = -1; ++ } ++ for (int i = 0; i < 2; i++) { ++ if (thread_group->shutdown_pipe[i] != -1) { ++ close(thread_group->shutdown_pipe[i]); ++ thread_group->shutdown_pipe[i] = -1; ++ } ++ } ++} ++ ++/** ++ Wake sleeping thread from waiting list ++*/ ++static int wake_thread(thread_group_t *thread_group, bool due_to_stall) noexcept { ++ DBUG_ENTER("wake_thread"); ++ worker_thread_t *thread = thread_group->waiting_threads.front(); ++ if (thread) { ++ thread->woken = true; ++ thread_group->waiting_threads.remove(thread); ++ mysql_cond_signal(&thread->cond); ++ TP_INCREMENT_GROUP_COUNTER(thread_group, wakes); ++ if (due_to_stall) { ++ TP_INCREMENT_GROUP_COUNTER(thread_group, wakes_due_to_stall); ++ } ++ DBUG_RETURN(0); ++ } ++ DBUG_RETURN(1); /* no thread in waiter list => missed wakeup */ ++} ++ ++/** ++ Shutdown for thread group ++*/ ++static void thread_group_close(thread_group_t *thread_group) noexcept { ++ DBUG_ENTER("thread_group_close"); ++ ++ mysql_mutex_lock(&thread_group->mutex); ++ if (thread_group->thread_count == 0) { ++ mysql_mutex_unlock(&thread_group->mutex); ++ thread_group_destroy(thread_group); ++ DBUG_VOID_RETURN; ++ } ++ ++ thread_group->shutdown = true; ++ thread_group->listener = nullptr; ++ ++ if (pipe(thread_group->shutdown_pipe)) { ++ mysql_mutex_unlock(&thread_group->mutex); ++ DBUG_VOID_RETURN; ++ } ++ ++ /* Wake listener */ ++ if (io_poll_associate_fd(thread_group->pollfd, ++ thread_group->shutdown_pipe[0], nullptr)) { ++ mysql_mutex_unlock(&thread_group->mutex); ++ DBUG_VOID_RETURN; ++ } ++ char c = 0; ++ if (write(thread_group->shutdown_pipe[1], &c, 1) < 0) { ++ mysql_mutex_unlock(&thread_group->mutex); ++ DBUG_VOID_RETURN; ++ } ++ ++ /* Wake all workers. */ ++ while (wake_thread(thread_group, false) == 0) { ++ } ++ ++ mysql_mutex_unlock(&thread_group->mutex); ++ DBUG_VOID_RETURN; ++} ++ ++/* ++ Add work to the queue. Maybe wake a worker if they all sleep. ++ ++ Currently, this function is only used when new connections need to ++ perform login (this is done in worker threads). ++*/ ++static void queue_put(thread_group_t *thread_group, connection_t *connection) { ++ DBUG_ENTER("queue_put"); ++ ++ mysql_mutex_lock(&thread_group->mutex); ++ connection->tickets = tp_get_thdvar_high_prio_tickets(connection->thd); ++ connection->enqueue_time = pool_timer.current_microtime; ++ ++ queue_push(thread_group, connection); ++ ++ /* In order to achieve the best running performance of the ++ number of threads, the conditions for the wake-up or ++ creation of worker threads are relaxed. */ ++ if (thread_group->active_thread_count < ++ 1 + (int)threadpool_oversubscribe) { ++ wake_or_create_thread(thread_group, false); ++ } ++ ++ mysql_mutex_unlock(&thread_group->mutex); ++ ++ DBUG_VOID_RETURN; ++} ++ ++/** ++ Retrieve a connection with pending event. ++ ++ Pending event in our case means that there is either a pending login request ++ (if connection is not yet logged in), or there are unread bytes on the socket. ++ ++ If there are no pending events currently, thread will wait. ++ If timeout specified in abstime parameter passes, the function returns nullptr. ++ ++ @param current_thread - current worker thread ++ @param thread_group - current thread group ++ @param abstime - absolute wait timeout ++ ++ @return ++ connection with pending event. ++ nullptr is returned if timeout has expired,or on shutdown. ++*/ ++static connection_t *get_event(worker_thread_t *current_thread, ++ thread_group_t *thread_group, ++ struct timespec *abstime) { ++ DBUG_ENTER("get_event"); ++ connection_t *connection = nullptr; ++ int err = 0; ++ ++ mysql_mutex_lock(&thread_group->mutex); ++ assert(thread_group->active_thread_count >= 0); ++ ++ for (;;) { ++ const bool oversubscribed = too_many_active_threads(*thread_group); ++ if (thread_group->shutdown) break; ++ ++ /* Check if queue is not empty */ ++ if (!oversubscribed) { ++ connection = queue_get(thread_group, WORKER); ++ if (connection) break; ++ } ++ ++ /* If there is currently no listener in the group, become one. */ ++ if (!thread_group->listener) { ++ thread_group->listener = current_thread; ++ thread_group->active_thread_count--; ++ mysql_mutex_unlock(&thread_group->mutex); ++ ++ connection = listener(thread_group); ++ ++ mysql_mutex_lock(&thread_group->mutex); ++ thread_group->active_thread_count++; ++ /* There is no listener anymore, it just returned. */ ++ thread_group->listener = nullptr; ++ break; ++ } ++ ++ /* ++ Last thing we try before going to sleep is to ++ pick a single event via epoll, without waiting (timeout 0) ++ */ ++ if (!oversubscribed) { ++ native_event nev; ++ if (io_poll_wait(thread_group->pollfd, &nev, 1, 0) == 1) { ++ thread_group->io_event_count++; ++ TP_INCREMENT_GROUP_COUNTER(thread_group, polls[WORKER]); ++ connection = (connection_t *)native_event_get_userdata(&nev); ++ ++ /* ++ Since we are going to perform an out-of-order event processing for the ++ connection, first check whether it is eligible for high priority ++ processing. We can get here even if there are queued events, so it ++ must either have a high priority ticket, or there must be not too many ++ busy threads (as if it was coming from a low priority queue). ++ */ ++ if (connection_is_high_prio(*connection)) ++ connection->tickets--; ++ else if (too_many_busy_threads(*thread_group)) { ++ /* ++ Not eligible for high priority processing. Restore tickets and put ++ it into the low priority queue. ++ */ ++ connection->tickets = tp_get_thdvar_high_prio_tickets(connection->thd); ++ thread_group->queue.push_back(connection); ++ connection = nullptr; ++ } ++ ++ if (connection) { ++ TP_INCREMENT_GROUP_COUNTER(thread_group, dequeues[WORKER]); ++ thread_group->queue_event_count++; ++ break; ++ } ++ } ++ } ++ ++ /* And now, finally sleep */ ++ current_thread->woken = false; /* wake() sets this to true */ ++ ++ /* ++ Add current thread to the head of the waiting list and wait. ++ It is important to add thread to the head rather than tail ++ as it ensures LIFO wakeup order (hot caches, working inactivity timeout) ++ */ ++ thread_group->waiting_threads.push_front(current_thread); ++ ++ thread_group->active_thread_count--; ++ if (abstime) { ++ err = mysql_cond_timedwait(¤t_thread->cond, &thread_group->mutex, ++ abstime); ++ } else { ++ err = mysql_cond_wait(¤t_thread->cond, &thread_group->mutex); ++ } ++ thread_group->active_thread_count++; ++ ++ if (!current_thread->woken) { ++ /* ++ Thread was not signalled by wake(), it might be a spurious wakeup or ++ a timeout. Anyhow, we need to remove ourselves from the list now. ++ If thread was explicitly woken, than caller removed us from the list. ++ */ ++ thread_group->waiting_threads.remove(current_thread); ++ } ++ ++ if (err) break; ++ } ++ ++ thread_group->stalled = false; ++ mysql_mutex_unlock(&thread_group->mutex); ++ ++ DBUG_RETURN(connection); ++} ++ ++/** ++ Tells the pool that worker starts waiting on IO, lock, condition, ++ sleep() or similar. ++*/ ++ ++static void wait_begin(thread_group_t *thread_group) noexcept { ++ DBUG_ENTER("wait_begin"); ++ mysql_mutex_lock(&thread_group->mutex); ++ thread_group->active_thread_count--; ++ thread_group->waiting_thread_count++; ++ ++ assert(thread_group->active_thread_count >= 0); ++ assert(thread_group->connection_count > 0); ++ ++#ifdef THREADPOOL_CREATE_THREADS_ON_WAIT ++ /* In order to achieve the best running performance of the ++ number of threads, the conditions for the wake-up or ++ creation of worker threads are relaxed. */ ++ if ((thread_group->active_thread_count < (1 + (int)threadpool_oversubscribe)) && ++ (!queues_are_empty(*thread_group) || !thread_group->listener)) { ++ /* ++ Group might stall while this thread waits, thus wake ++ or create a worker to prevent stall. ++ */ ++ wake_or_create_thread(thread_group); ++ } ++#endif ++ ++ mysql_mutex_unlock(&thread_group->mutex); ++ DBUG_VOID_RETURN; ++} ++ ++/** ++ Tells the pool has finished waiting. ++*/ ++static void wait_end(thread_group_t *thread_group) noexcept { ++ DBUG_ENTER("wait_end"); ++ mysql_mutex_lock(&thread_group->mutex); ++ thread_group->active_thread_count++; ++ thread_group->waiting_thread_count--; ++ mysql_mutex_unlock(&thread_group->mutex); ++ DBUG_VOID_RETURN; ++} ++ ++/** ++ Allocate/initialize a new connection structure. ++*/ ++ ++static connection_t *alloc_connection(THD *thd) noexcept { ++ DBUG_ENTER("alloc_connection"); ++ DBUG_EXECUTE_IF("simulate_tp_alloc_connection_oom", DBUG_RETURN(nullptr);); ++ ++ connection_t *connection = (connection_t *)my_malloc( ++ PSI_NOT_INSTRUMENTED /*key_memory_thread_pool_connection*/, ++ sizeof(connection_t), 0); ++ if (connection) { ++ connection->thd = thd; ++ connection->waiting = false; ++ connection->logged_in = false; ++ connection->bound_to_poll_descriptor = false; ++ connection->abs_wait_timeout = ULLONG_MAX; ++ connection->tickets = 0; ++ } ++ DBUG_RETURN(connection); ++} ++ ++/** ++ Add a new connection to thread pool.. ++*/ ++ ++bool tp_add_connection( ++ Channel_info *channel_info) { ++ DBUG_ENTER("Thread_pool_connection_handler::add_connection"); ++ ++ THD *const thd = channel_info->create_thd(); ++ ++ if (unlikely(!thd)) { ++ channel_info->send_error_and_close_channel(ER_OUT_OF_RESOURCES, 0, false); ++ DBUG_RETURN(true); ++ } ++ ++ connection_t *const connection = alloc_connection(thd); ++ ++ if (unlikely(!connection)) { ++ thd->get_protocol_classic()->end_net(); ++ delete thd; ++ // channel will be closed by send_error_and_close_channel() ++ channel_info->send_error_and_close_channel(ER_OUT_OF_RESOURCES, 0, false); ++ DBUG_RETURN(true); ++ } ++ ++ delete channel_info; ++ ++ thd->set_new_thread_id(); ++ thd->start_utime = my_micro_time(); ++ ++ threadpool_thds.insert(connection); ++ Global_THD_manager::get_instance()->add_thd(thd); ++ ++ thd->scheduler.data = connection; ++ ++ /* Assign connection to a group. */ ++ thread_group_t *group = &all_groups[thd->thread_id() % group_count]; ++ ++ connection->thread_group = group; ++ ++ if (thd->is_admin_connection()) { ++ my_thread_handle thread_id; ++ mysql_mutex_lock(&group->mutex); ++ int err = mysql_thread_create(key_worker_thread, &thread_id, ++ group->pthread_attr, admin_port_worker_main, connection); ++ ++ if (err) { ++ set_my_errno(errno); ++ print_pool_blocked_message(false); ++ } else { ++ group->admin_port_thread_count++; ++ } ++ mysql_mutex_unlock(&group->mutex); ++ } else { ++ mysql_mutex_lock(&group->mutex); ++ group->connection_count++; ++ mysql_mutex_unlock(&group->mutex); ++ ++ /* ++ Add connection to the work queue. Actual login ++ will be done by a worker thread. ++ */ ++ queue_put(group, connection); ++ } ++ ++ DBUG_RETURN(false); ++} ++ ++/** ++ Terminate connection. ++*/ ++static void connection_abort(connection_t *connection) { ++ DBUG_ENTER("connection_abort"); ++ threadpool_thds.erase(connection); ++ ++ thread_group_t *group = connection->thread_group; ++ bool is_admin_port = connection->thd->is_admin_connection(); ++ threadpool_remove_connection(connection->thd); ++ ++ if (!is_admin_port) { ++ mysql_mutex_lock(&group->mutex); ++ group->connection_count--; ++ mysql_mutex_unlock(&group->mutex); ++ } ++ ++ my_free(connection); ++ DBUG_VOID_RETURN; ++} ++ ++/** ++ Detach connection. ++*/ ++static void connection_detach(connection_t *connection) { ++ DBUG_ENTER("connection_detach"); ++ threadpool_thds.erase(connection); ++ ++ thread_group_t *group = connection->thread_group; ++ bool is_admin_port = connection->thd->is_admin_connection(); ++ Vio *const vio = connection->thd->get_protocol_classic()->get_vio(); ++ const int fd = mysql_socket_getfd(vio->mysql_socket); ++ mysql_mutex_lock(&group->mutex); ++ io_poll_disassociate_fd(group->pollfd, fd); ++ connection->bound_to_poll_descriptor = false; ++ mysql_mutex_unlock(&group->mutex); ++ ++ if (!is_admin_port) { ++ mysql_mutex_lock(&group->mutex); ++ group->connection_count--; ++ mysql_mutex_unlock(&group->mutex); ++ } ++ ++ my_thread_handle thread_id; ++ ++ if (mysql_thread_create(key_worker_thread, &thread_id, group->pthread_attr, ++ connection_detach_worker, connection->thd)) { ++ threadpool_remove_connection(connection->thd); ++ } ++ ++ my_free(connection); ++ DBUG_VOID_RETURN; ++} ++ ++ ++static void *connection_detach_worker(void *param) { ++ my_thread_init(); ++ DBUG_ENTER("connection_detach_worker"); ++ THD *thd = static_cast(param); ++ assert(thd != nullptr); ++ thread_attach(thd); ++ ++ while (1) { ++ if (threadpool_process_request(thd)) { ++ break; ++ } ++ } ++ ++ threadpool_remove_connection(thd); ++ return nullptr; ++} ++ ++/** ++ MySQL scheduler callback : kill connection ++*/ ++ ++void tp_post_kill_notification(THD *thd) noexcept { ++ DBUG_ENTER("tp_post_kill_notification"); ++ if (current_thd == thd || thd->system_thread) { ++ DBUG_VOID_RETURN; ++ } ++ ++ Vio *vio = thd->get_protocol_classic()->get_vio(); ++ if (vio) vio_cancel(vio, SHUT_RD); ++ DBUG_VOID_RETURN; ++} ++ ++alignas(CPU_LEVEL1_DCACHE_LINESIZE) std::atomic tp_waits[THD_WAIT_LAST]; ++ ++/** ++ MySQL scheduler callback: wait begin ++*/ ++void tp_wait_begin(THD *thd, int type MY_ATTRIBUTE((unused))) { ++ DBUG_ENTER("tp_wait_begin"); ++ ++ if (thd == nullptr) { ++ DBUG_VOID_RETURN; ++ } ++ ++ connection_t *connection = (connection_t *)thd->scheduler.data; ++ ++ if (connection && connection->thd && ++ !connection->thd->is_admin_connection()) { ++ assert(!connection->waiting); ++ connection->waiting = true; ++ assert(type > 0 && type < THD_WAIT_LAST); ++ tp_waits[type]++; ++ wait_begin(connection->thread_group); ++ } ++ DBUG_VOID_RETURN; ++} ++ ++/** ++ MySQL scheduler callback: wait end ++*/ ++ ++void tp_wait_end(THD *thd) { ++ DBUG_ENTER("tp_wait_end"); ++ ++ if (thd == nullptr) { ++ DBUG_VOID_RETURN; ++ } ++ connection_t *connection = (connection_t *)thd->scheduler.data; ++ ++ if (connection && connection->thd && ++ !connection->thd->is_admin_connection()) { ++ assert(connection->waiting); ++ connection->waiting = false; ++ wait_end(connection->thread_group); ++ } ++ DBUG_VOID_RETURN; ++} ++ ++static void set_next_timeout_check(ulonglong abstime) { ++ DBUG_ENTER("set_next_timeout_check"); ++ while (abstime < pool_timer.next_timeout_check.load()) { ++ uint64 old = pool_timer.next_timeout_check.load(); ++ pool_timer.next_timeout_check.compare_exchange_weak(old, abstime); ++ } ++ DBUG_VOID_RETURN; ++} ++ ++ ++ ++ inline ulong get_wait_timeout(THD *thd) noexcept { ++ return thd->variables.net_wait_timeout; ++ } ++ ++/** ++ Set wait timeout for connection. ++*/ ++ ++static void set_wait_timeout(connection_t *c) noexcept { ++ DBUG_ENTER("set_wait_timeout"); ++ /* ++ Calculate wait deadline for this connection. ++ Instead of using my_microsecond_getsystime() which has a syscall ++ overhead, use pool_timer.current_microtime and take ++ into account that its value could be off by at most ++ one tick interval. ++ */ ++ ++ c->abs_wait_timeout = ++ pool_timer.current_microtime.load(std::memory_order_relaxed) + ++ 1000LL * pool_timer.tick_interval + ++ 1000000LL * get_wait_timeout(c->thd); ++ ++ set_next_timeout_check(c->abs_wait_timeout); ++ DBUG_VOID_RETURN; ++} ++ ++/** ++ Handle a (rare) special case,where connection needs to ++ migrate to a different group because group_count has changed ++ after thread_pool_size setting. ++*/ ++ ++static int change_group(connection_t *c, thread_group_t *old_group, ++ thread_group_t *new_group) { ++ assert(c->thread_group == old_group); ++ ++ /* Remove connection from the old group. */ ++ if (c->bound_to_poll_descriptor) { ++ Vio *const vio = c->thd->get_protocol_classic()->get_vio(); ++ const int fd = mysql_socket_getfd(vio->mysql_socket); ++ mysql_mutex_lock(&old_group->mutex); ++ io_poll_disassociate_fd(old_group->pollfd, fd); ++ c->bound_to_poll_descriptor = false; ++ } else { ++ mysql_mutex_lock(&old_group->mutex); ++ } ++ c->thread_group->connection_count--; ++ mysql_mutex_unlock(&old_group->mutex); ++ ++ /* Add connection to the new group. */ ++ mysql_mutex_lock(&new_group->mutex); ++ c->thread_group = new_group; ++ new_group->connection_count++; ++ /* Ensure that there is a listener in the new group. */ ++ int ret = 0; ++ if (!new_group->thread_count) ret = create_worker(new_group, false); ++ mysql_mutex_unlock(&new_group->mutex); ++ return ret; ++} ++ ++static int start_io(connection_t *connection) { ++ /* ++ Usually, connection will stay in the same group for the entire ++ connection's life. However, we do allow group_count to ++ change at runtime, which means in rare cases when it changes is ++ connection should need to migrate to another group, this ensures ++ to ensure equal load between groups. ++ ++ So we recalculate in which group the connection should be, based ++ on thread_id and current group count, and migrate if necessary. ++ */ ++ thread_group_t *const group = ++ &all_groups[connection->thd->thread_id() % group_count]; ++ ++ if (group != connection->thread_group) { ++ if (change_group(connection, connection->thread_group, group)) return -1; ++ } ++ ++ /* ++ Bind to poll descriptor if not yet done. ++ */ ++ Vio *vio = connection->thd->get_protocol_classic()->get_vio(); ++ int fd = mysql_socket_getfd(vio->mysql_socket); ++ if (!connection->bound_to_poll_descriptor) { ++ connection->bound_to_poll_descriptor = true; ++ return io_poll_associate_fd(group->pollfd, fd, connection); ++ } ++ ++ return io_poll_start_read(group->pollfd, fd, connection); ++} ++ ++static void handle_event(connection_t *connection) { ++ DBUG_ENTER("handle_event"); ++ int err = 0; ++ ++ while (1) { ++ if (!connection->logged_in) { ++ err = threadpool_add_connection(connection->thd); ++ connection->logged_in = true; ++ } else { ++ err = threadpool_process_request(connection->thd); ++ } ++ ++ if (err) { ++ goto end; ++ } ++ ++ if (connection->thd == thd_to_detach) { ++ connection_detach(connection); ++ goto end_return; ++ } ++ ++ set_wait_timeout(connection); ++ ++ if (!connection_is_worker_continue(*connection)) { ++ break; ++ } ++ } ++ ++ if (!connection->thd->is_admin_connection()) { ++ err = start_io(connection); ++ } ++ ++end: ++ if (err || connection->thd->is_admin_connection()) { ++ connection_abort(connection); ++ } ++ ++end_return: ++ DBUG_VOID_RETURN; ++} ++ ++static void *admin_port_worker_main(void *param) { ++ my_thread_init(); ++ DBUG_ENTER("admin_port_worker_main"); ++ ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ PSI_THREAD_CALL(set_thread_account) ++ (nullptr, 0, nullptr, 0); ++#endif ++ ++ connection_t *connection = static_cast(param); ++ assert(connection != nullptr); ++ assert(connection->thread_group != nullptr); ++ thread_group_t *group = connection->thread_group; ++ ++ handle_event(connection); ++ ++ mysql_mutex_lock(&group->mutex); ++ group->admin_port_thread_count--; ++ mysql_mutex_unlock(&group->mutex); ++ ++ my_thread_end(); ++ return nullptr; ++} ++ ++/** ++ Worker thread's main ++*/ ++static void *worker_main(void *param) { ++ my_thread_init(); ++ ++ DBUG_ENTER("worker_main"); ++ ++ thread_group_t *thread_group = static_cast(param); ++ assert(thread_group != nullptr); ++ ++ if (threadpool_sched_affinity) { ++ group_affinity.bind_numa((thread_group - all_groups) / sizeof(thread_group_t)); ++ } ++ ++ /* Init per-thread structure */ ++ worker_thread_t this_thread; ++ mysql_cond_init(key_worker_cond, &this_thread.cond); ++ this_thread.thread_group = thread_group; ++ this_thread.event_count = 0; ++ ++#ifdef HAVE_PSI_THREAD_INTERFACE ++ PSI_THREAD_CALL(set_thread_account) ++ (nullptr, 0, nullptr, 0); ++#endif ++ ++ /* Run event loop */ ++ for (;;) { ++ struct timespec ts; ++ set_timespec(&ts, threadpool_idle_timeout); ++ connection_t *connection = get_event(&this_thread, thread_group, &ts); ++ ++ if (!connection) { ++ break; ++ } ++ ++ this_thread.event_count++; ++ handle_event(connection); ++ } ++ ++ /* Thread shutdown: cleanup per-worker-thread structure. */ ++ mysql_cond_destroy(&this_thread.cond); ++ ++ bool last_thread = false; /* last thread in group exits */ ++ mysql_mutex_lock(&thread_group->mutex); ++ add_thread_count(thread_group, -1); ++ last_thread= ((thread_group->thread_count == 0) && thread_group->shutdown); ++ mysql_mutex_unlock(&thread_group->mutex); ++ ++ /* Last thread in group exits and pool is terminating, destroy group.*/ ++ if (last_thread) { ++ thread_group_destroy(thread_group); ++ } ++ ++ my_thread_end(); ++ return nullptr; ++} ++ ++bool tp_init() { ++ DBUG_ENTER("tp_init"); ++ threadpool_started = true; ++ group_affinity.init(); ++ ++ for (uint i = 0; i < array_elements(all_groups); i++) { ++ thread_group_init(&all_groups[i], get_connection_attrib()); ++ } ++ tp_set_threadpool_size(threadpool_size); ++ if (group_count == 0) { ++ /* Something went wrong */ ++ sql_print_error("Can't set threadpool size to %d", threadpool_size); ++ DBUG_RETURN(true); ++ } ++#ifdef HAVE_PSI_INTERFACE ++ mysql_mutex_register("threadpool", mutex_list, array_elements(mutex_list)); ++ mysql_cond_register("threadpool", cond_list, array_elements(cond_list)); ++ mysql_thread_register("threadpool", thread_list, array_elements(thread_list)); ++#endif ++ ++ pool_timer.tick_interval = threadpool_stall_limit; ++ start_timer(&pool_timer); ++ DBUG_RETURN(false); ++} ++ ++void tp_end_thread() { ++ if (!threadpool_started) { ++ return; ++ } ++ ++ while (!threadpool_thds.empty()) { ++ my_sleep(10000); ++ } ++ ++ stop_timer(&pool_timer); ++ ++ for (uint i = 0; i < array_elements(all_groups); i++) { ++ thread_group_close(&all_groups[i]); ++ } ++ ++ threadpool_started = false; ++} ++ ++void tp_end() { ++ DBUG_ENTER("tp_end"); ++ threadpool_thds.killConns(); ++ ++ std::thread exit_tp(tp_end_thread); ++ exit_tp.detach(); ++ DBUG_VOID_RETURN; ++} ++ ++/** Ensure that poll descriptors are created when threadpool_size changes */ ++void tp_set_threadpool_size(uint size) noexcept { ++ if (!threadpool_started) return; ++ ++ bool success = true; ++ for (uint i = 0; i < size; i++) { ++ thread_group_t *group = &all_groups[i]; ++ mysql_mutex_lock(&group->mutex); ++ if (group->pollfd == -1) { ++ group->pollfd = io_poll_create(); ++ success = (group->pollfd >= 0); ++ if (!success) { ++ sql_print_error("io_poll_create() failed, errno=%d\n", errno); ++ break; ++ } ++ } ++ mysql_mutex_unlock(&all_groups[i].mutex); ++ if (!success) { ++ group_count = i; ++ return; ++ } ++ } ++ group_count = size; ++} ++ ++void tp_set_threadpool_stall_limit(uint limit) noexcept { ++ if (!threadpool_started) { ++ return; ++ } ++ ++ mysql_mutex_lock(&(pool_timer.mutex)); ++ pool_timer.tick_interval = limit; ++ mysql_mutex_unlock(&(pool_timer.mutex)); ++ mysql_cond_signal(&(pool_timer.cond)); ++} ++ ++/** ++ Calculate number of idle/waiting threads in the pool. ++ ++ Sum idle threads over all groups. ++ Don't do any locking, it is not required for stats. ++*/ ++int tp_get_idle_thread_count() noexcept { ++ int sum = 0; ++ for (uint i = 0; ++ i < array_elements(all_groups) && (all_groups[i].pollfd >= 0); i++) { ++ sum += (all_groups[i].thread_count - all_groups[i].active_thread_count); ++ } ++ return sum; ++} ++ ++/* Report threadpool problems */ ++ ++/** ++ Delay in microseconds, after which "pool blocked" message is printed. ++ (30 sec == 30 Mio usec) ++*/ ++#define BLOCK_MSG_DELAY 30 * 1000000 ++ ++#define MAX_THREADS_REACHED_MSG \ ++ "Threadpool could not create additional thread to handle queries, because the \ ++number of allowed threads was reached. Increasing 'thread_pool_max_threads' \ ++parameter can help in this situation.\n \ ++If 'admin_port' parameter is set, you can still connect to the database with \ ++superuser account (it must be TCP connection using admin_port as TCP port) \ ++and troubleshoot the situation. \ ++A likely cause of pool blocks are clients that lock resources for long time. \ ++'show processlist' or 'show engine innodb status' can give additional hints." ++ ++#define CREATE_THREAD_ERROR_MSG "Can't create threads in threadpool (errno=%d)." ++ ++/** ++ Write a message when blocking situation in threadpool occurs. ++ The message is written only when pool blocks for BLOCK_MSG_DELAY (30) seconds. ++ It will be just a single message for each blocking situation (to prevent ++ log flood). ++*/ ++static void print_pool_blocked_message(bool max_threads_reached) noexcept { ++ ulonglong now = my_microsecond_getsystime(); ++ static bool msg_written = false; ++ ++ if (pool_block_start == 0) { ++ pool_block_start = now; ++ msg_written = false; ++ } ++ ++ if (!msg_written && ((now > pool_block_start + BLOCK_MSG_DELAY) || ++ (now == pool_block_start))) { ++ if (max_threads_reached) ++ sql_print_error(MAX_THREADS_REACHED_MSG); ++ else ++ sql_print_error(CREATE_THREAD_ERROR_MSG, my_errno); ++ ++ if (now > pool_block_start) { ++ sql_print_information("Threadpool has been blocked for %u seconds\n", ++ (uint)((now - pool_block_start) / 1000000)); ++ } ++ /* avoid reperated messages for the same blocking situation */ ++ msg_written = true; ++ } ++} +diff --git a/plugin/thread_pool/threadpool_unix.h b/plugin/thread_pool/threadpool_unix.h +new file mode 100644 +index 00000000000..3c561f2da75 +--- /dev/null ++++ b/plugin/thread_pool/threadpool_unix.h +@@ -0,0 +1,135 @@ ++/* Copyright (C) 2012 Monty Program Ab ++ Copyright (C) 2022 Huawei Technologies Co., Ltd ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; version 2 of the License. ++ ++ This program 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 General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program; if not, write to the Free Software ++ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, ++ USA */ ++ ++#ifndef THREADPOOL_UNIX_H_ ++#define THREADPOOL_UNIX_H_ ++ ++#include "mysql/service_thd_wait.h" ++#include "sql/sql_plist.h" ++#include "sql/mysqld.h" ++#include "threadpool.h" ++#include "violite.h" ++#include "numa_affinity_manager.h" ++ ++#ifdef __linux__ ++#include ++typedef struct epoll_event native_event; ++#endif ++#if defined(__FreeBSD__) || defined(__APPLE__) ++#include ++typedef struct kevent native_event; ++#endif ++#if defined(__sun) ++#include ++typedef port_event_t native_event; ++#endif ++ ++#define my_microsecond_getsystime() (my_getsystime()/10) ++ ++struct thread_group_t; ++ ++/* Per-thread structure for workers */ ++struct worker_thread_t { ++ ulonglong event_count; /* number of request handled by this thread */ ++ thread_group_t *thread_group; ++ worker_thread_t *next_in_list; ++ worker_thread_t **prev_in_list; ++ ++ mysql_cond_t cond; ++ bool woken; ++}; ++ ++typedef I_P_List< ++ worker_thread_t, ++ I_P_List_adapter> ++ worker_list_t; ++ ++struct connection_t { ++ THD *thd; ++ thread_group_t *thread_group; ++ connection_t *next_in_queue; ++ connection_t **prev_in_queue; ++ ulonglong abs_wait_timeout; ++ ulonglong enqueue_time; ++ bool logged_in; ++ bool bound_to_poll_descriptor; ++ bool waiting; ++ uint tickets; ++}; ++ ++typedef I_P_List, ++ I_P_List_counter, I_P_List_fast_push_back> ++ connection_queue_t; ++ ++const int NQUEUES = 2; /* We have high and low priority queues */ ++ ++enum operation_origin ++{ ++ WORKER, ++ LISTENER ++}; ++ ++struct thread_group_counters_t ++{ ++ ulonglong thread_creations; ++ ulonglong thread_creations_due_to_stall; ++ ulonglong wakes; ++ ulonglong wakes_due_to_stall; ++ ulonglong throttles; ++ ulonglong stalls; ++ ulonglong dequeues[2]; ++ ulonglong polls[2]; ++}; ++ ++struct alignas(128) thread_group_t { ++ mysql_mutex_t mutex; ++ connection_queue_t queue; ++ connection_queue_t high_prio_queue; ++ worker_list_t waiting_threads; ++ worker_thread_t *listener; ++ pthread_attr_t *pthread_attr; ++ int pollfd; ++ int thread_count; ++ int admin_port_thread_count; ++ int dump_thread_count; ++ int active_thread_count; ++ int connection_count; ++ int waiting_thread_count; ++ /* Stats for the deadlock detection timer routine.*/ ++ int io_event_count; ++ int queue_event_count; ++ ulonglong last_thread_creation_time; ++ int shutdown_pipe[2]; ++ bool shutdown; ++ bool stalled; ++ thread_group_counters_t counters; ++ char padding[320 - sizeof(thread_group_counters_t)]; ++}; ++ ++static_assert(sizeof(thread_group_t) == 512, ++ "sizeof(thread_group_t) must be 512 to avoid false sharing"); ++ ++#define TP_INCREMENT_GROUP_COUNTER(group, var) do {group->counters.var++;}while(0) ++ ++extern thread_group_t all_groups[MAX_THREAD_GROUPS]; ++extern numa_affinity_manager group_affinity; ++ ++#endif // THREADPOOL_UNIX_H_ ++ diff --git a/KunpengBoostKit22.0.RC4-MTR-THREADPOOL-FOR-MySQL-8.0.25.patch b/KunpengBoostKit22.0.RC4-MTR-THREADPOOL-FOR-MySQL-8.0.25.patch new file mode 100644 index 000000000..a6e48b500 --- /dev/null +++ b/KunpengBoostKit22.0.RC4-MTR-THREADPOOL-FOR-MySQL-8.0.25.patch @@ -0,0 +1,5954 @@ +diff --git a/mysql-test/suite/thread_pool/r/pool_of_threads.result b/mysql-test/suite/thread_pool/r/pool_of_threads.result +new file mode 100644 +index 00000000000..28bb0ce569d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/pool_of_threads.result +@@ -0,0 +1,2278 @@ ++# restart:--plugin-load-add=thread_pool.so --thread_pool_size=2 --thread_pool_max_threads=2 --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --loose-skip-mysqlx ++drop table if exists t1,t2,t3,t4; ++CREATE TABLE t1 ( ++Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, ++Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL ++); ++Warnings: ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++INSERT INTO t1 VALUES (9410,9412); ++select period from t1; ++period ++9410 ++select * from t1; ++Period Varor_period ++9410 9412 ++select t1.* from t1; ++Period Varor_period ++9410 9412 ++CREATE TABLE t2 ( ++auto int not null auto_increment, ++fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL, ++companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL, ++fld3 char(30) DEFAULT '' NOT NULL, ++fld4 char(35) DEFAULT '' NOT NULL, ++fld5 char(35) DEFAULT '' NOT NULL, ++fld6 char(4) DEFAULT '' NOT NULL, ++UNIQUE fld1 (fld1), ++KEY fld3 (fld3), ++PRIMARY KEY (auto) ++); ++Warnings: ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++select t2.fld3 from t2 where companynr = 58 and fld3 like "%imaginable%"; ++fld3 ++imaginable ++select fld3 from t2 where fld3 like "%cultivation" ; ++fld3 ++cultivation ++select t2.fld3,companynr from t2 where companynr = 57+1 order by fld3; ++fld3 companynr ++concoct 58 ++druggists 58 ++engrossing 58 ++Eurydice 58 ++exclaimers 58 ++ferociousness 58 ++hopelessness 58 ++Huey 58 ++imaginable 58 ++judges 58 ++merging 58 ++ostrich 58 ++peering 58 ++Phelps 58 ++presumes 58 ++Ruth 58 ++sentences 58 ++Shylock 58 ++straggled 58 ++synergy 58 ++thanking 58 ++tying 58 ++unlocks 58 ++select fld3,companynr from t2 where companynr = 58 order by fld3; ++fld3 companynr ++concoct 58 ++druggists 58 ++engrossing 58 ++Eurydice 58 ++exclaimers 58 ++ferociousness 58 ++hopelessness 58 ++Huey 58 ++imaginable 58 ++judges 58 ++merging 58 ++ostrich 58 ++peering 58 ++Phelps 58 ++presumes 58 ++Ruth 58 ++sentences 58 ++Shylock 58 ++straggled 58 ++synergy 58 ++thanking 58 ++tying 58 ++unlocks 58 ++select fld3 from t2 order by fld3 desc limit 10; ++fld3 ++youthfulness ++yelped ++Wotan ++workers ++Witt ++witchcraft ++Winsett ++Willy ++willed ++wildcats ++select fld3 from t2 order by fld3 desc limit 5; ++fld3 ++youthfulness ++yelped ++Wotan ++workers ++Witt ++select fld3 from t2 order by fld3 desc limit 5,5; ++fld3 ++witchcraft ++Winsett ++Willy ++willed ++wildcats ++select t2.fld3 from t2 where fld3 = 'honeysuckle'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'honeysuckl_'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'hon_ysuckl_'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'honeysuckle%'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'h%le'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'honeysuckle_'; ++fld3 ++select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%'; ++fld3 ++explain select t2.fld3 from t2 where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ref fld3 fld3 120 const # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` IGNORE INDEX (`fld3`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` USE INDEX (`fld1`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ref fld3 fld3 120 const # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` USE INDEX (`fld3`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ref fld3 fld3 120 const # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` USE INDEX (`fld3`) USE INDEX (`fld1`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 ignore index (fld3,not_used); ++ERROR 42000: Key 'not_used' doesn't exist in table 't2' ++explain select fld3 from t2 use index (not_used); ++ERROR 42000: Key 'not_used' doesn't exist in table 't2' ++select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; ++fld3 ++honeysuckle ++honoring ++explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL range fld3 fld3 120 NULL # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where ((`test`.`t2`.`fld3` >= 'honeysuckle') and (`test`.`t2`.`fld3` <= 'honoring')) order by `test`.`t2`.`fld3` ++select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3; ++fld1 fld3 ++148504 Colombo ++068305 Colombo ++000000 nondecreasing ++select fld1,fld3 from t2 where companynr = 37 and fld3 = 'appendixes'; ++fld1 fld3 ++232605 appendixes ++1232605 appendixes ++1232606 appendixes ++1232607 appendixes ++1232608 appendixes ++1232609 appendixes ++select fld1 from t2 where fld1=250501 or fld1="250502"; ++fld1 ++250501 ++250502 ++explain select fld1 from t2 where fld1=250501 or fld1="250502"; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL range fld1 fld1 4 NULL # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld1` AS `fld1` from `test`.`t2` where ((`test`.`t2`.`fld1` = 250501) or (`test`.`t2`.`fld1` = 250502)) ++select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; ++fld1 ++250501 ++250502 ++250505 ++250601 ++explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL range fld1 fld1 4 NULL # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld1` AS `fld1` from `test`.`t2` where ((`test`.`t2`.`fld1` = 250501) or (`test`.`t2`.`fld1` = 250502) or ((`test`.`t2`.`fld1` >= 250505) and (`test`.`t2`.`fld1` <= 250601)) or (`test`.`t2`.`fld1` between 250501 and 250502)) ++select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%'; ++fld1 fld3 ++012001 flanking ++013602 foldout ++013606 fingerings ++018007 fanatic ++018017 featherweight ++018054 fetters ++018103 flint ++018104 flopping ++036002 funereal ++038017 fetched ++038205 firearm ++058004 Fenton ++088303 feminine ++186002 freakish ++188007 flurried ++188505 fitting ++198006 furthermore ++202301 Fitzpatrick ++208101 fiftieth ++208113 freest ++218008 finishers ++218022 feed ++218401 faithful ++226205 foothill ++226209 furnishings ++228306 forthcoming ++228311 fated ++231315 freezes ++232102 forgivably ++238007 filial ++238008 fixedly ++select fld3 from t2 where fld3 like "L%" and fld3 = "ok"; ++fld3 ++select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly"); ++fld3 ++Chantilly ++select fld1,fld3 from t2 where fld1 like "25050%"; ++fld1 fld3 ++250501 poisoning ++250502 Iraqis ++250503 heaving ++250504 population ++250505 bomb ++select fld1,fld3 from t2 where fld1 like "25050_"; ++fld1 fld3 ++250501 poisoning ++250502 Iraqis ++250503 heaving ++250504 population ++250505 bomb ++select distinct companynr from t2; ++companynr ++00 ++37 ++36 ++50 ++58 ++29 ++40 ++53 ++65 ++41 ++34 ++68 ++select distinct companynr from t2 order by companynr; ++companynr ++00 ++29 ++34 ++36 ++37 ++40 ++41 ++50 ++53 ++58 ++65 ++68 ++select distinct companynr from t2 order by companynr desc; ++companynr ++68 ++65 ++58 ++53 ++50 ++41 ++40 ++37 ++36 ++34 ++29 ++00 ++select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%"; ++fld3 period ++obliterates 9410 ++offload 9410 ++opaquely 9410 ++organizer 9410 ++overestimating 9410 ++overlay 9410 ++select distinct fld3 from t2 where companynr = 34 order by fld3; ++fld3 ++absentee ++accessed ++ahead ++alphabetic ++Asiaticizations ++attitude ++aye ++bankruptcies ++belays ++Blythe ++bomb ++boulevard ++bulldozes ++cannot ++caressing ++charcoal ++checksumming ++chess ++clubroom ++colorful ++cosy ++creator ++crying ++Darius ++diffusing ++duality ++Eiffel ++Epiphany ++Ernestine ++explorers ++exterminated ++famine ++forked ++Gershwins ++heaving ++Hodges ++Iraqis ++Italianization ++Lagos ++landslide ++libretto ++Majorca ++mastering ++narrowed ++occurred ++offerers ++Palestine ++Peruvianizes ++pharmaceutic ++poisoning ++population ++Pygmalion ++rats ++realest ++recording ++regimented ++retransmitting ++reviver ++rouses ++scars ++sicker ++sleepwalk ++stopped ++sugars ++translatable ++uncles ++unexpected ++uprisings ++versatility ++vest ++select distinct fld3 from t2 limit 10; ++fld3 ++abates ++abiding ++Abraham ++abrogating ++absentee ++abut ++accessed ++accruing ++accumulating ++accuracies ++select distinct fld3 from t2 having fld3 like "A%" limit 10; ++fld3 ++abates ++abiding ++Abraham ++abrogating ++absentee ++abut ++accessed ++accruing ++accumulating ++accuracies ++select distinct substring(fld3,1,3) from t2 where fld3 like "A%"; ++substring(fld3,1,3) ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++Adl ++adm ++Ado ++ads ++adv ++aer ++aff ++afi ++afl ++afo ++agi ++ahe ++aim ++air ++Ald ++alg ++ali ++all ++alp ++alr ++ama ++ame ++amm ++ana ++and ++ane ++Ang ++ani ++Ann ++Ant ++api ++app ++aqu ++Ara ++arc ++Arm ++arr ++Art ++Asi ++ask ++asp ++ass ++ast ++att ++aud ++Aug ++aut ++ave ++avo ++awe ++aye ++Azt ++select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10; ++a ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10; ++substring(fld3,1,3) ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10; ++a ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++create table t3 ( ++period int not null, ++name char(32) not null, ++companynr int not null, ++price double(11,0), ++price2 double(11,0), ++key (period), ++key (name) ++); ++Warnings: ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++create temporary table tmp select * from t3; ++Warnings: ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++alter table t3 add t2nr int not null auto_increment primary key first; ++drop table tmp; ++SET BIG_TABLES=1; ++select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10; ++namn ++Abraham Abraham ++abrogating abrogating ++admonishing admonishing ++Adolph Adolph ++afield afield ++aging aging ++ammonium ammonium ++analyzable analyzable ++animals animals ++animized animized ++SET BIG_TABLES=0; ++select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10; ++concat(fld3," ",fld3) ++Abraham Abraham ++abrogating abrogating ++admonishing admonishing ++Adolph Adolph ++afield afield ++aging aging ++ammonium ammonium ++analyzable analyzable ++animals animals ++animized animized ++select distinct fld5 from t2 limit 10; ++fld5 ++neat ++Steinberg ++jarring ++tinily ++balled ++persist ++attainments ++fanatic ++measures ++rightfulness ++select distinct companynr, fld3,count(*) from t2 group by companynr,fld3 order by companynr, fld3 limit 10; ++companynr fld3 count(*) ++00 affixed 1 ++00 and 1 ++00 annoyers 1 ++00 Anthony 1 ++00 assayed 1 ++00 assurers 1 ++00 attendants 1 ++00 bedlam 1 ++00 bedpost 1 ++00 boasted 1 ++SET BIG_TABLES=1; ++select distinct companynr, fld3,count(*) from t2 group by companynr,fld3 order by companynr, fld3 limit 10; ++companynr fld3 count(*) ++00 affixed 1 ++00 and 1 ++00 annoyers 1 ++00 Anthony 1 ++00 assayed 1 ++00 assurers 1 ++00 attendants 1 ++00 bedlam 1 ++00 bedpost 1 ++00 boasted 1 ++SET BIG_TABLES=0; ++select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10; ++fld3 repeat("a",length(fld3)) count(*) ++Baird aaaaa 1 ++balled aaaaaa 1 ++ballgown aaaaaaaa 1 ++Baltimorean aaaaaaaaaaa 1 ++bankruptcies aaaaaaaaaaaa 1 ++Barry aaaaa 1 ++batting aaaaaaa 1 ++beaner aaaaaa 1 ++beasts aaaaaa 1 ++beaters aaaaaaa 1 ++select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2; ++companynr rtrim(space(512+companynr)) ++37 ++78 ++101 ++154 ++311 ++447 ++512 ++select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by fld3; ++fld3 ++explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL fld1 NULL NULL NULL # # Using where; Using temporary; Using filesort ++1 SIMPLE t3 NULL eq_ref PRIMARY PRIMARY 4 test.t2.fld1 # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t3`.`t2nr` AS `t2nr`,`test`.`t2`.`fld3` AS `fld3` from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`companynr` = 34) and (`test`.`t2`.`fld1` = `test`.`t3`.`t2nr`)) order by `test`.`t3`.`t2nr`,`test`.`t2`.`fld3` ++explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t1 NULL ALL period NULL NULL NULL # # Using temporary; Using filesort ++1 SIMPLE t3 NULL ref period period 4 test.t1.period # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t1`.`t2nr` AS `t2nr`,`test`.`t1`.`period` AS `period`,`test`.`t1`.`name` AS `name`,`test`.`t1`.`companynr` AS `companynr`,`test`.`t1`.`price` AS `price`,`test`.`t1`.`price2` AS `price2`,`test`.`t3`.`t2nr` AS `t2nr`,`test`.`t3`.`period` AS `period`,`test`.`t3`.`name` AS `name`,`test`.`t3`.`companynr` AS `companynr`,`test`.`t3`.`price` AS `price`,`test`.`t3`.`price2` AS `price2` from `test`.`t3` `t1` join `test`.`t3` where (`test`.`t3`.`period` = `test`.`t1`.`period`) order by `test`.`t3`.`period` ++explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t3 NULL index period period 4 NULL # # NULL ++1 SIMPLE t1 NULL ref period period 4 test.t3.period # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t1`.`t2nr` AS `t2nr`,`test`.`t1`.`period` AS `period`,`test`.`t1`.`name` AS `name`,`test`.`t1`.`companynr` AS `companynr`,`test`.`t1`.`price` AS `price`,`test`.`t1`.`price2` AS `price2`,`test`.`t3`.`t2nr` AS `t2nr`,`test`.`t3`.`period` AS `period`,`test`.`t3`.`name` AS `name`,`test`.`t3`.`companynr` AS `companynr`,`test`.`t3`.`price` AS `price`,`test`.`t3`.`price2` AS `price2` from `test`.`t3` `t1` join `test`.`t3` where (`test`.`t1`.`period` = `test`.`t3`.`period`) order by `test`.`t3`.`period` limit 10 ++explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t1 NULL index period period 4 NULL # # NULL ++1 SIMPLE t3 NULL ref period period 4 test.t1.period # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t1`.`t2nr` AS `t2nr`,`test`.`t1`.`period` AS `period`,`test`.`t1`.`name` AS `name`,`test`.`t1`.`companynr` AS `companynr`,`test`.`t1`.`price` AS `price`,`test`.`t1`.`price2` AS `price2`,`test`.`t3`.`t2nr` AS `t2nr`,`test`.`t3`.`period` AS `period`,`test`.`t3`.`name` AS `name`,`test`.`t3`.`companynr` AS `companynr`,`test`.`t3`.`price` AS `price`,`test`.`t3`.`price2` AS `price2` from `test`.`t3` `t1` join `test`.`t3` where (`test`.`t3`.`period` = `test`.`t1`.`period`) order by `test`.`t1`.`period` limit 10 ++select period from t1; ++period ++9410 ++select period from t1 where period=1900; ++period ++select fld3,period from t1,t2 where fld1 = 011401 order by period; ++fld3 period ++breaking 9410 ++select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001; ++fld3 period ++breaking 1001 ++explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL const fld1 fld1 4 const # # NULL ++1 SIMPLE t3 NULL const PRIMARY,period PRIMARY 4 const # # NULL ++Warnings: ++Note 1003 /* select#1 */ select 'breaking' AS `fld3`,'1001' AS `period` from `test`.`t2` join `test`.`t3` where true ++select fld3,period from t2,t1 where companynr*10 = 37*10; ++fld3 period ++Abraham 9410 ++Aden 9410 ++Adolph 9410 ++Aldrich 9410 ++Alison 9410 ++Anatole 9410 ++Antarctica 9410 ++Antares 9410 ++Arabia 9410 ++Artemia 9410 ++Augustine 9410 ++Baird 9410 ++Beebe 9410 ++Butterfield 9410 ++CERN 9410 ++Cassites 9410 ++Chicana 9410 ++Chippewa 9410 ++Clayton 9410 ++Conley 9410 ++Connally 9410 ++Crays 9410 ++DiMaggio 9410 ++Dutchman 9410 ++Eulerian 9410 ++Evanston 9410 ++Everhart 9410 ++Fenton 9410 ++Fitzpatrick 9410 ++Galatean 9410 ++Gandhian 9410 ++Ganymede 9410 ++Goldstine 9410 ++Gothicism 9410 ++Graves 9410 ++Greenberg 9410 ++Gurkha 9410 ++Hawaii 9410 ++Hegelian 9410 ++Hornblower 9410 ++Huffman 9410 ++Hunter 9410 ++Joplin 9410 ++Judas 9410 ++Kane 9410 ++Kantian 9410 ++Kevin 9410 ++Kinsey 9410 ++Kline 9410 ++Lars 9410 ++Latinizes 9410 ++Lillian 9410 ++Lizzy 9410 ++Majorca 9410 ++Manhattanize 9410 ++McGovern 9410 ++Melinda 9410 ++Merritt 9410 ++Micronesia 9410 ++Miles 9410 ++Miltonism 9410 ++Nabisco 9410 ++Nazis 9410 ++Newtonian 9410 ++Norwalk 9410 ++Pandora 9410 ++Parsifal 9410 ++Peruvian 9410 ++Punjab 9410 ++Pyle 9410 ++Quixotism 9410 ++Romano 9410 ++Romans 9410 ++Sabine 9410 ++Sault 9410 ++Saxony 9410 ++Selfridge 9410 ++Shanghais 9410 ++Simla 9410 ++Simon 9410 ++Stalin 9410 ++Steinberg 9410 ++Taoism 9410 ++Teresa 9410 ++Tipperary 9410 ++Weissmuller 9410 ++Winsett 9410 ++Wotan 9410 ++abates 9410 ++abrogating 9410 ++accessed 9410 ++admiring 9410 ++admonishing 9410 ++afield 9410 ++afore 9410 ++aging 9410 ++airships 9410 ++alike 9410 ++allot 9410 ++already 9410 ++amenities 9410 ++ammonium 9410 ++analogy 9410 ++analyzable 9410 ++animals 9410 ++animized 9410 ++annihilates 9410 ++announced 9410 ++announces 9410 ++apiary 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++arriving 9410 ++arteriole 9410 ++assails 9410 ++astound 9410 ++attainments 9410 ++attrition 9410 ++audiology 9410 ++avenge 9410 ++avoidable 9410 ++babies 9410 ++babysitting 9410 ++balled 9410 ++beaner 9410 ++beaters 9410 ++bee 9410 ++befouled 9410 ++bellow 9410 ++bestseller 9410 ++betroth 9410 ++bewilderingly 9410 ++bills 9410 ++bitterroot 9410 ++bivalves 9410 ++bloater 9410 ++bloodbath 9410 ++boat 9410 ++boom 9410 ++boorish 9410 ++boulder 9410 ++breaking 9410 ++brunch 9410 ++buckboards 9410 ++burlesque 9410 ++cage 9410 ++capably 9410 ++capped 9410 ++cascade 9410 ++causality 9410 ++cautioned 9410 ++ceiling 9410 ++celery 9410 ++certificates 9410 ++chafe 9410 ++chaperone 9410 ++charges 9410 ++chasm 9410 ++checkpoints 9410 ++chewing 9410 ++chews 9410 ++chillingly 9410 ++chronicle 9410 ++ciphers 9410 ++civics 9410 ++clamored 9410 ++clenched 9410 ++clockers 9410 ++coexist 9410 ++cokes 9410 ++combed 9410 ++coming 9410 ++commencements 9410 ++commonplace 9410 ++communicants 9410 ++compartment 9410 ++comprehensive 9410 ++comprised 9410 ++conceptions 9410 ++concludes 9410 ++congregates 9410 ++contrary 9410 ++contrasted 9410 ++convenient 9410 ++convulsion 9410 ++corset 9410 ++count 9410 ++coverings 9410 ++craziness 9410 ++creak 9410 ++creek 9410 ++critiques 9410 ++crunches 9410 ++culled 9410 ++cult 9410 ++cupboard 9410 ++cured 9410 ++cute 9410 ++daughter 9410 ++decliner 9410 ++decomposition 9410 ++deductions 9410 ++dehydrate 9410 ++deludes 9410 ++denizen 9410 ++denotative 9410 ++denounces 9410 ++dental 9410 ++dentally 9410 ++descendants 9410 ++despot 9410 ++destroyer 9410 ++detectably 9410 ++dialysis 9410 ++dimensions 9410 ++disable 9410 ++discounts 9410 ++disentangle 9410 ++disobedience 9410 ++dissociate 9410 ++dogging 9410 ++dopers 9410 ++drains 9410 ++dreaded 9410 ++ducks 9410 ++dusted 9410 ++effortlessly 9410 ++electroencephalography 9410 ++elite 9410 ++embassies 9410 ++employing 9410 ++encompass 9410 ++encompasses 9410 ++environing 9410 ++epistle 9410 ++equilibrium 9410 ++erases 9410 ++error 9410 ++eschew 9410 ++eternal 9410 ++evened 9410 ++evenhandedly 9410 ++eventful 9410 ++excises 9410 ++exclamation 9410 ++excrete 9410 ++exhausts 9410 ++expelled 9410 ++extents 9410 ++externally 9410 ++extracted 9410 ++faithful 9410 ++fanatic 9410 ++fated 9410 ++featherweight 9410 ++feed 9410 ++feminine 9410 ++fetched 9410 ++fetters 9410 ++fiftieth 9410 ++filial 9410 ++fingerings 9410 ++finishers 9410 ++firearm 9410 ++fitting 9410 ++fixedly 9410 ++flanking 9410 ++flint 9410 ++flopping 9410 ++flurried 9410 ++foldout 9410 ++foothill 9410 ++forgivably 9410 ++forthcoming 9410 ++freakish 9410 ++freest 9410 ++freezes 9410 ++funereal 9410 ++furnishings 9410 ++furthermore 9410 ++gadfly 9410 ++gainful 9410 ++galling 9410 ++garage 9410 ++gentleman 9410 ++gifted 9410 ++gleaning 9410 ++glut 9410 ++goblins 9410 ++governing 9410 ++gradually 9410 ++grazing 9410 ++gritty 9410 ++groupings 9410 ++guides 9410 ++guitars 9410 ++handgun 9410 ++handy 9410 ++heiress 9410 ++hoarder 9410 ++honoring 9410 ++hostess 9410 ++humanness 9410 ++humiliation 9410 ++humility 9410 ++hushes 9410 ++husky 9410 ++hypothesizer 9410 ++icon 9410 ++ideas 9410 ++impelling 9410 ++impending 9410 ++imperial 9410 ++imperiously 9410 ++imprint 9410 ++impulsive 9410 ++inaccuracy 9410 ++inch 9410 ++incidentals 9410 ++incorrectly 9410 ++incurring 9410 ++index 9410 ++indulge 9410 ++indulgences 9410 ++ineffective 9410 ++infallibly 9410 ++infest 9410 ++inform 9410 ++inmate 9410 ++insolence 9410 ++instruments 9410 ++intelligibility 9410 ++intentness 9410 ++intercepted 9410 ++interdependent 9410 ++interrelationships 9410 ++interrogate 9410 ++investigations 9410 ++irresponsibly 9410 ++jarring 9410 ++journalizing 9410 ++juveniles 9410 ++kanji 9410 ++kingdom 9410 ++kiting 9410 ++labeled 9410 ++languages 9410 ++laterally 9410 ++lawgiver 9410 ++leaflet 9410 ++leavings 9410 ++lectured 9410 ++leftover 9410 ++lewdly 9410 ++lied 9410 ++linear 9410 ++lists 9410 ++lithograph 9410 ++lore 9410 ++luckily 9410 ++males 9410 ++marginal 9410 ++mastering 9410 ++mayoral 9410 ++meanwhile 9410 ++measures 9410 ++measures 9410 ++mechanizing 9410 ++medical 9410 ++meditation 9410 ++metaphysically 9410 ++mineral 9410 ++miniaturizes 9410 ++minima 9410 ++minion 9410 ++minting 9410 ++misted 9410 ++misunderstander 9410 ++mixture 9410 ++motors 9410 ++mournfulness 9410 ++multilayer 9410 ++mumbles 9410 ++mushrooms 9410 ++mystic 9410 ++navies 9410 ++navigate 9410 ++neat 9410 ++neonatal 9410 ++nested 9410 ++noncritical 9410 ++normalizes 9410 ++obliterates 9410 ++offload 9410 ++opaquely 9410 ++organizer 9410 ++overestimating 9410 ++overlay 9410 ++parametrized 9410 ++parenthood 9410 ++parters 9410 ++participated 9410 ++partridges 9410 ++peacock 9410 ++peeked 9410 ++pellagra 9410 ++percentage 9410 ++percentage 9410 ++persist 9410 ++perturb 9410 ++pessimist 9410 ++pests 9410 ++petted 9410 ++pictures 9410 ++pithed 9410 ++pityingly 9410 ++poison 9410 ++posed 9410 ++positioning 9410 ++postulation 9410 ++praised 9410 ++precaution 9410 ++precipitable 9410 ++preclude 9410 ++presentation 9410 ++pressure 9410 ++previewing 9410 ++priceless 9410 ++primary 9410 ++psychic 9410 ++publicly 9410 ++puddings 9410 ++quagmire 9410 ++quitter 9410 ++railway 9410 ++raining 9410 ++rains 9410 ++ravines 9410 ++readable 9410 ++realized 9410 ++realtor 9410 ++reassigned 9410 ++recruited 9410 ++reduce 9410 ++regimented 9410 ++registration 9410 ++relatively 9410 ++relaxing 9410 ++relishing 9410 ++relives 9410 ++renew 9410 ++repelled 9410 ++repetitions 9410 ++reporters 9410 ++reporters 9410 ++repressions 9410 ++resplendent 9410 ++resumes 9410 ++rifles 9410 ++rightful 9410 ++rightfully 9410 ++rightfulness 9410 ++ripeness 9410 ++riser 9410 ++roped 9410 ++rudeness 9410 ++rules 9410 ++rural 9410 ++rusting 9410 ++sadly 9410 ++sags 9410 ++sanding 9410 ++saplings 9410 ++sating 9410 ++save 9410 ++sawtooth 9410 ++scarf 9410 ++scatterbrain 9410 ++scheduling 9410 ++schemer 9410 ++scholastics 9410 ++scornfully 9410 ++secures 9410 ++securing 9410 ++seminaries 9410 ++serializations 9410 ++serpents 9410 ++serving 9410 ++severely 9410 ++sews 9410 ++shapelessly 9410 ++shipyard 9410 ++shooter 9410 ++similarities 9410 ++skulking 9410 ++slaughter 9410 ++sloping 9410 ++smoothed 9410 ++snatching 9410 ++socializes 9410 ++sophomore 9410 ++sorters 9410 ++spatial 9410 ++specification 9410 ++specifics 9410 ++spongers 9410 ++spools 9410 ++sportswriting 9410 ++sporty 9410 ++squabbled 9410 ++squeaking 9410 ++squeezes 9410 ++stabilizes 9410 ++stairway 9410 ++standardizes 9410 ++star 9410 ++starlet 9410 ++stated 9410 ++stint 9410 ++stodgy 9410 ++store 9410 ++straight 9410 ++stranglings 9410 ++subdirectory 9410 ++subjective 9410 ++subschema 9410 ++succumbed 9410 ++suites 9410 ++sumac 9410 ++sureties 9410 ++swaying 9410 ++sweetish 9410 ++swelling 9410 ++syndicate 9410 ++taxonomically 9410 ++techniques 9410 ++teem 9410 ++teethe 9410 ++tempering 9410 ++terminal 9410 ++terminator 9410 ++terminators 9410 ++test 9410 ++testicle 9410 ++textures 9410 ++theorizers 9410 ++throttles 9410 ++tidiness 9410 ++timesharing 9410 ++tinily 9410 ++tinting 9410 ++title 9410 ++tragedies 9410 ++traitor 9410 ++trimmings 9410 ++tropics 9410 ++unaffected 9410 ++uncovering 9410 ++undoes 9410 ++ungrateful 9410 ++universals 9410 ++unplug 9410 ++unruly 9410 ++untying 9410 ++unwilling 9410 ++vacuuming 9410 ++validate 9410 ++vanish 9410 ++ventilate 9410 ++veranda 9410 ++vests 9410 ++wallet 9410 ++waltz 9410 ++warm 9410 ++warningly 9410 ++watering 9410 ++weasels 9410 ++western 9410 ++whiteners 9410 ++widens 9410 ++witchcraft 9410 ++workers 9410 ++yelped 9410 ++youthfulness 9410 ++select fld3,period,price,price2 from t2,t3 where t2.fld1=t3.t2nr and period >= 1001 and period <= 1002 and t2.companynr = 37 order by fld3,period, price; ++fld3 period price price2 ++admonishing 1002 28357832 8723648 ++analyzable 1002 28357832 8723648 ++annihilates 1001 5987435 234724 ++Antares 1002 28357832 8723648 ++astound 1001 5987435 234724 ++audiology 1001 5987435 234724 ++Augustine 1002 28357832 8723648 ++Baird 1002 28357832 8723648 ++bewilderingly 1001 5987435 234724 ++breaking 1001 5987435 234724 ++Conley 1001 5987435 234724 ++dentally 1002 28357832 8723648 ++dissociate 1002 28357832 8723648 ++elite 1001 5987435 234724 ++eschew 1001 5987435 234724 ++Eulerian 1001 5987435 234724 ++flanking 1001 5987435 234724 ++foldout 1002 28357832 8723648 ++funereal 1002 28357832 8723648 ++galling 1002 28357832 8723648 ++Graves 1001 5987435 234724 ++grazing 1001 5987435 234724 ++groupings 1001 5987435 234724 ++handgun 1001 5987435 234724 ++humility 1002 28357832 8723648 ++impulsive 1002 28357832 8723648 ++inch 1001 5987435 234724 ++intelligibility 1001 5987435 234724 ++jarring 1001 5987435 234724 ++lawgiver 1001 5987435 234724 ++lectured 1002 28357832 8723648 ++Merritt 1002 28357832 8723648 ++neonatal 1001 5987435 234724 ++offload 1002 28357832 8723648 ++parters 1002 28357832 8723648 ++pityingly 1002 28357832 8723648 ++puddings 1002 28357832 8723648 ++Punjab 1001 5987435 234724 ++quitter 1002 28357832 8723648 ++realtor 1001 5987435 234724 ++relaxing 1001 5987435 234724 ++repetitions 1001 5987435 234724 ++resumes 1001 5987435 234724 ++Romans 1002 28357832 8723648 ++rusting 1001 5987435 234724 ++scholastics 1001 5987435 234724 ++skulking 1002 28357832 8723648 ++stated 1002 28357832 8723648 ++suites 1002 28357832 8723648 ++sureties 1001 5987435 234724 ++testicle 1002 28357832 8723648 ++tinily 1002 28357832 8723648 ++tragedies 1001 5987435 234724 ++trimmings 1001 5987435 234724 ++vacuuming 1001 5987435 234724 ++ventilate 1001 5987435 234724 ++wallet 1001 5987435 234724 ++Weissmuller 1002 28357832 8723648 ++Wotan 1002 28357832 8723648 ++select t2.fld1,fld3,period,price,price2 from t2,t3 where t2.fld1>= 18201 and t2.fld1 <= 18811 and t2.fld1=t3.t2nr and period = 1001 and t2.companynr = 37; ++fld1 fld3 period price price2 ++018201 relaxing 1001 5987435 234724 ++018601 vacuuming 1001 5987435 234724 ++018801 inch 1001 5987435 234724 ++018811 repetitions 1001 5987435 234724 ++create table t4 ( ++companynr tinyint(2) unsigned zerofill NOT NULL default '00', ++companyname char(30) NOT NULL default '', ++PRIMARY KEY (companynr), ++UNIQUE KEY companyname(companyname) ++) MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; ++Warnings: ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; ++companynr companyname ++00 Unknown ++29 company 1 ++34 company 2 ++36 company 3 ++37 company 4 ++40 company 5 ++41 company 6 ++50 company 11 ++53 company 7 ++58 company 8 ++65 company 9 ++68 company 10 ++select SQL_SMALL_RESULT t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; ++companynr companyname ++00 Unknown ++37 company 4 ++36 company 3 ++50 company 11 ++58 company 8 ++29 company 1 ++40 company 5 ++53 company 7 ++65 company 9 ++41 company 6 ++34 company 2 ++68 company 10 ++select * from t1,t1 t12; ++Period Varor_period Period Varor_period ++9410 9412 9410 9412 ++select t2.fld1,t22.fld1 from t2,t2 t22 where t2.fld1 >= 250501 and t2.fld1 <= 250505 and t22.fld1 >= 250501 and t22.fld1 <= 250505; ++fld1 fld1 ++250501 250501 ++250501 250502 ++250501 250503 ++250501 250504 ++250501 250505 ++250502 250501 ++250502 250502 ++250502 250503 ++250502 250504 ++250502 250505 ++250503 250501 ++250503 250502 ++250503 250503 ++250503 250504 ++250503 250505 ++250504 250501 ++250504 250502 ++250504 250503 ++250504 250504 ++250504 250505 ++250505 250501 ++250505 250502 ++250505 250503 ++250505 250504 ++250505 250505 ++insert into t2 (fld1, companynr) values (999999,99); ++analyze table t2,t4; ++Table Op Msg_type Msg_text ++test.t2 analyze status OK ++test.t4 analyze status OK ++select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; ++companynr companyname ++99 NULL ++select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null; ++count(*) ++1199 ++explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # 100.00 NULL ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # 100.00 Using where; Not exists ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t2` left join `test`.`t4` on((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`)) where (`test`.`t4`.`companynr` is null) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # 100.00 Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # 10.00 Using where; Not exists; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t2`.`companynr` is null) ++select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; ++companynr companyname ++select count(*) from t2 left join t4 using (companynr) where companynr is not null; ++count(*) ++1200 ++explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # NULL Impossible WHERE ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t2` left join `test`.`t4` on(multiple equal(`test`.`t2`.`companynr`, `test`.`t4`.`companynr`)) where false ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # NULL Impossible WHERE ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on(multiple equal(`test`.`t4`.`companynr`, `test`.`t2`.`companynr`)) where false ++delete from t2 where fld1=999999; ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` join `test`.`t2` where ((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`) and (`test`.`t2`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` join `test`.`t2` where ((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`) and (`test`.`t2`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` join `test`.`t2` where ((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`) and (`test`.`t2`.`companynr` > 0) and (`test`.`t2`.`companynr` > 0)) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t4`.`companynr` > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t4`.`companynr` > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t4`.`companynr` > 0) and (`test`.`t4`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t2`.`companynr` > 0) or (`test`.`t2`.`companynr` is null)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index PRIMARY companyname 120 NULL # # Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t2`.`companynr` > 0) or (`test`.`t4`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (ifnull(`test`.`t2`.`companynr`,1) > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t4`.`companynr` > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t4`.`companynr` > 0) or (`test`.`t4`.`companynr` > 0)) ++explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using where; Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (ifnull(`test`.`t4`.`companynr`,1) > 0) ++select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; ++companynr companynr ++37 36 ++41 40 ++explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using index; Using temporary ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select distinct `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companynr` AS `companynr` from `test`.`t2` join `test`.`t4` where (`test`.`t2`.`companynr` = (`test`.`t4`.`companynr` + 1)) ++select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008; ++fld1 companynr fld3 period ++038008 37 reporters 1008 ++038208 37 Selfridge 1008 ++select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t2.fld1 = 38208 or t2.fld1 = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009; ++fld1 companynr fld3 period ++038008 37 reporters 1008 ++038208 37 Selfridge 1008 ++select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t3.t2nr = 38208 or t3.t2nr = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009; ++fld1 companynr fld3 period ++038008 37 reporters 1008 ++038208 37 Selfridge 1008 ++select period from t1 where (((period > 0) or period < 10000 or (period = 1900)) and (period=1900 and period <= 1901) or (period=1903 and (period=1903)) and period>=1902) or ((period=1904 or period=1905) or (period=1906 or period>1907)) or (period=1908 and period = 1909); ++period ++9410 ++select period from t1 where ((period > 0 and period < 1) or (((period > 0 and period < 100) and (period > 10)) or (period > 10)) or (period > 0 and (period > 5 or period > 6))); ++period ++9410 ++select a.fld1 from t2 as a,t2 b where ((a.fld1 = 250501 and a.fld1=b.fld1) or a.fld1=250502 or a.fld1=250503 or (a.fld1=250505 and a.fld1<=b.fld1 and b.fld1>=a.fld1)) and a.fld1=b.fld1; ++fld1 ++250501 ++250502 ++250503 ++250505 ++select fld1 from t2 where fld1 in (250502,98005,98006,250503,250605,250606) and fld1 >=250502 and fld1 not in (250605,250606); ++fld1 ++250502 ++250503 ++select fld1 from t2 where fld1 between 250502 and 250504; ++fld1 ++250502 ++250503 ++250504 ++select fld3 from t2 where (((fld3 like "_%L%" ) or (fld3 like "%ok%")) and ( fld3 like "L%" or fld3 like "G%")) and fld3 like "L%" ; ++fld3 ++label ++labeled ++labeled ++landslide ++laterally ++leaflet ++lewdly ++Lillian ++luckily ++select count(*) from t1; ++count(*) ++1 ++select companynr,count(*),sum(fld1) from t2 group by companynr; ++companynr count(*) sum(fld1) ++00 82 10355753 ++37 588 83602098 ++36 215 22786296 ++50 11 1595438 ++58 23 2254293 ++29 95 14473298 ++40 37 6618386 ++53 4 793210 ++65 10 2284055 ++41 52 12816335 ++34 70 17788966 ++68 12 3097288 ++select companynr,count(*) from t2 group by companynr order by companynr desc limit 5; ++companynr count(*) ++68 12 ++65 10 ++58 23 ++53 4 ++50 11 ++select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; ++count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) ++70 absentee vest 17788966 254128.0857 3272.5939722090234 10709871.306938833 ++explain select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++Warnings: ++Note 1003 /* select#1 */ select count(0) AS `count(*)`,min(`test`.`t2`.`fld4`) AS `min(fld4)`,max(`test`.`t2`.`fld4`) AS `max(fld4)`,sum(`test`.`t2`.`fld1`) AS `sum(fld1)`,avg(`test`.`t2`.`fld1`) AS `avg(fld1)`,std(`test`.`t2`.`fld1`) AS `std(fld1)`,variance(`test`.`t2`.`fld1`) AS `variance(fld1)` from `test`.`t2` where ((`test`.`t2`.`companynr` = 34) and (`test`.`t2`.`fld4` <> '')) ++select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr order by companynr limit 3; ++companynr count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) ++00 82 Anthony windmills 10355753 126289.6707 115550.97568479746 13352027981.708656 ++29 95 abut wetness 14473298 152350.5053 8368.547956641249 70032594.90260443 ++34 70 absentee vest 17788966 254128.0857 3272.5939722090234 10709871.306938833 ++select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr order by companynr,t2nr limit 10; ++companynr t2nr count(price) sum(price) min(price) max(price) avg(price) ++37 1 1 5987435 5987435 5987435 5987435.0000 ++37 2 1 28357832 28357832 28357832 28357832.0000 ++37 3 1 39654943 39654943 39654943 39654943.0000 ++37 11 1 5987435 5987435 5987435 5987435.0000 ++37 12 1 28357832 28357832 28357832 28357832.0000 ++37 13 1 39654943 39654943 39654943 39654943.0000 ++37 21 1 5987435 5987435 5987435 5987435.0000 ++37 22 1 28357832 28357832 28357832 28357832.0000 ++37 23 1 39654943 39654943 39654943 39654943.0000 ++37 31 1 5987435 5987435 5987435 5987435.0000 ++select /*! SQL_SMALL_RESULT */ ++companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr, t2nr order by companynr,t2nr limit 10; ++companynr t2nr count(price) sum(price) min(price) max(price) avg(price) ++37 1 1 5987435 5987435 5987435 5987435.0000 ++37 2 1 28357832 28357832 28357832 28357832.0000 ++37 3 1 39654943 39654943 39654943 39654943.0000 ++37 11 1 5987435 5987435 5987435 5987435.0000 ++37 12 1 28357832 28357832 28357832 28357832.0000 ++37 13 1 39654943 39654943 39654943 39654943.0000 ++37 21 1 5987435 5987435 5987435 5987435.0000 ++37 22 1 28357832 28357832 28357832 28357832.0000 ++37 23 1 39654943 39654943 39654943 39654943.0000 ++37 31 1 5987435 5987435 5987435 5987435.0000 ++select companynr,count(price),sum(price),min(price),max(price),avg(price) from t3 group by companynr ; ++companynr count(price) sum(price) min(price) max(price) avg(price) ++37 12543 309394878010 5987435 39654943 24666736.6667 ++78 8362 414611089292 726498 98439034 49582766.0000 ++101 4181 3489454238 834598 834598 834598.0000 ++154 4181 4112197254950 983543950 983543950 983543950.0000 ++311 4181 979599938 234298 234298 234298.0000 ++447 4181 9929180954 2374834 2374834 2374834.0000 ++512 4181 3288532102 786542 786542 786542.0000 ++select distinct mod(companynr,10) from t4 group by companynr; ++mod(companynr,10) ++9 ++8 ++0 ++4 ++6 ++7 ++1 ++3 ++5 ++select distinct 1 from t4 group by companynr; ++1 ++1 ++select count(distinct fld1) from t2; ++count(distinct fld1) ++1199 ++select companynr,count(distinct fld1) from t2 group by companynr; ++companynr count(distinct fld1) ++00 82 ++29 95 ++34 70 ++36 215 ++37 588 ++40 37 ++41 52 ++50 11 ++53 4 ++58 23 ++65 10 ++68 12 ++select companynr,count(*) from t2 group by companynr; ++companynr count(*) ++00 82 ++37 588 ++36 215 ++50 11 ++58 23 ++29 95 ++40 37 ++53 4 ++65 10 ++41 52 ++34 70 ++68 12 ++select companynr,count(distinct concat(fld1,repeat(65,1000))) from t2 group by companynr; ++companynr count(distinct concat(fld1,repeat(65,1000))) ++00 82 ++29 95 ++34 70 ++36 215 ++37 588 ++40 37 ++41 52 ++50 11 ++53 4 ++58 23 ++65 10 ++68 12 ++select companynr,count(distinct concat(fld1,repeat(65,200))) from t2 group by companynr; ++companynr count(distinct concat(fld1,repeat(65,200))) ++00 82 ++29 95 ++34 70 ++36 215 ++37 588 ++40 37 ++41 52 ++50 11 ++53 4 ++58 23 ++65 10 ++68 12 ++select companynr,count(distinct floor(fld1/100)) from t2 group by companynr; ++companynr count(distinct floor(fld1/100)) ++00 47 ++29 35 ++34 14 ++36 69 ++37 108 ++40 16 ++41 11 ++50 9 ++53 1 ++58 1 ++65 1 ++68 1 ++select companynr,count(distinct concat(repeat(65,1000),floor(fld1/100))) from t2 group by companynr; ++companynr count(distinct concat(repeat(65,1000),floor(fld1/100))) ++00 47 ++29 35 ++34 14 ++36 69 ++37 108 ++40 16 ++41 11 ++50 9 ++53 1 ++58 1 ++65 1 ++68 1 ++select sum(fld1),fld3 from t2 where fld3="Romans" group by fld1 limit 10; ++sum(fld1) fld3 ++11402 Romans ++select name,count(*) from t3 where name='cloakroom' group by name; ++name count(*) ++cloakroom 4181 ++select name,count(*) from t3 where name='cloakroom' and price>10 group by name; ++name count(*) ++cloakroom 4181 ++select count(*) from t3 where name='cloakroom' and price2=823742; ++count(*) ++4181 ++select name,count(*) from t3 where name='cloakroom' and price2=823742 group by name; ++name count(*) ++cloakroom 4181 ++select name,count(*) from t3 where name >= "extramarital" and price <= 39654943 group by name; ++name count(*) ++extramarital 4181 ++gazer 4181 ++gems 4181 ++Iranizes 4181 ++spates 4181 ++tucked 4181 ++violinist 4181 ++select t2.fld3,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name; ++fld3 count(*) ++spates 4181 ++select companynr|0,companyname from t4 group by 1; ++companynr|0 companyname ++29 company 1 ++68 company 10 ++50 company 11 ++34 company 2 ++36 company 3 ++37 company 4 ++40 company 5 ++41 company 6 ++53 company 7 ++58 company 8 ++65 company 9 ++0 Unknown ++select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname; ++companynr companyname count(*) ++29 company 1 95 ++68 company 10 12 ++50 company 11 11 ++34 company 2 70 ++36 company 3 215 ++37 company 4 588 ++40 company 5 37 ++41 company 6 52 ++53 company 7 4 ++58 company 8 23 ++65 company 9 10 ++00 Unknown 82 ++select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name; ++fld1 count(*) ++158402 4181 ++select sum(Period)/count(*) from t1; ++sum(Period)/count(*) ++9410.0000 ++select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr; ++companynr count sum diff func ++37 12543 309394878010 0.0000 464091 ++78 8362 414611089292 0.0000 652236 ++101 4181 3489454238 0.0000 422281 ++154 4181 4112197254950 0.0000 643874 ++311 4181 979599938 0.0000 1300291 ++447 4181 9929180954 0.0000 1868907 ++512 4181 3288532102 0.0000 2140672 ++select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg; ++companynr avg ++154 983543950.0000 ++select companynr,count(*) from t2 group by companynr order by 2 desc; ++companynr count(*) ++37 588 ++36 215 ++29 95 ++00 82 ++34 70 ++41 52 ++40 37 ++58 23 ++68 12 ++50 11 ++65 10 ++53 4 ++select companynr,count(*) from t2 where companynr > 40 group by companynr order by 2 desc; ++companynr count(*) ++41 52 ++58 23 ++68 12 ++50 11 ++65 10 ++53 4 ++select t2.fld4,t2.fld1,count(price),sum(price),min(price),max(price),avg(price) from t3,t2 where t3.companynr = 37 and t2.fld1 = t3.t2nr group by fld1,t2.fld4; ++fld4 fld1 count(price) sum(price) min(price) max(price) avg(price) ++teethe 000001 1 5987435 5987435 5987435 5987435.0000 ++dreaded 011401 1 5987435 5987435 5987435 5987435.0000 ++scholastics 011402 1 28357832 28357832 28357832 28357832.0000 ++audiology 011403 1 39654943 39654943 39654943 39654943.0000 ++wallet 011501 1 5987435 5987435 5987435 5987435.0000 ++parters 011701 1 5987435 5987435 5987435 5987435.0000 ++eschew 011702 1 28357832 28357832 28357832 28357832.0000 ++quitter 011703 1 39654943 39654943 39654943 39654943.0000 ++neat 012001 1 5987435 5987435 5987435 5987435.0000 ++Steinberg 012003 1 39654943 39654943 39654943 39654943.0000 ++balled 012301 1 5987435 5987435 5987435 5987435.0000 ++persist 012302 1 28357832 28357832 28357832 28357832.0000 ++attainments 012303 1 39654943 39654943 39654943 39654943.0000 ++capably 012501 1 5987435 5987435 5987435 5987435.0000 ++impulsive 012602 1 28357832 28357832 28357832 28357832.0000 ++starlet 012603 1 39654943 39654943 39654943 39654943.0000 ++featherweight 012701 1 5987435 5987435 5987435 5987435.0000 ++pessimist 012702 1 28357832 28357832 28357832 28357832.0000 ++daughter 012703 1 39654943 39654943 39654943 39654943.0000 ++lawgiver 013601 1 5987435 5987435 5987435 5987435.0000 ++stated 013602 1 28357832 28357832 28357832 28357832.0000 ++readable 013603 1 39654943 39654943 39654943 39654943.0000 ++testicle 013801 1 5987435 5987435 5987435 5987435.0000 ++Parsifal 013802 1 28357832 28357832 28357832 28357832.0000 ++leavings 013803 1 39654943 39654943 39654943 39654943.0000 ++squeaking 013901 1 5987435 5987435 5987435 5987435.0000 ++contrasted 016001 1 5987435 5987435 5987435 5987435.0000 ++leftover 016201 1 5987435 5987435 5987435 5987435.0000 ++whiteners 016202 1 28357832 28357832 28357832 28357832.0000 ++erases 016301 1 5987435 5987435 5987435 5987435.0000 ++Punjab 016302 1 28357832 28357832 28357832 28357832.0000 ++Merritt 016303 1 39654943 39654943 39654943 39654943.0000 ++sweetish 018001 1 5987435 5987435 5987435 5987435.0000 ++dogging 018002 1 28357832 28357832 28357832 28357832.0000 ++scornfully 018003 1 39654943 39654943 39654943 39654943.0000 ++fetters 018012 1 28357832 28357832 28357832 28357832.0000 ++bivalves 018013 1 39654943 39654943 39654943 39654943.0000 ++skulking 018021 1 5987435 5987435 5987435 5987435.0000 ++flint 018022 1 28357832 28357832 28357832 28357832.0000 ++flopping 018023 1 39654943 39654943 39654943 39654943.0000 ++Judas 018032 1 28357832 28357832 28357832 28357832.0000 ++vacuuming 018033 1 39654943 39654943 39654943 39654943.0000 ++medical 018041 1 5987435 5987435 5987435 5987435.0000 ++bloodbath 018042 1 28357832 28357832 28357832 28357832.0000 ++subschema 018043 1 39654943 39654943 39654943 39654943.0000 ++interdependent 018051 1 5987435 5987435 5987435 5987435.0000 ++Graves 018052 1 28357832 28357832 28357832 28357832.0000 ++neonatal 018053 1 39654943 39654943 39654943 39654943.0000 ++sorters 018061 1 5987435 5987435 5987435 5987435.0000 ++Conley 018101 1 5987435 5987435 5987435 5987435.0000 ++lectured 018102 1 28357832 28357832 28357832 28357832.0000 ++Abraham 018103 1 39654943 39654943 39654943 39654943.0000 ++cage 018201 1 5987435 5987435 5987435 5987435.0000 ++hushes 018202 1 28357832 28357832 28357832 28357832.0000 ++Simla 018402 1 28357832 28357832 28357832 28357832.0000 ++reporters 018403 1 39654943 39654943 39654943 39654943.0000 ++coexist 018601 1 5987435 5987435 5987435 5987435.0000 ++Beebe 018602 1 28357832 28357832 28357832 28357832.0000 ++Taoism 018603 1 39654943 39654943 39654943 39654943.0000 ++Connally 018801 1 5987435 5987435 5987435 5987435.0000 ++fetched 018802 1 28357832 28357832 28357832 28357832.0000 ++checkpoints 018803 1 39654943 39654943 39654943 39654943.0000 ++gritty 018811 1 5987435 5987435 5987435 5987435.0000 ++firearm 018812 1 28357832 28357832 28357832 28357832.0000 ++minima 019101 1 5987435 5987435 5987435 5987435.0000 ++Selfridge 019102 1 28357832 28357832 28357832 28357832.0000 ++disable 019103 1 39654943 39654943 39654943 39654943.0000 ++witchcraft 019201 1 5987435 5987435 5987435 5987435.0000 ++betroth 030501 1 5987435 5987435 5987435 5987435.0000 ++Manhattanize 030502 1 28357832 28357832 28357832 28357832.0000 ++imprint 030503 1 39654943 39654943 39654943 39654943.0000 ++swelling 031901 1 5987435 5987435 5987435 5987435.0000 ++interrelationships 036001 1 5987435 5987435 5987435 5987435.0000 ++riser 036002 1 28357832 28357832 28357832 28357832.0000 ++bee 038001 1 5987435 5987435 5987435 5987435.0000 ++kanji 038002 1 28357832 28357832 28357832 28357832.0000 ++dental 038003 1 39654943 39654943 39654943 39654943.0000 ++railway 038011 1 5987435 5987435 5987435 5987435.0000 ++validate 038012 1 28357832 28357832 28357832 28357832.0000 ++normalizes 038013 1 39654943 39654943 39654943 39654943.0000 ++Kline 038101 1 5987435 5987435 5987435 5987435.0000 ++Anatole 038102 1 28357832 28357832 28357832 28357832.0000 ++partridges 038103 1 39654943 39654943 39654943 39654943.0000 ++recruited 038201 1 5987435 5987435 5987435 5987435.0000 ++dimensions 038202 1 28357832 28357832 28357832 28357832.0000 ++Chicana 038203 1 39654943 39654943 39654943 39654943.0000 ++epistle 018062 1 28357832 28357832 28357832 28357832.0000 ++select t3.companynr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 group by companynr,fld3; ++companynr fld3 sum(price) ++512 boat 786542 ++512 capably 786542 ++512 decliner 786542 ++512 dopers 786542 ++512 erases 786542 ++512 cupboard 786542 ++512 Miles 786542 ++512 Micronesia 786542 ++512 descendants 786542 ++512 skies 786542 ++select t2.companynr,count(*),min(fld3),max(fld3),sum(price),avg(price) from t2,t3 where t3.companynr >= 30 and t3.companynr <= 58 and t3.t2nr = t2.fld1 and 1+1=2 group by t2.companynr; ++companynr count(*) min(fld3) max(fld3) sum(price) avg(price) ++00 1 Omaha Omaha 5987435 5987435.0000 ++37 83 Abraham Wotan 1908978016 22999735.1325 ++36 1 dubbed dubbed 28357832 28357832.0000 ++50 2 scribbled tapestry 68012775 34006387.5000 ++select t3.companynr+0,t3.t2nr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 37 group by 1,t3.t2nr,fld3,fld3,fld3,fld3,fld3 order by fld1; ++t3.companynr+0 t2nr fld3 sum(price) ++37 1 Omaha 5987435 ++37 11401 breaking 5987435 ++37 11402 Romans 28357832 ++37 11403 intercepted 39654943 ++37 11501 bewilderingly 5987435 ++37 11701 astound 5987435 ++37 11702 admonishing 28357832 ++37 11703 sumac 39654943 ++37 12001 flanking 5987435 ++37 12003 combed 39654943 ++37 12301 Eulerian 5987435 ++37 12302 dubbed 28357832 ++37 12303 Kane 39654943 ++37 12501 annihilates 5987435 ++37 12602 Wotan 28357832 ++37 12603 snatching 39654943 ++37 12701 grazing 5987435 ++37 12702 Baird 28357832 ++37 12703 celery 39654943 ++37 13601 handgun 5987435 ++37 13602 foldout 28357832 ++37 13603 mystic 39654943 ++37 13801 intelligibility 5987435 ++37 13802 Augustine 28357832 ++37 13803 teethe 39654943 ++37 13901 scholastics 5987435 ++37 16001 audiology 5987435 ++37 16201 wallet 5987435 ++37 16202 parters 28357832 ++37 16301 eschew 5987435 ++37 16302 quitter 28357832 ++37 16303 neat 39654943 ++37 18001 jarring 5987435 ++37 18002 tinily 28357832 ++37 18003 balled 39654943 ++37 18012 impulsive 28357832 ++37 18013 starlet 39654943 ++37 18021 lawgiver 5987435 ++37 18022 stated 28357832 ++37 18023 readable 39654943 ++37 18032 testicle 28357832 ++37 18033 Parsifal 39654943 ++37 18041 Punjab 5987435 ++37 18042 Merritt 28357832 ++37 18043 Quixotism 39654943 ++37 18051 sureties 5987435 ++37 18052 puddings 28357832 ++37 18053 tapestry 39654943 ++37 18061 trimmings 5987435 ++37 18062 humility 28357832 ++37 18101 tragedies 5987435 ++37 18102 skulking 28357832 ++37 18103 flint 39654943 ++37 18201 relaxing 5987435 ++37 18202 offload 28357832 ++37 18402 suites 28357832 ++37 18403 lists 39654943 ++37 18601 vacuuming 5987435 ++37 18602 dentally 28357832 ++37 18603 humanness 39654943 ++37 18801 inch 5987435 ++37 18802 Weissmuller 28357832 ++37 18803 irresponsibly 39654943 ++37 18811 repetitions 5987435 ++37 18812 Antares 28357832 ++37 19101 ventilate 5987435 ++37 19102 pityingly 28357832 ++37 19103 interdependent 39654943 ++37 19201 Graves 5987435 ++37 30501 neonatal 5987435 ++37 30502 scribbled 28357832 ++37 30503 chafe 39654943 ++37 31901 realtor 5987435 ++37 36001 elite 5987435 ++37 36002 funereal 28357832 ++37 38001 Conley 5987435 ++37 38002 lectured 28357832 ++37 38003 Abraham 39654943 ++37 38011 groupings 5987435 ++37 38012 dissociate 28357832 ++37 38013 coexist 39654943 ++37 38101 rusting 5987435 ++37 38102 galling 28357832 ++37 38103 obliterates 39654943 ++37 38201 resumes 5987435 ++37 38202 analyzable 28357832 ++37 38203 terminator 39654943 ++select sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1= t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008; ++sum(price) ++234298 ++select t2.fld1,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1 = t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008 or t3.t2nr = t2.fld1 and t2.fld1 = 38008 group by t2.fld1; ++fld1 sum(price) ++038008 234298 ++explain select fld3 from t2 where 1>2 or 2>3; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # # Impossible WHERE ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where false ++explain select fld3 from t2 where fld1=fld1; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where true ++select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502; ++companynr fld1 ++34 250501 ++34 250502 ++select companynr,fld1 from t2 WHERE fld1>=250501 HAVING fld1<=250502; ++companynr fld1 ++34 250501 ++34 250502 ++select companynr,count(*) as count,sum(fld1) as sum from t2 group by companynr having count > 40 and sum/count >= 120000; ++companynr count sum ++00 82 10355753 ++37 588 83602098 ++29 95 14473298 ++41 52 12816335 ++34 70 17788966 ++select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ; ++companynr ++00 ++37 ++29 ++41 ++34 ++select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40; ++companynr companyname count(*) ++50 company 11 11 ++58 company 8 23 ++40 company 5 37 ++53 company 7 4 ++65 company 9 10 ++41 company 6 52 ++68 company 10 12 ++select count(*) from t2; ++count(*) ++1199 ++select count(*) from t2 where fld1 < 098024; ++count(*) ++387 ++select min(fld1) from t2 where fld1>= 098024; ++min(fld1) ++98024 ++select max(fld1) from t2 where fld1>= 098024; ++max(fld1) ++1232609 ++select count(*) from t3 where price2=76234234; ++count(*) ++4181 ++select count(*) from t3 where companynr=512 and price2=76234234; ++count(*) ++4181 ++explain select min(fld1),max(fld1),count(*) from t2; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL index NULL fld1 4 NULL # # Using index ++Warnings: ++Note 1003 /* select#1 */ select min(`test`.`t2`.`fld1`) AS `min(fld1)`,max(`test`.`t2`.`fld1`) AS `max(fld1)`,count(0) AS `count(*)` from `test`.`t2` ++select min(fld1),max(fld1),count(*) from t2; ++min(fld1) max(fld1) count(*) ++0 1232609 1199 ++select min(t2nr),max(t2nr) from t3 where t2nr=2115 and price2=823742; ++min(t2nr) max(t2nr) ++2115 2115 ++select count(*),min(t2nr),max(t2nr) from t3 where name='spates' and companynr=78; ++count(*) min(t2nr) max(t2nr) ++4181 4 41804 ++select t2nr,count(*) from t3 where name='gems' group by t2nr limit 20; ++t2nr count(*) ++9 1 ++19 1 ++29 1 ++39 1 ++49 1 ++59 1 ++69 1 ++79 1 ++89 1 ++99 1 ++109 1 ++119 1 ++129 1 ++139 1 ++149 1 ++159 1 ++169 1 ++179 1 ++189 1 ++199 1 ++select max(t2nr) from t3 where price=983543950; ++max(t2nr) ++41807 ++select t1.period from t3 t1 limit 1; ++period ++1001 ++select t1.period from t1 as t1 limit 1; ++period ++9410 ++select t1.period as "Nuvarande period" from t1 as t1 limit 1; ++Nuvarande period ++9410 ++select period as ok_period from t1 limit 1; ++ok_period ++9410 ++select period as ok_period from t1 group by ok_period limit 1; ++ok_period ++9410 ++select 1+1 as summa from t1 group by summa limit 1; ++summa ++2 ++select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1; ++Nuvarande period ++9410 ++show tables; ++Tables_in_test ++t1 ++t2 ++t3 ++t4 ++show tables from test like "s%"; ++Tables_in_test (s%) ++show tables from test like "t?"; ++Tables_in_test (t?) ++show full columns from t2; ++Field Type Collation Null Key Default Extra Privileges Comment ++auto int NULL NO PRI NULL auto_increment select,insert,update,references ++fld1 int(6) unsigned zerofill NULL NO UNI 000000 select,insert,update,references ++companynr tinyint(2) unsigned zerofill NULL NO 00 select,insert,update,references ++fld3 char(30) utf8mb4_0900_ai_ci NO MUL select,insert,update,references ++fld4 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld5 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld6 char(4) utf8mb4_0900_ai_ci NO select,insert,update,references ++show full columns from t2 from test like 'f%'; ++Field Type Collation Null Key Default Extra Privileges Comment ++fld1 int(6) unsigned zerofill NULL NO UNI 000000 select,insert,update,references ++fld3 char(30) utf8mb4_0900_ai_ci NO MUL select,insert,update,references ++fld4 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld5 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld6 char(4) utf8mb4_0900_ai_ci NO select,insert,update,references ++show full columns from t2 from test like 's%'; ++Field Type Collation Null Key Default Extra Privileges Comment ++analyze table t2; ++Table Op Msg_type Msg_text ++test.t2 analyze status OK ++show keys from t2; ++Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression ++t2 0 PRIMARY 1 auto A # NULL NULL BTREE YES NULL ++t2 0 fld1 1 fld1 A # NULL NULL BTREE YES NULL ++t2 1 fld3 1 fld3 A # NULL NULL BTREE YES NULL ++drop table t4, t3, t2, t1; ++SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; ++CREATE TABLE t1 ( ++cont_nr int(11) NOT NULL auto_increment, ++ver_nr int(11) NOT NULL default '0', ++aufnr int(11) NOT NULL default '0', ++username varchar(50) NOT NULL default '', ++hdl_nr int(11) NOT NULL default '0', ++eintrag date NOT NULL default '0000-00-00', ++st_klasse varchar(40) NOT NULL default '', ++st_wert varchar(40) NOT NULL default '', ++st_zusatz varchar(40) NOT NULL default '', ++st_bemerkung varchar(255) NOT NULL default '', ++kunden_art varchar(40) NOT NULL default '', ++mcbs_knr int(11) default NULL, ++mcbs_aufnr int(11) NOT NULL default '0', ++schufa_status char(1) default '?', ++bemerkung text, ++wirknetz text, ++wf_igz int(11) NOT NULL default '0', ++tarifcode varchar(80) default NULL, ++recycle char(1) default NULL, ++sim varchar(30) default NULL, ++mcbs_tpl varchar(30) default NULL, ++emp_nr int(11) NOT NULL default '0', ++laufzeit int(11) default NULL, ++hdl_name varchar(30) default NULL, ++prov_hdl_nr int(11) NOT NULL default '0', ++auto_wirknetz varchar(50) default NULL, ++auto_billing varchar(50) default NULL, ++touch timestamp NOT NULL, ++kategorie varchar(50) default NULL, ++kundentyp varchar(20) NOT NULL default '', ++sammel_rech_msisdn varchar(30) NOT NULL default '', ++p_nr varchar(9) NOT NULL default '', ++suffix char(3) NOT NULL default '', ++PRIMARY KEY (cont_nr), ++KEY idx_aufnr(aufnr), ++KEY idx_hdl_nr(hdl_nr), ++KEY idx_st_klasse(st_klasse), ++KEY ver_nr(ver_nr), ++KEY eintrag_idx(eintrag), ++KEY emp_nr_idx(emp_nr), ++KEY wf_igz(wf_igz), ++KEY touch(touch), ++KEY hdl_tag(eintrag,hdl_nr), ++KEY prov_hdl_nr(prov_hdl_nr), ++KEY mcbs_aufnr(mcbs_aufnr), ++KEY kundentyp(kundentyp), ++KEY p_nr(p_nr,suffix) ++); ++Warnings: ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++SET sql_mode = default; ++INSERT INTO t1 VALUES (3359356,405,3359356,'Mustermann Musterfrau',52500,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1485525,2122316,'+','','N',1909160,'MobilComSuper92000D2',NULL,NULL,'MS9ND2',3,24,'MobilCom Shop Koeln',52500,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359357,468,3359357,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1503580,2139699,'+','','P',1909171,'MobilComSuper9D1T10SFreisprech(Akquise)',NULL,NULL,'MS9NS1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359358,407,3359358,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1501358,2137473,'N','','N',1909159,'MobilComSuper92000D2',NULL,NULL,'MS9ND2',325,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359359,468,3359359,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1507831,2143894,'+','','P',1909162,'MobilComSuper9D1T10SFreisprech(Akquise)',NULL,NULL,'MS9NS1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359360,0,0,'Mustermann Musterfrau',29674907,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1900169997,2414578,'+',NULL,'N',1909148,'',NULL,NULL,'RV99066_2',20,NULL,'POS',29674907,NULL,NULL,20010202105916,'Mobilfunk','','','97317481','007'); ++INSERT INTO t1 VALUES (3359361,406,3359361,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag storniert','','(7001-84):Storno, Kd. möchte nicht mehr','privat',NULL,0,'+','','P',1909150,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',325,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359362,406,3359362,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1509984,2145874,'+','','P',1909154,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++SELECT ELT(FIELD(kundentyp,'PP','PPA','PG','PGA','FK','FKA','FP','FPA','K','KA','V','VA',''), 'Privat (Private Nutzung)','Privat (Private Nutzung) Sitz im Ausland','Privat (geschaeftliche Nutzung)','Privat (geschaeftliche Nutzung) Sitz im Ausland','Firma (Kapitalgesellschaft)','Firma (Kapitalgesellschaft) Sitz im Ausland','Firma (Personengesellschaft)','Firma (Personengesellschaft) Sitz im Ausland','oeff. rechtl. Koerperschaft','oeff. rechtl. Koerperschaft Sitz im Ausland','Eingetragener Verein','Eingetragener Verein Sitz im Ausland','Typ unbekannt') AS Kundentyp ,kategorie FROM t1 WHERE hdl_nr < 2000000 AND kategorie IN ('Prepaid','Mobilfunk') AND st_klasse = 'Workflow' GROUP BY kundentyp ORDER BY kategorie; ++Kundentyp kategorie ++Privat (Private Nutzung) Mobilfunk ++Warnings: ++Warning 1052 Column 'kundentyp' in group statement is ambiguous ++drop table t1; ++call mtr.add_suppression("Threadpool could not create additional thread to handle queries"); ++SELECT sleep(50000); ++SELECT sleep(50000); ++# -- Success: more than --thread_pool_max_threads normal connections not possible ++SELECT 'Connection on extra port ok'; ++Connection on extra port ok ++Connection on extra port ok ++KILL QUERY @id; ++KILL QUERY @id; ++SELECT 'Connection on extra port 2 ok'; ++Connection on extra port 2 ok ++Connection on extra port 2 ok ++SELECT 'Connection on extra port 3 ok'; ++Connection on extra port 3 ok ++Connection on extra port 3 ok ++sleep(50000) ++1 ++sleep(50000) ++1 +diff --git a/mysql-test/suite/thread_pool/r/pool_of_threads_high_prio_tickets.result b/mysql-test/suite/thread_pool/r/pool_of_threads_high_prio_tickets.result +new file mode 100644 +index 00000000000..7b465d19c23 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/pool_of_threads_high_prio_tickets.result +@@ -0,0 +1,2275 @@ ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=2 --thread_pool_max_threads=2 --thread_pool_high_prio_tickets=2 --loose-skip-mysqlx ++SELECT @@thread_pool_high_prio_tickets; ++@@thread_pool_high_prio_tickets ++2 ++drop table if exists t1,t2,t3,t4; ++CREATE TABLE t1 ( ++Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, ++Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL ++); ++Warnings: ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++INSERT INTO t1 VALUES (9410,9412); ++select period from t1; ++period ++9410 ++select * from t1; ++Period Varor_period ++9410 9412 ++select t1.* from t1; ++Period Varor_period ++9410 9412 ++CREATE TABLE t2 ( ++auto int not null auto_increment, ++fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL, ++companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL, ++fld3 char(30) DEFAULT '' NOT NULL, ++fld4 char(35) DEFAULT '' NOT NULL, ++fld5 char(35) DEFAULT '' NOT NULL, ++fld6 char(4) DEFAULT '' NOT NULL, ++UNIQUE fld1 (fld1), ++KEY fld3 (fld3), ++PRIMARY KEY (auto) ++); ++Warnings: ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++select t2.fld3 from t2 where companynr = 58 and fld3 like "%imaginable%"; ++fld3 ++imaginable ++select fld3 from t2 where fld3 like "%cultivation" ; ++fld3 ++cultivation ++select t2.fld3,companynr from t2 where companynr = 57+1 order by fld3; ++fld3 companynr ++concoct 58 ++druggists 58 ++engrossing 58 ++Eurydice 58 ++exclaimers 58 ++ferociousness 58 ++hopelessness 58 ++Huey 58 ++imaginable 58 ++judges 58 ++merging 58 ++ostrich 58 ++peering 58 ++Phelps 58 ++presumes 58 ++Ruth 58 ++sentences 58 ++Shylock 58 ++straggled 58 ++synergy 58 ++thanking 58 ++tying 58 ++unlocks 58 ++select fld3,companynr from t2 where companynr = 58 order by fld3; ++fld3 companynr ++concoct 58 ++druggists 58 ++engrossing 58 ++Eurydice 58 ++exclaimers 58 ++ferociousness 58 ++hopelessness 58 ++Huey 58 ++imaginable 58 ++judges 58 ++merging 58 ++ostrich 58 ++peering 58 ++Phelps 58 ++presumes 58 ++Ruth 58 ++sentences 58 ++Shylock 58 ++straggled 58 ++synergy 58 ++thanking 58 ++tying 58 ++unlocks 58 ++select fld3 from t2 order by fld3 desc limit 10; ++fld3 ++youthfulness ++yelped ++Wotan ++workers ++Witt ++witchcraft ++Winsett ++Willy ++willed ++wildcats ++select fld3 from t2 order by fld3 desc limit 5; ++fld3 ++youthfulness ++yelped ++Wotan ++workers ++Witt ++select fld3 from t2 order by fld3 desc limit 5,5; ++fld3 ++witchcraft ++Winsett ++Willy ++willed ++wildcats ++select t2.fld3 from t2 where fld3 = 'honeysuckle'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'honeysuckl_'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'hon_ysuckl_'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'honeysuckle%'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'h%le'; ++fld3 ++honeysuckle ++select t2.fld3 from t2 where fld3 LIKE 'honeysuckle_'; ++fld3 ++select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%'; ++fld3 ++explain select t2.fld3 from t2 where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ref fld3 fld3 120 const # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` IGNORE INDEX (`fld3`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` USE INDEX (`fld1`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ref fld3 fld3 120 const # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` USE INDEX (`fld3`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle'; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ref fld3 fld3 120 const # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` USE INDEX (`fld3`) USE INDEX (`fld1`) where (`test`.`t2`.`fld3` = 'honeysuckle') ++explain select fld3 from t2 ignore index (fld3,not_used); ++ERROR 42000: Key 'not_used' doesn't exist in table 't2' ++explain select fld3 from t2 use index (not_used); ++ERROR 42000: Key 'not_used' doesn't exist in table 't2' ++select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; ++fld3 ++honeysuckle ++honoring ++explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL range fld3 fld3 120 NULL # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where ((`test`.`t2`.`fld3` >= 'honeysuckle') and (`test`.`t2`.`fld3` <= 'honoring')) order by `test`.`t2`.`fld3` ++select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3; ++fld1 fld3 ++148504 Colombo ++068305 Colombo ++000000 nondecreasing ++select fld1,fld3 from t2 where companynr = 37 and fld3 = 'appendixes'; ++fld1 fld3 ++232605 appendixes ++1232605 appendixes ++1232606 appendixes ++1232607 appendixes ++1232608 appendixes ++1232609 appendixes ++select fld1 from t2 where fld1=250501 or fld1="250502"; ++fld1 ++250501 ++250502 ++explain select fld1 from t2 where fld1=250501 or fld1="250502"; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL range fld1 fld1 4 NULL # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld1` AS `fld1` from `test`.`t2` where ((`test`.`t2`.`fld1` = 250501) or (`test`.`t2`.`fld1` = 250502)) ++select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; ++fld1 ++250501 ++250502 ++250505 ++250601 ++explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL range fld1 fld1 4 NULL # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld1` AS `fld1` from `test`.`t2` where ((`test`.`t2`.`fld1` = 250501) or (`test`.`t2`.`fld1` = 250502) or ((`test`.`t2`.`fld1` >= 250505) and (`test`.`t2`.`fld1` <= 250601)) or (`test`.`t2`.`fld1` between 250501 and 250502)) ++select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%'; ++fld1 fld3 ++012001 flanking ++013602 foldout ++013606 fingerings ++018007 fanatic ++018017 featherweight ++018054 fetters ++018103 flint ++018104 flopping ++036002 funereal ++038017 fetched ++038205 firearm ++058004 Fenton ++088303 feminine ++186002 freakish ++188007 flurried ++188505 fitting ++198006 furthermore ++202301 Fitzpatrick ++208101 fiftieth ++208113 freest ++218008 finishers ++218022 feed ++218401 faithful ++226205 foothill ++226209 furnishings ++228306 forthcoming ++228311 fated ++231315 freezes ++232102 forgivably ++238007 filial ++238008 fixedly ++select fld3 from t2 where fld3 like "L%" and fld3 = "ok"; ++fld3 ++select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly"); ++fld3 ++Chantilly ++select fld1,fld3 from t2 where fld1 like "25050%"; ++fld1 fld3 ++250501 poisoning ++250502 Iraqis ++250503 heaving ++250504 population ++250505 bomb ++select fld1,fld3 from t2 where fld1 like "25050_"; ++fld1 fld3 ++250501 poisoning ++250502 Iraqis ++250503 heaving ++250504 population ++250505 bomb ++select distinct companynr from t2; ++companynr ++00 ++37 ++36 ++50 ++58 ++29 ++40 ++53 ++65 ++41 ++34 ++68 ++select distinct companynr from t2 order by companynr; ++companynr ++00 ++29 ++34 ++36 ++37 ++40 ++41 ++50 ++53 ++58 ++65 ++68 ++select distinct companynr from t2 order by companynr desc; ++companynr ++68 ++65 ++58 ++53 ++50 ++41 ++40 ++37 ++36 ++34 ++29 ++00 ++select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%"; ++fld3 period ++obliterates 9410 ++offload 9410 ++opaquely 9410 ++organizer 9410 ++overestimating 9410 ++overlay 9410 ++select distinct fld3 from t2 where companynr = 34 order by fld3; ++fld3 ++absentee ++accessed ++ahead ++alphabetic ++Asiaticizations ++attitude ++aye ++bankruptcies ++belays ++Blythe ++bomb ++boulevard ++bulldozes ++cannot ++caressing ++charcoal ++checksumming ++chess ++clubroom ++colorful ++cosy ++creator ++crying ++Darius ++diffusing ++duality ++Eiffel ++Epiphany ++Ernestine ++explorers ++exterminated ++famine ++forked ++Gershwins ++heaving ++Hodges ++Iraqis ++Italianization ++Lagos ++landslide ++libretto ++Majorca ++mastering ++narrowed ++occurred ++offerers ++Palestine ++Peruvianizes ++pharmaceutic ++poisoning ++population ++Pygmalion ++rats ++realest ++recording ++regimented ++retransmitting ++reviver ++rouses ++scars ++sicker ++sleepwalk ++stopped ++sugars ++translatable ++uncles ++unexpected ++uprisings ++versatility ++vest ++select distinct fld3 from t2 limit 10; ++fld3 ++abates ++abiding ++Abraham ++abrogating ++absentee ++abut ++accessed ++accruing ++accumulating ++accuracies ++select distinct fld3 from t2 having fld3 like "A%" limit 10; ++fld3 ++abates ++abiding ++Abraham ++abrogating ++absentee ++abut ++accessed ++accruing ++accumulating ++accuracies ++select distinct substring(fld3,1,3) from t2 where fld3 like "A%"; ++substring(fld3,1,3) ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++Adl ++adm ++Ado ++ads ++adv ++aer ++aff ++afi ++afl ++afo ++agi ++ahe ++aim ++air ++Ald ++alg ++ali ++all ++alp ++alr ++ama ++ame ++amm ++ana ++and ++ane ++Ang ++ani ++Ann ++Ant ++api ++app ++aqu ++Ara ++arc ++Arm ++arr ++Art ++Asi ++ask ++asp ++ass ++ast ++att ++aud ++Aug ++aut ++ave ++avo ++awe ++aye ++Azt ++select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10; ++a ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10; ++substring(fld3,1,3) ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10; ++a ++aba ++abi ++Abr ++abs ++abu ++acc ++acq ++acu ++Ade ++adj ++create table t3 ( ++period int not null, ++name char(32) not null, ++companynr int not null, ++price double(11,0), ++price2 double(11,0), ++key (period), ++key (name) ++); ++Warnings: ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++create temporary table tmp select * from t3; ++Warnings: ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++Warning 1681 Specifying number of digits for floating point data types is deprecated and will be removed in a future release. ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++insert into tmp select * from t3; ++insert into t3 select * from tmp; ++alter table t3 add t2nr int not null auto_increment primary key first; ++drop table tmp; ++SET BIG_TABLES=1; ++select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10; ++namn ++Abraham Abraham ++abrogating abrogating ++admonishing admonishing ++Adolph Adolph ++afield afield ++aging aging ++ammonium ammonium ++analyzable analyzable ++animals animals ++animized animized ++SET BIG_TABLES=0; ++select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10; ++concat(fld3," ",fld3) ++Abraham Abraham ++abrogating abrogating ++admonishing admonishing ++Adolph Adolph ++afield afield ++aging aging ++ammonium ammonium ++analyzable analyzable ++animals animals ++animized animized ++select distinct fld5 from t2 limit 10; ++fld5 ++neat ++Steinberg ++jarring ++tinily ++balled ++persist ++attainments ++fanatic ++measures ++rightfulness ++select distinct companynr, fld3,count(*) from t2 group by companynr,fld3 order by companynr, fld3 limit 10; ++companynr fld3 count(*) ++00 affixed 1 ++00 and 1 ++00 annoyers 1 ++00 Anthony 1 ++00 assayed 1 ++00 assurers 1 ++00 attendants 1 ++00 bedlam 1 ++00 bedpost 1 ++00 boasted 1 ++SET BIG_TABLES=1; ++select distinct companynr, fld3,count(*) from t2 group by companynr,fld3 order by companynr, fld3 limit 10; ++companynr fld3 count(*) ++00 affixed 1 ++00 and 1 ++00 annoyers 1 ++00 Anthony 1 ++00 assayed 1 ++00 assurers 1 ++00 attendants 1 ++00 bedlam 1 ++00 bedpost 1 ++00 boasted 1 ++SET BIG_TABLES=0; ++select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10; ++fld3 repeat("a",length(fld3)) count(*) ++Baird aaaaa 1 ++balled aaaaaa 1 ++ballgown aaaaaaaa 1 ++Baltimorean aaaaaaaaaaa 1 ++bankruptcies aaaaaaaaaaaa 1 ++Barry aaaaa 1 ++batting aaaaaaa 1 ++beaner aaaaaa 1 ++beasts aaaaaa 1 ++beaters aaaaaaa 1 ++select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2; ++companynr rtrim(space(512+companynr)) ++37 ++78 ++101 ++154 ++311 ++447 ++512 ++select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by fld3; ++fld3 ++explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL fld1 NULL NULL NULL # # Using where; Using temporary; Using filesort ++1 SIMPLE t3 NULL eq_ref PRIMARY PRIMARY 4 test.t2.fld1 # # Using where; Using index ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t3`.`t2nr` AS `t2nr`,`test`.`t2`.`fld3` AS `fld3` from `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`companynr` = 34) and (`test`.`t2`.`fld1` = `test`.`t3`.`t2nr`)) order by `test`.`t3`.`t2nr`,`test`.`t2`.`fld3` ++explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t1 NULL ALL period NULL NULL NULL # # Using temporary; Using filesort ++1 SIMPLE t3 NULL ref period period 4 test.t1.period # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t1`.`t2nr` AS `t2nr`,`test`.`t1`.`period` AS `period`,`test`.`t1`.`name` AS `name`,`test`.`t1`.`companynr` AS `companynr`,`test`.`t1`.`price` AS `price`,`test`.`t1`.`price2` AS `price2`,`test`.`t3`.`t2nr` AS `t2nr`,`test`.`t3`.`period` AS `period`,`test`.`t3`.`name` AS `name`,`test`.`t3`.`companynr` AS `companynr`,`test`.`t3`.`price` AS `price`,`test`.`t3`.`price2` AS `price2` from `test`.`t3` `t1` join `test`.`t3` where (`test`.`t3`.`period` = `test`.`t1`.`period`) order by `test`.`t3`.`period` ++explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t3 NULL index period period 4 NULL # # NULL ++1 SIMPLE t1 NULL ref period period 4 test.t3.period # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t1`.`t2nr` AS `t2nr`,`test`.`t1`.`period` AS `period`,`test`.`t1`.`name` AS `name`,`test`.`t1`.`companynr` AS `companynr`,`test`.`t1`.`price` AS `price`,`test`.`t1`.`price2` AS `price2`,`test`.`t3`.`t2nr` AS `t2nr`,`test`.`t3`.`period` AS `period`,`test`.`t3`.`name` AS `name`,`test`.`t3`.`companynr` AS `companynr`,`test`.`t3`.`price` AS `price`,`test`.`t3`.`price2` AS `price2` from `test`.`t3` `t1` join `test`.`t3` where (`test`.`t1`.`period` = `test`.`t3`.`period`) order by `test`.`t3`.`period` limit 10 ++explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t1 NULL index period period 4 NULL # # NULL ++1 SIMPLE t3 NULL ref period period 4 test.t1.period # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t1`.`t2nr` AS `t2nr`,`test`.`t1`.`period` AS `period`,`test`.`t1`.`name` AS `name`,`test`.`t1`.`companynr` AS `companynr`,`test`.`t1`.`price` AS `price`,`test`.`t1`.`price2` AS `price2`,`test`.`t3`.`t2nr` AS `t2nr`,`test`.`t3`.`period` AS `period`,`test`.`t3`.`name` AS `name`,`test`.`t3`.`companynr` AS `companynr`,`test`.`t3`.`price` AS `price`,`test`.`t3`.`price2` AS `price2` from `test`.`t3` `t1` join `test`.`t3` where (`test`.`t3`.`period` = `test`.`t1`.`period`) order by `test`.`t1`.`period` limit 10 ++select period from t1; ++period ++9410 ++select period from t1 where period=1900; ++period ++select fld3,period from t1,t2 where fld1 = 011401 order by period; ++fld3 period ++breaking 9410 ++select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001; ++fld3 period ++breaking 1001 ++explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL const fld1 fld1 4 const # # NULL ++1 SIMPLE t3 NULL const PRIMARY,period PRIMARY 4 const # # NULL ++Warnings: ++Note 1003 /* select#1 */ select 'breaking' AS `fld3`,'1001' AS `period` from `test`.`t2` join `test`.`t3` where true ++select fld3,period from t2,t1 where companynr*10 = 37*10; ++fld3 period ++Abraham 9410 ++Aden 9410 ++Adolph 9410 ++Aldrich 9410 ++Alison 9410 ++Anatole 9410 ++Antarctica 9410 ++Antares 9410 ++Arabia 9410 ++Artemia 9410 ++Augustine 9410 ++Baird 9410 ++Beebe 9410 ++Butterfield 9410 ++CERN 9410 ++Cassites 9410 ++Chicana 9410 ++Chippewa 9410 ++Clayton 9410 ++Conley 9410 ++Connally 9410 ++Crays 9410 ++DiMaggio 9410 ++Dutchman 9410 ++Eulerian 9410 ++Evanston 9410 ++Everhart 9410 ++Fenton 9410 ++Fitzpatrick 9410 ++Galatean 9410 ++Gandhian 9410 ++Ganymede 9410 ++Goldstine 9410 ++Gothicism 9410 ++Graves 9410 ++Greenberg 9410 ++Gurkha 9410 ++Hawaii 9410 ++Hegelian 9410 ++Hornblower 9410 ++Huffman 9410 ++Hunter 9410 ++Joplin 9410 ++Judas 9410 ++Kane 9410 ++Kantian 9410 ++Kevin 9410 ++Kinsey 9410 ++Kline 9410 ++Lars 9410 ++Latinizes 9410 ++Lillian 9410 ++Lizzy 9410 ++Majorca 9410 ++Manhattanize 9410 ++McGovern 9410 ++Melinda 9410 ++Merritt 9410 ++Micronesia 9410 ++Miles 9410 ++Miltonism 9410 ++Nabisco 9410 ++Nazis 9410 ++Newtonian 9410 ++Norwalk 9410 ++Pandora 9410 ++Parsifal 9410 ++Peruvian 9410 ++Punjab 9410 ++Pyle 9410 ++Quixotism 9410 ++Romano 9410 ++Romans 9410 ++Sabine 9410 ++Sault 9410 ++Saxony 9410 ++Selfridge 9410 ++Shanghais 9410 ++Simla 9410 ++Simon 9410 ++Stalin 9410 ++Steinberg 9410 ++Taoism 9410 ++Teresa 9410 ++Tipperary 9410 ++Weissmuller 9410 ++Winsett 9410 ++Wotan 9410 ++abates 9410 ++abrogating 9410 ++accessed 9410 ++admiring 9410 ++admonishing 9410 ++afield 9410 ++afore 9410 ++aging 9410 ++airships 9410 ++alike 9410 ++allot 9410 ++already 9410 ++amenities 9410 ++ammonium 9410 ++analogy 9410 ++analyzable 9410 ++animals 9410 ++animized 9410 ++annihilates 9410 ++announced 9410 ++announces 9410 ++apiary 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++appendixes 9410 ++arriving 9410 ++arteriole 9410 ++assails 9410 ++astound 9410 ++attainments 9410 ++attrition 9410 ++audiology 9410 ++avenge 9410 ++avoidable 9410 ++babies 9410 ++babysitting 9410 ++balled 9410 ++beaner 9410 ++beaters 9410 ++bee 9410 ++befouled 9410 ++bellow 9410 ++bestseller 9410 ++betroth 9410 ++bewilderingly 9410 ++bills 9410 ++bitterroot 9410 ++bivalves 9410 ++bloater 9410 ++bloodbath 9410 ++boat 9410 ++boom 9410 ++boorish 9410 ++boulder 9410 ++breaking 9410 ++brunch 9410 ++buckboards 9410 ++burlesque 9410 ++cage 9410 ++capably 9410 ++capped 9410 ++cascade 9410 ++causality 9410 ++cautioned 9410 ++ceiling 9410 ++celery 9410 ++certificates 9410 ++chafe 9410 ++chaperone 9410 ++charges 9410 ++chasm 9410 ++checkpoints 9410 ++chewing 9410 ++chews 9410 ++chillingly 9410 ++chronicle 9410 ++ciphers 9410 ++civics 9410 ++clamored 9410 ++clenched 9410 ++clockers 9410 ++coexist 9410 ++cokes 9410 ++combed 9410 ++coming 9410 ++commencements 9410 ++commonplace 9410 ++communicants 9410 ++compartment 9410 ++comprehensive 9410 ++comprised 9410 ++conceptions 9410 ++concludes 9410 ++congregates 9410 ++contrary 9410 ++contrasted 9410 ++convenient 9410 ++convulsion 9410 ++corset 9410 ++count 9410 ++coverings 9410 ++craziness 9410 ++creak 9410 ++creek 9410 ++critiques 9410 ++crunches 9410 ++culled 9410 ++cult 9410 ++cupboard 9410 ++cured 9410 ++cute 9410 ++daughter 9410 ++decliner 9410 ++decomposition 9410 ++deductions 9410 ++dehydrate 9410 ++deludes 9410 ++denizen 9410 ++denotative 9410 ++denounces 9410 ++dental 9410 ++dentally 9410 ++descendants 9410 ++despot 9410 ++destroyer 9410 ++detectably 9410 ++dialysis 9410 ++dimensions 9410 ++disable 9410 ++discounts 9410 ++disentangle 9410 ++disobedience 9410 ++dissociate 9410 ++dogging 9410 ++dopers 9410 ++drains 9410 ++dreaded 9410 ++ducks 9410 ++dusted 9410 ++effortlessly 9410 ++electroencephalography 9410 ++elite 9410 ++embassies 9410 ++employing 9410 ++encompass 9410 ++encompasses 9410 ++environing 9410 ++epistle 9410 ++equilibrium 9410 ++erases 9410 ++error 9410 ++eschew 9410 ++eternal 9410 ++evened 9410 ++evenhandedly 9410 ++eventful 9410 ++excises 9410 ++exclamation 9410 ++excrete 9410 ++exhausts 9410 ++expelled 9410 ++extents 9410 ++externally 9410 ++extracted 9410 ++faithful 9410 ++fanatic 9410 ++fated 9410 ++featherweight 9410 ++feed 9410 ++feminine 9410 ++fetched 9410 ++fetters 9410 ++fiftieth 9410 ++filial 9410 ++fingerings 9410 ++finishers 9410 ++firearm 9410 ++fitting 9410 ++fixedly 9410 ++flanking 9410 ++flint 9410 ++flopping 9410 ++flurried 9410 ++foldout 9410 ++foothill 9410 ++forgivably 9410 ++forthcoming 9410 ++freakish 9410 ++freest 9410 ++freezes 9410 ++funereal 9410 ++furnishings 9410 ++furthermore 9410 ++gadfly 9410 ++gainful 9410 ++galling 9410 ++garage 9410 ++gentleman 9410 ++gifted 9410 ++gleaning 9410 ++glut 9410 ++goblins 9410 ++governing 9410 ++gradually 9410 ++grazing 9410 ++gritty 9410 ++groupings 9410 ++guides 9410 ++guitars 9410 ++handgun 9410 ++handy 9410 ++heiress 9410 ++hoarder 9410 ++honoring 9410 ++hostess 9410 ++humanness 9410 ++humiliation 9410 ++humility 9410 ++hushes 9410 ++husky 9410 ++hypothesizer 9410 ++icon 9410 ++ideas 9410 ++impelling 9410 ++impending 9410 ++imperial 9410 ++imperiously 9410 ++imprint 9410 ++impulsive 9410 ++inaccuracy 9410 ++inch 9410 ++incidentals 9410 ++incorrectly 9410 ++incurring 9410 ++index 9410 ++indulge 9410 ++indulgences 9410 ++ineffective 9410 ++infallibly 9410 ++infest 9410 ++inform 9410 ++inmate 9410 ++insolence 9410 ++instruments 9410 ++intelligibility 9410 ++intentness 9410 ++intercepted 9410 ++interdependent 9410 ++interrelationships 9410 ++interrogate 9410 ++investigations 9410 ++irresponsibly 9410 ++jarring 9410 ++journalizing 9410 ++juveniles 9410 ++kanji 9410 ++kingdom 9410 ++kiting 9410 ++labeled 9410 ++languages 9410 ++laterally 9410 ++lawgiver 9410 ++leaflet 9410 ++leavings 9410 ++lectured 9410 ++leftover 9410 ++lewdly 9410 ++lied 9410 ++linear 9410 ++lists 9410 ++lithograph 9410 ++lore 9410 ++luckily 9410 ++males 9410 ++marginal 9410 ++mastering 9410 ++mayoral 9410 ++meanwhile 9410 ++measures 9410 ++measures 9410 ++mechanizing 9410 ++medical 9410 ++meditation 9410 ++metaphysically 9410 ++mineral 9410 ++miniaturizes 9410 ++minima 9410 ++minion 9410 ++minting 9410 ++misted 9410 ++misunderstander 9410 ++mixture 9410 ++motors 9410 ++mournfulness 9410 ++multilayer 9410 ++mumbles 9410 ++mushrooms 9410 ++mystic 9410 ++navies 9410 ++navigate 9410 ++neat 9410 ++neonatal 9410 ++nested 9410 ++noncritical 9410 ++normalizes 9410 ++obliterates 9410 ++offload 9410 ++opaquely 9410 ++organizer 9410 ++overestimating 9410 ++overlay 9410 ++parametrized 9410 ++parenthood 9410 ++parters 9410 ++participated 9410 ++partridges 9410 ++peacock 9410 ++peeked 9410 ++pellagra 9410 ++percentage 9410 ++percentage 9410 ++persist 9410 ++perturb 9410 ++pessimist 9410 ++pests 9410 ++petted 9410 ++pictures 9410 ++pithed 9410 ++pityingly 9410 ++poison 9410 ++posed 9410 ++positioning 9410 ++postulation 9410 ++praised 9410 ++precaution 9410 ++precipitable 9410 ++preclude 9410 ++presentation 9410 ++pressure 9410 ++previewing 9410 ++priceless 9410 ++primary 9410 ++psychic 9410 ++publicly 9410 ++puddings 9410 ++quagmire 9410 ++quitter 9410 ++railway 9410 ++raining 9410 ++rains 9410 ++ravines 9410 ++readable 9410 ++realized 9410 ++realtor 9410 ++reassigned 9410 ++recruited 9410 ++reduce 9410 ++regimented 9410 ++registration 9410 ++relatively 9410 ++relaxing 9410 ++relishing 9410 ++relives 9410 ++renew 9410 ++repelled 9410 ++repetitions 9410 ++reporters 9410 ++reporters 9410 ++repressions 9410 ++resplendent 9410 ++resumes 9410 ++rifles 9410 ++rightful 9410 ++rightfully 9410 ++rightfulness 9410 ++ripeness 9410 ++riser 9410 ++roped 9410 ++rudeness 9410 ++rules 9410 ++rural 9410 ++rusting 9410 ++sadly 9410 ++sags 9410 ++sanding 9410 ++saplings 9410 ++sating 9410 ++save 9410 ++sawtooth 9410 ++scarf 9410 ++scatterbrain 9410 ++scheduling 9410 ++schemer 9410 ++scholastics 9410 ++scornfully 9410 ++secures 9410 ++securing 9410 ++seminaries 9410 ++serializations 9410 ++serpents 9410 ++serving 9410 ++severely 9410 ++sews 9410 ++shapelessly 9410 ++shipyard 9410 ++shooter 9410 ++similarities 9410 ++skulking 9410 ++slaughter 9410 ++sloping 9410 ++smoothed 9410 ++snatching 9410 ++socializes 9410 ++sophomore 9410 ++sorters 9410 ++spatial 9410 ++specification 9410 ++specifics 9410 ++spongers 9410 ++spools 9410 ++sportswriting 9410 ++sporty 9410 ++squabbled 9410 ++squeaking 9410 ++squeezes 9410 ++stabilizes 9410 ++stairway 9410 ++standardizes 9410 ++star 9410 ++starlet 9410 ++stated 9410 ++stint 9410 ++stodgy 9410 ++store 9410 ++straight 9410 ++stranglings 9410 ++subdirectory 9410 ++subjective 9410 ++subschema 9410 ++succumbed 9410 ++suites 9410 ++sumac 9410 ++sureties 9410 ++swaying 9410 ++sweetish 9410 ++swelling 9410 ++syndicate 9410 ++taxonomically 9410 ++techniques 9410 ++teem 9410 ++teethe 9410 ++tempering 9410 ++terminal 9410 ++terminator 9410 ++terminators 9410 ++test 9410 ++testicle 9410 ++textures 9410 ++theorizers 9410 ++throttles 9410 ++tidiness 9410 ++timesharing 9410 ++tinily 9410 ++tinting 9410 ++title 9410 ++tragedies 9410 ++traitor 9410 ++trimmings 9410 ++tropics 9410 ++unaffected 9410 ++uncovering 9410 ++undoes 9410 ++ungrateful 9410 ++universals 9410 ++unplug 9410 ++unruly 9410 ++untying 9410 ++unwilling 9410 ++vacuuming 9410 ++validate 9410 ++vanish 9410 ++ventilate 9410 ++veranda 9410 ++vests 9410 ++wallet 9410 ++waltz 9410 ++warm 9410 ++warningly 9410 ++watering 9410 ++weasels 9410 ++western 9410 ++whiteners 9410 ++widens 9410 ++witchcraft 9410 ++workers 9410 ++yelped 9410 ++youthfulness 9410 ++select fld3,period,price,price2 from t2,t3 where t2.fld1=t3.t2nr and period >= 1001 and period <= 1002 and t2.companynr = 37 order by fld3,period, price; ++fld3 period price price2 ++admonishing 1002 28357832 8723648 ++analyzable 1002 28357832 8723648 ++annihilates 1001 5987435 234724 ++Antares 1002 28357832 8723648 ++astound 1001 5987435 234724 ++audiology 1001 5987435 234724 ++Augustine 1002 28357832 8723648 ++Baird 1002 28357832 8723648 ++bewilderingly 1001 5987435 234724 ++breaking 1001 5987435 234724 ++Conley 1001 5987435 234724 ++dentally 1002 28357832 8723648 ++dissociate 1002 28357832 8723648 ++elite 1001 5987435 234724 ++eschew 1001 5987435 234724 ++Eulerian 1001 5987435 234724 ++flanking 1001 5987435 234724 ++foldout 1002 28357832 8723648 ++funereal 1002 28357832 8723648 ++galling 1002 28357832 8723648 ++Graves 1001 5987435 234724 ++grazing 1001 5987435 234724 ++groupings 1001 5987435 234724 ++handgun 1001 5987435 234724 ++humility 1002 28357832 8723648 ++impulsive 1002 28357832 8723648 ++inch 1001 5987435 234724 ++intelligibility 1001 5987435 234724 ++jarring 1001 5987435 234724 ++lawgiver 1001 5987435 234724 ++lectured 1002 28357832 8723648 ++Merritt 1002 28357832 8723648 ++neonatal 1001 5987435 234724 ++offload 1002 28357832 8723648 ++parters 1002 28357832 8723648 ++pityingly 1002 28357832 8723648 ++puddings 1002 28357832 8723648 ++Punjab 1001 5987435 234724 ++quitter 1002 28357832 8723648 ++realtor 1001 5987435 234724 ++relaxing 1001 5987435 234724 ++repetitions 1001 5987435 234724 ++resumes 1001 5987435 234724 ++Romans 1002 28357832 8723648 ++rusting 1001 5987435 234724 ++scholastics 1001 5987435 234724 ++skulking 1002 28357832 8723648 ++stated 1002 28357832 8723648 ++suites 1002 28357832 8723648 ++sureties 1001 5987435 234724 ++testicle 1002 28357832 8723648 ++tinily 1002 28357832 8723648 ++tragedies 1001 5987435 234724 ++trimmings 1001 5987435 234724 ++vacuuming 1001 5987435 234724 ++ventilate 1001 5987435 234724 ++wallet 1001 5987435 234724 ++Weissmuller 1002 28357832 8723648 ++Wotan 1002 28357832 8723648 ++select t2.fld1,fld3,period,price,price2 from t2,t3 where t2.fld1>= 18201 and t2.fld1 <= 18811 and t2.fld1=t3.t2nr and period = 1001 and t2.companynr = 37; ++fld1 fld3 period price price2 ++018201 relaxing 1001 5987435 234724 ++018601 vacuuming 1001 5987435 234724 ++018801 inch 1001 5987435 234724 ++018811 repetitions 1001 5987435 234724 ++create table t4 ( ++companynr tinyint(2) unsigned zerofill NOT NULL default '00', ++companyname char(30) NOT NULL default '', ++PRIMARY KEY (companynr), ++UNIQUE KEY companyname(companyname) ++) MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; ++Warnings: ++Warning 1681 The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; ++companynr companyname ++00 Unknown ++29 company 1 ++34 company 2 ++36 company 3 ++37 company 4 ++40 company 5 ++41 company 6 ++50 company 11 ++53 company 7 ++58 company 8 ++65 company 9 ++68 company 10 ++select SQL_SMALL_RESULT t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; ++companynr companyname ++00 Unknown ++37 company 4 ++36 company 3 ++50 company 11 ++58 company 8 ++29 company 1 ++40 company 5 ++53 company 7 ++65 company 9 ++41 company 6 ++34 company 2 ++68 company 10 ++select * from t1,t1 t12; ++Period Varor_period Period Varor_period ++9410 9412 9410 9412 ++select t2.fld1,t22.fld1 from t2,t2 t22 where t2.fld1 >= 250501 and t2.fld1 <= 250505 and t22.fld1 >= 250501 and t22.fld1 <= 250505; ++fld1 fld1 ++250501 250501 ++250501 250502 ++250501 250503 ++250501 250504 ++250501 250505 ++250502 250501 ++250502 250502 ++250502 250503 ++250502 250504 ++250502 250505 ++250503 250501 ++250503 250502 ++250503 250503 ++250503 250504 ++250503 250505 ++250504 250501 ++250504 250502 ++250504 250503 ++250504 250504 ++250504 250505 ++250505 250501 ++250505 250502 ++250505 250503 ++250505 250504 ++250505 250505 ++insert into t2 (fld1, companynr) values (999999,99); ++analyze table t2,t4; ++Table Op Msg_type Msg_text ++test.t2 analyze status OK ++test.t4 analyze status OK ++select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; ++companynr companyname ++99 NULL ++select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null; ++count(*) ++1199 ++explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # 100.00 NULL ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # 100.00 Using where; Not exists ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t2` left join `test`.`t4` on((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`)) where (`test`.`t4`.`companynr` is null) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # 100.00 Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # 10.00 Using where; Not exists; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t2`.`companynr` is null) ++select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; ++companynr companyname ++select count(*) from t2 left join t4 using (companynr) where companynr is not null; ++count(*) ++1200 ++explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # NULL Impossible WHERE ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t2` left join `test`.`t4` on(multiple equal(`test`.`t2`.`companynr`, `test`.`t4`.`companynr`)) where false ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # NULL Impossible WHERE ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on(multiple equal(`test`.`t4`.`companynr`, `test`.`t2`.`companynr`)) where false ++delete from t2 where fld1=999999; ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` join `test`.`t2` where ((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`) and (`test`.`t2`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` join `test`.`t2` where ((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`) and (`test`.`t2`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++1 SIMPLE t4 NULL eq_ref PRIMARY PRIMARY 1 test.t2.companynr # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` join `test`.`t2` where ((`test`.`t4`.`companynr` = `test`.`t2`.`companynr`) and (`test`.`t2`.`companynr` > 0) and (`test`.`t2`.`companynr` > 0)) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t4`.`companynr` > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t4`.`companynr` > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t4`.`companynr` > 0) and (`test`.`t4`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t2`.`companynr` > 0) or (`test`.`t2`.`companynr` is null)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index PRIMARY companyname 120 NULL # # Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t2`.`companynr` > 0) or (`test`.`t4`.`companynr` > 0)) ++explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (ifnull(`test`.`t2`.`companynr`,1) > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (`test`.`t4`.`companynr` > 0) ++explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL range PRIMARY PRIMARY 1 NULL # # Using where ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where ((`test`.`t4`.`companynr` > 0) or (`test`.`t4`.`companynr` > 0)) ++explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using where; Using index ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t4`.`companynr` AS `companynr`,`test`.`t4`.`companyname` AS `companyname` from `test`.`t4` left join `test`.`t2` on((`test`.`t2`.`companynr` = `test`.`t4`.`companynr`)) where (ifnull(`test`.`t4`.`companynr`,1) > 0) ++select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; ++companynr companynr ++37 36 ++41 40 ++explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t4 NULL index NULL companyname 120 NULL # # Using index; Using temporary ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where; Using join buffer (hash join) ++Warnings: ++Note 1003 /* select#1 */ select distinct `test`.`t2`.`companynr` AS `companynr`,`test`.`t4`.`companynr` AS `companynr` from `test`.`t2` join `test`.`t4` where (`test`.`t2`.`companynr` = (`test`.`t4`.`companynr` + 1)) ++select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008; ++fld1 companynr fld3 period ++038008 37 reporters 1008 ++038208 37 Selfridge 1008 ++select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t2.fld1 = 38208 or t2.fld1 = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009; ++fld1 companynr fld3 period ++038008 37 reporters 1008 ++038208 37 Selfridge 1008 ++select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t3.t2nr = 38208 or t3.t2nr = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009; ++fld1 companynr fld3 period ++038008 37 reporters 1008 ++038208 37 Selfridge 1008 ++select period from t1 where (((period > 0) or period < 10000 or (period = 1900)) and (period=1900 and period <= 1901) or (period=1903 and (period=1903)) and period>=1902) or ((period=1904 or period=1905) or (period=1906 or period>1907)) or (period=1908 and period = 1909); ++period ++9410 ++select period from t1 where ((period > 0 and period < 1) or (((period > 0 and period < 100) and (period > 10)) or (period > 10)) or (period > 0 and (period > 5 or period > 6))); ++period ++9410 ++select a.fld1 from t2 as a,t2 b where ((a.fld1 = 250501 and a.fld1=b.fld1) or a.fld1=250502 or a.fld1=250503 or (a.fld1=250505 and a.fld1<=b.fld1 and b.fld1>=a.fld1)) and a.fld1=b.fld1; ++fld1 ++250501 ++250502 ++250503 ++250505 ++select fld1 from t2 where fld1 in (250502,98005,98006,250503,250605,250606) and fld1 >=250502 and fld1 not in (250605,250606); ++fld1 ++250502 ++250503 ++select fld1 from t2 where fld1 between 250502 and 250504; ++fld1 ++250502 ++250503 ++250504 ++select fld3 from t2 where (((fld3 like "_%L%" ) or (fld3 like "%ok%")) and ( fld3 like "L%" or fld3 like "G%")) and fld3 like "L%" ; ++fld3 ++label ++labeled ++labeled ++landslide ++laterally ++leaflet ++lewdly ++Lillian ++luckily ++select count(*) from t1; ++count(*) ++1 ++select companynr,count(*),sum(fld1) from t2 group by companynr; ++companynr count(*) sum(fld1) ++00 82 10355753 ++37 588 83602098 ++36 215 22786296 ++50 11 1595438 ++58 23 2254293 ++29 95 14473298 ++40 37 6618386 ++53 4 793210 ++65 10 2284055 ++41 52 12816335 ++34 70 17788966 ++68 12 3097288 ++select companynr,count(*) from t2 group by companynr order by companynr desc limit 5; ++companynr count(*) ++68 12 ++65 10 ++58 23 ++53 4 ++50 11 ++select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; ++count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) ++70 absentee vest 17788966 254128.0857 3272.5939722090234 10709871.306938833 ++explain select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # Using where ++Warnings: ++Note 1003 /* select#1 */ select count(0) AS `count(*)`,min(`test`.`t2`.`fld4`) AS `min(fld4)`,max(`test`.`t2`.`fld4`) AS `max(fld4)`,sum(`test`.`t2`.`fld1`) AS `sum(fld1)`,avg(`test`.`t2`.`fld1`) AS `avg(fld1)`,std(`test`.`t2`.`fld1`) AS `std(fld1)`,variance(`test`.`t2`.`fld1`) AS `variance(fld1)` from `test`.`t2` where ((`test`.`t2`.`companynr` = 34) and (`test`.`t2`.`fld4` <> '')) ++select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr order by companynr limit 3; ++companynr count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) ++00 82 Anthony windmills 10355753 126289.6707 115550.97568479746 13352027981.708656 ++29 95 abut wetness 14473298 152350.5053 8368.547956641249 70032594.90260443 ++34 70 absentee vest 17788966 254128.0857 3272.5939722090234 10709871.306938833 ++select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr order by companynr,t2nr limit 10; ++companynr t2nr count(price) sum(price) min(price) max(price) avg(price) ++37 1 1 5987435 5987435 5987435 5987435.0000 ++37 2 1 28357832 28357832 28357832 28357832.0000 ++37 3 1 39654943 39654943 39654943 39654943.0000 ++37 11 1 5987435 5987435 5987435 5987435.0000 ++37 12 1 28357832 28357832 28357832 28357832.0000 ++37 13 1 39654943 39654943 39654943 39654943.0000 ++37 21 1 5987435 5987435 5987435 5987435.0000 ++37 22 1 28357832 28357832 28357832 28357832.0000 ++37 23 1 39654943 39654943 39654943 39654943.0000 ++37 31 1 5987435 5987435 5987435 5987435.0000 ++select /*! SQL_SMALL_RESULT */ ++companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr, t2nr order by companynr,t2nr limit 10; ++companynr t2nr count(price) sum(price) min(price) max(price) avg(price) ++37 1 1 5987435 5987435 5987435 5987435.0000 ++37 2 1 28357832 28357832 28357832 28357832.0000 ++37 3 1 39654943 39654943 39654943 39654943.0000 ++37 11 1 5987435 5987435 5987435 5987435.0000 ++37 12 1 28357832 28357832 28357832 28357832.0000 ++37 13 1 39654943 39654943 39654943 39654943.0000 ++37 21 1 5987435 5987435 5987435 5987435.0000 ++37 22 1 28357832 28357832 28357832 28357832.0000 ++37 23 1 39654943 39654943 39654943 39654943.0000 ++37 31 1 5987435 5987435 5987435 5987435.0000 ++select companynr,count(price),sum(price),min(price),max(price),avg(price) from t3 group by companynr ; ++companynr count(price) sum(price) min(price) max(price) avg(price) ++37 12543 309394878010 5987435 39654943 24666736.6667 ++78 8362 414611089292 726498 98439034 49582766.0000 ++101 4181 3489454238 834598 834598 834598.0000 ++154 4181 4112197254950 983543950 983543950 983543950.0000 ++311 4181 979599938 234298 234298 234298.0000 ++447 4181 9929180954 2374834 2374834 2374834.0000 ++512 4181 3288532102 786542 786542 786542.0000 ++select distinct mod(companynr,10) from t4 group by companynr; ++mod(companynr,10) ++9 ++8 ++0 ++4 ++6 ++7 ++1 ++3 ++5 ++select distinct 1 from t4 group by companynr; ++1 ++1 ++select count(distinct fld1) from t2; ++count(distinct fld1) ++1199 ++select companynr,count(distinct fld1) from t2 group by companynr; ++companynr count(distinct fld1) ++00 82 ++29 95 ++34 70 ++36 215 ++37 588 ++40 37 ++41 52 ++50 11 ++53 4 ++58 23 ++65 10 ++68 12 ++select companynr,count(*) from t2 group by companynr; ++companynr count(*) ++00 82 ++37 588 ++36 215 ++50 11 ++58 23 ++29 95 ++40 37 ++53 4 ++65 10 ++41 52 ++34 70 ++68 12 ++select companynr,count(distinct concat(fld1,repeat(65,1000))) from t2 group by companynr; ++companynr count(distinct concat(fld1,repeat(65,1000))) ++00 82 ++29 95 ++34 70 ++36 215 ++37 588 ++40 37 ++41 52 ++50 11 ++53 4 ++58 23 ++65 10 ++68 12 ++select companynr,count(distinct concat(fld1,repeat(65,200))) from t2 group by companynr; ++companynr count(distinct concat(fld1,repeat(65,200))) ++00 82 ++29 95 ++34 70 ++36 215 ++37 588 ++40 37 ++41 52 ++50 11 ++53 4 ++58 23 ++65 10 ++68 12 ++select companynr,count(distinct floor(fld1/100)) from t2 group by companynr; ++companynr count(distinct floor(fld1/100)) ++00 47 ++29 35 ++34 14 ++36 69 ++37 108 ++40 16 ++41 11 ++50 9 ++53 1 ++58 1 ++65 1 ++68 1 ++select companynr,count(distinct concat(repeat(65,1000),floor(fld1/100))) from t2 group by companynr; ++companynr count(distinct concat(repeat(65,1000),floor(fld1/100))) ++00 47 ++29 35 ++34 14 ++36 69 ++37 108 ++40 16 ++41 11 ++50 9 ++53 1 ++58 1 ++65 1 ++68 1 ++select sum(fld1),fld3 from t2 where fld3="Romans" group by fld1 limit 10; ++sum(fld1) fld3 ++11402 Romans ++select name,count(*) from t3 where name='cloakroom' group by name; ++name count(*) ++cloakroom 4181 ++select name,count(*) from t3 where name='cloakroom' and price>10 group by name; ++name count(*) ++cloakroom 4181 ++select count(*) from t3 where name='cloakroom' and price2=823742; ++count(*) ++4181 ++select name,count(*) from t3 where name='cloakroom' and price2=823742 group by name; ++name count(*) ++cloakroom 4181 ++select name,count(*) from t3 where name >= "extramarital" and price <= 39654943 group by name; ++name count(*) ++extramarital 4181 ++gazer 4181 ++gems 4181 ++Iranizes 4181 ++spates 4181 ++tucked 4181 ++violinist 4181 ++select t2.fld3,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name; ++fld3 count(*) ++spates 4181 ++select companynr|0,companyname from t4 group by 1; ++companynr|0 companyname ++29 company 1 ++68 company 10 ++50 company 11 ++34 company 2 ++36 company 3 ++37 company 4 ++40 company 5 ++41 company 6 ++53 company 7 ++58 company 8 ++65 company 9 ++0 Unknown ++select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname; ++companynr companyname count(*) ++29 company 1 95 ++68 company 10 12 ++50 company 11 11 ++34 company 2 70 ++36 company 3 215 ++37 company 4 588 ++40 company 5 37 ++41 company 6 52 ++53 company 7 4 ++58 company 8 23 ++65 company 9 10 ++00 Unknown 82 ++select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name; ++fld1 count(*) ++158402 4181 ++select sum(Period)/count(*) from t1; ++sum(Period)/count(*) ++9410.0000 ++select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr; ++companynr count sum diff func ++37 12543 309394878010 0.0000 464091 ++78 8362 414611089292 0.0000 652236 ++101 4181 3489454238 0.0000 422281 ++154 4181 4112197254950 0.0000 643874 ++311 4181 979599938 0.0000 1300291 ++447 4181 9929180954 0.0000 1868907 ++512 4181 3288532102 0.0000 2140672 ++select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg; ++companynr avg ++154 983543950.0000 ++select companynr,count(*) from t2 group by companynr order by 2 desc; ++companynr count(*) ++37 588 ++36 215 ++29 95 ++00 82 ++34 70 ++41 52 ++40 37 ++58 23 ++68 12 ++50 11 ++65 10 ++53 4 ++select companynr,count(*) from t2 where companynr > 40 group by companynr order by 2 desc; ++companynr count(*) ++41 52 ++58 23 ++68 12 ++50 11 ++65 10 ++53 4 ++select t2.fld4,t2.fld1,count(price),sum(price),min(price),max(price),avg(price) from t3,t2 where t3.companynr = 37 and t2.fld1 = t3.t2nr group by fld1,t2.fld4; ++fld4 fld1 count(price) sum(price) min(price) max(price) avg(price) ++teethe 000001 1 5987435 5987435 5987435 5987435.0000 ++dreaded 011401 1 5987435 5987435 5987435 5987435.0000 ++scholastics 011402 1 28357832 28357832 28357832 28357832.0000 ++audiology 011403 1 39654943 39654943 39654943 39654943.0000 ++wallet 011501 1 5987435 5987435 5987435 5987435.0000 ++parters 011701 1 5987435 5987435 5987435 5987435.0000 ++eschew 011702 1 28357832 28357832 28357832 28357832.0000 ++quitter 011703 1 39654943 39654943 39654943 39654943.0000 ++neat 012001 1 5987435 5987435 5987435 5987435.0000 ++Steinberg 012003 1 39654943 39654943 39654943 39654943.0000 ++balled 012301 1 5987435 5987435 5987435 5987435.0000 ++persist 012302 1 28357832 28357832 28357832 28357832.0000 ++attainments 012303 1 39654943 39654943 39654943 39654943.0000 ++capably 012501 1 5987435 5987435 5987435 5987435.0000 ++impulsive 012602 1 28357832 28357832 28357832 28357832.0000 ++starlet 012603 1 39654943 39654943 39654943 39654943.0000 ++featherweight 012701 1 5987435 5987435 5987435 5987435.0000 ++pessimist 012702 1 28357832 28357832 28357832 28357832.0000 ++daughter 012703 1 39654943 39654943 39654943 39654943.0000 ++lawgiver 013601 1 5987435 5987435 5987435 5987435.0000 ++stated 013602 1 28357832 28357832 28357832 28357832.0000 ++readable 013603 1 39654943 39654943 39654943 39654943.0000 ++testicle 013801 1 5987435 5987435 5987435 5987435.0000 ++Parsifal 013802 1 28357832 28357832 28357832 28357832.0000 ++leavings 013803 1 39654943 39654943 39654943 39654943.0000 ++squeaking 013901 1 5987435 5987435 5987435 5987435.0000 ++contrasted 016001 1 5987435 5987435 5987435 5987435.0000 ++leftover 016201 1 5987435 5987435 5987435 5987435.0000 ++whiteners 016202 1 28357832 28357832 28357832 28357832.0000 ++erases 016301 1 5987435 5987435 5987435 5987435.0000 ++Punjab 016302 1 28357832 28357832 28357832 28357832.0000 ++Merritt 016303 1 39654943 39654943 39654943 39654943.0000 ++sweetish 018001 1 5987435 5987435 5987435 5987435.0000 ++dogging 018002 1 28357832 28357832 28357832 28357832.0000 ++scornfully 018003 1 39654943 39654943 39654943 39654943.0000 ++fetters 018012 1 28357832 28357832 28357832 28357832.0000 ++bivalves 018013 1 39654943 39654943 39654943 39654943.0000 ++skulking 018021 1 5987435 5987435 5987435 5987435.0000 ++flint 018022 1 28357832 28357832 28357832 28357832.0000 ++flopping 018023 1 39654943 39654943 39654943 39654943.0000 ++Judas 018032 1 28357832 28357832 28357832 28357832.0000 ++vacuuming 018033 1 39654943 39654943 39654943 39654943.0000 ++medical 018041 1 5987435 5987435 5987435 5987435.0000 ++bloodbath 018042 1 28357832 28357832 28357832 28357832.0000 ++subschema 018043 1 39654943 39654943 39654943 39654943.0000 ++interdependent 018051 1 5987435 5987435 5987435 5987435.0000 ++Graves 018052 1 28357832 28357832 28357832 28357832.0000 ++neonatal 018053 1 39654943 39654943 39654943 39654943.0000 ++sorters 018061 1 5987435 5987435 5987435 5987435.0000 ++Conley 018101 1 5987435 5987435 5987435 5987435.0000 ++lectured 018102 1 28357832 28357832 28357832 28357832.0000 ++Abraham 018103 1 39654943 39654943 39654943 39654943.0000 ++cage 018201 1 5987435 5987435 5987435 5987435.0000 ++hushes 018202 1 28357832 28357832 28357832 28357832.0000 ++Simla 018402 1 28357832 28357832 28357832 28357832.0000 ++reporters 018403 1 39654943 39654943 39654943 39654943.0000 ++coexist 018601 1 5987435 5987435 5987435 5987435.0000 ++Beebe 018602 1 28357832 28357832 28357832 28357832.0000 ++Taoism 018603 1 39654943 39654943 39654943 39654943.0000 ++Connally 018801 1 5987435 5987435 5987435 5987435.0000 ++fetched 018802 1 28357832 28357832 28357832 28357832.0000 ++checkpoints 018803 1 39654943 39654943 39654943 39654943.0000 ++gritty 018811 1 5987435 5987435 5987435 5987435.0000 ++firearm 018812 1 28357832 28357832 28357832 28357832.0000 ++minima 019101 1 5987435 5987435 5987435 5987435.0000 ++Selfridge 019102 1 28357832 28357832 28357832 28357832.0000 ++disable 019103 1 39654943 39654943 39654943 39654943.0000 ++witchcraft 019201 1 5987435 5987435 5987435 5987435.0000 ++betroth 030501 1 5987435 5987435 5987435 5987435.0000 ++Manhattanize 030502 1 28357832 28357832 28357832 28357832.0000 ++imprint 030503 1 39654943 39654943 39654943 39654943.0000 ++swelling 031901 1 5987435 5987435 5987435 5987435.0000 ++interrelationships 036001 1 5987435 5987435 5987435 5987435.0000 ++riser 036002 1 28357832 28357832 28357832 28357832.0000 ++bee 038001 1 5987435 5987435 5987435 5987435.0000 ++kanji 038002 1 28357832 28357832 28357832 28357832.0000 ++dental 038003 1 39654943 39654943 39654943 39654943.0000 ++railway 038011 1 5987435 5987435 5987435 5987435.0000 ++validate 038012 1 28357832 28357832 28357832 28357832.0000 ++normalizes 038013 1 39654943 39654943 39654943 39654943.0000 ++Kline 038101 1 5987435 5987435 5987435 5987435.0000 ++Anatole 038102 1 28357832 28357832 28357832 28357832.0000 ++partridges 038103 1 39654943 39654943 39654943 39654943.0000 ++recruited 038201 1 5987435 5987435 5987435 5987435.0000 ++dimensions 038202 1 28357832 28357832 28357832 28357832.0000 ++Chicana 038203 1 39654943 39654943 39654943 39654943.0000 ++epistle 018062 1 28357832 28357832 28357832 28357832.0000 ++select t3.companynr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 group by companynr,fld3; ++companynr fld3 sum(price) ++512 boat 786542 ++512 capably 786542 ++512 decliner 786542 ++512 dopers 786542 ++512 erases 786542 ++512 cupboard 786542 ++512 Miles 786542 ++512 Micronesia 786542 ++512 descendants 786542 ++512 skies 786542 ++select t2.companynr,count(*),min(fld3),max(fld3),sum(price),avg(price) from t2,t3 where t3.companynr >= 30 and t3.companynr <= 58 and t3.t2nr = t2.fld1 and 1+1=2 group by t2.companynr; ++companynr count(*) min(fld3) max(fld3) sum(price) avg(price) ++00 1 Omaha Omaha 5987435 5987435.0000 ++37 83 Abraham Wotan 1908978016 22999735.1325 ++36 1 dubbed dubbed 28357832 28357832.0000 ++50 2 scribbled tapestry 68012775 34006387.5000 ++select t3.companynr+0,t3.t2nr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 37 group by 1,t3.t2nr,fld3,fld3,fld3,fld3,fld3 order by fld1; ++t3.companynr+0 t2nr fld3 sum(price) ++37 1 Omaha 5987435 ++37 11401 breaking 5987435 ++37 11402 Romans 28357832 ++37 11403 intercepted 39654943 ++37 11501 bewilderingly 5987435 ++37 11701 astound 5987435 ++37 11702 admonishing 28357832 ++37 11703 sumac 39654943 ++37 12001 flanking 5987435 ++37 12003 combed 39654943 ++37 12301 Eulerian 5987435 ++37 12302 dubbed 28357832 ++37 12303 Kane 39654943 ++37 12501 annihilates 5987435 ++37 12602 Wotan 28357832 ++37 12603 snatching 39654943 ++37 12701 grazing 5987435 ++37 12702 Baird 28357832 ++37 12703 celery 39654943 ++37 13601 handgun 5987435 ++37 13602 foldout 28357832 ++37 13603 mystic 39654943 ++37 13801 intelligibility 5987435 ++37 13802 Augustine 28357832 ++37 13803 teethe 39654943 ++37 13901 scholastics 5987435 ++37 16001 audiology 5987435 ++37 16201 wallet 5987435 ++37 16202 parters 28357832 ++37 16301 eschew 5987435 ++37 16302 quitter 28357832 ++37 16303 neat 39654943 ++37 18001 jarring 5987435 ++37 18002 tinily 28357832 ++37 18003 balled 39654943 ++37 18012 impulsive 28357832 ++37 18013 starlet 39654943 ++37 18021 lawgiver 5987435 ++37 18022 stated 28357832 ++37 18023 readable 39654943 ++37 18032 testicle 28357832 ++37 18033 Parsifal 39654943 ++37 18041 Punjab 5987435 ++37 18042 Merritt 28357832 ++37 18043 Quixotism 39654943 ++37 18051 sureties 5987435 ++37 18052 puddings 28357832 ++37 18053 tapestry 39654943 ++37 18061 trimmings 5987435 ++37 18062 humility 28357832 ++37 18101 tragedies 5987435 ++37 18102 skulking 28357832 ++37 18103 flint 39654943 ++37 18201 relaxing 5987435 ++37 18202 offload 28357832 ++37 18402 suites 28357832 ++37 18403 lists 39654943 ++37 18601 vacuuming 5987435 ++37 18602 dentally 28357832 ++37 18603 humanness 39654943 ++37 18801 inch 5987435 ++37 18802 Weissmuller 28357832 ++37 18803 irresponsibly 39654943 ++37 18811 repetitions 5987435 ++37 18812 Antares 28357832 ++37 19101 ventilate 5987435 ++37 19102 pityingly 28357832 ++37 19103 interdependent 39654943 ++37 19201 Graves 5987435 ++37 30501 neonatal 5987435 ++37 30502 scribbled 28357832 ++37 30503 chafe 39654943 ++37 31901 realtor 5987435 ++37 36001 elite 5987435 ++37 36002 funereal 28357832 ++37 38001 Conley 5987435 ++37 38002 lectured 28357832 ++37 38003 Abraham 39654943 ++37 38011 groupings 5987435 ++37 38012 dissociate 28357832 ++37 38013 coexist 39654943 ++37 38101 rusting 5987435 ++37 38102 galling 28357832 ++37 38103 obliterates 39654943 ++37 38201 resumes 5987435 ++37 38202 analyzable 28357832 ++37 38203 terminator 39654943 ++select sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1= t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008; ++sum(price) ++234298 ++select t2.fld1,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1 = t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008 or t3.t2nr = t2.fld1 and t2.fld1 = 38008 group by t2.fld1; ++fld1 sum(price) ++038008 234298 ++explain select fld3 from t2 where 1>2 or 2>3; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # # Impossible WHERE ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where false ++explain select fld3 from t2 where fld1=fld1; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL ALL NULL NULL NULL NULL # # NULL ++Warnings: ++Note 1003 /* select#1 */ select `test`.`t2`.`fld3` AS `fld3` from `test`.`t2` where true ++select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502; ++companynr fld1 ++34 250501 ++34 250502 ++select companynr,fld1 from t2 WHERE fld1>=250501 HAVING fld1<=250502; ++companynr fld1 ++34 250501 ++34 250502 ++select companynr,count(*) as count,sum(fld1) as sum from t2 group by companynr having count > 40 and sum/count >= 120000; ++companynr count sum ++00 82 10355753 ++37 588 83602098 ++29 95 14473298 ++41 52 12816335 ++34 70 17788966 ++select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ; ++companynr ++00 ++37 ++29 ++41 ++34 ++select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40; ++companynr companyname count(*) ++50 company 11 11 ++58 company 8 23 ++40 company 5 37 ++53 company 7 4 ++65 company 9 10 ++41 company 6 52 ++68 company 10 12 ++select count(*) from t2; ++count(*) ++1199 ++select count(*) from t2 where fld1 < 098024; ++count(*) ++387 ++select min(fld1) from t2 where fld1>= 098024; ++min(fld1) ++98024 ++select max(fld1) from t2 where fld1>= 098024; ++max(fld1) ++1232609 ++select count(*) from t3 where price2=76234234; ++count(*) ++4181 ++select count(*) from t3 where companynr=512 and price2=76234234; ++count(*) ++4181 ++explain select min(fld1),max(fld1),count(*) from t2; ++id select_type table partitions type possible_keys key key_len ref rows filtered Extra ++1 SIMPLE t2 NULL index NULL fld1 4 NULL # # Using index ++Warnings: ++Note 1003 /* select#1 */ select min(`test`.`t2`.`fld1`) AS `min(fld1)`,max(`test`.`t2`.`fld1`) AS `max(fld1)`,count(0) AS `count(*)` from `test`.`t2` ++select min(fld1),max(fld1),count(*) from t2; ++min(fld1) max(fld1) count(*) ++0 1232609 1199 ++select min(t2nr),max(t2nr) from t3 where t2nr=2115 and price2=823742; ++min(t2nr) max(t2nr) ++2115 2115 ++select count(*),min(t2nr),max(t2nr) from t3 where name='spates' and companynr=78; ++count(*) min(t2nr) max(t2nr) ++4181 4 41804 ++select t2nr,count(*) from t3 where name='gems' group by t2nr limit 20; ++t2nr count(*) ++9 1 ++19 1 ++29 1 ++39 1 ++49 1 ++59 1 ++69 1 ++79 1 ++89 1 ++99 1 ++109 1 ++119 1 ++129 1 ++139 1 ++149 1 ++159 1 ++169 1 ++179 1 ++189 1 ++199 1 ++select max(t2nr) from t3 where price=983543950; ++max(t2nr) ++41807 ++select t1.period from t3 t1 limit 1; ++period ++1001 ++select t1.period from t1 as t1 limit 1; ++period ++9410 ++select t1.period as "Nuvarande period" from t1 as t1 limit 1; ++Nuvarande period ++9410 ++select period as ok_period from t1 limit 1; ++ok_period ++9410 ++select period as ok_period from t1 group by ok_period limit 1; ++ok_period ++9410 ++select 1+1 as summa from t1 group by summa limit 1; ++summa ++2 ++select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1; ++Nuvarande period ++9410 ++show tables; ++Tables_in_test ++t1 ++t2 ++t3 ++t4 ++show tables from test like "s%"; ++Tables_in_test (s%) ++show tables from test like "t?"; ++Tables_in_test (t?) ++show full columns from t2; ++Field Type Collation Null Key Default Extra Privileges Comment ++auto int NULL NO PRI NULL auto_increment select,insert,update,references ++fld1 int(6) unsigned zerofill NULL NO UNI 000000 select,insert,update,references ++companynr tinyint(2) unsigned zerofill NULL NO 00 select,insert,update,references ++fld3 char(30) utf8mb4_0900_ai_ci NO MUL select,insert,update,references ++fld4 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld5 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld6 char(4) utf8mb4_0900_ai_ci NO select,insert,update,references ++show full columns from t2 from test like 'f%'; ++Field Type Collation Null Key Default Extra Privileges Comment ++fld1 int(6) unsigned zerofill NULL NO UNI 000000 select,insert,update,references ++fld3 char(30) utf8mb4_0900_ai_ci NO MUL select,insert,update,references ++fld4 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld5 char(35) utf8mb4_0900_ai_ci NO select,insert,update,references ++fld6 char(4) utf8mb4_0900_ai_ci NO select,insert,update,references ++show full columns from t2 from test like 's%'; ++Field Type Collation Null Key Default Extra Privileges Comment ++analyze table t2; ++Table Op Msg_type Msg_text ++test.t2 analyze status OK ++show keys from t2; ++Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression ++t2 0 PRIMARY 1 auto A # NULL NULL BTREE YES NULL ++t2 0 fld1 1 fld1 A # NULL NULL BTREE YES NULL ++t2 1 fld3 1 fld3 A # NULL NULL BTREE YES NULL ++drop table t4, t3, t2, t1; ++SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; ++CREATE TABLE t1 ( ++cont_nr int(11) NOT NULL auto_increment, ++ver_nr int(11) NOT NULL default '0', ++aufnr int(11) NOT NULL default '0', ++username varchar(50) NOT NULL default '', ++hdl_nr int(11) NOT NULL default '0', ++eintrag date NOT NULL default '0000-00-00', ++st_klasse varchar(40) NOT NULL default '', ++st_wert varchar(40) NOT NULL default '', ++st_zusatz varchar(40) NOT NULL default '', ++st_bemerkung varchar(255) NOT NULL default '', ++kunden_art varchar(40) NOT NULL default '', ++mcbs_knr int(11) default NULL, ++mcbs_aufnr int(11) NOT NULL default '0', ++schufa_status char(1) default '?', ++bemerkung text, ++wirknetz text, ++wf_igz int(11) NOT NULL default '0', ++tarifcode varchar(80) default NULL, ++recycle char(1) default NULL, ++sim varchar(30) default NULL, ++mcbs_tpl varchar(30) default NULL, ++emp_nr int(11) NOT NULL default '0', ++laufzeit int(11) default NULL, ++hdl_name varchar(30) default NULL, ++prov_hdl_nr int(11) NOT NULL default '0', ++auto_wirknetz varchar(50) default NULL, ++auto_billing varchar(50) default NULL, ++touch timestamp NOT NULL, ++kategorie varchar(50) default NULL, ++kundentyp varchar(20) NOT NULL default '', ++sammel_rech_msisdn varchar(30) NOT NULL default '', ++p_nr varchar(9) NOT NULL default '', ++suffix char(3) NOT NULL default '', ++PRIMARY KEY (cont_nr), ++KEY idx_aufnr(aufnr), ++KEY idx_hdl_nr(hdl_nr), ++KEY idx_st_klasse(st_klasse), ++KEY ver_nr(ver_nr), ++KEY eintrag_idx(eintrag), ++KEY emp_nr_idx(emp_nr), ++KEY wf_igz(wf_igz), ++KEY touch(touch), ++KEY hdl_tag(eintrag,hdl_nr), ++KEY prov_hdl_nr(prov_hdl_nr), ++KEY mcbs_aufnr(mcbs_aufnr), ++KEY kundentyp(kundentyp), ++KEY p_nr(p_nr,suffix) ++); ++Warnings: ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++Warning 1681 Integer display width is deprecated and will be removed in a future release. ++SET sql_mode = default; ++INSERT INTO t1 VALUES (3359356,405,3359356,'Mustermann Musterfrau',52500,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1485525,2122316,'+','','N',1909160,'MobilComSuper92000D2',NULL,NULL,'MS9ND2',3,24,'MobilCom Shop Koeln',52500,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359357,468,3359357,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1503580,2139699,'+','','P',1909171,'MobilComSuper9D1T10SFreisprech(Akquise)',NULL,NULL,'MS9NS1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359358,407,3359358,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1501358,2137473,'N','','N',1909159,'MobilComSuper92000D2',NULL,NULL,'MS9ND2',325,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359359,468,3359359,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1507831,2143894,'+','','P',1909162,'MobilComSuper9D1T10SFreisprech(Akquise)',NULL,NULL,'MS9NS1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359360,0,0,'Mustermann Musterfrau',29674907,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1900169997,2414578,'+',NULL,'N',1909148,'',NULL,NULL,'RV99066_2',20,NULL,'POS',29674907,NULL,NULL,20010202105916,'Mobilfunk','','','97317481','007'); ++INSERT INTO t1 VALUES (3359361,406,3359361,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag storniert','','(7001-84):Storno, Kd. möchte nicht mehr','privat',NULL,0,'+','','P',1909150,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',325,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++INSERT INTO t1 VALUES (3359362,406,3359362,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1509984,2145874,'+','','P',1909154,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); ++SELECT ELT(FIELD(kundentyp,'PP','PPA','PG','PGA','FK','FKA','FP','FPA','K','KA','V','VA',''), 'Privat (Private Nutzung)','Privat (Private Nutzung) Sitz im Ausland','Privat (geschaeftliche Nutzung)','Privat (geschaeftliche Nutzung) Sitz im Ausland','Firma (Kapitalgesellschaft)','Firma (Kapitalgesellschaft) Sitz im Ausland','Firma (Personengesellschaft)','Firma (Personengesellschaft) Sitz im Ausland','oeff. rechtl. Koerperschaft','oeff. rechtl. Koerperschaft Sitz im Ausland','Eingetragener Verein','Eingetragener Verein Sitz im Ausland','Typ unbekannt') AS Kundentyp ,kategorie FROM t1 WHERE hdl_nr < 2000000 AND kategorie IN ('Prepaid','Mobilfunk') AND st_klasse = 'Workflow' GROUP BY kundentyp ORDER BY kategorie; ++Kundentyp kategorie ++Privat (Private Nutzung) Mobilfunk ++Warnings: ++Warning 1052 Column 'kundentyp' in group statement is ambiguous ++drop table t1; ++CREATE TABLE t1(a INT); ++START TRANSACTION; ++INSERT INTO t1 VALUES (1); ++SELECT * FROM t1; ++a ++1 ++INSERT INTO t1 VALUES (2); ++SELECT * FROM t1; ++a ++1 ++2 ++COMMIT; ++DROP TABLE t1; +diff --git a/mysql-test/suite/thread_pool/r/threadpool_admin_port.result b/mysql-test/suite/thread_pool/r/threadpool_admin_port.result +new file mode 100644 +index 00000000000..bcfecc16b06 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_admin_port.result +@@ -0,0 +1,27 @@ ++# Stop DB server which was created by MTR default ++# Starting up server ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 --thread_pool_toobusy=3 --admin-port=ADMIN_PORT ++SELECT CURRENT_USER(); ++CURRENT_USER() ++root@localhost ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT CURRENT_USER(); ++CURRENT_USER() ++root@localhost ++SELECT CURRENT_USER(); ++CURRENT_USER() ++root@localhost ++select user, command, state, info from information_schema.processlist where user = "root" order by id asc; ++user command state info ++root Sleep NULL ++root Query executing SELECT benchmark(9999999999, md5('very long command 1')) ++root Query executing SELECT benchmark(9999999999, md5('very long command 1')) ++root Query executing SELECT benchmark(9999999999, md5('very long command 1')) ++root Query executing SELECT benchmark(9999999999, md5('very long command 1')) ++root Query executing SELECT benchmark(9999999999, md5('very long command 1')) ++root Sleep NULL ++root Query executing select user, command, state, info from information_schema.processlist where user = "root" order by id asc +diff --git a/mysql-test/suite/thread_pool/r/threadpool_new_connection.result b/mysql-test/suite/thread_pool/r/threadpool_new_connection.result +new file mode 100644 +index 00000000000..ea0c4ad5d93 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_new_connection.result +@@ -0,0 +1,3 @@ ++# restart:--plugin-load-add=thread_pool.so --thread_pool_size=2 ++group 1 deviation is accepted ++group 2 deviation is accepted +diff --git a/mysql-test/suite/thread_pool/r/threadpool_pool_size.result b/mysql-test/suite/thread_pool/r/threadpool_pool_size.result +new file mode 100644 +index 00000000000..48ef7a5e2e4 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_pool_size.result +@@ -0,0 +1,39 @@ ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 --thread_pool_stall_limit=60000 --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 2')); ++SELECT COUNT(Id) FROM INFORMATION_SCHEMA.processlist where Info like 'SELECT benchmark(9999999999, md5(\'very long command%'; ++COUNT(Id) ++2 ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(CONNECTIONS) ++3 ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(ACTIVE_THREADS) ++3 ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(STANDBY_THREADS) ++0 ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(QUEUE_LENGTH) ++0 ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(HAS_LISTENER) ++0 ++SELECT SUM(IS_STALLED) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(IS_STALLED) ++0 ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++COUNT(*) ++0 ++SELECT SUM(THREAD_CREATIONS_DUE_TO_STALL) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SUM(THREAD_CREATIONS_DUE_TO_STALL) ++0 ++SELECT SUM(WAKES_DUE_TO_STALL) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SUM(WAKES_DUE_TO_STALL) ++0 ++SELECT SUM(THROTTLES) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SUM(THROTTLES) ++0 ++SELECT SUM(STALLS) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SUM(STALLS) ++0 +diff --git a/mysql-test/suite/thread_pool/r/threadpool_shutdown.result b/mysql-test/suite/thread_pool/r/threadpool_shutdown.result +new file mode 100644 +index 00000000000..4469020db02 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_shutdown.result +@@ -0,0 +1,36 @@ ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 ++CREATE DATABASE db1; ++CREATE TABLE db1.t1 ( ++c1 int NOT NULL, ++c2 int NOT NULL, ++PRIMARY KEY (c1) ++); ++INSERT INTO db1.t1 (c1,c2) VALUES (1,11); ++INSERT INTO db1.t1 (c1,c2) VALUES (2,22); ++INSERT INTO db1.t1 (c1,c2) VALUES (3,33); ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 FOR UPDATE; ++c1 c2 ++2 22 ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++# Shutdown the server ++# Start the server ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 2')); ++# Shutdown the server ++# Start the server ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 ++SELECT * FROM db1.t1 WHERE c1=1; ++c1 c2 ++1 11 ++SELECT * FROM db1.t1 WHERE c1=2; ++c1 c2 ++2 22 ++# Shutdown the server ++# Start the server ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 ++# Cleanup ++DROP TABLE db1.t1; ++DROP DATABASE db1; +diff --git a/mysql-test/suite/thread_pool/r/threadpool_too_busy_active-debug.result b/mysql-test/suite/thread_pool/r/threadpool_too_busy_active-debug.result +new file mode 100644 +index 00000000000..983d5eeef0f +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_too_busy_active-debug.result +@@ -0,0 +1,34 @@ ++# restart: --plugin-load-add=thread_pool.so --loose-thread_pool_size=1 --loose-thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 2')); ++SELECT 1; ++queue_length 0 ++1 ++1 ++SELECT 1; ++queue_length 0 ++1 ++1 ++SET GLOBAL debug="+d,threadpool_io_poll_wait_at_least_2_events"; ++SELECT 1; ++SET GLOBAL debug="-d,threadpool_io_poll_wait_at_least_2_events"; ++SELECT 1; ++queue_length 1 ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(CONNECTIONS) ++5 ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(ACTIVE_THREADS) ++2 ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(STANDBY_THREADS) ++0 ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(QUEUE_LENGTH) ++1 ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(HAS_LISTENER) ++1 ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++COUNT(*) ++1 +diff --git a/mysql-test/suite/thread_pool/r/threadpool_too_busy_active.result b/mysql-test/suite/thread_pool/r/threadpool_too_busy_active.result +new file mode 100644 +index 00000000000..1eb619bd164 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_too_busy_active.result +@@ -0,0 +1,27 @@ ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 2')); ++You should see a Lost connection message ++ERROR HY000: Lost connection to MySQL server at 'waiting for initial communication packet', system error: 110 ++Found 1 stuck connections ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(CONNECTIONS) ++4 ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(ACTIVE_THREADS) ++2 ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(STANDBY_THREADS) ++0 ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(QUEUE_LENGTH) ++1 ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(HAS_LISTENER) ++1 ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++COUNT(*) ++1 ++SELECT SUM(THREAD_CREATIONS_DUE_TO_STALL) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SUM(THREAD_CREATIONS_DUE_TO_STALL) ++1 +diff --git a/mysql-test/suite/thread_pool/r/threadpool_too_busy_corner_case.result b/mysql-test/suite/thread_pool/r/threadpool_too_busy_corner_case.result +new file mode 100644 +index 00000000000..4fb19d56198 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_too_busy_corner_case.result +@@ -0,0 +1,22 @@ ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++SELECT benchmark(9999999999, md5('very long command 1')); ++SELECT benchmark(9999999999, md5('very long command 2')); ++You should see a Lost connection message ++ERROR HY000: Lost connection to MySQL server at 'waiting for initial communication packet', system error: 110 ++SELECT 1; ++queue_length 2 ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(CONNECTIONS) ++5 ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(ACTIVE_THREADS) ++2 ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(STANDBY_THREADS) ++0 ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(HAS_LISTENER) ++1 ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++COUNT(*) ++2 +diff --git a/mysql-test/suite/thread_pool/r/threadpool_too_busy_wait-debug.result b/mysql-test/suite/thread_pool/r/threadpool_too_busy_wait-debug.result +new file mode 100644 +index 00000000000..fc137b59193 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_too_busy_wait-debug.result +@@ -0,0 +1,63 @@ ++CREATE DATABASE db1; ++CREATE TABLE db1.t1 ( ++c1 int NOT NULL, ++c2 int NOT NULL, ++PRIMARY KEY (c1) ++); ++INSERT INTO db1.t1 (c1,c2) VALUES (1,11); ++INSERT INTO db1.t1 (c1,c2) VALUES (2,22); ++INSERT INTO db1.t1 (c1,c2) VALUES (3,33); ++# restart: --plugin-load-add=thread_pool.so --loose-thread_pool_size=1 --loose-thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 FOR UPDATE; ++c1 c2 ++2 22 ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++SELECT 1; ++queue_length 0 ++1 ++1 ++SELECT 1; ++queue_length 0 ++1 ++1 ++SET GLOBAL debug="+d,threadpool_io_poll_wait_at_least_2_events"; ++SELECT 1; ++SET GLOBAL debug="-d,threadpool_io_poll_wait_at_least_2_events"; ++SELECT 1; ++queue_length 1 ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(CONNECTIONS) ++6 ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(ACTIVE_THREADS) ++1 ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(STANDBY_THREADS) ++2 ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(QUEUE_LENGTH) ++1 ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(HAS_LISTENER) ++1 ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++COUNT(*) ++1 ++ROLLBACK; ++c1 c2 ++2 22 ++ROLLBACK; ++c1 c2 ++2 22 ++ROLLBACK; ++1 ++1 ++1 ++1 ++Clean up ++DROP TABLE db1.t1; ++DROP DATABASE db1; +diff --git a/mysql-test/suite/thread_pool/r/threadpool_too_busy_wait.result b/mysql-test/suite/thread_pool/r/threadpool_too_busy_wait.result +new file mode 100644 +index 00000000000..1c4daa9faf9 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/r/threadpool_too_busy_wait.result +@@ -0,0 +1,52 @@ ++CREATE DATABASE db1; ++CREATE TABLE db1.t1 ( ++c1 int NOT NULL, ++c2 int NOT NULL, ++PRIMARY KEY (c1) ++); ++INSERT INTO db1.t1 (c1,c2) VALUES (1,11); ++INSERT INTO db1.t1 (c1,c2) VALUES (2,22); ++INSERT INTO db1.t1 (c1,c2) VALUES (3,33); ++# restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 FOR UPDATE; ++c1 c2 ++2 22 ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++You should see a Lost connection message ++ERROR HY000: Lost connection to MySQL server at 'waiting for initial communication packet', system error: 110 ++Found 1 stuck connections ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(CONNECTIONS) ++5 ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(ACTIVE_THREADS) ++1 ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(STANDBY_THREADS) ++2 ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(QUEUE_LENGTH) ++1 ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SUM(HAS_LISTENER) ++1 ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++COUNT(*) ++1 ++SELECT COUNT FROM INFORMATION_SCHEMA.THREAD_POOL_WAITS WHERE REASON='Row_lock'; ++COUNT ++2 ++ROLLBACK; ++c1 c2 ++2 22 ++ROLLBACK; ++c1 c2 ++2 22 ++ROLLBACK; ++Clean up ++DROP TABLE db1.t1; ++DROP DATABASE db1; +diff --git a/mysql-test/suite/thread_pool/t/pool_of_threads.cnf b/mysql-test/suite/thread_pool/t/pool_of_threads.cnf +new file mode 100644 +index 00000000000..0f3d5cc4687 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/pool_of_threads.cnf +@@ -0,0 +1,6 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++ ++[client] ++connect-timeout= 2 +diff --git a/mysql-test/suite/thread_pool/t/pool_of_threads.test b/mysql-test/suite/thread_pool/t/pool_of_threads.test +new file mode 100644 +index 00000000000..d9097d08a96 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/pool_of_threads.test +@@ -0,0 +1,81 @@ ++# Restart with plugin-load-add=thread_pool.so ++# and run a number of tests ++ ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++# Calculate value for admin port ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--let $restart_parameters=restart:--plugin-load-add=thread_pool.so --thread_pool_size=2 --thread_pool_max_threads=2 --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --loose-skip-mysqlx ++--replace_result $ADMIN_PORT ADMIN_PORT ++--source include/restart_mysqld.inc ++ ++-- source include/common-tests.inc ++ ++# Test that we cannot have more simultaneous connections than ++# --thread-pool-size on the standard port, but _can_ have additional ++# connections on the extra port. ++call mtr.add_suppression("Threadpool could not create additional thread to handle queries"); ++ ++# First set two connections running, and check that extra connection ++# on normal port fails due to --thread-pool-max_threads=2 ++connection default; ++let $default_id = `select connection_id()`; ++send SELECT sleep(50000); ++--sleep 2.5 ++ ++connect(con2,localhost,root,,); ++connection con2; ++let $con2_id = `select connection_id()`; ++send SELECT sleep(50000); ++--sleep 2.5 ++ ++--disable_abort_on_error ++--disable_result_log ++--disable_query_log ++connect(con3,localhost,root,,); ++--enable_query_log ++--enable_result_log ++--enable_abort_on_error ++let $error = $mysql_errno; ++if (!$error) ++{ ++ --echo # -- Error: managed to establish more than --thread_pool_max_threads connections ++} ++if ($error) ++{ ++ --echo # -- Success: more than --thread_pool_max_threads normal connections not possible ++} ++ ++# This time use the extra port to successfully connect. ++ ++connect(extracon,127.0.0.1,root,,test,$ADMIN_PORT,); ++connection extracon; ++SELECT 'Connection on extra port ok'; ++ ++# Kill long queries in other connections ++let @ignore = `select @id := $default_id`; ++KILL QUERY @id; ++let @ignore = `select @id := $con2_id`; ++KILL QUERY @id; ++ ++connect(extracon2,127.0.0.1,root,,test,$ADMIN_PORT,); ++connection extracon2; ++SELECT 'Connection on extra port 2 ok'; ++ ++connect(extracon3,127.0.0.1,root,,test,$ADMIN_PORT,); ++connection extracon3; ++SELECT 'Connection on extra port 3 ok'; ++ ++disconnect extracon2; ++disconnect extracon3; ++ ++connection default; ++--reap ++connection con2; ++--reap ++# MTR will restart the server with default args for us +diff --git a/mysql-test/suite/thread_pool/t/pool_of_threads_high_prio_tickets.cnf b/mysql-test/suite/thread_pool/t/pool_of_threads_high_prio_tickets.cnf +new file mode 100644 +index 00000000000..0f3d5cc4687 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/pool_of_threads_high_prio_tickets.cnf +@@ -0,0 +1,6 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++ ++[client] ++connect-timeout= 2 +diff --git a/mysql-test/suite/thread_pool/t/pool_of_threads_high_prio_tickets.test b/mysql-test/suite/thread_pool/t/pool_of_threads_high_prio_tickets.test +new file mode 100644 +index 00000000000..bcd1a0e7ccb +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/pool_of_threads_high_prio_tickets.test +@@ -0,0 +1,19 @@ ++# Restart with plugin-load-add=thread_pool.so ++# and run some basic tests with --thread_pool_high_prio_tickets=2 ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=2 --thread_pool_max_threads=2 --thread_pool_high_prio_tickets=2 --loose-skip-mysqlx ++--source include/restart_mysqld.inc ++SELECT @@thread_pool_high_prio_tickets; ++ ++-- source include/common-tests.inc ++ ++CREATE TABLE t1(a INT); ++ ++START TRANSACTION; ++INSERT INTO t1 VALUES (1); ++SELECT * FROM t1; ++INSERT INTO t1 VALUES (2); ++SELECT * FROM t1; ++COMMIT; ++ ++DROP TABLE t1; +diff --git a/mysql-test/suite/thread_pool/t/threadpool_admin_port.cnf b/mysql-test/suite/thread_pool/t/threadpool_admin_port.cnf +new file mode 100644 +index 00000000000..ab6b4f4594d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_admin_port.cnf +@@ -0,0 +1,8 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++max_connections=6 ++admin_address=127.0.0.1 ++ ++[client] ++connect-timeout=5 +diff --git a/mysql-test/suite/thread_pool/t/threadpool_admin_port.test b/mysql-test/suite/thread_pool/t/threadpool_admin_port.test +new file mode 100644 +index 00000000000..99eb0d62f1b +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_admin_port.test +@@ -0,0 +1,83 @@ ++# Restart with plugin-load-add=thread_pool.so ++--echo # Stop DB server which was created by MTR default ++ ++--let $MYSQLD_DATADIR= `SELECT @@datadir` ++ ++--source include/shutdown_mysqld.inc ++ ++# Calculate value for admin port ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--echo # Starting up server ++--force-cpdir $MYSQLD_DATADIR $MYSQL_TMP_DIR/newdd ++--replace_result $ADMIN_PORT ADMIN_PORT ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 --thread_pool_toobusy=3 --admin-port=$ADMIN_PORT ++--source include/start_mysqld.inc ++ ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++connection default; ++SELECT CURRENT_USER(); ++ ++connect(conn0,127.0.0.1,root,,,); ++connect(conn1,127.0.0.1,root,,,); ++connect(conn2,127.0.0.1,root,,,); ++connect(conn3,127.0.0.1,root,,,); ++connect(conn4,127.0.0.1,root,,,); ++ ++connection conn0; ++--let $conn0_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++sleep 1; ++ ++connection conn1; ++--let $conn1_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++sleep 1; ++ ++connection conn2; ++--let $conn2_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++sleep 1; ++ ++connection conn3; ++--let $conn3_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++sleep 1; ++ ++connection conn4; ++--let $conn4_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++sleep 1; ++ ++# too_many_active and reach max_connections ++ ++connect(admin_tcp_con,127.0.0.1,root,,,$ADMIN_PORT,,TCP); ++connection admin_tcp_con; ++SELECT CURRENT_USER(); ++ ++connect(admin_local_con,localhost,root,,,$ADMIN_PORT,,TCP); ++connection admin_local_con; ++SELECT CURRENT_USER(); ++ ++select user, command, state, info from information_schema.processlist where user = "root" order by id asc; ++ ++--disable_query_log ++eval KILL QUERY $conn0_id; ++eval KILL QUERY $conn1_id; ++eval KILL QUERY $conn2_id; ++eval KILL QUERY $conn3_id; ++eval KILL QUERY $conn4_id; ++--enable_query_log ++ ++--disconnect conn0 ++--disconnect conn1 ++--disconnect conn2 ++--disconnect conn3 ++--disconnect conn4 ++--disconnect admin_tcp_con ++--disconnect admin_local_con +diff --git a/mysql-test/suite/thread_pool/t/threadpool_new_connection.cnf b/mysql-test/suite/thread_pool/t/threadpool_new_connection.cnf +new file mode 100644 +index 00000000000..628047db6eb +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_new_connection.cnf +@@ -0,0 +1,6 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++ ++[client] ++connect-timeout=2 +diff --git a/mysql-test/suite/thread_pool/t/threadpool_new_connection.test b/mysql-test/suite/thread_pool/t/threadpool_new_connection.test +new file mode 100644 +index 00000000000..59e3801d7c0 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_new_connection.test +@@ -0,0 +1,48 @@ ++# Restart with plugin-load-add=thread_pool.so ++ ++--let $restart_parameters=restart:--plugin-load-add=thread_pool.so --thread_pool_size=2 ++--source include/restart_mysqld.inc ++ ++# Test that the new incoming connectins are dispatched to thread groups properly ++ ++# Set up $total_connection_number new connections ++--let $counter=1 # 1 for default connection ++--let $total_connection_number=100 ++while ($counter < $total_connection_number) ++{ ++ connect(conn$counter,127.0.0.1,root); ++ connection conn$counter; ++ --inc $counter ++} ++ ++connection default; ++ ++# Get connection number for each thread group. Evaluate its deviation from average is acceptable. ++--let $counter=0 ++--let $connection_sum=0 ++--let $MASTER_THREAD_POOL_SIZE=`SELECT @@thread_pool_size` ++--let $average_connection_numer=`SELECT CEIL($total_connection_number / $MASTER_THREAD_POOL_SIZE)` ++--let $deviation_threshold=`SELECT CEIL($average_connection_numer / 2)` ++ ++while ($counter<$MASTER_THREAD_POOL_SIZE) ++{ ++ --let group_connection_number=`SELECT CONNECTIONS FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS WHERE GROUP_ID=$counter` ++ --inc $counter ++ --let $connection_sum=`SELECT $connection_sum + $group_connection_number` ++ --let $deviation=`SELECT ABS($group_connection_number - $average_connection_numer)` ++ --let $reject=0 ++ if($deviation > $deviation_threshold) ++ { ++ --let $reject=1 ++ --echo group $counter deviation is rejected. $deviation exceeds threshold $deviation_threshold ++ } ++ if($reject == 0) ++ { ++ --echo group $counter deviation is accepted ++ } ++} ++ ++if($connection_sum != $total_connection_number) ++{ ++ --echo connection number mismatch: expected=$total_connection_number, actual=$connection_sum ++} +diff --git a/mysql-test/suite/thread_pool/t/threadpool_pool_size.cnf b/mysql-test/suite/thread_pool/t/threadpool_pool_size.cnf +new file mode 100644 +index 00000000000..1462b559a1d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_pool_size.cnf +@@ -0,0 +1,8 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++innodb_lock_wait_timeout=3600 ++loose-debug-sync-timeout=300 ++ ++[client] ++connect-timeout=2 +\ No newline at end of file +diff --git a/mysql-test/suite/thread_pool/t/threadpool_pool_size.test b/mysql-test/suite/thread_pool/t/threadpool_pool_size.test +new file mode 100644 +index 00000000000..30aff1b3879 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_pool_size.test +@@ -0,0 +1,58 @@ ++# Restart with plugin-load-add=thread_pool.so ++ ++# Test that each thread group will have one or more active threads if neither any stall or wait happens, no matter what's the number of cores available underneath. ++# Here thread_pool_stall_limit is set to a large value, to make those "very long command" treated as not stalled command. ++ ++# Calculate value for admin port ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 --thread_pool_stall_limit=60000 --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++--replace_result $ADMIN_PORT ADMIN_PORT ++--source include/restart_mysqld.inc ++ ++connect(extracon,127.0.0.1,root,,,$ADMIN_PORT); ++connect(conn1,127.0.0.1,root,,,$MASTER_MYPORT); ++connect(conn2,127.0.0.1,root,,,$MASTER_MYPORT); ++ ++connection conn1; ++--let $conn1_id = `SELECT connection_id()` ++ ++connection conn2; ++--let $conn2_id = `SELECT connection_id()` ++ ++connection conn1; ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++ ++connection conn2; ++SEND SELECT benchmark(9999999999, md5('very long command 2')); ++ ++# Test that only one command is being executed ++connection extracon; ++SELECT COUNT(Id) FROM INFORMATION_SCHEMA.processlist where Info like 'SELECT benchmark(9999999999, md5(\'very long command%'; ++# Test that under this circumstance, information offered by information schema is as expected ++# I_S.THREAD_POOL_GROUPS ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(IS_STALLED) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++# I_S.THREAD_POOL_QUEUES ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++# I_S.THREAD_POOL_STATS ++SELECT SUM(THREAD_CREATIONS_DUE_TO_STALL) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SELECT SUM(WAKES_DUE_TO_STALL) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SELECT SUM(THROTTLES) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++SELECT SUM(STALLS) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++ ++# Clean up ++--disable_query_log ++eval KILL QUERY $conn1_id; ++eval KILL QUERY $conn2_id; ++--enable_query_log +diff --git a/mysql-test/suite/thread_pool/t/threadpool_shutdown.cnf b/mysql-test/suite/thread_pool/t/threadpool_shutdown.cnf +new file mode 100644 +index 00000000000..d95d8529ab1 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_shutdown.cnf +@@ -0,0 +1,3 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] +diff --git a/mysql-test/suite/thread_pool/t/threadpool_shutdown.test b/mysql-test/suite/thread_pool/t/threadpool_shutdown.test +new file mode 100644 +index 00000000000..fe0932fb3a6 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_shutdown.test +@@ -0,0 +1,76 @@ ++# Restart with plugin-load-add=thread_pool.so ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_oversubscribe=3 ++--source include/restart_mysqld.inc ++ ++# initialize data ++CREATE DATABASE db1; ++CREATE TABLE db1.t1 ( ++ c1 int NOT NULL, ++ c2 int NOT NULL, ++ PRIMARY KEY (c1) ++); ++INSERT INTO db1.t1 (c1,c2) VALUES (1,11); ++INSERT INTO db1.t1 (c1,c2) VALUES (2,22); ++INSERT INTO db1.t1 (c1,c2) VALUES (3,33); ++ ++connect(conn0,127.0.0.1,root,,db1); ++connect(conn1,127.0.0.1,root,,db1); ++ ++connection conn0; ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 FOR UPDATE; ++ ++connection conn1; ++START TRANSACTION; ++SEND SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++ ++connection default; ++--echo # Shutdown the server ++--source include/shutdown_mysqld.inc ++ ++--echo # Start the server ++--source include/start_mysqld.inc ++ ++connect(conn2,127.0.0.1,root,,db1); ++connect(conn3,127.0.0.1,root,,db1); ++ ++connection conn2; ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++ ++connection conn3; ++SEND SELECT benchmark(9999999999, md5('very long command 2')); ++ ++connection default; ++--echo # Shutdown the server ++--source include/shutdown_mysqld.inc ++ ++--echo # Start the server ++--source include/start_mysqld.inc ++ ++connect(conn4,127.0.0.1,root,,db1); ++connect(conn5,127.0.0.1,root,,db1); ++ ++connection conn4; ++SELECT * FROM db1.t1 WHERE c1=1; ++ ++connection conn5; ++SELECT * FROM db1.t1 WHERE c1=2; ++ ++connection default; ++--echo # Shutdown the server ++--source include/shutdown_mysqld.inc ++ ++--echo # Start the server ++--source include/start_mysqld.inc ++ ++--echo # Cleanup ++DROP TABLE db1.t1; ++DROP DATABASE db1; ++ ++disconnect conn0; ++disconnect conn1; ++disconnect conn2; ++disconnect conn3; ++disconnect conn4; ++disconnect conn5; +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_active-debug.cnf b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active-debug.cnf +new file mode 100644 +index 00000000000..1462b559a1d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active-debug.cnf +@@ -0,0 +1,8 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++innodb_lock_wait_timeout=3600 ++loose-debug-sync-timeout=300 ++ ++[client] ++connect-timeout=2 +\ No newline at end of file +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_active-debug.test b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active-debug.test +new file mode 100644 +index 00000000000..a1f1ab1241d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active-debug.test +@@ -0,0 +1,100 @@ ++--source include/have_debug.inc ++ ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++# Calculate value for admin port ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --loose-thread_pool_size=1 --loose-thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++--replace_result $ADMIN_PORT ADMIN_PORT ++--source include/restart_mysqld.inc ++ ++# Test that existed connection may or may not be able to execute command, depending on the timing of io events's arrival ++ ++connect(extracon,127.0.0.1,root,,,$ADMIN_PORT); ++connect(conn1,127.0.0.1,root); ++connect(conn2,127.0.0.1,root); ++connect(conn3,127.0.0.1,root); ++connect(conn4,127.0.0.1,root); ++ ++connection conn1; ++--let $conn1_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++ ++--sleep 1 ++ ++connection conn2; ++--let $conn2_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 2')); ++ ++# Test that listener polls 1 queue_event and process it. Verify it 2 times. ++--let $counter=0 ++while ($counter<2) ++{ ++ connection conn3; ++ SEND SELECT 1; ++ --sleep 1 ++ ++ # ASSERT queue length = 0 ++ connection extracon; ++ --let queue_length=`SELECT QUEUE_LENGTH FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS` ++ --echo queue_length $queue_length ++ ++ connection conn3; ++ REAP; ++ ++ --inc $counter ++} ++ ++# Execute this command in thread pool handler, so that the next command will be first of the two required io events. ++SET GLOBAL debug="+d,threadpool_io_poll_wait_at_least_2_events"; ++--sleep 1 ++ ++# Test that listener polls 2 queue_events and process one of them, leaving the other in low priority queue ++ ++# First of the 2 required io events, listener will execute another io_poll_wait ++connection conn3; ++SEND SELECT 1; ++ ++# Disable threadpool_io_poll_wait_at_least_2_events ++connection extracon; ++SET GLOBAL debug="-d,threadpool_io_poll_wait_at_least_2_events"; ++--sleep 1 ++ ++# Second of the two required io events, listener will deal with the 2 io_events, either process one of them or put both to queue. ++connection conn4; ++SEND SELECT 1; ++--sleep 1 ++ ++# ASSERT queue length = 1 ++connection extracon; ++--let queue_length=`SELECT QUEUE_LENGTH FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS` ++--echo queue_length $queue_length ++# Test that under this circumstance, information offered by information schema is as expected ++# I_S.THREAD_POOL_GROUPS ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++# I_S.THREAD_POOL_QUEUES ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++ ++# Clean up ++--disable_query_log ++eval KILL QUERY $conn1_id; ++eval KILL QUERY $conn2_id; ++--enable_query_log ++ ++--sleep 1 ++ ++connection default; ++disconnect conn1; ++disconnect conn2; ++disconnect conn3; ++disconnect conn4; ++disconnect extracon; +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.cnf b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.cnf +new file mode 100644 +index 00000000000..1462b559a1d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.cnf +@@ -0,0 +1,8 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++innodb_lock_wait_timeout=3600 ++loose-debug-sync-timeout=300 ++ ++[client] ++connect-timeout=2 +\ No newline at end of file +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test +new file mode 100644 +index 00000000000..44fa0296964 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test +@@ -0,0 +1,61 @@ ++# Restart with plugin-load-add=thread_pool.so ++ ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++# Calculate value for admin port ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++--replace_result $ADMIN_PORT ADMIN_PORT ++--source include/restart_mysqld.inc ++ ++connect(conn1,127.0.0.1,root); ++connect(conn2,127.0.0.1,root); ++ ++connection conn1; ++--let $conn1_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++ ++--sleep 1 ++ ++connection conn2; ++--let $conn2_id = `SELECT connection_id()` ++SEND SELECT benchmark(9999999999, md5('very long command 2')); ++ ++# Test that new connection cannot be established ++--disable_abort_on_error ++--echo You should see a Lost connection message ++connect(conn3,127.0.0.1,root); ++--enable_abort_on_error ++ ++connect(extracon,127.0.0.1,root,,,$ADMIN_PORT); ++connection extracon; ++--let $conn_id_number=`SELECT COUNT(ID) FROM information_schema.processlist WHERE USER="unauthenticated user" AND HOST="connecting host" AND COMMAND="Connect"` ++--echo Found $conn_id_number stuck connections ++# Test that under this circumstance, information offered by information schema is as expected ++# I_S.THREAD_POOL_GROUPS ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++# I_S.THREAD_POOL_QUEUES ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++# I_S.THREAD_POOL_STATS ++SELECT SUM(THREAD_CREATIONS_DUE_TO_STALL) FROM INFORMATION_SCHEMA.THREAD_POOL_STATS; ++ ++--disable_query_log ++--eval KILL QUERY $conn1_id ++--eval KILL QUERY $conn2_id ++--enable_query_log ++ ++--sleep 1 ++ ++connection default; ++disconnect conn1; ++disconnect conn2; ++disconnect extracon; +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_corner_case.cnf b/mysql-test/suite/thread_pool/t/threadpool_too_busy_corner_case.cnf +new file mode 100644 +index 00000000000..ea0701e68d5 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_corner_case.cnf +@@ -0,0 +1,7 @@ ++!include include/default_my.cnf ++ ++[mysqld.1]innodb_lock_wait_timeout=3600 ++loose-debug-sync-timeout=300 ++ ++[client] ++connect-timeout=2 +\ No newline at end of file +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_corner_case.test b/mysql-test/suite/thread_pool/t/threadpool_too_busy_corner_case.test +new file mode 100644 +index 00000000000..513d21f9255 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_corner_case.test +@@ -0,0 +1,76 @@ ++# Restart with plugin-load-add=thread_pool.so ++ ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++# Calculate value for admin port ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++--replace_result $ADMIN_PORT ADMIN_PORT ++--source include/restart_mysqld.inc ++ ++# Test that in certain case the listener won't process the only io event it just polled, when too busy condition is already met. ++ ++connect(extracon,127.0.0.1,root,,,$ADMIN_PORT); ++connect(conn1,127.0.0.1,root); ++connect(conn2,127.0.0.1,root); ++connect(conn3,127.0.0.1,root); ++ ++connection conn1; ++--let $conn1_id = `SELECT connection_id()` ++ ++connection conn2; ++--let $conn2_id = `SELECT connection_id()` ++ ++connection conn3; ++--let $conn3_id = `SELECT connection_id()` ++ ++connection conn1; ++SEND SELECT benchmark(9999999999, md5('very long command 1')); ++ ++--sleep 1 ++connection conn2; ++SEND SELECT benchmark(9999999999, md5('very long command 2')); ++ ++--sleep 1 ++ ++# The connect will timeout, but an io_event was put to low priority queue successfully. ++--disable_abort_on_error ++--echo You should see a Lost connection message ++connect(conn4,127.0.0.1,root); ++--enable_abort_on_error ++ ++--sleep 1 ++connection conn3; ++SEND SELECT 1; ++ ++# The listener resumes and puts the the polled io_event to low priority queue, which make the queue length 2. ++--sleep 1 ++connection extracon; ++--let queue_length=`SELECT QUEUE_LENGTH FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS` ++--echo queue_length $queue_length ++# Test that under this circumstance, information offered by information schema is as expected ++# I_S.THREAD_POOL_GROUPS ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++# I_S.THREAD_POOL_QUEUES ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++ ++# Clean up ++connection extracon; ++--disable_query_log ++eval KILL QUERY $conn1_id; ++eval KILL QUERY $conn2_id; ++--enable_query_log ++ ++connection default; ++disconnect conn1; ++disconnect conn2; ++disconnect conn3; ++disconnect extracon; +\ No newline at end of file +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.cnf b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.cnf +new file mode 100644 +index 00000000000..1462b559a1d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.cnf +@@ -0,0 +1,8 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++innodb_lock_wait_timeout=3600 ++loose-debug-sync-timeout=300 ++ ++[client] ++connect-timeout=2 +\ No newline at end of file +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.test b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.test +new file mode 100644 +index 00000000000..e1371b5e731 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.test +@@ -0,0 +1,130 @@ ++--source include/have_debug.inc ++ ++# Test that existed connection may or may not be able to execute command, depending on the timing of io events's arrival ++ ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++# initialize data ++CREATE DATABASE db1; ++CREATE TABLE db1.t1 ( ++ c1 int NOT NULL, ++ c2 int NOT NULL, ++ PRIMARY KEY (c1) ++); ++INSERT INTO db1.t1 (c1,c2) VALUES (1,11); ++INSERT INTO db1.t1 (c1,c2) VALUES (2,22); ++INSERT INTO db1.t1 (c1,c2) VALUES (3,33); ++ ++# Calculate value for admin port ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --loose-thread_pool_size=1 --loose-thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++--replace_result $ADMIN_PORT ADMIN_PORT ++--source include/restart_mysqld.inc ++ ++connect(extracon,127.0.0.1,root,,,$ADMIN_PORT); ++connect(conn0,127.0.0.1,root,,db1); ++connect(conn1,127.0.0.1,root,,db1); ++connect(conn2,127.0.0.1,root,,db1); ++connect(conn3,127.0.0.1,root,,db1); ++connect(conn4,127.0.0.1,root,,db1); ++ ++connection conn0; ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 FOR UPDATE; ++--sleep 1 ++ ++connection conn1; ++START TRANSACTION; ++SEND SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++ ++connection conn2; ++START TRANSACTION; ++SEND SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++ ++# Test that listener polls 1 queue_event and process it. Verify it 2 times. ++--let $counter=0 ++while ($counter<2) ++{ ++ connection conn3; ++ SEND SELECT 1; ++ --sleep 1 ++ ++ # ASSERT queue length = 0 ++ connection extracon; ++ --let queue_length=`SELECT QUEUE_LENGTH FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS` ++ --echo queue_length $queue_length ++ ++ connection conn3; ++ REAP; ++ ++ --inc $counter ++} ++ ++# Execute this command in thread pool handler, so that the next command will be first of the two required io events. ++SET GLOBAL debug="+d,threadpool_io_poll_wait_at_least_2_events"; ++--sleep 1 ++ ++# Test that listener polls 2 queue_events and process one of them, leaving the other in low priority queue ++ ++# First of the 2 required io events, listener will execute another io_poll_wait ++connection conn3; ++SEND SELECT 1; ++ ++# Disable threadpool_io_poll_wait_at_least_2_events ++connection extracon; ++SET GLOBAL debug="-d,threadpool_io_poll_wait_at_least_2_events"; ++--sleep 1 ++ ++# Second of the two required io events, listener will deal with the 2 io_events, either process one of them or put both to queue. ++connection conn4; ++SEND SELECT 1; ++--sleep 1 ++ ++# ASSERT queue length = 1 ++connection extracon; ++--let queue_length=`SELECT QUEUE_LENGTH FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS` ++--echo queue_length $queue_length ++# Test that under this circumstance, information offered by information schema is as expected ++# I_S.THREAD_POOL_GROUPS ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++# I_S.THREAD_POOL_QUEUES ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++ ++# Clean up ++connection conn0; ++ROLLBACK; ++ ++connection conn1; ++REAP; ++ROLLBACK; ++ ++connection conn2; ++REAP; ++ROLLBACK; ++ ++connection conn3; ++REAP; ++ ++connection conn4; ++REAP; ++ ++connection extracon; ++--echo Clean up ++DROP TABLE db1.t1; ++DROP DATABASE db1; ++ ++disconnect conn0; ++disconnect conn1; ++disconnect conn2; ++disconnect conn3; ++disconnect conn4; ++disconnect extracon; +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait.cnf b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait.cnf +new file mode 100644 +index 00000000000..1462b559a1d +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait.cnf +@@ -0,0 +1,8 @@ ++!include include/default_my.cnf ++ ++[mysqld.1] ++innodb_lock_wait_timeout=3600 ++loose-debug-sync-timeout=300 ++ ++[client] ++connect-timeout=2 +\ No newline at end of file +diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait.test b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait.test +new file mode 100644 +index 00000000000..209845abc07 +--- /dev/null ++++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait.test +@@ -0,0 +1,85 @@ ++# Restart with plugin-load-add=thread_pool.so ++ ++--disable_query_log ++CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); ++CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); ++--enable_query_log ++ ++# initialize data ++CREATE DATABASE db1; ++CREATE TABLE db1.t1 ( ++ c1 int NOT NULL, ++ c2 int NOT NULL, ++ PRIMARY KEY (c1) ++); ++INSERT INTO db1.t1 (c1,c2) VALUES (1,11); ++INSERT INTO db1.t1 (c1,c2) VALUES (2,22); ++INSERT INTO db1.t1 (c1,c2) VALUES (3,33); ++ ++# Calculate value for admin port ++--let $PORT_OFFSET = 1 ++--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET ++ ++--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=1 --thread_pool_toobusy=1 --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 ++--replace_result $ADMIN_PORT ADMIN_PORT ++--source include/restart_mysqld.inc ++ ++connect(conn0,127.0.0.1,root,,db1); ++connect(conn1,127.0.0.1,root,,db1); ++connect(conn2,127.0.0.1,root,,db1); ++ ++connection conn0; ++START TRANSACTION; ++SELECT * FROM db1.t1 WHERE c1=2 FOR UPDATE; ++ ++connection conn1; ++START TRANSACTION; ++SEND SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++ ++connection conn2; ++START TRANSACTION; ++SEND SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; ++ ++# Test that new connection cannot be established ++--disable_abort_on_error ++--echo You should see a Lost connection message ++connect(conn3,127.0.0.1,root,,db1); ++--enable_abort_on_error ++ ++connect(extracon,127.0.0.1,root,,,$ADMIN_PORT,); ++connection extracon; ++--let $conn_id_number=`SELECT COUNT(ID) FROM information_schema.processlist WHERE USER="unauthenticated user" AND HOST="connecting host" AND COMMAND="Connect"` ++--echo Found $conn_id_number stuck connections ++# Test that under this circumstance, information offered by information schema is as expected ++# I_S.THREAD_POOL_GROUPS ++SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(ACTIVE_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(STANDBY_THREADS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(QUEUE_LENGTH) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++SELECT SUM(HAS_LISTENER) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; ++# I_S.THREAD_POOL_QUEUES ++SELECT COUNT(*) FROM INFORMATION_SCHEMA.THREAD_POOL_QUEUES; ++# I_S.THREAD_POOL_WAITS ++SELECT COUNT FROM INFORMATION_SCHEMA.THREAD_POOL_WAITS WHERE REASON='Row_lock'; ++ ++connection conn0; ++ROLLBACK; ++ ++connection conn1; ++REAP; ++ROLLBACK; ++ ++connection conn2; ++REAP; ++ROLLBACK; ++ ++connection extracon; ++--echo Clean up ++DROP TABLE db1.t1; ++DROP DATABASE db1; ++ ++connection default; ++disconnect conn0; ++disconnect conn1; ++disconnect conn2; ++disconnect extracon; -- Gitee