diff --git a/include/my_sys.h b/include/my_sys.h index 67741f7ff87..24aa4a95ff4 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -52,6 +52,9 @@ typedef struct my_aio_result { #define MY_INIT(name) { my_progname= name; my_init(); } +extern ulonglong my_interval_timer(void); +#define microsecond_interval_timer() (my_interval_timer()/1000) + /** Max length of an error message generated by mysys utilities. Some mysys functions produce error messages. These mostly go diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index d6d5b0cbacb..98b35330d29 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -44,7 +44,8 @@ THD_WAIT_BINLOG= 8, THD_WAIT_GROUP_COMMIT= 9, THD_WAIT_SYNC= 10, - THD_WAIT_LAST= 11 + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 } thd_wait_type; extern struct thd_wait_service_st { void (*thd_wait_begin_func)(void*, int); diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index 8b65cbb4660..d00dbd91b35 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -44,7 +44,8 @@ THD_WAIT_BINLOG= 8, THD_WAIT_GROUP_COMMIT= 9, THD_WAIT_SYNC= 10, - THD_WAIT_LAST= 11 + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 } thd_wait_type; extern struct thd_wait_service_st { void (*thd_wait_begin_func)(void*, int); diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index 492ad97ea87..9835933022c 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -44,7 +44,8 @@ THD_WAIT_BINLOG= 8, THD_WAIT_GROUP_COMMIT= 9, THD_WAIT_SYNC= 10, - THD_WAIT_LAST= 11 + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 } thd_wait_type; extern struct thd_wait_service_st { void (*thd_wait_begin_func)(void*, int); diff --git a/include/mysql/service_thd_wait.h b/include/mysql/service_thd_wait.h index 6b47a4ff21e..c35b35df820 100644 --- a/include/mysql/service_thd_wait.h +++ b/include/mysql/service_thd_wait.h @@ -74,7 +74,8 @@ typedef enum _thd_wait_type_e { THD_WAIT_BINLOG= 8, THD_WAIT_GROUP_COMMIT= 9, THD_WAIT_SYNC= 10, - THD_WAIT_LAST= 11 + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 } thd_wait_type; extern struct thd_wait_service_st { diff --git a/include/mysql/thread_pool_priv.h b/include/mysql/thread_pool_priv.h index ee197709767..aad5dcd0943 100644 --- a/include/mysql/thread_pool_priv.h +++ b/include/mysql/thread_pool_priv.h @@ -107,7 +107,7 @@ void end_connection(THD *thd); /* Release resources of the THD object */ void thd_release_resources(THD *thd); /* Decrement connection counter */ -void dec_connection_count(); +void dec_connection_count(THD *thd); /* Destroy THD object */ void destroy_thd(THD *thd); /* Remove the THD from the set of global threads. */ diff --git a/include/violite.h b/include/violite.h index 1cd9c8792cd..b28dcd96fe5 100644 --- a/include/violite.h +++ b/include/violite.h @@ -74,6 +74,7 @@ Vio* vio_new_win32shared_memory(HANDLE handle_file_map, void vio_delete(Vio* vio); int vio_shutdown(Vio* vio); +int vio_cancel(Vio* vio, int how); my_bool vio_reset(Vio* vio, enum enum_vio_type type, my_socket sd, void *ssl, uint flags); size_t vio_read(Vio *vio, uchar * buf, size_t size); @@ -105,6 +106,8 @@ ssize_t vio_pending(Vio *vio); #endif /* Set timeout for a network operation. */ int vio_timeout(Vio *vio, uint which, int timeout_sec); +extern void vio_set_wait_callback(void (*before_wait)(void), + void (*after_wait)(void)); /* Connect to a peer. */ my_bool vio_socket_connect(Vio *vio, struct sockaddr *addr, socklen_t len, int timeout); @@ -190,6 +193,7 @@ void vio_end(void); #define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive) #define vio_should_retry(vio) (vio)->should_retry(vio) #define vio_was_timeout(vio) (vio)->was_timeout(vio) +#define vio_cancel(vio, how) ((vio)->viocancel)(vio, how) #define vio_shutdown(vio) ((vio)->vioshutdown)(vio) #define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen) #define vio_io_wait(vio, event, timeout) (vio)->io_wait(vio, event, timeout) @@ -256,6 +260,7 @@ struct st_vio descriptors, handles can remain valid after a shutdown. */ int (*vioshutdown)(Vio*); + int (*viocancel)(Vio*, int); my_bool (*is_connected)(Vio*); my_bool (*has_data) (Vio*); int (*io_wait)(Vio*, enum enum_vio_io_event, int); diff --git a/mysql-test/include/have_pool_of_threads.inc b/mysql-test/include/have_pool_of_threads.inc new file mode 100644 index 00000000000..ab93a62d568 --- /dev/null +++ b/mysql-test/include/have_pool_of_threads.inc @@ -0,0 +1,4 @@ +-- require r/have_pool_of_threads.require +disable_query_log; +show variables like 'thread_handling'; +enable_query_log; diff --git a/mysql-test/r/have_pool_of_threads.require b/mysql-test/r/have_pool_of_threads.require new file mode 100644 index 00000000000..04e46a71903 --- /dev/null +++ b/mysql-test/r/have_pool_of_threads.require @@ -0,0 +1,2 @@ +Variable_name Value +thread_handling pool-of-threads diff --git a/mysql-test/r/information_schema-big.result b/mysql-test/r/information_schema-big.result index b8b6dc6d182..2c6bad01694 100644 --- a/mysql-test/r/information_schema-big.result +++ b/mysql-test/r/information_schema-big.result @@ -43,6 +43,7 @@ SCHEMATA SCHEMA_NAME SCHEMA_PRIVILEGES TABLE_SCHEMA SESSION_STATUS VARIABLE_NAME SESSION_VARIABLES VARIABLE_NAME +SQL_FILTER_INFO TYPE STATISTICS TABLE_SCHEMA TABLES TABLE_SCHEMA TABLESPACES TABLESPACE_NAME @@ -51,6 +52,15 @@ TABLE_PRIVILEGES TABLE_SCHEMA TRIGGERS TRIGGER_SCHEMA USER_PRIVILEGES GRANTEE VIEWS TABLE_SCHEMA +TABLE_STATISTICS TABLE_SCHEMA +INDEX_STATISTICS TABLE_SCHEMA +THREAD_GROUP_STATUS ID +TokuDB_file_map table_schema +TokuDB_trx trx_id +TokuDB_locks locks_table_schema +TokuDB_lock_waits lock_waits_table_schema +TokuDB_fractal_tree_block_map table_schema +TokuDB_fractal_tree_info table_schema SELECT t.table_name, c1.column_name FROM information_schema.tables t INNER JOIN @@ -91,6 +101,7 @@ SCHEMATA SCHEMA_NAME SCHEMA_PRIVILEGES TABLE_SCHEMA SESSION_STATUS VARIABLE_NAME SESSION_VARIABLES VARIABLE_NAME +SQL_FILTER_INFO TYPE STATISTICS TABLE_SCHEMA TABLES TABLE_SCHEMA TABLESPACES TABLESPACE_NAME @@ -99,3 +110,12 @@ TABLE_PRIVILEGES TABLE_SCHEMA TRIGGERS TRIGGER_SCHEMA USER_PRIVILEGES GRANTEE VIEWS TABLE_SCHEMA +TABLE_STATISTICS TABLE_SCHEMA +INDEX_STATISTICS TABLE_SCHEMA +THREAD_GROUP_STATUS ID +TokuDB_file_map table_schema +TokuDB_trx trx_id +TokuDB_locks locks_table_schema +TokuDB_lock_waits lock_waits_table_schema +TokuDB_fractal_tree_block_map table_schema +TokuDB_fractal_tree_info table_schema diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index d6a10de6463..591854c62b0 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -87,6 +87,7 @@ USER_PRIVILEGES VIEWS TABLE_STATISTICS INDEX_STATISTICS +THREAD_GROUP_STATUS TokuDB_file_map TokuDB_trx TokuDB_locks @@ -134,6 +135,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TRIGGERS TRIGGERS TABLE_STATISTICS TABLE_STATISTICS +THREAD_GROUP_STATUS THREAD_GROUP_STATUS TokuDB_file_map TokuDB_file_map TokuDB_trx TokuDB_trx TokuDB_locks TokuDB_locks @@ -161,6 +163,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TRIGGERS TRIGGERS TABLE_STATISTICS TABLE_STATISTICS +THREAD_GROUP_STATUS THREAD_GROUP_STATUS TokuDB_file_map TokuDB_file_map TokuDB_trx TokuDB_trx TokuDB_locks TokuDB_locks @@ -188,6 +191,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TRIGGERS TRIGGERS TABLE_STATISTICS TABLE_STATISTICS +THREAD_GROUP_STATUS THREAD_GROUP_STATUS TokuDB_file_map TokuDB_file_map TokuDB_trx TokuDB_trx TokuDB_locks TokuDB_locks @@ -688,6 +692,7 @@ TABLE_CONSTRAINTS TABLE_PRIVILEGES TRIGGERS TABLE_STATISTICS +THREAD_GROUP_STATUS TokuDB_file_map TokuDB_trx TokuDB_locks @@ -705,6 +710,7 @@ TABLE_CONSTRAINTS SYSTEM VIEW TABLE_PRIVILEGES SYSTEM VIEW TRIGGERS SYSTEM VIEW TABLE_STATISTICS SYSTEM VIEW +THREAD_GROUP_STATUS SYSTEM VIEW TokuDB_file_map SYSTEM VIEW TokuDB_trx SYSTEM VIEW TokuDB_locks SYSTEM VIEW @@ -725,6 +731,7 @@ TABLE_CONSTRAINTS TABLE_PRIVILEGES TRIGGERS TABLE_STATISTICS +THREAD_GROUP_STATUS TokuDB_file_map TokuDB_trx TokuDB_locks @@ -951,7 +958,7 @@ table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name not like 'ndb%' AND table_name not like 'innodb_%' GROUP BY TABLE_SCHEMA; table_schema count(*) -information_schema 40 +information_schema 41 mysql 25 create table t1 (i int, j int); create trigger trg1 before insert on t1 for each row @@ -1422,6 +1429,7 @@ TABLESPACES information_schema.TABLESPACES 1 TABLE_CONSTRAINTS information_schema.TABLE_CONSTRAINTS 1 TABLE_PRIVILEGES information_schema.TABLE_PRIVILEGES 1 TABLE_STATISTICS information_schema.TABLE_STATISTICS 1 +THREAD_GROUP_STATUS information_schema.THREAD_GROUP_STATUS 1 TokuDB_file_map information_schema.TokuDB_file_map 1 TokuDB_fractal_tree_block_map information_schema.TokuDB_fractal_tree_block_map 1 TokuDB_fractal_tree_info information_schema.TokuDB_fractal_tree_info 1 diff --git a/mysql-test/r/information_schema_db.result b/mysql-test/r/information_schema_db.result index 3cdd81734a6..afe96c03874 100644 --- a/mysql-test/r/information_schema_db.result +++ b/mysql-test/r/information_schema_db.result @@ -39,6 +39,7 @@ USER_PRIVILEGES VIEWS TABLE_STATISTICS INDEX_STATISTICS +THREAD_GROUP_STATUS TokuDB_file_map TokuDB_trx TokuDB_locks @@ -53,6 +54,7 @@ TABLE_CONSTRAINTS TABLE_PRIVILEGES TRIGGERS TABLE_STATISTICS +THREAD_GROUP_STATUS TokuDB_file_map TokuDB_trx TokuDB_locks diff --git a/mysql-test/r/mysqld--help-notwin.result b/mysql-test/r/mysqld--help-notwin.result index b6c7f18606e..34878c09181 100644 --- a/mysql-test/r/mysqld--help-notwin.result +++ b/mysql-test/r/mysqld--help-notwin.result @@ -242,6 +242,11 @@ The following options may be given as the first argument: With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running. Disable with --skip-external-locking. + --extra-max-connections=# + The number of connections on extra-port + --extra-port=# Extra port number to use for tcp connections in a + one-thread-per-connection manner. 0 means don't use + another port --flush Flush MyISAM tables to disk between SQL commands --flush-time=# A dedicated thread is created to flush all tables at the given interval @@ -1047,8 +1052,46 @@ The following options may be given as the first argument: How many threads we should keep in a cache for reuse --thread-handling=name Define threads usage for handling queries, one of - one-thread-per-connection, no-threads, loaded-dynamically + one-thread-per-connection, no-threads, pool-of-threads + --thread-pool-high-prio-mode=name + 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. + --thread-pool-high-prio-tickets=# + Number of tickets to enter the high priority event queue + for each transaction. + --thread-pool-idle-timeout=# + Timeout in seconds for an idle thread in the thread + pool.Worker thread will be shutdown after timeout + --thread-pool-max-threads=# + Maximus allowed number of worker threads in the thread + pool + --thread-pool-oversubscribe=# + How many additional active worker threads in a group are + allowed. + --thread-pool-size=# + 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). + --thread-pool-stall-limit=# + 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. --thread-stack=# The stack size for each thread + --threadpool-workaround-epoll-bug + Workaround Linux kernel bug: missing events in epoll, if + EPOLL_CTL_MOD is used.The bug is fixed in the newest 3.x + kernel series --time-format=name The TIME format (ignored) --timed-mutexes Specify whether to time mutexes. Deprecated, has no effect. @@ -1268,6 +1311,8 @@ event-scheduler OFF expire-logs-days 0 explicit-defaults-for-timestamp FALSE external-locking FALSE +extra-max-connections 10000 +extra-port 0 flush FALSE flush-time 0 ft-boolean-syntax + -><()~*:""&| @@ -1515,7 +1560,15 @@ table-open-cache-instances 1 tc-heuristic-recover COMMIT thread-cache-size 9 thread-handling one-thread-per-connection +thread-pool-high-prio-mode transactions +thread-pool-high-prio-tickets -1 +thread-pool-idle-timeout 60 +thread-pool-max-threads 100000 +thread-pool-oversubscribe 3 +thread-pool-size 24 +thread-pool-stall-limit 10 thread-stack 262144 +threadpool-workaround-epoll-bug FALSE time-format %H:%i:%s timed-mutexes FALSE tmp-table-size 16777216 diff --git a/mysql-test/r/mysqlshow.result b/mysql-test/r/mysqlshow.result index 5c5d28d58ac..e082b493a21 100644 --- a/mysql-test/r/mysqlshow.result +++ b/mysql-test/r/mysqlshow.result @@ -113,6 +113,7 @@ Database: information_schema | VIEWS | | TABLE_STATISTICS | | INDEX_STATISTICS | +| THREAD_GROUP_STATUS | | TokuDB_file_map | | TokuDB_trx | | INNODB_SYS_DATAFILES | @@ -187,6 +188,7 @@ Database: INFORMATION_SCHEMA | VIEWS | | TABLE_STATISTICS | | INDEX_STATISTICS | +| THREAD_GROUP_STATUS | | TokuDB_file_map | | TokuDB_trx | | INNODB_SYS_DATAFILES | diff --git a/mysql-test/r/pool_of_threads.result b/mysql-test/r/pool_of_threads.result new file mode 100644 index 00000000000..0cb84105cdf --- /dev/null +++ b/mysql-test/r/pool_of_threads.result @@ -0,0 +1,2174 @@ +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 +); +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) +); +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld3 fld3 30 NULL 2 Using where; Using index +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld1 fld1 4 NULL 2 Using where; Using index +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld1 fld1 4 NULL 4 Using where; Using index +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) +); +create temporary table tmp engine = myisam 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; +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 fld3,count(*) from t2 group by companynr,fld3 limit 10; +fld3 count(*) +affixed 1 +and 1 +annoyers 1 +Anthony 1 +assayed 1 +assurers 1 +attendants 1 +bedlam 1 +bedpost 1 +boasted 1 +SET BIG_TABLES=1; +select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10; +fld3 count(*) +affixed 1 +and 1 +annoyers 1 +Anthony 1 +assayed 1 +assurers 1 +attendants 1 +bedlam 1 +bedpost 1 +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(*) +circus aaaaaa 1 +cited aaaaa 1 +Colombo aaaaaaa 1 +congresswoman aaaaaaaaaaaaa 1 +contrition aaaaaaaaaa 1 +corny aaaaa 1 +cultivation aaaaaaaaaaa 1 +definiteness aaaaaaaaaaaa 1 +demultiplex aaaaaaaaaaa 1 +disappointing aaaaaaaaaaaaa 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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index +explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort +1 SIMPLE t3 ref period period 4 test.t1.period 4181 NULL +explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t3 index period period 4 NULL 1 NULL +1 SIMPLE t1 ref period period 4 test.t3.period 4181 NULL +explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index period period 4 NULL 1 NULL +1 SIMPLE t3 ref period period 4 test.t1.period 4181 NULL +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 const fld1 fld1 4 const 1 NULL +1 SIMPLE t3 const PRIMARY,period PRIMARY 4 const 1 NULL +select fld3,period from t2,t1 where companynr*10 = 37*10; +fld3 period +breaking 9410 +Romans 9410 +intercepted 9410 +bewilderingly 9410 +astound 9410 +admonishing 9410 +sumac 9410 +flanking 9410 +combed 9410 +subjective 9410 +scatterbrain 9410 +Eulerian 9410 +Kane 9410 +overlay 9410 +perturb 9410 +goblins 9410 +annihilates 9410 +Wotan 9410 +snatching 9410 +concludes 9410 +laterally 9410 +yelped 9410 +grazing 9410 +Baird 9410 +celery 9410 +misunderstander 9410 +handgun 9410 +foldout 9410 +mystic 9410 +succumbed 9410 +Nabisco 9410 +fingerings 9410 +aging 9410 +afield 9410 +ammonium 9410 +boat 9410 +intelligibility 9410 +Augustine 9410 +teethe 9410 +dreaded 9410 +scholastics 9410 +audiology 9410 +wallet 9410 +parters 9410 +eschew 9410 +quitter 9410 +neat 9410 +Steinberg 9410 +jarring 9410 +tinily 9410 +balled 9410 +persist 9410 +attainments 9410 +fanatic 9410 +measures 9410 +rightfulness 9410 +capably 9410 +impulsive 9410 +starlet 9410 +terminators 9410 +untying 9410 +announces 9410 +featherweight 9410 +pessimist 9410 +daughter 9410 +decliner 9410 +lawgiver 9410 +stated 9410 +readable 9410 +attrition 9410 +cascade 9410 +motors 9410 +interrogate 9410 +pests 9410 +stairway 9410 +dopers 9410 +testicle 9410 +Parsifal 9410 +leavings 9410 +postulation 9410 +squeaking 9410 +contrasted 9410 +leftover 9410 +whiteners 9410 +erases 9410 +Punjab 9410 +Merritt 9410 +Quixotism 9410 +sweetish 9410 +dogging 9410 +scornfully 9410 +bellow 9410 +bills 9410 +cupboard 9410 +sureties 9410 +puddings 9410 +fetters 9410 +bivalves 9410 +incurring 9410 +Adolph 9410 +pithed 9410 +Miles 9410 +trimmings 9410 +tragedies 9410 +skulking 9410 +flint 9410 +flopping 9410 +relaxing 9410 +offload 9410 +suites 9410 +lists 9410 +animized 9410 +multilayer 9410 +standardizes 9410 +Judas 9410 +vacuuming 9410 +dentally 9410 +humanness 9410 +inch 9410 +Weissmuller 9410 +irresponsibly 9410 +luckily 9410 +culled 9410 +medical 9410 +bloodbath 9410 +subschema 9410 +animals 9410 +Micronesia 9410 +repetitions 9410 +Antares 9410 +ventilate 9410 +pityingly 9410 +interdependent 9410 +Graves 9410 +neonatal 9410 +chafe 9410 +honoring 9410 +realtor 9410 +elite 9410 +funereal 9410 +abrogating 9410 +sorters 9410 +Conley 9410 +lectured 9410 +Abraham 9410 +Hawaii 9410 +cage 9410 +hushes 9410 +Simla 9410 +reporters 9410 +Dutchman 9410 +descendants 9410 +groupings 9410 +dissociate 9410 +coexist 9410 +Beebe 9410 +Taoism 9410 +Connally 9410 +fetched 9410 +checkpoints 9410 +rusting 9410 +galling 9410 +obliterates 9410 +traitor 9410 +resumes 9410 +analyzable 9410 +terminator 9410 +gritty 9410 +firearm 9410 +minima 9410 +Selfridge 9410 +disable 9410 +witchcraft 9410 +betroth 9410 +Manhattanize 9410 +imprint 9410 +peeked 9410 +swelling 9410 +interrelationships 9410 +riser 9410 +Gandhian 9410 +peacock 9410 +bee 9410 +kanji 9410 +dental 9410 +scarf 9410 +chasm 9410 +insolence 9410 +syndicate 9410 +alike 9410 +imperial 9410 +convulsion 9410 +railway 9410 +validate 9410 +normalizes 9410 +comprehensive 9410 +chewing 9410 +denizen 9410 +schemer 9410 +chronicle 9410 +Kline 9410 +Anatole 9410 +partridges 9410 +brunch 9410 +recruited 9410 +dimensions 9410 +Chicana 9410 +announced 9410 +praised 9410 +employing 9410 +linear 9410 +quagmire 9410 +western 9410 +relishing 9410 +serving 9410 +scheduling 9410 +lore 9410 +eventful 9410 +arteriole 9410 +disentangle 9410 +cured 9410 +Fenton 9410 +avoidable 9410 +drains 9410 +detectably 9410 +husky 9410 +impelling 9410 +undoes 9410 +evened 9410 +squeezes 9410 +destroyer 9410 +rudeness 9410 +beaner 9410 +boorish 9410 +Everhart 9410 +encompass 9410 +mushrooms 9410 +Alison 9410 +externally 9410 +pellagra 9410 +cult 9410 +creek 9410 +Huffman 9410 +Majorca 9410 +governing 9410 +gadfly 9410 +reassigned 9410 +intentness 9410 +craziness 9410 +psychic 9410 +squabbled 9410 +burlesque 9410 +capped 9410 +extracted 9410 +DiMaggio 9410 +exclamation 9410 +subdirectory 9410 +Gothicism 9410 +feminine 9410 +metaphysically 9410 +sanding 9410 +Miltonism 9410 +freakish 9410 +index 9410 +straight 9410 +flurried 9410 +denotative 9410 +coming 9410 +commencements 9410 +gentleman 9410 +gifted 9410 +Shanghais 9410 +sportswriting 9410 +sloping 9410 +navies 9410 +leaflet 9410 +shooter 9410 +Joplin 9410 +babies 9410 +assails 9410 +admiring 9410 +swaying 9410 +Goldstine 9410 +fitting 9410 +Norwalk 9410 +analogy 9410 +deludes 9410 +cokes 9410 +Clayton 9410 +exhausts 9410 +causality 9410 +sating 9410 +icon 9410 +throttles 9410 +communicants 9410 +dehydrate 9410 +priceless 9410 +publicly 9410 +incidentals 9410 +commonplace 9410 +mumbles 9410 +furthermore 9410 +cautioned 9410 +parametrized 9410 +registration 9410 +sadly 9410 +positioning 9410 +babysitting 9410 +eternal 9410 +hoarder 9410 +congregates 9410 +rains 9410 +workers 9410 +sags 9410 +unplug 9410 +garage 9410 +boulder 9410 +specifics 9410 +Teresa 9410 +Winsett 9410 +convenient 9410 +buckboards 9410 +amenities 9410 +resplendent 9410 +sews 9410 +participated 9410 +Simon 9410 +certificates 9410 +Fitzpatrick 9410 +Evanston 9410 +misted 9410 +textures 9410 +save 9410 +count 9410 +rightful 9410 +chaperone 9410 +Lizzy 9410 +clenched 9410 +effortlessly 9410 +accessed 9410 +beaters 9410 +Hornblower 9410 +vests 9410 +indulgences 9410 +infallibly 9410 +unwilling 9410 +excrete 9410 +spools 9410 +crunches 9410 +overestimating 9410 +ineffective 9410 +humiliation 9410 +sophomore 9410 +star 9410 +rifles 9410 +dialysis 9410 +arriving 9410 +indulge 9410 +clockers 9410 +languages 9410 +Antarctica 9410 +percentage 9410 +ceiling 9410 +specification 9410 +regimented 9410 +ciphers 9410 +pictures 9410 +serpents 9410 +allot 9410 +realized 9410 +mayoral 9410 +opaquely 9410 +hostess 9410 +fiftieth 9410 +incorrectly 9410 +decomposition 9410 +stranglings 9410 +mixture 9410 +electroencephalography 9410 +similarities 9410 +charges 9410 +freest 9410 +Greenberg 9410 +tinting 9410 +expelled 9410 +warm 9410 +smoothed 9410 +deductions 9410 +Romano 9410 +bitterroot 9410 +corset 9410 +securing 9410 +environing 9410 +cute 9410 +Crays 9410 +heiress 9410 +inform 9410 +avenge 9410 +universals 9410 +Kinsey 9410 +ravines 9410 +bestseller 9410 +equilibrium 9410 +extents 9410 +relatively 9410 +pressure 9410 +critiques 9410 +befouled 9410 +rightfully 9410 +mechanizing 9410 +Latinizes 9410 +timesharing 9410 +Aden 9410 +embassies 9410 +males 9410 +shapelessly 9410 +mastering 9410 +Newtonian 9410 +finishers 9410 +abates 9410 +teem 9410 +kiting 9410 +stodgy 9410 +feed 9410 +guitars 9410 +airships 9410 +store 9410 +denounces 9410 +Pyle 9410 +Saxony 9410 +serializations 9410 +Peruvian 9410 +taxonomically 9410 +kingdom 9410 +stint 9410 +Sault 9410 +faithful 9410 +Ganymede 9410 +tidiness 9410 +gainful 9410 +contrary 9410 +Tipperary 9410 +tropics 9410 +theorizers 9410 +renew 9410 +already 9410 +terminal 9410 +Hegelian 9410 +hypothesizer 9410 +warningly 9410 +journalizing 9410 +nested 9410 +Lars 9410 +saplings 9410 +foothill 9410 +labeled 9410 +imperiously 9410 +reporters 9410 +furnishings 9410 +precipitable 9410 +discounts 9410 +excises 9410 +Stalin 9410 +despot 9410 +ripeness 9410 +Arabia 9410 +unruly 9410 +mournfulness 9410 +boom 9410 +slaughter 9410 +Sabine 9410 +handy 9410 +rural 9410 +organizer 9410 +shipyard 9410 +civics 9410 +inaccuracy 9410 +rules 9410 +juveniles 9410 +comprised 9410 +investigations 9410 +stabilizes 9410 +seminaries 9410 +Hunter 9410 +sporty 9410 +test 9410 +weasels 9410 +CERN 9410 +tempering 9410 +afore 9410 +Galatean 9410 +techniques 9410 +error 9410 +veranda 9410 +severely 9410 +Cassites 9410 +forthcoming 9410 +guides 9410 +vanish 9410 +lied 9410 +sawtooth 9410 +fated 9410 +gradually 9410 +widens 9410 +preclude 9410 +evenhandedly 9410 +percentage 9410 +disobedience 9410 +humility 9410 +gleaning 9410 +petted 9410 +bloater 9410 +minion 9410 +marginal 9410 +apiary 9410 +measures 9410 +precaution 9410 +repelled 9410 +primary 9410 +coverings 9410 +Artemia 9410 +navigate 9410 +spatial 9410 +Gurkha 9410 +meanwhile 9410 +Melinda 9410 +Butterfield 9410 +Aldrich 9410 +previewing 9410 +glut 9410 +unaffected 9410 +inmate 9410 +mineral 9410 +impending 9410 +meditation 9410 +ideas 9410 +miniaturizes 9410 +lewdly 9410 +title 9410 +youthfulness 9410 +creak 9410 +Chippewa 9410 +clamored 9410 +freezes 9410 +forgivably 9410 +reduce 9410 +McGovern 9410 +Nazis 9410 +epistle 9410 +socializes 9410 +conceptions 9410 +Kevin 9410 +uncovering 9410 +chews 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +raining 9410 +infest 9410 +compartment 9410 +minting 9410 +ducks 9410 +roped 9410 +waltz 9410 +Lillian 9410 +repressions 9410 +chillingly 9410 +noncritical 9410 +lithograph 9410 +spongers 9410 +parenthood 9410 +posed 9410 +instruments 9410 +filial 9410 +fixedly 9410 +relives 9410 +Pandora 9410 +watering 9410 +ungrateful 9410 +secures 9410 +poison 9410 +dusted 9410 +encompasses 9410 +presentation 9410 +Kantian 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) +) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; +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 +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 * 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 +250502 250501 +250503 250501 +250504 250501 +250505 250501 +250501 250502 +250502 250502 +250503 250502 +250504 250502 +250505 250502 +250501 250503 +250502 250503 +250503 250503 +250504 250503 +250505 250503 +250501 250504 +250502 250504 +250503 250504 +250504 250504 +250505 250504 +250501 250505 +250502 250505 +250503 250505 +250504 250505 +250505 250505 +insert into t2 (fld1, companynr) values (999999,99); +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1200 NULL +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using where; Not exists +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1200 Using where; Not exists; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 NULL +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 NULL +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 NULL +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t4 index NULL PRIMARY 1 NULL 12 Using index; Using temporary +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 +29 95 14473298 +34 70 17788966 +36 215 22786296 +37 588 83602098 +40 37 6618386 +41 52 12816335 +50 11 1595438 +53 4 793210 +58 23 2254293 +65 10 2284055 +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 extended 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 type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 100.00 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 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 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 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) +0 +9 +4 +6 +7 +1 +3 +8 +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 +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,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 +0 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 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 +epistle 018062 1 28357832 28357832 28357832 28357832.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 +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 cupboard 786542 +512 decliner 786542 +512 descendants 786542 +512 dopers 786542 +512 erases 786542 +512 Micronesia 786542 +512 Miles 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 +36 1 dubbed dubbed 28357832 28357832.0000 +37 83 Abraham Wotan 1908978016 22999735.1325 +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 type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +explain select fld3 from t2 where fld1=fld1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 NULL +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 +29 95 14473298 +34 70 17788966 +37 588 83602098 +41 52 12816335 +select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ; +companynr +00 +29 +34 +37 +41 +select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40; +companynr companyname count(*) +68 company 10 12 +50 company 11 11 +40 company 5 37 +41 company 6 52 +53 company 7 4 +58 company 8 23 +65 company 9 10 +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 type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +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(11) NULL NO PRI NULL auto_increment # +fld1 int(6) unsigned zerofill NULL NO UNI 000000 # +companynr tinyint(2) unsigned zerofill NULL NO 00 # +fld3 char(30) latin1_swedish_ci NO MUL # +fld4 char(35) latin1_swedish_ci NO # +fld5 char(35) latin1_swedish_ci NO # +fld6 char(4) latin1_swedish_ci NO # +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 # +fld3 char(30) latin1_swedish_ci NO MUL # +fld4 char(35) latin1_swedish_ci NO # +fld5 char(35) latin1_swedish_ci NO # +fld6 char(4) latin1_swedish_ci NO # +show full columns from t2 from test like 's%'; +Field Type Collation Null Key Default Extra Privileges Comment +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 +t2 0 PRIMARY 1 auto A 1199 NULL NULL BTREE +t2 0 fld1 1 fld1 A 1199 NULL NULL BTREE +t2 1 fld3 1 fld3 A NULL NULL NULL BTREE +drop table t4, t3, t2, t1; +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) +) ENGINE=MyISAM; +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; +set GLOBAL debug="+d,rds_local_pool_of_threads"; +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 +# -- Success: more than --extra-max-connections + 1 normal connections not possible +sleep(50000) +1 +sleep(50000) +1 +select count(*) from information_schema.THREAD_GROUP_STATUS; +count(*) +2 +set GLOBAL debug="-d,rds_local_pool_of_threads"; diff --git a/mysql-test/r/pool_of_threads_high_prio_tickets.result b/mysql-test/r/pool_of_threads_high_prio_tickets.result new file mode 100644 index 00000000000..f34bf8274b3 --- /dev/null +++ b/mysql-test/r/pool_of_threads_high_prio_tickets.result @@ -0,0 +1,2169 @@ +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 +); +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) +); +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld3 fld3 30 NULL 2 Using where; Using index +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld1 fld1 4 NULL 2 Using where; Using index +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld1 fld1 4 NULL 4 Using where; Using index +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) +); +create temporary table tmp engine = myisam 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; +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 fld3,count(*) from t2 group by companynr,fld3 limit 10; +fld3 count(*) +affixed 1 +and 1 +annoyers 1 +Anthony 1 +assayed 1 +assurers 1 +attendants 1 +bedlam 1 +bedpost 1 +boasted 1 +SET BIG_TABLES=1; +select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10; +fld3 count(*) +affixed 1 +and 1 +annoyers 1 +Anthony 1 +assayed 1 +assurers 1 +attendants 1 +bedlam 1 +bedpost 1 +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(*) +circus aaaaaa 1 +cited aaaaa 1 +Colombo aaaaaaa 1 +congresswoman aaaaaaaaaaaaa 1 +contrition aaaaaaaaaa 1 +corny aaaaa 1 +cultivation aaaaaaaaaaa 1 +definiteness aaaaaaaaaaaa 1 +demultiplex aaaaaaaaaaa 1 +disappointing aaaaaaaaaaaaa 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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index +explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort +1 SIMPLE t3 ref period period 4 test.t1.period 4181 NULL +explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t3 index period period 4 NULL 1 NULL +1 SIMPLE t1 ref period period 4 test.t3.period 4181 NULL +explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index period period 4 NULL 1 NULL +1 SIMPLE t3 ref period period 4 test.t1.period 4181 NULL +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 const fld1 fld1 4 const 1 NULL +1 SIMPLE t3 const PRIMARY,period PRIMARY 4 const 1 NULL +select fld3,period from t2,t1 where companynr*10 = 37*10; +fld3 period +breaking 9410 +Romans 9410 +intercepted 9410 +bewilderingly 9410 +astound 9410 +admonishing 9410 +sumac 9410 +flanking 9410 +combed 9410 +subjective 9410 +scatterbrain 9410 +Eulerian 9410 +Kane 9410 +overlay 9410 +perturb 9410 +goblins 9410 +annihilates 9410 +Wotan 9410 +snatching 9410 +concludes 9410 +laterally 9410 +yelped 9410 +grazing 9410 +Baird 9410 +celery 9410 +misunderstander 9410 +handgun 9410 +foldout 9410 +mystic 9410 +succumbed 9410 +Nabisco 9410 +fingerings 9410 +aging 9410 +afield 9410 +ammonium 9410 +boat 9410 +intelligibility 9410 +Augustine 9410 +teethe 9410 +dreaded 9410 +scholastics 9410 +audiology 9410 +wallet 9410 +parters 9410 +eschew 9410 +quitter 9410 +neat 9410 +Steinberg 9410 +jarring 9410 +tinily 9410 +balled 9410 +persist 9410 +attainments 9410 +fanatic 9410 +measures 9410 +rightfulness 9410 +capably 9410 +impulsive 9410 +starlet 9410 +terminators 9410 +untying 9410 +announces 9410 +featherweight 9410 +pessimist 9410 +daughter 9410 +decliner 9410 +lawgiver 9410 +stated 9410 +readable 9410 +attrition 9410 +cascade 9410 +motors 9410 +interrogate 9410 +pests 9410 +stairway 9410 +dopers 9410 +testicle 9410 +Parsifal 9410 +leavings 9410 +postulation 9410 +squeaking 9410 +contrasted 9410 +leftover 9410 +whiteners 9410 +erases 9410 +Punjab 9410 +Merritt 9410 +Quixotism 9410 +sweetish 9410 +dogging 9410 +scornfully 9410 +bellow 9410 +bills 9410 +cupboard 9410 +sureties 9410 +puddings 9410 +fetters 9410 +bivalves 9410 +incurring 9410 +Adolph 9410 +pithed 9410 +Miles 9410 +trimmings 9410 +tragedies 9410 +skulking 9410 +flint 9410 +flopping 9410 +relaxing 9410 +offload 9410 +suites 9410 +lists 9410 +animized 9410 +multilayer 9410 +standardizes 9410 +Judas 9410 +vacuuming 9410 +dentally 9410 +humanness 9410 +inch 9410 +Weissmuller 9410 +irresponsibly 9410 +luckily 9410 +culled 9410 +medical 9410 +bloodbath 9410 +subschema 9410 +animals 9410 +Micronesia 9410 +repetitions 9410 +Antares 9410 +ventilate 9410 +pityingly 9410 +interdependent 9410 +Graves 9410 +neonatal 9410 +chafe 9410 +honoring 9410 +realtor 9410 +elite 9410 +funereal 9410 +abrogating 9410 +sorters 9410 +Conley 9410 +lectured 9410 +Abraham 9410 +Hawaii 9410 +cage 9410 +hushes 9410 +Simla 9410 +reporters 9410 +Dutchman 9410 +descendants 9410 +groupings 9410 +dissociate 9410 +coexist 9410 +Beebe 9410 +Taoism 9410 +Connally 9410 +fetched 9410 +checkpoints 9410 +rusting 9410 +galling 9410 +obliterates 9410 +traitor 9410 +resumes 9410 +analyzable 9410 +terminator 9410 +gritty 9410 +firearm 9410 +minima 9410 +Selfridge 9410 +disable 9410 +witchcraft 9410 +betroth 9410 +Manhattanize 9410 +imprint 9410 +peeked 9410 +swelling 9410 +interrelationships 9410 +riser 9410 +Gandhian 9410 +peacock 9410 +bee 9410 +kanji 9410 +dental 9410 +scarf 9410 +chasm 9410 +insolence 9410 +syndicate 9410 +alike 9410 +imperial 9410 +convulsion 9410 +railway 9410 +validate 9410 +normalizes 9410 +comprehensive 9410 +chewing 9410 +denizen 9410 +schemer 9410 +chronicle 9410 +Kline 9410 +Anatole 9410 +partridges 9410 +brunch 9410 +recruited 9410 +dimensions 9410 +Chicana 9410 +announced 9410 +praised 9410 +employing 9410 +linear 9410 +quagmire 9410 +western 9410 +relishing 9410 +serving 9410 +scheduling 9410 +lore 9410 +eventful 9410 +arteriole 9410 +disentangle 9410 +cured 9410 +Fenton 9410 +avoidable 9410 +drains 9410 +detectably 9410 +husky 9410 +impelling 9410 +undoes 9410 +evened 9410 +squeezes 9410 +destroyer 9410 +rudeness 9410 +beaner 9410 +boorish 9410 +Everhart 9410 +encompass 9410 +mushrooms 9410 +Alison 9410 +externally 9410 +pellagra 9410 +cult 9410 +creek 9410 +Huffman 9410 +Majorca 9410 +governing 9410 +gadfly 9410 +reassigned 9410 +intentness 9410 +craziness 9410 +psychic 9410 +squabbled 9410 +burlesque 9410 +capped 9410 +extracted 9410 +DiMaggio 9410 +exclamation 9410 +subdirectory 9410 +Gothicism 9410 +feminine 9410 +metaphysically 9410 +sanding 9410 +Miltonism 9410 +freakish 9410 +index 9410 +straight 9410 +flurried 9410 +denotative 9410 +coming 9410 +commencements 9410 +gentleman 9410 +gifted 9410 +Shanghais 9410 +sportswriting 9410 +sloping 9410 +navies 9410 +leaflet 9410 +shooter 9410 +Joplin 9410 +babies 9410 +assails 9410 +admiring 9410 +swaying 9410 +Goldstine 9410 +fitting 9410 +Norwalk 9410 +analogy 9410 +deludes 9410 +cokes 9410 +Clayton 9410 +exhausts 9410 +causality 9410 +sating 9410 +icon 9410 +throttles 9410 +communicants 9410 +dehydrate 9410 +priceless 9410 +publicly 9410 +incidentals 9410 +commonplace 9410 +mumbles 9410 +furthermore 9410 +cautioned 9410 +parametrized 9410 +registration 9410 +sadly 9410 +positioning 9410 +babysitting 9410 +eternal 9410 +hoarder 9410 +congregates 9410 +rains 9410 +workers 9410 +sags 9410 +unplug 9410 +garage 9410 +boulder 9410 +specifics 9410 +Teresa 9410 +Winsett 9410 +convenient 9410 +buckboards 9410 +amenities 9410 +resplendent 9410 +sews 9410 +participated 9410 +Simon 9410 +certificates 9410 +Fitzpatrick 9410 +Evanston 9410 +misted 9410 +textures 9410 +save 9410 +count 9410 +rightful 9410 +chaperone 9410 +Lizzy 9410 +clenched 9410 +effortlessly 9410 +accessed 9410 +beaters 9410 +Hornblower 9410 +vests 9410 +indulgences 9410 +infallibly 9410 +unwilling 9410 +excrete 9410 +spools 9410 +crunches 9410 +overestimating 9410 +ineffective 9410 +humiliation 9410 +sophomore 9410 +star 9410 +rifles 9410 +dialysis 9410 +arriving 9410 +indulge 9410 +clockers 9410 +languages 9410 +Antarctica 9410 +percentage 9410 +ceiling 9410 +specification 9410 +regimented 9410 +ciphers 9410 +pictures 9410 +serpents 9410 +allot 9410 +realized 9410 +mayoral 9410 +opaquely 9410 +hostess 9410 +fiftieth 9410 +incorrectly 9410 +decomposition 9410 +stranglings 9410 +mixture 9410 +electroencephalography 9410 +similarities 9410 +charges 9410 +freest 9410 +Greenberg 9410 +tinting 9410 +expelled 9410 +warm 9410 +smoothed 9410 +deductions 9410 +Romano 9410 +bitterroot 9410 +corset 9410 +securing 9410 +environing 9410 +cute 9410 +Crays 9410 +heiress 9410 +inform 9410 +avenge 9410 +universals 9410 +Kinsey 9410 +ravines 9410 +bestseller 9410 +equilibrium 9410 +extents 9410 +relatively 9410 +pressure 9410 +critiques 9410 +befouled 9410 +rightfully 9410 +mechanizing 9410 +Latinizes 9410 +timesharing 9410 +Aden 9410 +embassies 9410 +males 9410 +shapelessly 9410 +mastering 9410 +Newtonian 9410 +finishers 9410 +abates 9410 +teem 9410 +kiting 9410 +stodgy 9410 +feed 9410 +guitars 9410 +airships 9410 +store 9410 +denounces 9410 +Pyle 9410 +Saxony 9410 +serializations 9410 +Peruvian 9410 +taxonomically 9410 +kingdom 9410 +stint 9410 +Sault 9410 +faithful 9410 +Ganymede 9410 +tidiness 9410 +gainful 9410 +contrary 9410 +Tipperary 9410 +tropics 9410 +theorizers 9410 +renew 9410 +already 9410 +terminal 9410 +Hegelian 9410 +hypothesizer 9410 +warningly 9410 +journalizing 9410 +nested 9410 +Lars 9410 +saplings 9410 +foothill 9410 +labeled 9410 +imperiously 9410 +reporters 9410 +furnishings 9410 +precipitable 9410 +discounts 9410 +excises 9410 +Stalin 9410 +despot 9410 +ripeness 9410 +Arabia 9410 +unruly 9410 +mournfulness 9410 +boom 9410 +slaughter 9410 +Sabine 9410 +handy 9410 +rural 9410 +organizer 9410 +shipyard 9410 +civics 9410 +inaccuracy 9410 +rules 9410 +juveniles 9410 +comprised 9410 +investigations 9410 +stabilizes 9410 +seminaries 9410 +Hunter 9410 +sporty 9410 +test 9410 +weasels 9410 +CERN 9410 +tempering 9410 +afore 9410 +Galatean 9410 +techniques 9410 +error 9410 +veranda 9410 +severely 9410 +Cassites 9410 +forthcoming 9410 +guides 9410 +vanish 9410 +lied 9410 +sawtooth 9410 +fated 9410 +gradually 9410 +widens 9410 +preclude 9410 +evenhandedly 9410 +percentage 9410 +disobedience 9410 +humility 9410 +gleaning 9410 +petted 9410 +bloater 9410 +minion 9410 +marginal 9410 +apiary 9410 +measures 9410 +precaution 9410 +repelled 9410 +primary 9410 +coverings 9410 +Artemia 9410 +navigate 9410 +spatial 9410 +Gurkha 9410 +meanwhile 9410 +Melinda 9410 +Butterfield 9410 +Aldrich 9410 +previewing 9410 +glut 9410 +unaffected 9410 +inmate 9410 +mineral 9410 +impending 9410 +meditation 9410 +ideas 9410 +miniaturizes 9410 +lewdly 9410 +title 9410 +youthfulness 9410 +creak 9410 +Chippewa 9410 +clamored 9410 +freezes 9410 +forgivably 9410 +reduce 9410 +McGovern 9410 +Nazis 9410 +epistle 9410 +socializes 9410 +conceptions 9410 +Kevin 9410 +uncovering 9410 +chews 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +raining 9410 +infest 9410 +compartment 9410 +minting 9410 +ducks 9410 +roped 9410 +waltz 9410 +Lillian 9410 +repressions 9410 +chillingly 9410 +noncritical 9410 +lithograph 9410 +spongers 9410 +parenthood 9410 +posed 9410 +instruments 9410 +filial 9410 +fixedly 9410 +relives 9410 +Pandora 9410 +watering 9410 +ungrateful 9410 +secures 9410 +poison 9410 +dusted 9410 +encompasses 9410 +presentation 9410 +Kantian 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) +) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; +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 +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 * 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 +250502 250501 +250503 250501 +250504 250501 +250505 250501 +250501 250502 +250502 250502 +250503 250502 +250504 250502 +250505 250502 +250501 250503 +250502 250503 +250503 250503 +250504 250503 +250505 250503 +250501 250504 +250502 250504 +250503 250504 +250504 250504 +250505 250504 +250501 250505 +250502 250505 +250503 250505 +250504 250505 +250505 250505 +insert into t2 (fld1, companynr) values (999999,99); +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1200 NULL +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using where; Not exists +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1200 Using where; Not exists; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 NULL +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 NULL +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 NULL +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 NULL +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 type possible_keys key key_len ref rows Extra +1 SIMPLE t4 index NULL PRIMARY 1 NULL 12 Using index; Using temporary +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where; Using join buffer (Block Nested Loop) +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 +29 95 14473298 +34 70 17788966 +36 215 22786296 +37 588 83602098 +40 37 6618386 +41 52 12816335 +50 11 1595438 +53 4 793210 +58 23 2254293 +65 10 2284055 +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 extended 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 type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 100.00 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 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 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 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) +0 +9 +4 +6 +7 +1 +3 +8 +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 +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,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 +0 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 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 +epistle 018062 1 28357832 28357832 28357832 28357832.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 +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 cupboard 786542 +512 decliner 786542 +512 descendants 786542 +512 dopers 786542 +512 erases 786542 +512 Micronesia 786542 +512 Miles 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 +36 1 dubbed dubbed 28357832 28357832.0000 +37 83 Abraham Wotan 1908978016 22999735.1325 +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 type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +explain select fld3 from t2 where fld1=fld1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 NULL +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 +29 95 14473298 +34 70 17788966 +37 588 83602098 +41 52 12816335 +select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ; +companynr +00 +29 +34 +37 +41 +select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40; +companynr companyname count(*) +68 company 10 12 +50 company 11 11 +40 company 5 37 +41 company 6 52 +53 company 7 4 +58 company 8 23 +65 company 9 10 +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 type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +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(11) NULL NO PRI NULL auto_increment # +fld1 int(6) unsigned zerofill NULL NO UNI 000000 # +companynr tinyint(2) unsigned zerofill NULL NO 00 # +fld3 char(30) latin1_swedish_ci NO MUL # +fld4 char(35) latin1_swedish_ci NO # +fld5 char(35) latin1_swedish_ci NO # +fld6 char(4) latin1_swedish_ci NO # +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 # +fld3 char(30) latin1_swedish_ci NO MUL # +fld4 char(35) latin1_swedish_ci NO # +fld5 char(35) latin1_swedish_ci NO # +fld6 char(4) latin1_swedish_ci NO # +show full columns from t2 from test like 's%'; +Field Type Collation Null Key Default Extra Privileges Comment +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 +t2 0 PRIMARY 1 auto A 1199 NULL NULL BTREE +t2 0 fld1 1 fld1 A 1199 NULL NULL BTREE +t2 1 fld3 1 fld3 A NULL NULL NULL BTREE +drop table t4, t3, t2, t1; +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) +) ENGINE=MyISAM; +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/funcs_1/r/is_columns_is.result b/mysql-test/suite/funcs_1/r/is_columns_is.result index 89a90b48490..30edb2eecc7 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is.result @@ -322,6 +322,14 @@ def information_schema TABLE_STATISTICS ROWS_READ 3 0 NO bigint NULL NULL 19 0 N def information_schema TABLE_STATISTICS ROWS_UPDATED 8 0 NO bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select def information_schema TABLE_STATISTICS TABLE_NAME 2 NO varchar 192 576 NULL NULL NULL utf8 utf8_general_ci varchar(192) select def information_schema TABLE_STATISTICS TABLE_SCHEMA 1 NO varchar 192 576 NULL NULL NULL utf8 utf8_general_ci varchar(192) select +def information_schema THREAD_GROUP_STATUS ACTIVE_THREAD_COUNT 3 0 NO int NULL NULL 10 0 NULL NULL NULL int(21) unsigned select +def information_schema THREAD_GROUP_STATUS CONNECTION_COUNT 4 0 NO int NULL NULL 10 0 NULL NULL NULL int(21) unsigned select +def information_schema THREAD_GROUP_STATUS DUMP_COUNT 6 0 NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select +def information_schema THREAD_GROUP_STATUS HIGH_QUEUE_COUNT 8 0 NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select +def information_schema THREAD_GROUP_STATUS ID 1 0 NO int NULL NULL 10 0 NULL NULL NULL int(21) unsigned select +def information_schema THREAD_GROUP_STATUS LOW_QUEUE_COUNT 7 0 NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select +def information_schema THREAD_GROUP_STATUS THREAD_COUNT 2 0 NO int NULL NULL 10 0 NULL NULL NULL int(21) unsigned select +def information_schema THREAD_GROUP_STATUS WAITING_THREAD_COUNT 5 0 NO int NULL NULL 10 0 NULL NULL NULL int(21) unsigned select def information_schema TokuDB_file_map dictionary_name 1 NO varchar 256 768 NULL NULL NULL utf8 utf8_general_ci varchar(256) select def information_schema TokuDB_file_map internal_file_name 2 NO varchar 256 768 NULL NULL NULL utf8 utf8_general_ci varchar(256) select def information_schema TokuDB_file_map table_dictionary_name 5 NO varchar 256 768 NULL NULL NULL utf8 utf8_general_ci varchar(256) select @@ -778,6 +786,14 @@ NULL information_schema TABLE_STATISTICS ROWS_CHANGED_X_INDEXES bigint NULL NULL NULL information_schema TABLE_STATISTICS ROWS_INSERTED bigint NULL NULL NULL NULL bigint(21) NULL information_schema TABLE_STATISTICS ROWS_DELETED bigint NULL NULL NULL NULL bigint(21) NULL information_schema TABLE_STATISTICS ROWS_UPDATED bigint NULL NULL NULL NULL bigint(21) +NULL information_schema THREAD_GROUP_STATUS ID int NULL NULL NULL NULL int(21) unsigned +NULL information_schema THREAD_GROUP_STATUS THREAD_COUNT int NULL NULL NULL NULL int(21) unsigned +NULL information_schema THREAD_GROUP_STATUS ACTIVE_THREAD_COUNT int NULL NULL NULL NULL int(21) unsigned +NULL information_schema THREAD_GROUP_STATUS CONNECTION_COUNT int NULL NULL NULL NULL int(21) unsigned +NULL information_schema THREAD_GROUP_STATUS WAITING_THREAD_COUNT int NULL NULL NULL NULL int(21) unsigned +NULL information_schema THREAD_GROUP_STATUS DUMP_COUNT bigint NULL NULL NULL NULL bigint(21) unsigned +NULL information_schema THREAD_GROUP_STATUS LOW_QUEUE_COUNT bigint NULL NULL NULL NULL bigint(21) unsigned +NULL information_schema THREAD_GROUP_STATUS HIGH_QUEUE_COUNT bigint NULL NULL NULL NULL bigint(21) unsigned 3.0000 information_schema TokuDB_file_map dictionary_name varchar 256 768 utf8 utf8_general_ci varchar(256) 3.0000 information_schema TokuDB_file_map internal_file_name varchar 256 768 utf8 utf8_general_ci varchar(256) 3.0000 information_schema TokuDB_file_map table_schema varchar 256 768 utf8 utf8_general_ci varchar(256) diff --git a/mysql-test/suite/funcs_1/r/is_tables_is.result b/mysql-test/suite/funcs_1/r/is_tables_is.result index 0ef695ee08e..cb1e34d618b 100644 --- a/mysql-test/suite/funcs_1/r/is_tables_is.result +++ b/mysql-test/suite/funcs_1/r/is_tables_is.result @@ -705,6 +705,29 @@ user_comment Separator ----------------------------------------------------- TABLE_CATALOG def TABLE_SCHEMA information_schema +TABLE_NAME THREAD_GROUP_STATUS +TABLE_TYPE SYSTEM VIEW +ENGINE MEMORY +VERSION 10 +ROW_FORMAT Fixed +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8_general_ci +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +user_comment +Separator ----------------------------------------------------- +TABLE_CATALOG def +TABLE_SCHEMA information_schema TABLE_NAME TokuDB_file_map TABLE_TYPE SYSTEM VIEW ENGINE MEMORY @@ -1619,6 +1642,29 @@ user_comment Separator ----------------------------------------------------- TABLE_CATALOG def TABLE_SCHEMA information_schema +TABLE_NAME THREAD_GROUP_STATUS +TABLE_TYPE SYSTEM VIEW +ENGINE MEMORY +VERSION 10 +ROW_FORMAT Fixed +TABLE_ROWS #TBLR# +AVG_ROW_LENGTH #ARL# +DATA_LENGTH #DL# +MAX_DATA_LENGTH #MDL# +INDEX_LENGTH #IL# +DATA_FREE #DF# +AUTO_INCREMENT NULL +CREATE_TIME #CRT# +UPDATE_TIME #UT# +CHECK_TIME #CT# +TABLE_COLLATION utf8_general_ci +CHECKSUM NULL +CREATE_OPTIONS #CO# +TABLE_COMMENT #TC# +user_comment +Separator ----------------------------------------------------- +TABLE_CATALOG def +TABLE_SCHEMA information_schema TABLE_NAME TokuDB_file_map TABLE_TYPE SYSTEM VIEW ENGINE MEMORY diff --git a/mysql-test/suite/sys_vars/r/all_vars.result b/mysql-test/suite/sys_vars/r/all_vars.result index 71b709382f0..5b25be9525d 100644 --- a/mysql-test/suite/sys_vars/r/all_vars.result +++ b/mysql-test/suite/sys_vars/r/all_vars.result @@ -14,6 +14,10 @@ left join t1 on variable_name=test_name where test_name is null ORDER BY variabl There should be *no* variables listed below: ANONYMOUS_IN_GTID_OUT_ENABLE ANONYMOUS_IN_GTID_OUT_ENABLE +EXTRA_MAX_CONNECTIONS +EXTRA_MAX_CONNECTIONS +EXTRA_PORT +EXTRA_PORT INNODB_AUTOINC_PERSISTENT INNODB_AUTOINC_PERSISTENT INNODB_AUTOINC_PERSISTENT_INTERVAL @@ -66,8 +70,11 @@ RPL_SEMI_SYNC_SLAVE_DELAY_MASTER RPL_SEMI_SYNC_SLAVE_DELAY_MASTER RPL_SEMI_SYNC_SLAVE_KILL_CONN_TIMEOUT RPL_SEMI_SYNC_SLAVE_KILL_CONN_TIMEOUT +SEQUENCE_READ_SKIP_CACHE SLAVE_PR_MODE SLAVE_PR_MODE +THREADPOOL_WORKAROUND_EPOLL_BUG +THREADPOOL_WORKAROUND_EPOLL_BUG TOKUDB_ALTER_PRINT_ERROR TOKUDB_ALTER_PRINT_ERROR TOKUDB_ANALYZE_DELETE_FRACTION diff --git a/mysql-test/suite/sys_vars/r/thread_pool_high_prio_mode_basic.result b/mysql-test/suite/sys_vars/r/thread_pool_high_prio_mode_basic.result new file mode 100644 index 00000000000..03979587a1f --- /dev/null +++ b/mysql-test/suite/sys_vars/r/thread_pool_high_prio_mode_basic.result @@ -0,0 +1,37 @@ +SET @start_global_value = @@GLOBAL.thread_pool_high_prio_mode; +SET @@GLOBAL.thread_pool_high_prio_mode=DEFAULT; +SELECT @@GLOBAL.thread_pool_high_prio_mode; +@@GLOBAL.thread_pool_high_prio_mode +transactions +SET @@SESSION.thread_pool_high_prio_mode=DEFAULT; +SELECT @@SESSION.thread_pool_high_prio_mode; +@@SESSION.thread_pool_high_prio_mode +transactions +SHOW GLOBAL VARIABLES LIKE 'thread_pool_high_prio_mode'; +Variable_name Value +thread_pool_high_prio_mode transactions +SHOW SESSION VARIABLES LIKE 'thread_pool_high_prio_mode'; +Variable_name Value +thread_pool_high_prio_mode transactions +SET @@thread_pool_high_prio_mode='transactions'; +SELECT @@thread_pool_high_prio_mode; +@@thread_pool_high_prio_mode +transactions +SET @@thread_pool_high_prio_mode='statements'; +SELECT @@thread_pool_high_prio_mode; +@@thread_pool_high_prio_mode +statements +SET @@thread_pool_high_prio_mode='none'; +SELECT @@thread_pool_high_prio_mode; +@@thread_pool_high_prio_mode +none +SET @@thread_pool_high_prio_mode='foo'; +ERROR 42000: Variable 'thread_pool_high_prio_mode' can't be set to the value of 'foo' +SET @@thread_pool_high_prio_mode=1.1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_high_prio_mode' +SET @@thread_pool_high_prio_mode=1e1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_high_prio_mode' +SET @@GLOBAL.thread_pool_high_prio_mode = @start_global_value; +select count(*) from information_schema.THREAD_GROUP_STATUS; +count(*) +0 diff --git a/mysql-test/suite/sys_vars/r/thread_pool_high_prio_tickets_basic.result b/mysql-test/suite/sys_vars/r/thread_pool_high_prio_tickets_basic.result new file mode 100644 index 00000000000..4c14c5a5040 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/thread_pool_high_prio_tickets_basic.result @@ -0,0 +1,52 @@ +SET @start_global_value = @@global.thread_pool_high_prio_tickets; +set @@global.thread_pool_high_prio_tickets=default; +select @@global.thread_pool_high_prio_tickets; +@@global.thread_pool_high_prio_tickets +4294967295 +set @@session.thread_pool_high_prio_tickets=default; +select @@session.thread_pool_high_prio_tickets; +@@session.thread_pool_high_prio_tickets +4294967295 +show global variables like 'thread_pool_high_prio_tickets'; +Variable_name Value +thread_pool_high_prio_tickets 4294967295 +show session variables like 'thread_pool_high_prio_tickets'; +Variable_name Value +thread_pool_high_prio_tickets 4294967295 +select * from information_schema.global_variables where variable_name='thread_pool_high_prio_tickets'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_HIGH_PRIO_TICKETS 4294967295 +select * from information_schema.session_variables where variable_name='thread_pool_high_prio_tickets'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_HIGH_PRIO_TICKETS 4294967295 +set global thread_pool_high_prio_tickets=60; +select @@global.thread_pool_high_prio_tickets; +@@global.thread_pool_high_prio_tickets +60 +set global thread_pool_high_prio_tickets=4294967295; +select @@global.thread_pool_high_prio_tickets; +@@global.thread_pool_high_prio_tickets +4294967295 +set session thread_pool_high_prio_tickets=1; +select @@session.thread_pool_high_prio_tickets; +@@session.thread_pool_high_prio_tickets +1 +set global thread_pool_high_prio_tickets=1.1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_high_prio_tickets' +set global thread_pool_high_prio_tickets=1e1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_high_prio_tickets' +set global thread_pool_high_prio_tickets="foo"; +ERROR 42000: Incorrect argument type to variable 'thread_pool_high_prio_tickets' +set global thread_pool_high_prio_tickets=-1; +Warnings: +Warning 1292 Truncated incorrect thread_pool_high_prio_tickets value: '-1' +select @@global.thread_pool_high_prio_tickets; +@@global.thread_pool_high_prio_tickets +0 +set global thread_pool_high_prio_tickets=10000000000; +Warnings: +Warning 1292 Truncated incorrect thread_pool_high_prio_tickets value: '10000000000' +select @@global.thread_pool_high_prio_tickets; +@@global.thread_pool_high_prio_tickets +4294967295 +set @@global.thread_pool_high_prio_tickets = @start_global_value; diff --git a/mysql-test/suite/sys_vars/r/thread_pool_idle_timeout_basic.result b/mysql-test/suite/sys_vars/r/thread_pool_idle_timeout_basic.result new file mode 100644 index 00000000000..8dedbd0f2d2 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/thread_pool_idle_timeout_basic.result @@ -0,0 +1,47 @@ +SET @start_global_value = @@global.thread_pool_idle_timeout; +select @@global.thread_pool_idle_timeout; +@@global.thread_pool_idle_timeout +60 +select @@session.thread_pool_idle_timeout; +ERROR HY000: Variable 'thread_pool_idle_timeout' is a GLOBAL variable +show global variables like 'thread_pool_idle_timeout'; +Variable_name Value +thread_pool_idle_timeout 60 +show session variables like 'thread_pool_idle_timeout'; +Variable_name Value +thread_pool_idle_timeout 60 +select * from information_schema.global_variables where variable_name='thread_pool_idle_timeout'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_IDLE_TIMEOUT 60 +select * from information_schema.session_variables where variable_name='thread_pool_idle_timeout'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_IDLE_TIMEOUT 60 +set global thread_pool_idle_timeout=60; +select @@global.thread_pool_idle_timeout; +@@global.thread_pool_idle_timeout +60 +set global thread_pool_idle_timeout=4294967295; +select @@global.thread_pool_idle_timeout; +@@global.thread_pool_idle_timeout +4294967295 +set session thread_pool_idle_timeout=1; +ERROR HY000: Variable 'thread_pool_idle_timeout' is a GLOBAL variable and should be set with SET GLOBAL +set global thread_pool_idle_timeout=1.1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_idle_timeout' +set global thread_pool_idle_timeout=1e1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_idle_timeout' +set global thread_pool_idle_timeout="foo"; +ERROR 42000: Incorrect argument type to variable 'thread_pool_idle_timeout' +set global thread_pool_idle_timeout=-1; +Warnings: +Warning 1292 Truncated incorrect thread_pool_idle_timeout value: '-1' +select @@global.thread_pool_idle_timeout; +@@global.thread_pool_idle_timeout +1 +set global thread_pool_idle_timeout=10000000000; +Warnings: +Warning 1292 Truncated incorrect thread_pool_idle_timeout value: '10000000000' +select @@global.thread_pool_idle_timeout; +@@global.thread_pool_idle_timeout +4294967295 +SET @@global.thread_pool_idle_timeout = @start_global_value; diff --git a/mysql-test/suite/sys_vars/r/thread_pool_max_threads_basic.result b/mysql-test/suite/sys_vars/r/thread_pool_max_threads_basic.result new file mode 100644 index 00000000000..7fdceea50aa --- /dev/null +++ b/mysql-test/suite/sys_vars/r/thread_pool_max_threads_basic.result @@ -0,0 +1,53 @@ +SET @start_global_value = @@global.thread_pool_max_threads; +select @@global.thread_pool_max_threads; +@@global.thread_pool_max_threads +100000 +select @@session.thread_pool_max_threads; +ERROR HY000: Variable 'thread_pool_max_threads' is a GLOBAL variable +show global variables like 'thread_pool_max_threads'; +Variable_name Value +thread_pool_max_threads 100000 +show session variables like 'thread_pool_max_threads'; +Variable_name Value +thread_pool_max_threads 100000 +select * from information_schema.global_variables where variable_name='thread_pool_max_threads'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_MAX_THREADS 100000 +select * from information_schema.session_variables where variable_name='thread_pool_max_threads'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_MAX_THREADS 100000 +set global thread_pool_max_threads=1; +select @@global.thread_pool_max_threads; +@@global.thread_pool_max_threads +1 +set global thread_pool_max_threads=65536; +select @@global.thread_pool_max_threads; +@@global.thread_pool_max_threads +65536 +set global thread_pool_max_threads=100001; +Warnings: +Warning 1292 Truncated incorrect thread_pool_max_threads value: '100001' +select @@global.thread_pool_max_threads; +@@global.thread_pool_max_threads +100000 +set session thread_pool_max_threads=1; +ERROR HY000: Variable 'thread_pool_max_threads' is a GLOBAL variable and should be set with SET GLOBAL +set global thread_pool_max_threads=1.1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_max_threads' +set global thread_pool_max_threads=1e1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_max_threads' +set global thread_pool_max_threads="foo"; +ERROR 42000: Incorrect argument type to variable 'thread_pool_max_threads' +set global thread_pool_max_threads=0; +Warnings: +Warning 1292 Truncated incorrect thread_pool_max_threads value: '0' +select @@global.thread_pool_max_threads; +@@global.thread_pool_max_threads +1 +set global thread_pool_max_threads=10000000000; +Warnings: +Warning 1292 Truncated incorrect thread_pool_max_threads value: '10000000000' +select @@global.thread_pool_max_threads; +@@global.thread_pool_max_threads +100000 +SET @@global.thread_pool_max_threads = @start_global_value; diff --git a/mysql-test/suite/sys_vars/r/thread_pool_oversubscribe_basic.result b/mysql-test/suite/sys_vars/r/thread_pool_oversubscribe_basic.result new file mode 100644 index 00000000000..a9f1afa9f62 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/thread_pool_oversubscribe_basic.result @@ -0,0 +1,47 @@ +SET @start_global_value = @@global.thread_pool_oversubscribe; +select @@global.thread_pool_oversubscribe; +@@global.thread_pool_oversubscribe +3 +select @@session.thread_pool_oversubscribe; +ERROR HY000: Variable 'thread_pool_oversubscribe' is a GLOBAL variable +show global variables like 'thread_pool_oversubscribe'; +Variable_name Value +thread_pool_oversubscribe 3 +show session variables like 'thread_pool_oversubscribe'; +Variable_name Value +thread_pool_oversubscribe 3 +select * from information_schema.global_variables where variable_name='thread_pool_oversubscribe'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_OVERSUBSCRIBE 3 +select * from information_schema.session_variables where variable_name='thread_pool_oversubscribe'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_OVERSUBSCRIBE 3 +set global thread_pool_oversubscribe=60; +select @@global.thread_pool_oversubscribe; +@@global.thread_pool_oversubscribe +60 +set global thread_pool_oversubscribe=1000; +select @@global.thread_pool_oversubscribe; +@@global.thread_pool_oversubscribe +1000 +set session thread_pool_oversubscribe=1; +ERROR HY000: Variable 'thread_pool_oversubscribe' is a GLOBAL variable and should be set with SET GLOBAL +set global thread_pool_oversubscribe=1.1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_oversubscribe' +set global thread_pool_oversubscribe=1e1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_oversubscribe' +set global thread_pool_oversubscribe="foo"; +ERROR 42000: Incorrect argument type to variable 'thread_pool_oversubscribe' +set global thread_pool_oversubscribe=-1; +Warnings: +Warning 1292 Truncated incorrect thread_pool_oversubscribe value: '-1' +select @@global.thread_pool_oversubscribe; +@@global.thread_pool_oversubscribe +1 +set global thread_pool_oversubscribe=10000000000; +Warnings: +Warning 1292 Truncated incorrect thread_pool_oversubscribe value: '10000000000' +select @@global.thread_pool_oversubscribe; +@@global.thread_pool_oversubscribe +1000 +set @@global.thread_pool_oversubscribe = @start_global_value; diff --git a/mysql-test/suite/sys_vars/r/thread_pool_size_basic.result b/mysql-test/suite/sys_vars/r/thread_pool_size_basic.result new file mode 100644 index 00000000000..70d46cbe067 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/thread_pool_size_basic.result @@ -0,0 +1,41 @@ +SET @start_global_value = @@global.thread_pool_size; +select @@global.thread_pool_size; +@@global.thread_pool_size +# +select @@session.thread_pool_size; +ERROR HY000: Variable 'thread_pool_size' is a GLOBAL variable +show global variables like 'thread_pool_size'; +Variable_name Value +thread_pool_size # +show session variables like 'thread_pool_size'; +Variable_name Value +thread_pool_size # +select * from information_schema.global_variables where variable_name='thread_pool_size'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_SIZE # +select * from information_schema.session_variables where variable_name='thread_pool_size'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_SIZE # +set global thread_pool_size=1; +select @@global.thread_pool_size; +@@global.thread_pool_size +1 +set global thread_pool_size=128; +select @@global.thread_pool_size; +@@global.thread_pool_size +128 +set session thread_pool_size=1; +ERROR HY000: Variable 'thread_pool_size' is a GLOBAL variable and should be set with SET GLOBAL +set global thread_pool_size=1.1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_size' +set global thread_pool_size=1e1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_size' +set global thread_pool_size="foo"; +ERROR 42000: Incorrect argument type to variable 'thread_pool_size' +set global thread_pool_size=-1; +Warnings: +Warning 1292 Truncated incorrect thread_pool_size value: '-1' +set global thread_pool_size=100000; +Warnings: +Warning 1292 Truncated incorrect thread_pool_size value: '100000' +SET @@global.thread_pool_size = @start_global_value; diff --git a/mysql-test/suite/sys_vars/r/thread_pool_stall_limit_basic.result b/mysql-test/suite/sys_vars/r/thread_pool_stall_limit_basic.result new file mode 100644 index 00000000000..9c806399568 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/thread_pool_stall_limit_basic.result @@ -0,0 +1,47 @@ +SET @start_global_value = @@global.thread_pool_stall_limit; +select @@global.thread_pool_stall_limit; +@@global.thread_pool_stall_limit +10 +select @@session.thread_pool_stall_limit; +ERROR HY000: Variable 'thread_pool_stall_limit' is a GLOBAL variable +show global variables like 'thread_pool_stall_limit'; +Variable_name Value +thread_pool_stall_limit 10 +show session variables like 'thread_pool_stall_limit'; +Variable_name Value +thread_pool_stall_limit 10 +select * from information_schema.global_variables where variable_name='thread_pool_stall_limit'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_STALL_LIMIT 10 +select * from information_schema.session_variables where variable_name='thread_pool_stall_limit'; +VARIABLE_NAME VARIABLE_VALUE +THREAD_POOL_STALL_LIMIT 10 +set global thread_pool_stall_limit=60; +select @@global.thread_pool_stall_limit; +@@global.thread_pool_stall_limit +60 +set global thread_pool_stall_limit=4294967295; +select @@global.thread_pool_stall_limit; +@@global.thread_pool_stall_limit +4294967295 +set session thread_pool_stall_limit=1; +ERROR HY000: Variable 'thread_pool_stall_limit' is a GLOBAL variable and should be set with SET GLOBAL +set global thread_pool_stall_limit=1.1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_stall_limit' +set global thread_pool_stall_limit=1e1; +ERROR 42000: Incorrect argument type to variable 'thread_pool_stall_limit' +set global thread_pool_stall_limit="foo"; +ERROR 42000: Incorrect argument type to variable 'thread_pool_stall_limit' +set global thread_pool_stall_limit=-1; +Warnings: +Warning 1292 Truncated incorrect thread_pool_stall_limit value: '-1' +select @@global.thread_pool_stall_limit; +@@global.thread_pool_stall_limit +1 +set global thread_pool_stall_limit=10000000000; +Warnings: +Warning 1292 Truncated incorrect thread_pool_stall_limit value: '10000000000' +select @@global.thread_pool_stall_limit; +@@global.thread_pool_stall_limit +4294967295 +set @@global.thread_pool_stall_limit = @start_global_value; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_high_prio_mode_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_high_prio_mode_basic.test new file mode 100644 index 00000000000..a85102aed7c --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_high_prio_mode_basic.test @@ -0,0 +1,36 @@ +--source include/not_windows.inc +--source include/not_embedded.inc + +SET @start_global_value = @@GLOBAL.thread_pool_high_prio_mode; + +# Test the default value +SET @@GLOBAL.thread_pool_high_prio_mode=DEFAULT; +SELECT @@GLOBAL.thread_pool_high_prio_mode; + +# Test that the session value is accepted +SET @@SESSION.thread_pool_high_prio_mode=DEFAULT; +SELECT @@SESSION.thread_pool_high_prio_mode; + +SHOW GLOBAL VARIABLES LIKE 'thread_pool_high_prio_mode'; +SHOW SESSION VARIABLES LIKE 'thread_pool_high_prio_mode'; + +SET @@thread_pool_high_prio_mode='transactions'; +SELECT @@thread_pool_high_prio_mode; + +SET @@thread_pool_high_prio_mode='statements'; +SELECT @@thread_pool_high_prio_mode; + +SET @@thread_pool_high_prio_mode='none'; +SELECT @@thread_pool_high_prio_mode; + +--error ER_WRONG_VALUE_FOR_VAR +SET @@thread_pool_high_prio_mode='foo'; + +--error ER_WRONG_TYPE_FOR_VAR +SET @@thread_pool_high_prio_mode=1.1; + +--error ER_WRONG_TYPE_FOR_VAR +SET @@thread_pool_high_prio_mode=1e1; + +SET @@GLOBAL.thread_pool_high_prio_mode = @start_global_value; +select count(*) from information_schema.THREAD_GROUP_STATUS; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_high_prio_tickets_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_high_prio_tickets_basic.test new file mode 100644 index 00000000000..f548da666f9 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_high_prio_tickets_basic.test @@ -0,0 +1,44 @@ +# uint global +--source include/not_windows.inc +--source include/not_embedded.inc +SET @start_global_value = @@global.thread_pool_high_prio_tickets; + +# Test the default value +set @@global.thread_pool_high_prio_tickets=default; +select @@global.thread_pool_high_prio_tickets; + +set @@session.thread_pool_high_prio_tickets=default; +select @@session.thread_pool_high_prio_tickets; + +show global variables like 'thread_pool_high_prio_tickets'; +show session variables like 'thread_pool_high_prio_tickets'; +select * from information_schema.global_variables where variable_name='thread_pool_high_prio_tickets'; +select * from information_schema.session_variables where variable_name='thread_pool_high_prio_tickets'; + +# +# show that it's writable +# +set global thread_pool_high_prio_tickets=60; +select @@global.thread_pool_high_prio_tickets; +set global thread_pool_high_prio_tickets=4294967295; +select @@global.thread_pool_high_prio_tickets; +set session thread_pool_high_prio_tickets=1; +select @@session.thread_pool_high_prio_tickets; + +# +# incorrect types +# +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_high_prio_tickets=1.1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_high_prio_tickets=1e1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_high_prio_tickets="foo"; + + +set global thread_pool_high_prio_tickets=-1; +select @@global.thread_pool_high_prio_tickets; +set global thread_pool_high_prio_tickets=10000000000; +select @@global.thread_pool_high_prio_tickets; + +set @@global.thread_pool_high_prio_tickets = @start_global_value; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_idle_timeout_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_idle_timeout_basic.test new file mode 100644 index 00000000000..4afcc0379f0 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_idle_timeout_basic.test @@ -0,0 +1,43 @@ +# uint global +--source include/not_windows.inc +--source include/not_embedded.inc +SET @start_global_value = @@global.thread_pool_idle_timeout; + +# +# exists as global only +# +select @@global.thread_pool_idle_timeout; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.thread_pool_idle_timeout; +show global variables like 'thread_pool_idle_timeout'; +show session variables like 'thread_pool_idle_timeout'; +select * from information_schema.global_variables where variable_name='thread_pool_idle_timeout'; +select * from information_schema.session_variables where variable_name='thread_pool_idle_timeout'; + +# +# show that it's writable +# +set global thread_pool_idle_timeout=60; +select @@global.thread_pool_idle_timeout; +set global thread_pool_idle_timeout=4294967295; +select @@global.thread_pool_idle_timeout; +--error ER_GLOBAL_VARIABLE +set session thread_pool_idle_timeout=1; + +# +# incorrect types +# +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_idle_timeout=1.1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_idle_timeout=1e1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_idle_timeout="foo"; + + +set global thread_pool_idle_timeout=-1; +select @@global.thread_pool_idle_timeout; +set global thread_pool_idle_timeout=10000000000; +select @@global.thread_pool_idle_timeout; + +SET @@global.thread_pool_idle_timeout = @start_global_value; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_max_threads_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_max_threads_basic.test new file mode 100644 index 00000000000..3333dc75c3b --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_max_threads_basic.test @@ -0,0 +1,44 @@ +# uint global +--source include/not_embedded.inc +SET @start_global_value = @@global.thread_pool_max_threads; + +# +# exists as global only +# +select @@global.thread_pool_max_threads; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.thread_pool_max_threads; +show global variables like 'thread_pool_max_threads'; +show session variables like 'thread_pool_max_threads'; +select * from information_schema.global_variables where variable_name='thread_pool_max_threads'; +select * from information_schema.session_variables where variable_name='thread_pool_max_threads'; + +# +# show that it's writable +# +set global thread_pool_max_threads=1; +select @@global.thread_pool_max_threads; +set global thread_pool_max_threads=65536; +select @@global.thread_pool_max_threads; +set global thread_pool_max_threads=100001; +select @@global.thread_pool_max_threads; +--error ER_GLOBAL_VARIABLE +set session thread_pool_max_threads=1; + +# +# incorrect types +# +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_max_threads=1.1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_max_threads=1e1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_max_threads="foo"; + + +set global thread_pool_max_threads=0; +select @@global.thread_pool_max_threads; +set global thread_pool_max_threads=10000000000; +select @@global.thread_pool_max_threads; + +SET @@global.thread_pool_max_threads = @start_global_value; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_min_threads_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_min_threads_basic.test new file mode 100644 index 00000000000..131fbe98502 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_min_threads_basic.test @@ -0,0 +1,43 @@ +# uint global +--source include/not_embedded.inc +--source include/windows.inc +SET @start_global_value = @@global.thread_pool_min_threads; + +# +# exists as global only +# +select @@global.thread_pool_min_threads; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.thread_pool_min_threads; +show global variables like 'thread_pool_min_threads'; +show session variables like 'thread_pool_min_threads'; +select * from information_schema.global_variables where variable_name='thread_pool_min_threads'; +select * from information_schema.session_variables where variable_name='thread_pool_min_threads'; + +# +# show that it's writable +# +set global thread_pool_min_threads=1; +select @@global.thread_pool_min_threads; +set global thread_pool_min_threads=65536; +select @@global.thread_pool_min_threads; +--error ER_GLOBAL_VARIABLE +set session thread_pool_min_threads=1; + +# +# incorrect types +# +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_min_threads=1.1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_min_threads=1e1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_min_threads="foo"; + + +set global thread_pool_min_threads=0; +select @@global.thread_pool_min_threads; +set global thread_pool_min_threads=10000000000; +select @@global.thread_pool_min_threads; + +SET @@global.thread_pool_min_threads = @start_global_value; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_oversubscribe_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_oversubscribe_basic.test new file mode 100644 index 00000000000..74f0f5e6ea7 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_oversubscribe_basic.test @@ -0,0 +1,43 @@ +# uint global +--source include/not_windows.inc +--source include/not_embedded.inc +SET @start_global_value = @@global.thread_pool_oversubscribe; + +# +# exists as global only +# +select @@global.thread_pool_oversubscribe; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.thread_pool_oversubscribe; +show global variables like 'thread_pool_oversubscribe'; +show session variables like 'thread_pool_oversubscribe'; +select * from information_schema.global_variables where variable_name='thread_pool_oversubscribe'; +select * from information_schema.session_variables where variable_name='thread_pool_oversubscribe'; + +# +# show that it's writable +# +set global thread_pool_oversubscribe=60; +select @@global.thread_pool_oversubscribe; +set global thread_pool_oversubscribe=1000; +select @@global.thread_pool_oversubscribe; +--error ER_GLOBAL_VARIABLE +set session thread_pool_oversubscribe=1; + +# +# incorrect types +# +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_oversubscribe=1.1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_oversubscribe=1e1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_oversubscribe="foo"; + + +set global thread_pool_oversubscribe=-1; +select @@global.thread_pool_oversubscribe; +set global thread_pool_oversubscribe=10000000000; +select @@global.thread_pool_oversubscribe; + +set @@global.thread_pool_oversubscribe = @start_global_value; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_size_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_size_basic.test new file mode 100644 index 00000000000..eeed58956a4 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_size_basic.test @@ -0,0 +1,47 @@ +# uint global +--source include/not_windows.inc +--source include/not_embedded.inc +SET @start_global_value = @@global.thread_pool_size; + +# +# exists as global only +# +--replace_column 1 # +select @@global.thread_pool_size; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.thread_pool_size; +--replace_column 2 # +show global variables like 'thread_pool_size'; +--replace_column 2 # +show session variables like 'thread_pool_size'; +--replace_column 2 # +select * from information_schema.global_variables where variable_name='thread_pool_size'; +--replace_column 2 # +select * from information_schema.session_variables where variable_name='thread_pool_size'; +--replace_column 2 # + +# +# show that it's writable +# +set global thread_pool_size=1; +select @@global.thread_pool_size; +set global thread_pool_size=128; +select @@global.thread_pool_size; +--error ER_GLOBAL_VARIABLE +set session thread_pool_size=1; + +# +# incorrect types +# +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_size=1.1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_size=1e1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_size="foo"; + +set global thread_pool_size=-1; + +set global thread_pool_size=100000; + +SET @@global.thread_pool_size = @start_global_value; diff --git a/mysql-test/suite/sys_vars/t/thread_pool_stall_limit_basic.test b/mysql-test/suite/sys_vars/t/thread_pool_stall_limit_basic.test new file mode 100644 index 00000000000..9b4e1df7ab0 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/thread_pool_stall_limit_basic.test @@ -0,0 +1,43 @@ +# uint global +--source include/not_windows.inc +--source include/not_embedded.inc +SET @start_global_value = @@global.thread_pool_stall_limit; + +# +# exists as global only +# +select @@global.thread_pool_stall_limit; +--error ER_INCORRECT_GLOBAL_LOCAL_VAR +select @@session.thread_pool_stall_limit; +show global variables like 'thread_pool_stall_limit'; +show session variables like 'thread_pool_stall_limit'; +select * from information_schema.global_variables where variable_name='thread_pool_stall_limit'; +select * from information_schema.session_variables where variable_name='thread_pool_stall_limit'; + +# +# show that it's writable +# +set global thread_pool_stall_limit=60; +select @@global.thread_pool_stall_limit; +set global thread_pool_stall_limit=4294967295; +select @@global.thread_pool_stall_limit; +--error ER_GLOBAL_VARIABLE +set session thread_pool_stall_limit=1; + +# +# incorrect types +# +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_stall_limit=1.1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_stall_limit=1e1; +--error ER_WRONG_TYPE_FOR_VAR +set global thread_pool_stall_limit="foo"; + + +set global thread_pool_stall_limit=-1; +select @@global.thread_pool_stall_limit; +set global thread_pool_stall_limit=10000000000; +select @@global.thread_pool_stall_limit; + +set @@global.thread_pool_stall_limit = @start_global_value; diff --git a/mysql-test/t/pool_of_threads.cnf b/mysql-test/t/pool_of_threads.cnf new file mode 100644 index 00000000000..5e80eac9ef6 --- /dev/null +++ b/mysql-test/t/pool_of_threads.cnf @@ -0,0 +1,15 @@ +!include include/default_my.cnf + +[mysqld.1] +loose-thread-handling= pool-of-threads +loose-thread_pool_size= 2 +loose-thread_pool_max_threads= 2 +extra-port= @ENV.MASTER_EXTRA_PORT +extra-max-connections=1 +log_warnings=0 + +[client] +connect-timeout= 2 + +[ENV] +MASTER_EXTRA_PORT= 13009 diff --git a/mysql-test/t/pool_of_threads.test b/mysql-test/t/pool_of_threads.test new file mode 100644 index 00000000000..bc616154f5b --- /dev/null +++ b/mysql-test/t/pool_of_threads.test @@ -0,0 +1,89 @@ +# Start with thread_handling=pool-of-threads +# and run a number of tests + +-- source include/have_debug.inc +-- source include/have_pool_of_threads.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. + +# First set two connections running, and check that extra connection +# on normal port fails due to --thread-pool-max_threads=2 +connection default; +set GLOBAL debug="+d,rds_local_pool_of_threads"; + +connect(con2,localhost,root,,); +connection con2; +let $con2_id = `select connection_id()`; +send SELECT sleep(50000); +--sleep 2.5 + +connect(con3,localhost,root,,); +connection con3; +let $con3_id = `select connection_id()`; +send SELECT sleep(50000); +--sleep 2.5 + +--disable_abort_on_error +--disable_result_log +--disable_query_log +connect(con4,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,$MASTER_EXTRA_PORT,); +connection extracon; +SELECT 'Connection on extra port ok'; + +# Kill long queries in other connections +let @ignore = `select @id := $con3_id`; +KILL QUERY @id; +let @ignore = `select @id := $con2_id`; +KILL QUERY @id; + +connect(extracon2,127.0.0.1,root,,test,$MASTER_EXTRA_PORT,); +connection extracon2; +SELECT 'Connection on extra port 2 ok'; + +--disable_query_log +call mtr.add_suppression("Too many connections"); +--enable_query_log +--disable_abort_on_error +--disable_result_log +--disable_query_log +connect(extracon3,127.0.0.1,root,,test,$MASTER_EXTRA_PORT,); +--enable_query_log +--enable_result_log +--enable_abort_on_error +let $error = $mysql_errno; +if (!$error) +{ + --echo # -- Error: managed to establish more than --extra-max-connections + 1 connections +} +if ($error) +{ + --echo # -- Success: more than --extra-max-connections + 1 normal connections not possible +} + +connection con2; +--reap +connection con3; +--reap + +connection default; +select count(*) from information_schema.THREAD_GROUP_STATUS; +set GLOBAL debug="-d,rds_local_pool_of_threads"; diff --git a/mysql-test/t/pool_of_threads_high_prio_tickets.cnf b/mysql-test/t/pool_of_threads_high_prio_tickets.cnf new file mode 100644 index 00000000000..3ed66ce75da --- /dev/null +++ b/mysql-test/t/pool_of_threads_high_prio_tickets.cnf @@ -0,0 +1,14 @@ +!include include/default_my.cnf + +[mysqld.1] +loose-thread-handling= pool-of-threads +loose-thread_pool_size= 2 +loose-thread_pool_max_threads= 2 +#extra-port= @ENV.MASTER_EXTRA_PORT +loose-thread_pool_high_prio_tickets=2 + +[client] +connect-timeout= 2 + +[ENV] +MASTER_EXTRA_PORT= 13009 diff --git a/mysql-test/t/pool_of_threads_high_prio_tickets.test b/mysql-test/t/pool_of_threads_high_prio_tickets.test new file mode 100644 index 00000000000..ddad70647d7 --- /dev/null +++ b/mysql-test/t/pool_of_threads_high_prio_tickets.test @@ -0,0 +1,19 @@ +# Start with thread_handling=pool-of-threads +# and run some basic tests with --thread_pool_high_prio_tickets=2 + +-- source include/have_pool_of_threads.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/mysys/my_getsystime.c b/mysys/my_getsystime.c index 5e9ff149113..efe26383a09 100644 --- a/mysys/my_getsystime.c +++ b/mysys/my_getsystime.c @@ -61,6 +61,49 @@ ulonglong my_getsystime() #endif } +/* + return number of nanoseconds since unspecified (but always the same) + point in the past + + NOTE: + Thus to get the current time we should use the system function + with the highest possible resolution + + The value is not anchored to any specific point in time (e.g.epoch) nor + is it subject to resetting or drifting by way of adjtime() or settimeofday(), + and thus it is *NOT* appropriate for getting the current timestamp. It can be + used for calculating time intervals, though. +*/ +ulonglong my_interval_timer() +{ +#ifdef HAVE_CLOCK_GETTIME + struct timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + return tp.tv_sec*1000000000ULL+tp.tv_nsec; +#elif defined(HAVE_GETHRTIME) + return gethrtime(); +#elif defined(__WIN__) + LARGE_INTEGER t_cnt; + if (query_performance_frequency) + { + QueryPerformanceCounter(&t_cnt); + return (t_cnt.QuadPart / query_performance_frequency * 1000000000ULL) + + ((t_cnt.QuadPart % query_performance_frequency) * 1000000000ULL / + query_performance_frequency); + } + else + { + ulonglong newtime; + GetSystemTimeAsFileTime((FILETIME*)&newtime); + return newtime*100ULL; + } +#else + /* TODO: check for other possibilities for hi-res timestamping */ + struct timeval tv; + gettimeofday(&tv,NULL); + return tv.tv_sec*1000000000ULL+tv.tv_usec*1000ULL; +#endif +} /** Return current time. diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index e89f9215feb..b4e3c83267e 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -186,6 +186,7 @@ SET(SQL_SHARED_SOURCES table_cache.cc thr_malloc.cc transaction.cc + threadpool_common.cc tztime.cc uniques.cc unireg.cc @@ -217,6 +218,13 @@ SET(SQL_SOURCE sql_client.cc ) +IF(WIN32) + SET(SQL_SOURCE ${SQL_SOURCE} threadpool_win.cc) +ELSE() + SET(SQL_SOURCE ${SQL_SOURCE} threadpool_unix.cc) +ENDIF() + + IF (WIN32 AND OPENSSL_APPLINK_C) SET_SOURCE_FILES_PROPERTIES( ../sql-common/client_authentication.cc diff --git a/sql/handler.h b/sql/handler.h index cddd8886b35..147153900b5 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -718,7 +718,8 @@ enum enum_schema_tables SCH_TRIGGERS, SCH_USER_PRIVILEGES, SCH_VARIABLES, - SCH_VIEWS + SCH_VIEWS, + SCH_THREAD_GROUP_STATUS }; struct TABLE_SHARE; diff --git a/sql/mdl.h b/sql/mdl.h index 3d2ba3ac0a6..8971b1532f1 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -773,6 +773,11 @@ class MDL_context m_tickets[MDL_EXPLICIT].is_empty()); } + inline bool has_explicit_locks() const + { + return !m_tickets[MDL_EXPLICIT].is_empty(); + } + MDL_savepoint mdl_savepoint() { return MDL_savepoint(m_tickets[MDL_STATEMENT].front(), diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 814419f6dcb..5c1d74936d5 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -119,6 +119,7 @@ #include #endif #include "table_cache.h" // table_cache_manager +#include "threadpool.h" using std::min; using std::max; @@ -503,6 +504,7 @@ TYPELIB gtid_mode_typelib= volatile sig_atomic_t calling_initgroups= 0; /**< Used in SIGSEGV handler. */ #endif uint mysqld_port, test_flags, select_errors, dropping_tables, ha_open_options; +uint mysqld_extra_port; uint mysqld_port_timeout; ulong delay_key_write_options; uint protocol_version; @@ -548,6 +550,7 @@ ulong specialflag=0; ulong binlog_cache_use= 0, binlog_cache_disk_use= 0; ulong binlog_stmt_cache_use= 0, binlog_stmt_cache_disk_use= 0; ulong max_connections, max_connect_errors; +ulong extra_max_connections; ulong rpl_stop_slave_timeout= LONG_TIMEOUT; my_bool log_bin_use_v1_row_events= 0; bool thread_cache_size_specified= false; @@ -1191,7 +1194,7 @@ static void charset_error_reporter(enum loglevel level, } C_MODE_END -static MYSQL_SOCKET unix_sock, ip_sock; +static MYSQL_SOCKET unix_sock, base_ip_sock, extra_ip_sock; struct rand_struct sql_rand; ///< used by sql_class.cc:THD::THD() #ifndef EMBEDDED_LIBRARY @@ -1258,6 +1261,10 @@ char *opt_ssl_ca= NULL, *opt_ssl_capath= NULL, *opt_ssl_cert= NULL, *opt_ssl_cipher= NULL, *opt_ssl_key= NULL, *opt_ssl_crl= NULL, *opt_ssl_crlpath= NULL; +static scheduler_functions thread_scheduler_struct, extra_thread_scheduler_struct; +scheduler_functions *thread_scheduler= &thread_scheduler_struct; +scheduler_functions *extra_thread_scheduler= &extra_thread_scheduler_struct; + #ifdef HAVE_OPENSSL #include #ifndef HAVE_YASSL @@ -1284,6 +1291,7 @@ struct st_VioSSLFd *ssl_acceptor_fd; LOCK_connection_count. */ uint connection_count= 0; +uint extra_connection_count= 0; mysql_cond_t COND_connection_count; /* Function declarations */ @@ -1384,11 +1392,17 @@ static void close_connections(void) DBUG_PRINT("quit",("Closing sockets")); if (!opt_disable_networking ) { - if (mysql_socket_getfd(ip_sock) != INVALID_SOCKET) + if (mysql_socket_getfd(base_ip_sock) != INVALID_SOCKET) + { + (void) mysql_socket_shutdown(base_ip_sock, SHUT_RDWR); + (void) mysql_socket_close(base_ip_sock); + base_ip_sock= MYSQL_INVALID_SOCKET; + } + if (mysql_socket_getfd(extra_ip_sock) != INVALID_SOCKET) { - (void) mysql_socket_shutdown(ip_sock, SHUT_RDWR); - (void) mysql_socket_close(ip_sock); - ip_sock= MYSQL_INVALID_SOCKET; + (void) mysql_socket_shutdown(extra_ip_sock, SHUT_RDWR); + (void) mysql_socket_close(extra_ip_sock); + extra_ip_sock= MYSQL_INVALID_SOCKET; } } #ifdef _WIN32 @@ -1458,7 +1472,7 @@ static void close_connections(void) DBUG_ASSERT(tmp->get_command() != COM_BINLOG_DUMP && tmp->get_command() != COM_BINLOG_DUMP_GTID); };); - MYSQL_CALLBACK(thread_scheduler, post_kill_notification, (tmp)); + MYSQL_CALLBACK(tmp->scheduler, post_kill_notification, (tmp)); mysql_mutex_lock(&tmp->LOCK_thd_data); if (tmp->mysys_var) { @@ -1502,7 +1516,7 @@ static void close_connections(void) tmp->get_command() == COM_BINLOG_DUMP_GTID) { tmp->killed= THD::KILL_CONNECTION; - MYSQL_CALLBACK(thread_scheduler, post_kill_notification, (tmp)); + MYSQL_CALLBACK(tmp->scheduler, post_kill_notification, (tmp)); mysql_mutex_lock(&tmp->LOCK_thd_data); if (tmp->mysys_var) { @@ -1586,10 +1600,17 @@ static void close_server_sock() #ifdef HAVE_CLOSE_SERVER_SOCK DBUG_ENTER("close_server_sock"); MYSQL_SOCKET tmp_sock; - tmp_sock=ip_sock; + tmp_sock= base_ip_sock; if (mysql_socket_getfd(tmp_sock) != INVALID_SOCKET) { - ip_sock= MYSQL_INVALID_SOCKET; + base_ip_sock= MYSQL_INVALID_SOCKET; + DBUG_PRINT("info",("calling shutdown on TCP/IP socket")); + (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR); + } + tmp_sock= extra_ip_sock; + if (mysql_socket_getfd(tmp_sock) != INVALID_SOCKET) + { + extra_ip_sock= MYSQL_INVALID_SOCKET; DBUG_PRINT("info",("calling shutdown on TCP/IP socket")); (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR); } @@ -1953,6 +1974,7 @@ void clean_up(bool print_message) sql_print_information(ER_DEFAULT(ER_SHUTDOWN_COMPLETE),my_progname); cleanup_errmsgs(); MYSQL_CALLBACK(thread_scheduler, end, ()); + MYSQL_CALLBACK(extra_thread_scheduler, end, ()); mysql_client_plugin_deinit(); finish_client_errs(); (void) my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST); // finish server errs @@ -2287,225 +2309,231 @@ static MYSQL_SOCKET create_socket(const struct addrinfo *addrinfo_list, return MYSQL_INVALID_SOCKET; } - -static void network_init(void) +static MYSQL_SOCKET activate_tcp_port(uint port) { -#ifdef HAVE_SYS_UN_H - struct sockaddr_un UNIXaddr; -#endif - int arg; - int ret; - uint waited; - uint this_wait; - uint retry; + int arg, ret; + uint waited, this_wait, retry; + struct addrinfo *ai; + struct addrinfo hints; char port_buf[NI_MAXSERV]; - DBUG_ENTER("network_init"); + MYSQL_SOCKET ip_sock= MYSQL_INVALID_SOCKET; + + const char *bind_address_str= NULL; + const char *ipv6_all_addresses= "::"; + const char *ipv4_all_addresses= "0.0.0.0"; + DBUG_ENTER("activate_tcp_port"); + sql_print_information("Server hostname (bind-address): '%s'; port: %d", + my_bind_addr_str, port); LINT_INIT(ret); + // Get list of IP-addresses associated with the bind-address. + memset(&hints, 0, sizeof(hints)); + hints.ai_flags= AI_PASSIVE; + hints.ai_socktype= SOCK_STREAM; + hints.ai_family= AF_UNSPEC; - if (MYSQL_CALLBACK_ELSE(thread_scheduler, init, (), 0)) - unireg_abort(1); /* purecov: inspected */ - - set_ports(); - - if (report_port == 0) + my_snprintf(port_buf, NI_MAXSERV, "%d", port); + if (strcasecmp(my_bind_addr_str, MY_BIND_ALL_ADDRESSES) == 0) { - report_port= mysqld_port; - } - -#ifndef DBUG_OFF - if (!opt_disable_networking) - DBUG_ASSERT(report_port != 0); -#endif - - if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap) - { - struct addrinfo *ai; - struct addrinfo hints; - - const char *bind_address_str= NULL; - const char *ipv6_all_addresses= "::"; - const char *ipv4_all_addresses= "0.0.0.0"; - - sql_print_information("Server hostname (bind-address): '%s'; port: %d", - my_bind_addr_str, mysqld_port); - - // Get list of IP-addresses associated with the bind-address. - - memset(&hints, 0, sizeof (hints)); - hints.ai_flags= AI_PASSIVE; - hints.ai_socktype= SOCK_STREAM; - hints.ai_family= AF_UNSPEC; + /* + That's the case when bind-address is set to a special value ('*'), + meaning "bind to all available IP addresses". If the box supports + the IPv6 stack, that means binding to '::'. If only IPv4 is available, + bind to '0.0.0.0'. + */ - my_snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port); + bool ipv6_available= false; - if (strcasecmp(my_bind_addr_str, MY_BIND_ALL_ADDRESSES) == 0) + if (!getaddrinfo(ipv6_all_addresses, port_buf, &hints, &ai)) { /* - That's the case when bind-address is set to a special value ('*'), - meaning "bind to all available IP addresses". If the box supports - the IPv6 stack, that means binding to '::'. If only IPv4 is available, - bind to '0.0.0.0'. + IPv6 might be available (the system might be able to resolve an IPv6 + address, but not be able to create an IPv6-socket). Try to create a + dummy IPv6-socket. Do not instrument that socket by P_S. */ - bool ipv6_available= false; + MYSQL_SOCKET s= mysql_socket_socket(0, AF_INET6, SOCK_STREAM, 0); - if (!getaddrinfo(ipv6_all_addresses, port_buf, &hints, &ai)) - { - /* - IPv6 might be available (the system might be able to resolve an IPv6 - address, but not be able to create an IPv6-socket). Try to create a - dummy IPv6-socket. Do not instrument that socket by P_S. - */ - - MYSQL_SOCKET s= mysql_socket_socket(0, AF_INET6, SOCK_STREAM, 0); - - ipv6_available= mysql_socket_getfd(s) != INVALID_SOCKET; - - mysql_socket_close(s); - } + ipv6_available= mysql_socket_getfd(s) != INVALID_SOCKET; if (ipv6_available) - { - sql_print_information("IPv6 is available."); - - // Address info (ai) for IPv6 address is already set. - - bind_address_str= ipv6_all_addresses; - } - else - { - sql_print_information("IPv6 is not available."); + mysql_socket_close(s); + } - // Retrieve address info (ai) for IPv4 address. + if (ipv6_available) + { + sql_print_information("IPv6 is available."); - if (getaddrinfo(ipv4_all_addresses, port_buf, &hints, &ai)) - { - sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); - sql_print_error("Can't start server: cannot resolve hostname!"); - unireg_abort(1); - } + // Address info (ai) for IPv6 address is already set. - bind_address_str= ipv4_all_addresses; - } + bind_address_str= ipv6_all_addresses; } else { - if (getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai)) + sql_print_information("IPv6 is not available."); + + // Retrieve address info (ai) for IPv4 address. + + if (getaddrinfo(ipv4_all_addresses, port_buf, &hints, &ai)) { - sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */ + sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); sql_print_error("Can't start server: cannot resolve hostname!"); - unireg_abort(1); /* purecov: tested */ + unireg_abort(1); } - bind_address_str= my_bind_addr_str; + bind_address_str= ipv4_all_addresses; } - - // Log all the IP-addresses. - for (struct addrinfo *cur_ai= ai; cur_ai != NULL; cur_ai= cur_ai->ai_next) + } + else + { + if (getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai)) { - char ip_addr[INET6_ADDRSTRLEN]; - - if (vio_getnameinfo(cur_ai->ai_addr, ip_addr, sizeof (ip_addr), - NULL, 0, NI_NUMERICHOST)) - { - sql_print_error("Fails to print out IP-address."); - continue; - } - - sql_print_information(" - '%s' resolves to '%s';", - bind_address_str, ip_addr); + sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */ + sql_print_error("Can't start server: cannot resolve hostname!"); + unireg_abort(1); /* purecov: tested */ } - /* - If the 'bind-address' option specifies the hostname, which resolves to - multiple IP-address, use the following rule: - - if there are IPv4-addresses, use the first IPv4-address - returned by getaddrinfo(); - - if there are IPv6-addresses, use the first IPv6-address - returned by getaddrinfo(); - */ + bind_address_str= my_bind_addr_str; - struct addrinfo *a = NULL; - ip_sock= create_socket(ai, AF_INET, &a); + } - if (mysql_socket_getfd(ip_sock) == INVALID_SOCKET) - ip_sock= create_socket(ai, AF_INET6, &a); + // Log all the IP-addresses. + for (struct addrinfo *cur_ai= ai; cur_ai != NULL; cur_ai= cur_ai->ai_next) + { + char ip_addr[INET6_ADDRSTRLEN]; - // Report user-error if we failed to create a socket. - if (mysql_socket_getfd(ip_sock) == INVALID_SOCKET) + if (vio_getnameinfo(cur_ai->ai_addr, ip_addr, sizeof (ip_addr), + NULL, 0, NI_NUMERICHOST)) { - sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */ - unireg_abort(1); /* purecov: tested */ + sql_print_error("Fails to print out IP-address."); + continue; } - mysql_socket_set_thread_owner(ip_sock); + sql_print_information(" - '%s' resolves to '%s';", + bind_address_str, ip_addr); + } + + /* + If the 'bind-address' option specifies the hostname, which resolves to + multiple IP-address, use the following rule: + - if there are IPv4-addresses, use the first IPv4-address + returned by getaddrinfo(); + - if there are IPv6-addresses, use the first IPv6-address + returned by getaddrinfo(); + */ + struct addrinfo *a; + ip_sock= create_socket(ai, AF_INET, &a); + + if (mysql_socket_getfd(ip_sock) == INVALID_SOCKET) + ip_sock= create_socket(ai, AF_INET6, &a); + + // Report user-error if we failed to create a socket. + if (mysql_socket_getfd(ip_sock) == INVALID_SOCKET) + { + sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */ + unireg_abort(1); /* purecov: tested */ + } + + mysql_socket_set_thread_owner(ip_sock); #ifndef __WIN__ - /* - We should not use SO_REUSEADDR on windows as this would enable a - user to open two mysqld servers with the same TCP/IP port. - */ - arg= 1; - (void) mysql_socket_setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,sizeof(arg)); + /* + We should not use SO_REUSEADDR on windows as this would enable a + user to open two mysqld servers with the same TCP/IP port. + */ + arg= 1; + (void) mysql_socket_setsockopt(ip_sock, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,sizeof(arg)); #endif /* __WIN__ */ #ifdef IPV6_V6ONLY - /* - For interoperability with older clients, IPv6 socket should - listen on both IPv6 and IPv4 wildcard addresses. - Turn off IPV6_V6ONLY option. + /* + For interoperability with older clients, IPv6 socket should + listen on both IPv6 and IPv4 wildcard addresses. + Turn off IPV6_V6ONLY option. - NOTE: this will work starting from Windows Vista only. - On Windows XP dual stack is not available, so it will not - listen on the corresponding IPv4-address. - */ - if (a->ai_family == AF_INET6) - { - arg= 0; + NOTE: this will work starting from Windows Vista only. + On Windows XP dual stack is not available, so it will not + listen on the corresponding IPv4-address. + */ + if (a->ai_family == AF_INET6) + { + arg= 0; - if (mysql_socket_setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, - (char *) &arg, sizeof (arg))) - { - sql_print_warning("Failed to reset IPV6_V6ONLY flag (error: %d). " - "The server will listen to IPv6 addresses only.", - (int) socket_errno); - } - } -#endif - /* - Sometimes the port is not released fast enough when stopping and - restarting the server. This happens quite often with the test suite - on busy Linux systems. Retry to bind the address at these intervals: - Sleep intervals: 1, 2, 4, 6, 9, 13, 17, 22, ... - Retry at second: 1, 3, 7, 13, 22, 35, 52, 74, ... - Limit the sequence by mysqld_port_timeout (set --port-open-timeout=#). - */ - for (waited= 0, retry= 1; ; retry++, waited+= this_wait) + if (mysql_socket_setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, + (char *) &arg, sizeof (arg))) { - if (((ret= mysql_socket_bind(ip_sock, a->ai_addr, a->ai_addrlen)) >= 0 ) || - (socket_errno != SOCKET_EADDRINUSE) || - (waited >= mysqld_port_timeout)) - break; - sql_print_information("Retrying bind on TCP/IP port %u", mysqld_port); - this_wait= retry * retry / 3 + 1; - sleep(this_wait); - } - freeaddrinfo(ai); - if (ret < 0) - { - DBUG_PRINT("error",("Got error: %d from bind",socket_errno)); - sql_perror("Can't start server: Bind on TCP/IP port"); - sql_print_error("Do you already have another mysqld server running on port: %d ?",mysqld_port); - unireg_abort(1); - } - if (mysql_socket_listen(ip_sock, (int)back_log) < 0) - { - sql_perror("Can't start server: listen() on TCP/IP port"); - sql_print_error("listen() on TCP/IP failed with error %d", - socket_errno); - unireg_abort(1); + sql_print_warning("Failed to reset IPV6_V6ONLY flag (error: %d). " + "The server will listen to IPv6 addresses only.", + (int) socket_errno); } } +#endif + /* + Sometimes the port is not released fast enough when stopping and + restarting the server. This happens quite often with the test suite + on busy Linux systems. Retry to bind the address at these intervals: + Sleep intervals: 1, 2, 4, 6, 9, 13, 17, 22, ... + Retry at second: 1, 3, 7, 13, 22, 35, 52, 74, ... + Limit the sequence by mysqld_port_timeout (set --port-open-timeout=#). + */ + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) + { + if (((ret= mysql_socket_bind(ip_sock, a->ai_addr, a->ai_addrlen)) >= 0 ) || + (socket_errno != SOCKET_EADDRINUSE) || + (waited >= mysqld_port_timeout)) + break; + sql_print_information("Retrying bind on TCP/IP port %u", port); + this_wait= retry * retry / 3 + 1; + sleep(this_wait); + } + freeaddrinfo(ai); + if (ret < 0) + { + DBUG_PRINT("error",("Got error: %d from bind",socket_errno)); + sql_perror("Can't start server: Bind on TCP/IP port"); + sql_print_error("Do you already have another mysqld server running on port: %d ?", port); + unireg_abort(1); + } + if (mysql_socket_listen(ip_sock, (int)back_log) < 0) + { + sql_perror("Can't start server: listen() on TCP/IP port"); + sql_print_error("listen() on TCP/IP failed with error %d", + socket_errno); + unireg_abort(1); + } + DBUG_RETURN(ip_sock); +} + + +static void network_init(void) +{ +#ifdef HAVE_SYS_UN_H + struct sockaddr_un UNIXaddr; +#endif + int arg; + DBUG_ENTER("network_init"); + + if (MYSQL_CALLBACK_ELSE(thread_scheduler, init, (), 0)) + unireg_abort(1); /* purecov: inspected */ + + set_ports(); + + if (report_port == 0) + { + report_port= mysqld_port; + } + +#ifndef DBUG_OFF + if (!opt_disable_networking) + DBUG_ASSERT(report_port != 0); +#endif + + if (!opt_disable_networking && !opt_bootstrap) + { + if (mysqld_port) + base_ip_sock= activate_tcp_port(mysqld_port); + if (mysqld_extra_port) + extra_ip_sock= activate_tcp_port(mysqld_extra_port); + } #ifdef _WIN32 /* create named pipe */ @@ -2650,7 +2678,7 @@ extern "C" sig_handler end_thread_signal(int sig MY_ATTRIBUTE((unused))) if (thd && ! thd->bootstrap) { statistic_increment(killed_threads, &LOCK_status); - MYSQL_CALLBACK(thread_scheduler, end_thread, (thd,0)); /* purecov: inspected */ + MYSQL_CALLBACK(thd->scheduler, end_thread, (thd,0)); /* purecov: inspected */ } } @@ -2675,11 +2703,13 @@ void thd_release_resources(THD *thd) dec_connection_count() */ -void dec_connection_count() +void dec_connection_count(THD *thd) { mysql_mutex_lock(&LOCK_connection_count); - --connection_count; - if (connection_count == 0) + + (*thd->scheduler->connection_count)--; + + if (*thd->scheduler->connection_count == 0) mysql_cond_signal(&COND_connection_count); mysql_mutex_unlock(&LOCK_connection_count); } @@ -2789,7 +2819,7 @@ bool one_thread_per_connection_end(THD *thd, bool block_pthread) thd->release_resources(); remove_global_thread(thd); - dec_connection_count(); + dec_connection_count(thd); if (kill_blocked_pthreads_flag) { // Do not block if we are about to shut down @@ -6291,7 +6321,7 @@ static void create_new_thread(THD *thd) mysql_mutex_lock(&LOCK_connection_count); - if (connection_count >= max_connections + 1 || abort_loop) + if (*thd->scheduler->connection_count >= *thd->scheduler->max_connections + 1 || abort_loop) { mysql_mutex_unlock(&LOCK_connection_count); @@ -6314,7 +6344,7 @@ static void create_new_thread(THD *thd) DBUG_VOID_RETURN; } - ++connection_count; + ++(*thd->scheduler->connection_count); if (connection_count > max_used_connections) max_used_connections= connection_count; @@ -6332,7 +6362,7 @@ static void create_new_thread(THD *thd) */ thd->thread_id= thd->variables.pseudo_thread_id= thread_id++; - MYSQL_CALLBACK(thread_scheduler, add_connection, (thd)); + MYSQL_CALLBACK(thd->scheduler, add_connection, (thd)); DBUG_VOID_RETURN; } @@ -6344,7 +6374,7 @@ inline void kill_broken_server() { /* hack to get around signals ignored in syscalls for problem OS's */ if (mysql_get_fd(unix_sock) == INVALID_SOCKET || - (!opt_disable_networking && mysql_socket_getfd(ip_sock) == INVALID_SOCKET)) + (!opt_disable_networking && mysql_socket_getfd(base_ip_sock) == INVALID_SOCKET)) { select_thread_in_use = 0; /* The following call will never return */ @@ -6360,6 +6390,28 @@ inline void kill_broken_server() #ifndef EMBEDDED_LIBRARY +/* get ip address from socket */ +void get_ip_address(char ipstr[], int array_size, MYSQL_SOCKET socket) +{ + struct sockaddr_storage addr; + socklen_t len= sizeof addr;; + + if (mysql_socket_getpeername(socket, (struct sockaddr*)&addr, &len)) + return; + + if (addr.ss_family == AF_INET) + { + struct sockaddr_in *s = (struct sockaddr_in *)&addr; + inet_ntop(AF_INET, &s->sin_addr, ipstr, array_size); + } + else + { // AF_INET6 + struct sockaddr_in6 *s = (struct sockaddr_in6 *)&addr; + inet_ntop(AF_INET6, &s->sin6_addr, ipstr, array_size); + } +} + + void handle_connections_sockets() { MYSQL_SOCKET sock= mysql_socket_invalid(); @@ -6367,39 +6419,58 @@ void handle_connections_sockets() uint error_count=0; THD *thd; struct sockaddr_storage cAddr; - int ip_flags=0,socket_flags=0,flags=0,retval; + int ip_flags=0, extra_ip_flags, socket_flags=0; + int flags=0,retval; st_vio *vio_tmp; #ifdef HAVE_POLL int socket_count= 0; - struct pollfd fds[2]; // for ip_sock and unix_sock - MYSQL_SOCKET pfs_fds[2]; // for performance schema + struct pollfd fds[3]; // for ip_sock, extra_ip_sock and unix_sock + MYSQL_SOCKET pfs_fds[3]; // for performance schema #else fd_set readFDs,clientFDs; - uint max_used_connection= max(mysql_socket_getfd(ip_sock), mysql_socket_getfd(unix_sock)) + 1; + uint max_used_connection= max(mysql_socket_getfd(base_ip_sock), + mysql_socket_getfd(extra_ip_sock), + mysql_socket_getfd(unix_sock)) + 1; #endif DBUG_ENTER("handle_connections_sockets"); (void) ip_flags; + (void) extra_ip_flags; (void) socket_flags; #ifndef HAVE_POLL FD_ZERO(&clientFDs); #endif - if (mysql_socket_getfd(ip_sock) != INVALID_SOCKET) + if (mysql_socket_getfd(base_ip_sock) != INVALID_SOCKET) + { + mysql_socket_set_thread_owner(base_ip_sock); +#ifdef HAVE_POLL + fds[socket_count].fd= mysql_socket_getfd(base_ip_sock); + fds[socket_count].events= POLLIN; + pfs_fds[socket_count]= base_ip_sock; + socket_count++; +#else + FD_SET(mysql_socket_getfd(base_ip_sock), &clientFDs); +#endif +#ifdef HAVE_FCNTL + ip_flags = fcntl(mysql_socket_getfd(base_ip_sock), F_GETFL, 0); +#endif + } + if (mysql_socket_getfd(extra_ip_sock) != INVALID_SOCKET) { - mysql_socket_set_thread_owner(ip_sock); + mysql_socket_set_thread_owner(extra_ip_sock); #ifdef HAVE_POLL - fds[socket_count].fd= mysql_socket_getfd(ip_sock); + fds[socket_count].fd= mysql_socket_getfd(extra_ip_sock); fds[socket_count].events= POLLIN; - pfs_fds[socket_count]= ip_sock; + pfs_fds[socket_count]= extra_ip_sock; socket_count++; #else - FD_SET(mysql_socket_getfd(ip_sock), &clientFDs); + FD_SET(mysql_socket_getfd(extra_ip_sock), &clientFDs); #endif #ifdef HAVE_FCNTL - ip_flags = fcntl(mysql_socket_getfd(ip_sock), F_GETFL, 0); + extra_ip_flags = fcntl(mysql_socket_getfd(extra_ip_sock), F_GETFL, 0); #endif } #ifdef HAVE_SYS_UN_H @@ -6476,10 +6547,16 @@ void handle_connections_sockets() } else #endif // HAVE_SYS_UN_H + if (FD_ISSET(mysql_socket_getfd(base_ip_sock), &readFDs)) { - sock = ip_sock; + sock = base_ip_sock; flags= ip_flags; } + else if (FD_ISSET(mysql_socket_getfd(extra_ip_sock), &readFDs)) + { + sock= extra_ip_sock; + flags= extra_ip_flags; + } #endif // HAVE_POLL #if !defined(NO_FCNTL_NONBLOCK) @@ -6531,7 +6608,8 @@ void handle_connections_sockets() #ifdef HAVE_LIBWRAP { - if (mysql_socket_getfd(sock) == mysql_socket_getfd(ip_sock)) + if (mysql_socket_getfd(sock) == mysql_socket_getfd(base_ip_sock) || + mysql_socket_getfd(sock) == mysql_socket_getfd(extra_ip_sock)) { struct request_info req; signal(SIGCHLD, SIG_DFL); @@ -6610,6 +6688,32 @@ void handle_connections_sockets() if (mysql_socket_getfd(sock) == mysql_socket_getfd(unix_sock)) thd->security_ctx->set_host((char*) my_localhost); + if (mysql_socket_getfd(sock) == mysql_socket_getfd(extra_ip_sock)) + thd->scheduler= extra_thread_scheduler; + + if ((thread_handling == SCHEDULER_POOL_THREADS) && !mysqld_extra_port) + { + if (thd->net.vio->localhost) + { + thd->scheduler= extra_thread_scheduler; + } + else + { + char ipstr[INET6_ADDRSTRLEN]= {0}; + get_ip_address(ipstr, INET6_ADDRSTRLEN, new_sock); + if (strncmp("127.0.0.1", ipstr, strlen("127.0.0.1")) == 0 || + strncmp("::1", ipstr, strlen("::1")) == 0) + thd->scheduler= extra_thread_scheduler; + + } + } + DBUG_EXECUTE_IF("rds_local_pool_of_threads", + { + if (mysql_socket_getfd(sock) != mysql_socket_getfd(extra_ip_sock)) + { + thd->scheduler= thread_scheduler; + } + }); create_new_thread(thd); } DBUG_VOID_RETURN; @@ -8052,6 +8156,16 @@ show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff) #endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ +#ifdef HAVE_POOL_OF_THREADS +int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff) +{ + var->type= SHOW_INT; + var->value= buff; + *(int *)buff= tp_get_idle_thread_count(); + return 0; +} +#endif + #define SHOW_FNAME(name) \ rpl_semi_sync_master_show_##name @@ -8103,6 +8217,7 @@ SHOW_VAR status_vars[]= { {"Delayed_errors", (char*) &delayed_insert_errors, SHOW_LONG}, {"Delayed_insert_threads", (char*) &delayed_insert_threads, SHOW_LONG_NOFLUSH}, {"Delayed_writes", (char*) &delayed_insert_writes, SHOW_LONG}, + {"Extra_threads_connected", (char*) &extra_connection_count, SHOW_INT}, {"Flush_commands", (char*) &refresh_version, SHOW_LONG_NOFLUSH}, {"Handler_commit", (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONGLONG_STATUS}, {"Handler_delete", (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONGLONG_STATUS}, @@ -8224,6 +8339,10 @@ SHOW_VAR status_vars[]= { {"Tc_log_max_pages_used", (char*) &tc_log_max_pages_used, SHOW_LONG}, {"Tc_log_page_size", (char*) &tc_log_page_size, SHOW_LONG_NOFLUSH}, {"Tc_log_page_waits", (char*) &tc_log_page_waits, SHOW_LONG}, +#endif +#ifdef HAVE_POOL_OF_THREADS + {"Threadpool_idle_threads", (char *) &show_threadpool_idle_threads, SHOW_FUNC}, + {"Threadpool_threads", (char *) &tp_stats.num_worker_threads, SHOW_INT}, #endif {"Threads_cached", (char*) &blocked_pthread_count, SHOW_LONG_NOFLUSH}, {"Threads_connected", (char*) &connection_count, SHOW_INT}, @@ -8444,7 +8563,8 @@ static int mysql_init_variables(void) opt_specialflag= SPECIAL_ENGLISH; unix_sock= MYSQL_INVALID_SOCKET; - ip_sock= MYSQL_INVALID_SOCKET; + base_ip_sock= MYSQL_INVALID_SOCKET; + extra_ip_sock= MYSQL_INVALID_SOCKET; mysql_home_ptr= mysql_home; pidfile_name_ptr= pidfile_name; log_error_file_ptr= log_error_file; @@ -9139,7 +9259,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr) } if (opt_disable_networking) - mysqld_port= 0; + mysqld_extra_port= mysqld_port= 0; if (opt_skip_show_db) opt_specialflag|= SPECIAL_SKIP_SHOW_DB; @@ -9219,12 +9339,24 @@ static int get_options(int *argc_ptr, char ***argv_ptr) return 1; #ifdef EMBEDDED_LIBRARY - one_thread_scheduler(); + one_thread_scheduler(thread_scheduler); + one_thread_scheduler(extra_thread_scheduler); #else if (thread_handling <= SCHEDULER_ONE_THREAD_PER_CONNECTION) - one_thread_per_connection_scheduler(); - else /* thread_handling == SCHEDULER_NO_THREADS) */ - one_thread_scheduler(); + one_thread_per_connection_scheduler(thread_scheduler, + &max_connections, + &connection_count); + else if (thread_handling == SCHEDULER_NO_THREADS) + one_thread_scheduler(thread_scheduler); + else + pool_of_threads_scheduler(thread_scheduler, &max_connections, + &connection_count); + + one_thread_per_connection_scheduler(extra_thread_scheduler, + &extra_max_connections, + &extra_connection_count); + + #endif global_system_variables.engine_condition_pushdown= diff --git a/sql/mysqld.h b/sql/mysqld.h index e36aa7c18c6..2fb84caadce 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -222,7 +222,7 @@ void kill_blocked_pthreads(); void refresh_status(THD *thd); bool is_secure_file_path(char *path); bool is_mysql_datadir_path(const char *path); -void dec_connection_count(); +void dec_connection_count(THD *thd); // These are needed for unit testing. void set_remaining_args(int argc, char **argv); @@ -913,6 +913,14 @@ extern "C" void unireg_clear(int exit_code); #define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0) #endif + +extern ulong thread_created; +extern uint mysqld_extra_port; +extern uint extra_connection_count; +extern ulong extra_max_connections; + +extern scheduler_functions *thread_scheduler, *extra_thread_scheduler; + inline void table_case_convert(char * name, uint length) { if (lower_case_table_names) diff --git a/sql/scheduler.cc b/sql/scheduler.cc index 248cebbdf4f..6022dc22cd7 100644 --- a/sql/scheduler.cc +++ b/sql/scheduler.cc @@ -26,6 +26,7 @@ #include "sql_callback.h" #include "global_threads.h" #include "mysql/thread_pool_priv.h" +#include /* End connection, in case when we are using 'no-threads' @@ -35,47 +36,13 @@ static bool no_threads_end(THD *thd, bool put_in_cache) { thd_release_resources(thd); remove_global_thread(thd); - dec_connection_count(); + dec_connection_count(thd); // THD is an incomplete type here, so use destroy_thd() to delete it. destroy_thd(thd); return 1; // Abort handle_one_connection } -static scheduler_functions one_thread_scheduler_functions= -{ - 1, // max_threads - NULL, // init - init_new_connection_handler_thread, // init_new_connection_thread -#ifndef EMBEDDED_LIBRARY - handle_connection_in_main_thread, // add_connection -#else - NULL, // add_connection -#endif // EMBEDDED_LIBRARY - NULL, // thd_wait_begin - NULL, // thd_wait_end - NULL, // post_kill_notification - no_threads_end, // end_thread - NULL, // end -}; - -#ifndef EMBEDDED_LIBRARY -static scheduler_functions one_thread_per_connection_scheduler_functions= -{ - 0, // max_threads - NULL, // init - init_new_connection_handler_thread, // init_new_connection_thread - create_thread_to_handle_connection, // add_connection - NULL, // thd_wait_begin - NULL, // thd_wait_end - NULL, // post_kill_notification - one_thread_per_connection_end, // end_thread - NULL, // end -}; -#endif // EMBEDDED_LIBRARY - - -scheduler_functions *thread_scheduler= NULL; /** @internal Helper functions to allow mysys to call the thread scheduler when @@ -86,21 +53,27 @@ scheduler_functions *thread_scheduler= NULL; extern "C" { static void scheduler_wait_lock_begin(void) { - MYSQL_CALLBACK(thread_scheduler, - thd_wait_begin, (current_thd, THD_WAIT_TABLE_LOCK)); + thd_wait_begin(NULL, THD_WAIT_TABLE_LOCK); } static void scheduler_wait_lock_end(void) { - MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (current_thd)); + thd_wait_end(NULL); } static void scheduler_wait_sync_begin(void) { - MYSQL_CALLBACK(thread_scheduler, - thd_wait_begin, (current_thd, THD_WAIT_TABLE_LOCK)); + thd_wait_begin(NULL, THD_WAIT_SYNC); } static void scheduler_wait_sync_end(void) { - MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (current_thd)); + thd_wait_end(NULL); +} + +static void scheduler_wait_net_begin(void) { + thd_wait_begin(NULL, THD_WAIT_NET); +} + +static void scheduler_wait_net_end(void) { + thd_wait_end(NULL); } }; /**@}*/ @@ -112,11 +85,13 @@ static void scheduler_wait_sync_end(void) { one_thread_scheduler() or one_thread_per_connection_scheduler() in mysqld.cc, so this init function will always be called. */ -static void scheduler_init() { +void scheduler_init() { thr_set_lock_wait_callback(scheduler_wait_lock_begin, scheduler_wait_lock_end); thr_set_sync_wait_callback(scheduler_wait_sync_begin, scheduler_wait_sync_end); + vio_set_wait_callback(scheduler_wait_net_begin, + scheduler_wait_net_end); } /* @@ -124,25 +99,38 @@ static void scheduler_init() { */ #ifndef EMBEDDED_LIBRARY -void one_thread_per_connection_scheduler() +void one_thread_per_connection_scheduler(scheduler_functions *func, + ulong *arg_max_connections, + uint *arg_connection_count) { scheduler_init(); - one_thread_per_connection_scheduler_functions.max_threads= max_connections; - thread_scheduler= &one_thread_per_connection_scheduler_functions; + func->max_threads= *arg_max_connections + 1; + func->max_connections= arg_max_connections; + func->connection_count= arg_connection_count; + func->init_new_connection_thread= init_new_connection_handler_thread; + func->add_connection= create_thread_to_handle_connection; + func->end_thread= one_thread_per_connection_end; } #endif /* Initailize scheduler for --thread-handling=no-threads */ - -void one_thread_scheduler() +void one_thread_scheduler(scheduler_functions *func) { scheduler_init(); - thread_scheduler= &one_thread_scheduler_functions; + func->max_threads= 1; + func->max_connections= &max_connections; + func->connection_count= &connection_count; +#ifndef EMBEDDED_LIBRARY + func->init_new_connection_thread= init_new_connection_handler_thread; + func->add_connection= handle_connection_in_main_thread; +#endif + func->end_thread= no_threads_end; } + /* Initialize scheduler for --thread-handling=one-thread-per-connection */ @@ -162,6 +150,8 @@ thd_scheduler::~thd_scheduler() { } + +#if 0 static scheduler_functions *saved_thread_scheduler; static uint saved_thread_handling; @@ -195,6 +185,12 @@ int my_thread_scheduler_reset() saved_thread_scheduler= 0; return 0; } +#else +extern "C" int my_thread_scheduler_set(scheduler_functions *scheduler) +{ return 1; } +extern "C" int my_thread_scheduler_reset() +{ return 1; } +#endif diff --git a/sql/scheduler.h b/sql/scheduler.h index 0835644b093..f5c047ee57c 100644 --- a/sql/scheduler.h +++ b/sql/scheduler.h @@ -27,6 +27,8 @@ class THD; struct scheduler_functions { uint max_threads; + uint *connection_count; + ulong *max_connections; bool (*init)(void); bool (*init_new_connection_thread)(void); void (*add_connection)(THD *thd); @@ -66,8 +68,21 @@ enum scheduler_types SCHEDULER_TYPES_COUNT }; -void one_thread_per_connection_scheduler(); -void one_thread_scheduler(); +void one_thread_per_connection_scheduler(scheduler_functions *func, + ulong *arg_max_connection, + uint *arg_connection_count); +void one_thread_scheduler(scheduler_functions *func); +#if !defined(EMBEDDED_LIBRARY) +#define HAVE_POOL_OF_THREADS 1 +void pool_of_threads_scheduler(scheduler_functions* func, + ulong *arg_max_connections, + uint *arg_connection_count); +#else +#define pool_of_threads_scheduler(A, B, C) \ + one_thread_per_connection_scheduler(A, B, C) +#endif + +extern void scheduler_init(); /* To be used for pool-of-threads (implemeneted differently on various OSs) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index a9c0021a922..e4b2593abd9 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -11388,7 +11388,7 @@ acl_authenticate(THD *thd, uint com_change_user_pkt_len) !(thd->main_security_ctx.master_access & SUPER_ACL)) { mysql_mutex_lock(&LOCK_connection_count); - bool count_ok= (connection_count <= max_connections); + bool count_ok= (*thd->scheduler->connection_count <= *thd->scheduler->max_connections); mysql_mutex_unlock(&LOCK_connection_count); if (!count_ok) { // too many connections diff --git a/sql/sql_class.cc b/sql/sql_class.cc index dd5938a43a2..dbaac9b265d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -217,7 +217,7 @@ bool foreign_key_prefix(Key *a, Key *b) */ void *thd_get_scheduler_data(THD *thd) { - return thd->scheduler.data; + return thd->event_scheduler.data; } /** @@ -228,7 +228,7 @@ void *thd_get_scheduler_data(THD *thd) */ void thd_set_scheduler_data(THD *thd, void *data) { - thd->scheduler.data= data; + thd->event_scheduler.data= data; } /** @@ -240,7 +240,7 @@ void thd_set_scheduler_data(THD *thd, void *data) */ PSI_thread *thd_get_psi(THD *thd) { - return thd->scheduler.m_psi; + return thd->event_scheduler.m_psi; } /** @@ -263,7 +263,7 @@ ulong thd_get_net_wait_timeout(THD* thd) */ void thd_set_psi(THD *thd, PSI_thread *psi) { - thd->scheduler.m_psi= psi; + thd->event_scheduler.m_psi= psi; } /** @@ -1022,6 +1022,13 @@ THD::THD(bool enable_plugins) stmt_arena= this; thread_stack= 0; catalog= (char*)"std"; // the only catalog we have for now + + /* for threadpool feature */ + scheduler= thread_scheduler; + event_scheduler.data= 0; + event_scheduler.m_psi= 0; + skip_wait_timeout= false; + main_security_ctx.init(); security_ctx= &main_security_ctx; no_errors= 0; @@ -1066,8 +1073,8 @@ THD::THD(bool enable_plugins) #endif #ifndef EMBEDDED_LIBRARY mysql_audit_init_thd(this); - net.vio=0; #endif + net.vio=0; client_capabilities= 0; // minimalistic client ull=0; system_thread= NON_SYSTEM_THREAD; @@ -1863,7 +1870,8 @@ void THD::awake(THD::killed_state state_to_set) reading the next statement. */ - shutdown_active_vio(); + if (active_vio) + vio_cancel(active_vio, SHUT_RDWR); } #endif @@ -1872,7 +1880,7 @@ void THD::awake(THD::killed_state state_to_set) /* Send an event to the scheduler that a thread should be killed. */ if (!slave_thread) - MYSQL_CALLBACK(thread_scheduler, post_kill_notification, (this)); + MYSQL_CALLBACK(scheduler, post_kill_notification, (this)); } /* Broadcast a condition to kick the target if it is waiting on it. */ @@ -4425,7 +4433,13 @@ extern "C" void thd_pool_wait_end(MYSQL_THD thd); */ extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type) { - MYSQL_CALLBACK(thread_scheduler, thd_wait_begin, (thd, wait_type)); + if (!thd) + { + thd= current_thd; + if (unlikely(!thd)) + return; + } + MYSQL_CALLBACK(thd->scheduler, thd_wait_begin, (thd, wait_type)); } /** @@ -4436,7 +4450,14 @@ extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type) */ extern "C" void thd_wait_end(MYSQL_THD thd) { - MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (thd)); + if (!thd) + { + thd= current_thd; + if (unlikely(!thd)) + return; + } + + MYSQL_CALLBACK(thd->scheduler, thd_wait_end, (thd)); } #else extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type) diff --git a/sql/sql_class.h b/sql/sql_class.h index 5e8ede0a341..ffb5eca3c41 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -579,6 +579,9 @@ typedef struct system_variables my_bool show_old_temporals; ulong rds_sql_max_iops; my_bool sequence_read_skip_cache; + + uint threadpool_high_prio_tickets; + ulong threadpool_high_prio_mode; } SV; @@ -2186,6 +2189,7 @@ class THD :public MDL_context_owner, NET net; // client connection descriptor /** Aditional network instrumentation for the server only. */ NET_SERVER m_net_server_extension; + scheduler_functions *scheduler; Protocol *protocol; // Current protocol Protocol_text protocol_text; // Normal protocol Protocol_binary protocol_binary; // Binary protocol @@ -2389,6 +2393,8 @@ class THD :public MDL_context_owner, } int binlog_flush_pending_rows_event(bool stmt_end, bool is_transactional); + bool skip_wait_timeout; + /** Determine the binlog format of the current statement. @@ -4052,7 +4058,7 @@ class THD :public MDL_context_owner, *p_db_length= db_length; return FALSE; } - thd_scheduler scheduler; + thd_scheduler event_scheduler; public: inline Internal_error_handler *get_internal_handler() @@ -5547,6 +5553,8 @@ inline bool add_group_to_list(THD *thd, Item *item, bool asc) return thd->lex->current_select->add_group_to_list(thd, item, asc); } +extern pthread_attr_t *get_connection_attrib(void); + #endif /* MYSQL_SERVER */ /** diff --git a/sql/sql_client.cc b/sql/sql_client.cc index 55ae4983272..bbbebe4fb22 100644 --- a/sql/sql_client.cc +++ b/sql/sql_client.cc @@ -34,6 +34,7 @@ void my_net_local_init(NET *net) { #ifndef EMBEDDED_LIBRARY net->max_packet= (uint) global_system_variables.net_buffer_length; + net->read_timeout= net->write_timeout= 0; my_net_set_read_timeout(net, (uint)global_system_variables.net_read_timeout); my_net_set_write_timeout(net, diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 37c6e294c0d..0f0d26067a3 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -714,7 +714,7 @@ bool setup_connection_thread_globals(THD *thd) { close_connection(thd, ER_OUT_OF_RESOURCES); statistic_increment(aborted_connects,&LOCK_status); - MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0)); + MYSQL_CALLBACK(thd->scheduler, end_thread, (thd, 0)); return 1; // Error } return 0; @@ -937,11 +937,11 @@ void do_handle_one_connection(THD *thd_arg) thd->thr_create_utime= my_micro_time(); - if (MYSQL_CALLBACK_ELSE(thread_scheduler, init_new_connection_thread, (), 0)) + if (MYSQL_CALLBACK_ELSE(thd->scheduler, init_new_connection_thread, (), 0)) { close_connection(thd, ER_OUT_OF_RESOURCES); statistic_increment(aborted_connects,&LOCK_status); - MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0)); + MYSQL_CALLBACK(thd->scheduler, end_thread, (thd, 0)); return; } @@ -992,7 +992,7 @@ void do_handle_one_connection(THD *thd_arg) end_thread: close_connection(thd); - if (MYSQL_CALLBACK_ELSE(thread_scheduler, end_thread, (thd, 1), 0)) + if (MYSQL_CALLBACK_ELSE(thd->scheduler, end_thread, (thd, 1), 0)) return; // Probably no-threads /* diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 5115569d1c2..fec16501e75 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -104,6 +104,7 @@ #include "sql_filter.h" #include "rpl_gtid.h" // set executed_gtid_set #include "sql_digest.h" +#include "threadpool.h" #include using std::max; @@ -930,27 +931,30 @@ bool do_command(THD *thd) the client, the connection is closed or "net_wait_timeout" number of seconds has passed. */ - THD_TRANS *trans= &thd->transaction.all; - Ha_trx_info *ha_info= trans->ha_list; - bool is_trx_read_only= ha_check_trx_read_only(ha_info); - if (thd->in_active_multi_stmt_transaction()) + if (!thd->skip_wait_timeout) { - if (thd->variables.trx_idle_timeout > 0) + THD_TRANS *trans= &thd->transaction.all; + Ha_trx_info *ha_info= trans->ha_list; + bool is_trx_read_only= ha_check_trx_read_only(ha_info); + if (thd->in_active_multi_stmt_transaction()) { - my_net_set_read_timeout(net, thd->variables.trx_idle_timeout); - } else if ((thd->variables.trx_readonly_idle_timeout > 0) && is_trx_read_only) - { - my_net_set_read_timeout(net, thd->variables.trx_readonly_idle_timeout); - } else if ((thd->variables.trx_changes_idle_timeout > 0) && !is_trx_read_only) - { - my_net_set_read_timeout(net, thd->variables.trx_changes_idle_timeout); + if (thd->variables.trx_idle_timeout > 0) + { + my_net_set_read_timeout(net, thd->variables.trx_idle_timeout); + } else if ((thd->variables.trx_readonly_idle_timeout > 0) && is_trx_read_only) + { + my_net_set_read_timeout(net, thd->variables.trx_readonly_idle_timeout); + } else if ((thd->variables.trx_changes_idle_timeout > 0) && !is_trx_read_only) + { + my_net_set_read_timeout(net, thd->variables.trx_changes_idle_timeout); + } else { + my_net_set_read_timeout(net, thd->variables.net_wait_timeout); + } } else { my_net_set_read_timeout(net, thd->variables.net_wait_timeout); } - } else { - my_net_set_read_timeout(net, thd->variables.net_wait_timeout); - } + } /* XXX: this code is here only to clear possible errors of init_connect. Consider moving to init_connect() instead. @@ -1625,10 +1629,14 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; #ifndef EMBEDDED_LIBRARY case COM_BINLOG_DUMP_GTID: + tp_dec_active_thread(thd, COM_BINLOG_DUMP_GTID); error= com_binlog_dump_gtid(thd, packet, packet_length); + tp_inc_active_thread(thd, COM_BINLOG_DUMP_GTID); break; case COM_BINLOG_DUMP: + tp_dec_active_thread(thd, COM_BINLOG_DUMP); error= com_binlog_dump(thd, packet, packet_length); + tp_inc_active_thread(thd, COM_BINLOG_DUMP); break; #endif case COM_REFRESH: diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 89e0ae1418c..3d3c0c5e1bf 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -57,6 +57,7 @@ #include "sql_optimizer.h" // JOIN #include "global_threads.h" #include "sql_filter.h" +#include "threadpool.h" #include using std::max; @@ -2367,6 +2368,47 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) DBUG_VOID_RETURN; } + +int fill_thread_group_info(THD *thd, TABLE_LIST* tables, Item* __attribute__((unused))) +{ + DBUG_ENTER("fill_thread_group_info"); + DBUG_ASSERT((thd != NULL) && (tables != NULL)); + + if (thread_handling != SCHEDULER_POOL_THREADS) + DBUG_RETURN(0); + + TABLE *table= tables->table; + thread_group_info *thread_groups= (thread_group_info*)malloc(sizeof(thread_group_info) * threadpool_size); + if (!thread_groups) + DBUG_RETURN(0); + + get_thread_group_info(thread_groups, threadpool_size); + + for (ulong i = 0; i < threadpool_size; i++) + { + thread_group_info *group= &thread_groups[i]; + + table->field[0]->store(group->group_id); + table->field[1]->store(group->thread_count); + table->field[2]->store(group->active_thread_count); + table->field[3]->store(group->connection_count); + table->field[4]->store(group->waiting_thread_count); + table->field[5]->store(group->dump_thread_count); + table->field[6]->store(group->low_queue_count); + table->field[7]->store(group->high_queue_count); + + if (schema_table_store_record(thd, table)) + { + free(thread_groups); //no cover line. + DBUG_RETURN(1); //no cover line. + } + + } + + free(thread_groups); + DBUG_RETURN(0); +} + int fill_schema_processlist(THD* thd, TABLE_LIST* tables, Item* cond) { TABLE *table= tables->table; @@ -8538,6 +8580,19 @@ ST_FIELD_INFO sql_filter_fields_info[] = {0, 0, MYSQL_TYPE_STRING, 0, 0, "", SKIP_OPEN_TABLE} }; +ST_FIELD_INFO thread_group_status_fields_info[] = +{ + {"ID", 21, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE }, + {"THREAD_COUNT", 21, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE}, + {"ACTIVE_THREAD_COUNT", 21, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE }, + {"CONNECTION_COUNT", 21, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE}, + {"WAITING_THREAD_COUNT", 21, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE}, + {"DUMP_COUNT", 21, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE}, + {"LOW_QUEUE_COUNT", 21, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE}, + {"HIGH_QUEUE_COUNT", 21, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, "", SKIP_OPEN_TABLE}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE } +}; + /** For creating fields of information_schema.OPTIMIZER_TRACE */ extern ST_FIELD_INFO optimizer_trace_info[]; @@ -8647,6 +8702,8 @@ ST_SCHEMA_TABLE schema_tables[]= fill_schema_table_stats, make_old_format, 0, -1, -1, 0, 0}, {"INDEX_STATISTICS", index_stats_fields_info, create_schema_table, fill_schema_index_stats, make_old_format, 0, -1, -1, 0, 0}, + {"THREAD_GROUP_STATUS", thread_group_status_fields_info, create_schema_table, + fill_thread_group_info, make_old_format, 0, -1, -1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index da7eb007305..974b6ee3e1f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -68,6 +68,10 @@ #include "semisync_master.h" #include "semisync_slave.h" + +#include "threadpool.h" +#define MAX_CONNECTIONS 100000 + char *rds_sql_select_filter= NULL; char *rds_sql_update_filter= NULL; char *rds_sql_delete_filter= NULL; @@ -1757,7 +1761,7 @@ static Sys_var_ulong Sys_max_binlog_size( static bool fix_max_connections(sys_var *self, THD *thd, enum_var_type type) { #ifndef EMBEDDED_LIBRARY - resize_thr_alarm(max_connections + + resize_thr_alarm(max_connections + extra_max_connections + global_system_variables.max_insert_delayed_threads + 10); #endif return false; @@ -1766,7 +1770,7 @@ static bool fix_max_connections(sys_var *self, THD *thd, enum_var_type type) static Sys_var_ulong Sys_max_connections( "max_connections", "The number of simultaneous clients allowed", GLOBAL_VAR(max_connections), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(1, 100000), + VALID_RANGE(1, MAX_CONNECTIONS), DEFAULT(MAX_CONNECTIONS_DEFAULT), BLOCK_SIZE(1), NO_MUTEX_GUARD, @@ -2542,13 +2546,19 @@ static Sys_var_ulong Sys_trans_prealloc_size( static const char *thread_handling_names[]= { - "one-thread-per-connection", "no-threads", "loaded-dynamically", + "one-thread-per-connection", "no-threads", +#ifdef HAVE_POOL_OF_THREADS + "pool-of-threads", +#endif 0 }; static Sys_var_enum Sys_thread_handling( "thread_handling", "Define threads usage for handling queries, one of " - "one-thread-per-connection, no-threads, loaded-dynamically" + "one-thread-per-connection, no-threads" +#ifdef HAVE_POOL_OF_THREADS + ", pool-of-threads" +#endif , READ_ONLY GLOBAL_VAR(thread_handling), CMD_LINE(REQUIRED_ARG), thread_handling_names, DEFAULT(0)); @@ -3139,6 +3149,132 @@ bool Sys_var_tx_read_only::session_update(THD *thd, set_var *var) } +#ifdef HAVE_POOL_OF_THREADS +static bool fix_tp_max_threads(sys_var *, THD *, enum_var_type) +{ +#ifdef _WIN32 + tp_set_max_threads(threadpool_max_threads); +#endif + return false; +} + +#ifdef _WIN32 +static bool fix_tp_min_threads(sys_var *, THD *, enum_var_type) +{ + tp_set_min_threads(threadpool_min_threads); + return false; +} +#endif + +#ifndef _WIN32 +static bool fix_threadpool_size(sys_var *, THD *, enum_var_type) +{ + tp_set_threadpool_size(threadpool_size); + return false; +} + +static bool fix_threadpool_stall_limit(sys_var *, THD *, enum_var_type) +{ + tp_set_threadpool_stall_limit(threadpool_stall_limit); + return false; +} +#endif + + +#ifdef _WIN32 +static Sys_var_uint Sys_threadpool_min_threads( + "thread_pool_min_threads", + "Minimum number of threads in the thread pool.", + GLOBAL_VAR(threadpool_min_threads), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(1, 256), DEFAULT(1), BLOCK_SIZE(1), + NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), + ON_UPDATE(fix_tp_min_threads)); +#else +static Sys_var_uint Sys_threadpool_idle_thread_timeout( + "thread_pool_idle_timeout", + "Timeout in seconds for an idle thread in the thread pool." + "Worker thread will be shutdown after timeout", + GLOBAL_VAR(threadpool_idle_timeout), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(1, UINT_MAX), DEFAULT(60), BLOCK_SIZE(1)); + +static Sys_var_uint Sys_threadpool_oversubscribe( + "thread_pool_oversubscribe", + "How many additional active worker threads in a group are allowed.", + GLOBAL_VAR(threadpool_oversubscribe), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(1, 1000), DEFAULT(3), BLOCK_SIZE(1)); + +static Sys_var_uint Sys_threadpool_size( + "thread_pool_size", + "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).", + GLOBAL_VAR(threadpool_size), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(1, MAX_THREAD_GROUPS), DEFAULT(my_getncpus()), BLOCK_SIZE(1), + NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), + ON_UPDATE(fix_threadpool_size)); + +static Sys_var_uint Sys_threadpool_stall_limit( + "thread_pool_stall_limit", + "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.", + GLOBAL_VAR(threadpool_stall_limit), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(1, UINT_MAX), DEFAULT(10), BLOCK_SIZE(1), + NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), + ON_UPDATE(fix_threadpool_stall_limit)); + +static Sys_var_uint Sys_threadpool_high_prio_tickets( + "thread_pool_high_prio_tickets", + "Number of tickets to enter the high priority event queue for each transaction.", + SESSION_VAR(threadpool_high_prio_tickets), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(0, UINT_MAX), DEFAULT(UINT_MAX), BLOCK_SIZE(1)); +static Sys_var_enum Sys_threadpool_high_prio_mode( + "thread_pool_high_prio_mode", + "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.", + SESSION_VAR(threadpool_high_prio_mode), CMD_LINE(REQUIRED_ARG), + threadpool_high_prio_mode_names, DEFAULT(TP_HIGH_PRIO_MODE_TRANSACTIONS)); +#ifdef __linux__ +static Sys_var_mybool Sys_threadpool_workaround_epoll_bug( + "threadpool_workaround_epoll_bug", + "Workaround Linux kernel bug: missing events in epoll, if EPOLL_CTL_MOD is used." + "The bug is fixed in the newest 3.x kernel series", + GLOBAL_VAR(threadpool_workaround_epoll_bug), CMD_LINE(OPT_ARG), DEFAULT(0)); +#endif /* __linux__*/ +#endif /* !WIN32 */ + +static Sys_var_uint Sys_threadpool_max_threads( + "thread_pool_max_threads", + "Maximus allowed number of worker threads in the thread pool", + GLOBAL_VAR(threadpool_max_threads), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(1, MAX_CONNECTIONS), DEFAULT(MAX_CONNECTIONS), BLOCK_SIZE(1), + NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), + ON_UPDATE(fix_tp_max_threads)); +#endif /* HAVE_POOL_OF_THREADS */ + +static Sys_var_uint Sys_extra_port( + "extra_port", + "Extra port number to use for tcp connections in a " + "one-thread-per-connection manner. 0 means don't use another port", + READ_ONLY GLOBAL_VAR(mysqld_extra_port), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(0, UINT_MAX32), DEFAULT(0), BLOCK_SIZE(1)); + +static Sys_var_ulong Sys_extra_max_connections( + "extra_max_connections", "The number of connections on extra-port", + GLOBAL_VAR(extra_max_connections), CMD_LINE(REQUIRED_ARG), + VALID_RANGE(1, MAX_CONNECTIONS), DEFAULT(10000), BLOCK_SIZE(1), NO_MUTEX_GUARD, + NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(fix_max_connections)); + + + static Sys_var_tx_read_only Sys_tx_read_only( "tx_read_only", "Set default transaction access mode to read only.", SESSION_VAR(tx_read_only), NO_CMD_LINE, DEFAULT(0), diff --git a/sql/threadpool.h b/sql/threadpool.h new file mode 100644 index 00000000000..b253fe12145 --- /dev/null +++ b/sql/threadpool.h @@ -0,0 +1,98 @@ +/* Copyright (C) 2012 Monty Program Ab + + 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 */ + +#define MAX_THREAD_GROUPS 128 + +enum tp_high_pri_mode_t { + TP_HIGH_PRIO_MODE_TRANSACTIONS, + TP_HIGH_PRIO_MODE_STATEMENTS, + TP_HIGH_PRIO_MODE_NONE +}; + +/* Threadpool parameters */ +extern uint threadpool_min_threads; /* Minimum threads in pool */ +extern uint threadpool_idle_timeout; /* Shutdown idle worker threads after this timeout */ +extern uint threadpool_size; /* Number of parallel executing threads */ +extern uint threadpool_stall_limit; /* time interval in 10 ms units for stall checks*/ +extern uint threadpool_max_threads; /* Maximum threads in pool */ +extern uint threadpool_oversubscribe; /* Maximum active 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); + +struct thread_group_info +{ + int group_id; + int thread_count; + int active_thread_count; + int connection_count; + int waiting_thread_count; + longlong dump_thread_count; + longlong low_queue_count; + longlong high_queue_count; +}; + +/* + Functions used by scheduler. + OS-specific implementations are in + threadpool_unix.cc or threadpool_win.cc +*/ +extern bool tp_init(); +extern void tp_add_connection(THD*); +extern void tp_wait_begin(THD *, int); +extern void tp_wait_end(THD*); +extern void tp_post_kill_notification(THD *thd); +extern void tp_end(void); + +/* reduce dump thread reference in threadpool */ +extern void tp_inc_active_thread(THD* thd, int command); +extern void tp_dec_active_thread(THD* thd, int command); + +/* Used in SHOW for threadpool_idle_thread_count */ +extern int tp_get_idle_thread_count(); +extern void get_thread_group_info(thread_group_info* thread_groups, + int group_count); + +/* + Threadpool statistics +*/ +struct TP_STATISTICS +{ + /* Current number of worker thread. */ + volatile int32 num_worker_threads; +}; + +extern TP_STATISTICS tp_stats; + + +/* Functions to set threadpool parameters */ +extern void tp_set_min_threads(uint val); +extern void tp_set_max_threads(uint val); +extern void tp_set_threadpool_size(uint val); +extern void tp_set_threadpool_stall_limit(uint val); + +/* Activate threadpool scheduler */ +extern void tp_scheduler(void); + +extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff); + +#ifdef __linux__ +extern my_bool threadpool_workaround_epoll_bug; +#endif diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc new file mode 100644 index 00000000000..268e0a6ab17 --- /dev/null +++ b/sql/threadpool_common.cc @@ -0,0 +1,287 @@ +/* Copyright (C) 2012 Monty Program Ab + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Threadpool parameters */ + +uint threadpool_min_threads; +uint threadpool_idle_timeout; +uint threadpool_size; +uint threadpool_stall_limit; +uint threadpool_max_threads; +uint threadpool_oversubscribe; + +/* Stats */ +TP_STATISTICS tp_stats; + + +extern "C" pthread_key(struct st_my_thread_var*, THR_KEY_mysys); +extern bool do_command(THD*); + +/* + 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 , e.g setting up + thread_stack/thread_ends_here pointers. + 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(). + +*/ +struct Worker_thread_context +{ +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + PSI_thread *psi_thread; +#endif + st_my_thread_var* mysys_var; + + void save() + { +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + psi_thread= PSI_server?PSI_server->get_thread():0; +#endif + mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); + } + + void restore() + { +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + if (PSI_server) + PSI_server->set_thread(psi_thread); +#endif + pthread_setspecific(THR_KEY_mysys,mysys_var); + pthread_setspecific(THR_THD, 0); + pthread_setspecific(THR_MALLOC, 0); + } +}; + + +/* + Attach/associate the connection with the OS thread, +*/ +static bool thread_attach(THD* thd) +{ + pthread_setspecific(THR_KEY_mysys,thd->mysys_var); + thd->thread_stack=(char*)&thd; + thd->store_globals(); +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + if (PSI_server) + PSI_server->set_thread(thd->event_scheduler.m_psi); +#endif + return 0; +} + + +int threadpool_add_connection(THD *thd) +{ + int retval=1; + Worker_thread_context worker_context; + worker_context.save(); + + /* + Create a new connection context: mysys_thread_var and PSI thread + Store them in THD. + */ + + pthread_setspecific(THR_KEY_mysys, 0); + my_thread_init(); + thd->mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); + if (!thd->mysys_var) + { + /* Out of memory? */ + worker_context.restore(); + return 1; + } +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + /* Create new PSI thread for use with the THD. */ + if (PSI_server) + { + thd->event_scheduler.m_psi = + PSI_server->new_thread(key_thread_one_connection, thd, thd->thread_id); + } +#endif + + /* Login. */ + thread_attach(thd); + ulonglong now= microsecond_interval_timer(); + thd->prior_thr_create_utime= now; + thd->start_utime= now; + thd->thr_create_utime= now; + + if (!setup_connection_thread_globals(thd)) + { + if (!login_connection(thd)) + { + MYSQL_AUDIT_NOTIFY_CONNECTION_CONNECT(thd); + prepare_new_connection_state(thd); + + /* + Check if THD is ok, as prepare_new_connection_state() + can fail, for example if init command failed. + */ + if (thd_is_connection_alive(thd)) + { + retval= 0; + thd->net.reading_or_writing= 1; + thd->skip_wait_timeout= true; + } + } + } + worker_context.restore(); + return retval; +} + + +void threadpool_remove_connection(THD *thd) +{ + Worker_thread_context worker_context; + worker_context.save(); + + thread_attach(thd); + thd->net.reading_or_writing= 0; + + end_connection(thd); + close_connection(thd, 0); + + thd->release_resources(); + dec_connection_count(thd); + + remove_global_thread(thd); + delete thd; + + /* + Free resources associated with this connection: + mysys thread_var and PSI thread. + */ + my_thread_end(); + + mysql_cond_broadcast(&COND_thread_count); + + worker_context.restore(); +} + +/** + Process a single client request or a single batch. +*/ +int threadpool_process_request(THD *thd) +{ + int retval= 0; + Worker_thread_context worker_context; + worker_context.save(); + + 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->net.reading_or_writing= 0; + mysql_audit_release(thd); + + if ((retval= do_command(thd)) != 0) + goto end; + + if (!thd_is_connection_alive(thd)) + { + retval= 1; + goto end; + } + + vio= thd->net.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->net.reading_or_writing= 1; + goto end; + } + } + +end: + worker_context.restore(); + return retval; +} + + +static scheduler_functions tp_scheduler_functions= +{ + 0, // max_threads + NULL, + NULL, + tp_init, // init + NULL, // init_new_connection_thread + tp_add_connection, // add_connection + tp_wait_begin, // thd_wait_begin + tp_wait_end, // thd_wait_end + tp_post_kill_notification, // post_kill_notification + NULL, // end_thread + tp_end // end +}; + +void pool_of_threads_scheduler(struct scheduler_functions *func, + ulong *arg_max_connections, + uint *arg_connection_count) +{ + *func = tp_scheduler_functions; + func->max_threads= threadpool_max_threads; + func->max_connections= arg_max_connections; + func->connection_count= arg_connection_count; + scheduler_init(); +} diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc new file mode 100644 index 00000000000..b6d59a50c71 --- /dev/null +++ b/sql/threadpool_unix.cc @@ -0,0 +1,1847 @@ +/* Copyright (C) 2012 Monty Program Ab + + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // thd_is_transaction_active() +#include +#include "debug_sync.h" +#ifdef __linux__ +#include +my_bool threadpool_workaround_epoll_bug; +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 + +/** Maximum number of native events a listener can read in one go */ +#define MAX_EVENTS 1024 + +/** Indicates that threadpool was initialized*/ +static bool threadpool_started= false; + +/** Define if wait_begin() should create threads if necessary without waiting +for stall detection to kick in */ +#define THREADPOOL_CREATE_THREADS_ON_WAIT + +/* Possible values for thread_pool_high_prio_mode */ +const char *threadpool_high_prio_mode_names[]= {"transactions", "statements", + "none", NullS}; +/* + 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 WITH_PERFSCHEMA_STORAGE_ENGINE +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}, + { &key_timer_mutex, "timer_mutex", PSI_FLAG_GLOBAL} +}; + +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}, + { &key_timer_cond, "timer_cond", PSI_FLAG_GLOBAL} +}; + +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}, + {&key_timer_thread, "timer_thread", PSI_FLAG_GLOBAL} +}; + +/* Macro to simplify performance schema registration */ +#define PSI_register(X) \ + if(PSI_server) PSI_server->register_ ## X("threadpool", X ## _list, array_elements(X ## _list)) +#endif + +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_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; + 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; + +struct 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 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; + ulonglong total_io_count; + ulonglong total_queue_count; + ulonglong dump_thread_count; + +} MY_ALIGNED(512); + +static thread_group_t all_groups[MAX_THREAD_GROUPS]; +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; + volatile uint64 current_microtime; + volatile uint64 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); +static void handle_event(connection_t *connection); +static int wake_or_create_thread(thread_group_t *thread_group); +static int create_worker(thread_group_t *thread_group); +static void *worker_main(void *param); +static void check_stall(thread_group_t *thread_group); +static void connection_abort(connection_t *connection); +void tp_post_kill_notification(THD *thd); +static void set_wait_timeout(connection_t *connection); +static void set_next_timeout_check(ulonglong abstime); +static void print_pool_blocked_message(bool); + +/** + 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) + Disassociate 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() +{ + return epoll_create(1); +} + + +int io_poll_associate_fd(int pollfd, int fd, void *data) +{ + 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); +} + +int io_poll_start_read(int pollfd, int fd, void *data) +{ + struct epoll_event ev; + ev.data.u64= 0; /* Keep valgrind happy */ + ev.data.ptr= data; + ev.events= EPOLLIN|EPOLLET|EPOLLERR|EPOLLRDHUP|EPOLLONESHOT; + if (threadpool_workaround_epoll_bug) + { + /* + On buggy kernel, replace EPOLL_CTL_MOD with EPOLL_CTL_DEL/ADD. + It takes one system call more, and affects speed considerably. + */ + int rc= epoll_ctl(pollfd, EPOLL_CTL_DEL, fd, NULL); + return (rc)? rc: epoll_ctl(pollfd, EPOLL_CTL_ADD, fd, &ev); + } + return epoll_ctl(pollfd, EPOLL_CTL_MOD, fd, &ev); +} + +int io_poll_disassociate_fd(int pollfd, int fd) +{ + 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 +*/ +int io_poll_wait(int pollfd, native_event *native_events, int maxevents, + int timeout_ms) +{ + 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) +{ + return event->data.ptr; +} + +#elif defined (__FreeBSD__) || defined (__APPLE__) +int io_poll_create() +{ + return kqueue(); +} + +int io_poll_start_read(int pollfd, int fd, void *data) +{ + struct kevent ke; + EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, + 0, 0, data); + return kevent(pollfd, &ke, 1, 0, 0, 0); +} + + +int io_poll_associate_fd(int pollfd, int fd, void *data) +{ + struct kevent ke; + EV_SET(&ke, fd, EVFILT_READ, EV_ADD|EV_ONESHOT, + 0, 0, data); + return io_poll_start_read(pollfd,fd, data); +} + + +int io_poll_disassociate_fd(int pollfd, int fd) +{ + struct kevent ke; + EV_SET(&ke,fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); + return kevent(pollfd, &ke, 1, 0, 0, 0); +} + + +int io_poll_wait(int pollfd, struct kevent *events, int maxevents, int timeout_ms) +{ + 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:NULL); + } + while (ret == -1 && errno == EINTR); + return ret; +} + +static void* native_event_get_userdata(native_event *event) +{ + return event->udata; +} + +#elif defined (__sun) + +static int io_poll_create() +{ + return port_create(); +} + +int io_poll_start_read(int pollfd, int fd, void *data) +{ + return port_associate(pollfd, PORT_SOURCE_FD, fd, POLLIN, data); +} + +static int io_poll_associate_fd(int pollfd, int fd, void *data) +{ + return io_poll_start_read(pollfd, fd, data); +} + +int io_poll_disassociate_fd(int pollfd, int fd) +{ + return port_dissociate(pollfd, PORT_SOURCE_FD, fd); +} + +int io_poll_wait(int pollfd, native_event *events, int maxevents, int timeout_ms) +{ + struct timespec ts; + int ret; + uint_t nget= 1; + if (timeout_ms >= 0) + { + ts.tv_sec= timeout_ms/1000; + ts.tv_nsec= (timeout_ms%1000)*1000000; + } + do + { + ret= port_getn(pollfd, events, maxevents, &nget, + (timeout_ms >= 0)?&ts:NULL); + } + while (ret == -1 && errno == EINTR); + DBUG_ASSERT(nget < INT_MAX); + return (int)nget; +} + +static void* native_event_get_userdata(native_event *event) +{ + return event->portev_user; +} +#else +#error not ported yet to this OS +#endif + +/* for dump thread only */ +void tp_inc_active_thread(THD* thd, int command) +{ + DBUG_ENTER("tp_inc_active_thread"); + DBUG_ASSERT(command == COM_BINLOG_DUMP_GTID || command == COM_BINLOG_DUMP); + connection_t *connection= (connection_t *)thd->event_scheduler.data; + if (connection) + { + thread_group_t *group= connection->thread_group; + mysql_mutex_lock(&group->mutex); + group->dump_thread_count--; + group->active_thread_count++; + mysql_mutex_unlock(&group->mutex); + } + DBUG_VOID_RETURN; +} + +/* for dump thread only */ +void tp_dec_active_thread(THD* thd, int command) +{ + DBUG_ENTER("tp_dec_active_thread"); + DBUG_ASSERT(command == COM_BINLOG_DUMP_GTID || command == COM_BINLOG_DUMP); + connection_t *connection= (connection_t*)thd->event_scheduler.data; + if (connection) + { + thread_group_t *group= connection->thread_group; + mysql_mutex_lock(&group->mutex); + group->dump_thread_count++; + group->active_thread_count--; + mysql_mutex_unlock(&group->mutex); + } + DBUG_VOID_RETURN; +} + +namespace { + +/* + Prevent too many threads executing at the same time,if the workload is + not CPU bound. +*/ + +inline bool too_many_active_threads(thread_group_t *thread_group) +{ + return (thread_group->active_thread_count >= 1+(int)threadpool_oversubscribe + && !thread_group->stalled); +} + +/* + Limit the number of 'busy' threads by 1 + thread_pool_oversubscribe. 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(thread_group_t *thread_group) +{ + return (thread_group->active_thread_count + thread_group->waiting_thread_count + > 1 + (int) threadpool_oversubscribe); +} + +/* + 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. +*/ + +inline bool connection_is_high_prio(connection_t *c) +{ + const ulong mode= c->thd->variables.threadpool_high_prio_mode; + + return (mode == TP_HIGH_PRIO_MODE_STATEMENTS) || + (mode == TP_HIGH_PRIO_MODE_TRANSACTIONS && + c->tickets > 0 && thd_is_transaction_active(c->thd)) || + c->thd->mdl_context.has_explicit_locks(); +} + +} // namespace + +/* Dequeue element from a workqueue */ + +static connection_t *queue_get(thread_group_t *thread_group) +{ + 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); +} + +/* + 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"); + + mysql_mutex_lock(&LOCK_thread_count); + Thread_iterator it= global_thread_list_begin(); + Thread_iterator end= global_thread_list_end(); + + /* Reset next timeout check, it will be recalculated in the loop below */ + my_atomic_fas64((volatile int64*)&timer->next_timeout_check, ULONGLONG_MAX); + + THD *thd; + for ( ; it != end; ++it) + { + thd= (*it); + if (thd->net.reading_or_writing != 1) + continue; + + connection_t *connection= (connection_t *)thd->event_scheduler.data; + if (!connection) + { + /* + Connection does not have scheduler data. This happens for example + if THD belongs to a different scheduler, that is listening to extra_port. + */ + continue; + } + + if(connection->abs_wait_timeout < timer->current_microtime) + { + /* 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); + } + } + mysql_mutex_unlock(&LOCK_thread_count); + 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) +{ + uint i; + pool_timer_t* timer=(pool_timer_t *)param; + + my_thread_init(); + DBUG_ENTER("timer_thread"); + timer->next_timeout_check= ULONGLONG_MAX; + timer->current_microtime= microsecond_interval_timer(); + + for(;;) + { + struct timespec ts; + int err; + + set_timespec_nsec(ts,timer->tick_interval*1000000); + mysql_mutex_lock(&timer->mutex); + err= mysql_cond_timedwait(&timer->cond, &timer->mutex, &ts); + if (timer->shutdown) + { + mysql_mutex_unlock(&timer->mutex); + break; + } + if (err == ETIMEDOUT) + { + timer->current_microtime= microsecond_interval_timer(); + + /* Check stalls in thread groups */ + for(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 <= timer->current_microtime) + timeout_check(timer); + } + mysql_mutex_unlock(&timer->mutex); + } + + mysql_mutex_destroy(&timer->mutex); + my_thread_end(); + return NULL; +} + +/* + 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(thread_group_t *tg) +{ + return (tg->high_prio_queue.is_empty() && + (tg->queue.is_empty() || too_many_busy_threads(tg))); +} + +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); + mysql_mutex_unlock(&thread_group->mutex); + return; + } + + /* Reset io event count */ + thread_group->io_event_count= 0; + + /* + Check whether requests from the workqueue 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 queue. Timer resets the counter to 0 on each run. + 2. Timer determines stall if this counter remains 0 since last check + and the queue 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 queue + stalls permanently? + A : No. If queue stalls 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; + wake_or_create_thread(thread_group); + } + + /* Reset queue event count */ + thread_group->queue_event_count= 0; + + mysql_mutex_unlock(&thread_group->mutex); +} + + +static int start_timer(pool_timer_t* timer) +{ + int res= 0; + pthread_t thread_id; + DBUG_ENTER("start_timer"); + mysql_mutex_init(key_timer_mutex,&timer->mutex, NULL); + mysql_cond_init(key_timer_cond, &timer->cond, NULL); + timer->shutdown = false; + res= mysql_thread_create(key_timer_thread,&thread_id, NULL, timer_thread, timer); + if (res) + sql_print_error("Can't create timer thread for threadpool (errno= %d).", res); + DBUG_RETURN(res); +} + + +static void stop_timer(pool_timer_t *timer) +{ + 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(worker_thread_t *current_thread, + thread_group_t *thread_group) +{ + DBUG_ENTER("listener"); + connection_t *retval= NULL; + + for(;;) + { + native_event ev[MAX_EVENTS]; + int cnt; + + if (thread_group->shutdown) + break; + + cnt = io_poll_wait(thread_group->pollfd, ev, MAX_EVENTS, -1); + + if (cnt <=0) + { + DBUG_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; + thread_group->total_io_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. + */ + + bool listener_picks_event= 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= c->thd->variables.threadpool_high_prio_tickets; + thread_group->queue.push_back(c); + } + } + + if (listener_picks_event) + { + /* Handle the first event. */ + retval= (connection_t *)native_event_get_userdata(&ev[0]); + mysql_mutex_unlock(&thread_group->mutex); + break; + } + + if(thread_group->active_thread_count==0) + { + /* We added some work items to queue, now wake a worker. */ + if(wake_thread(thread_group)) + { + /* + Wake failed, hence groups has no idle threads. Now check if there are + any threads in the group except listener. + */ + if(thread_group->thread_count == 1) + { + /* + Currently there is no worker thread in the group, as indicated by + thread_count == 1 (this means listener is the only one thread in + the group). + 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); + } + } + } + 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) +{ + thread_group->thread_count += count; + /* worker starts out and end in "active" state */ + thread_group->active_thread_count += count; + my_atomic_add32(&tp_stats.num_worker_threads, count); +} + + +/** + 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) +{ + pthread_t thread_id; + bool max_threads_reached= false; + int err; + + DBUG_ENTER("create_worker"); + if (tp_stats.num_worker_threads >= (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=microsecond_interval_timer(); + thread_created++; + add_thread_count(thread_group, 1); + } + else + { + 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(thread_group_t *thread_group) +{ + 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) +{ + DBUG_ENTER("wake_or_create_thread"); + + if (thread_group->shutdown) + DBUG_RETURN(0); + + if (wake_thread(thread_group) == 0) + DBUG_RETURN(0); + + if (thread_group->thread_count > thread_group->connection_count) + DBUG_RETURN(-1); + + + if (thread_group->active_thread_count == 0) + { + /* + We're better off creating a new thread here with no delay, either there + are no workers at all, 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)); + } + + ulonglong now = microsecond_interval_timer(); + 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)); + } + + DBUG_RETURN(-1); +} + + + +int thread_group_init(thread_group_t *thread_group, pthread_attr_t* thread_attr) +{ + DBUG_ENTER("thread_group_init"); + thread_group->pthread_attr = thread_attr; + mysql_mutex_init(key_group_mutex, &thread_group->mutex, NULL); + thread_group->pollfd= -1; + thread_group->shutdown_pipe[0]= -1; + thread_group->shutdown_pipe[1]= -1; + thread_group->total_io_count= 0; + thread_group->total_queue_count= 0; + DBUG_RETURN(0); +} + + +void thread_group_destroy(thread_group_t *thread_group) +{ + 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) +{ + 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); + DBUG_RETURN(0); + } + DBUG_RETURN(1); /* no thread in waiter list => missed wakeup */ +} + + +/** + Initiate shutdown for thread group. + + The shutdown is asynchronous, we only care to wake all threads in here, so + they can finish. We do not wait here until threads terminate. Final cleanup + of the group (thread_group_destroy) will be done by the last exiting threads. +*/ + +static void thread_group_close(thread_group_t *thread_group) +{ + 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= NULL; + + if (pipe(thread_group->shutdown_pipe)) + { + DBUG_VOID_RETURN; + } + + /* Wake listener */ + if (io_poll_associate_fd(thread_group->pollfd, + thread_group->shutdown_pipe[0], NULL)) + { + DBUG_VOID_RETURN; + } + char c= 0; + if (write(thread_group->shutdown_pipe[1], &c, 1) < 0) + DBUG_VOID_RETURN; + + /* Wake all workers. */ + while(wake_thread(thread_group) == 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= connection->thd->variables.threadpool_high_prio_tickets; + thread_group->queue.push_back(connection); + + if (thread_group->active_thread_count == 0) + wake_or_create_thread(thread_group); + + 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 NULL. + + @param current_thread - current worker thread + @param thread_group - current thread group + @param abstime - absolute wait timeout + + @return + connection with pending event. + NULL is returned if timeout has expired,or on shutdown. +*/ + +connection_t *get_event(worker_thread_t *current_thread, + thread_group_t *thread_group, struct timespec *abstime) +{ + DBUG_ENTER("get_event"); + connection_t *connection = NULL; + int err=0; + + mysql_mutex_lock(&thread_group->mutex); + DBUG_ASSERT(thread_group->active_thread_count >= 0); + + for(;;) + { + 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); + 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(current_thread, thread_group); + + mysql_mutex_lock(&thread_group->mutex); + thread_group->active_thread_count++; + /* There is no listener anymore, it just returned. */ + thread_group->listener= NULL; + 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++; + thread_group->total_io_count++; + 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= + connection->thd->variables.threadpool_high_prio_tickets; + thread_group->queue.push_back(connection); + connection= NULL; + } + + if (connection) + { + 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. +*/ + +void wait_begin(thread_group_t *thread_group) +{ + DBUG_ENTER("wait_begin"); + mysql_mutex_lock(&thread_group->mutex); + thread_group->active_thread_count--; + thread_group->waiting_thread_count++; + + DBUG_ASSERT(thread_group->active_thread_count >=0); + DBUG_ASSERT(thread_group->connection_count > 0); + +#ifdef THREADPOOL_CREATE_THREADS_ON_WAIT + if ((thread_group->active_thread_count == 0) && + (!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. +*/ + +void wait_end(thread_group_t *thread_group) +{ + 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. +*/ + +connection_t *alloc_connection(THD *thd) +{ + DBUG_ENTER("alloc_connection"); + + connection_t* connection = (connection_t *)my_malloc(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= ULONGLONG_MAX; + connection->tickets= 0; + } + DBUG_RETURN(connection); +} + +void get_thread_group_info(thread_group_info* thread_groups, int group_count) +{ + for (int i = 0; i < group_count; i++) + { + mysql_mutex_lock(&all_groups[i].mutex); + thread_groups[i].group_id= i; + thread_groups[i].thread_count= all_groups[i].thread_count; + thread_groups[i].active_thread_count= all_groups[i].active_thread_count; + thread_groups[i].connection_count= all_groups[i].connection_count; + thread_groups[i].waiting_thread_count= all_groups[i].waiting_thread_count; + thread_groups[i].dump_thread_count= all_groups[i].dump_thread_count; + thread_groups[i].low_queue_count= all_groups[i].queue.elements(); + thread_groups[i].high_queue_count= all_groups[i].high_prio_queue.elements(); + mysql_mutex_unlock(&all_groups[i].mutex); + } +} + +/** + Add a new connection to thread pool.. +*/ + +void tp_add_connection(THD *thd) +{ + DBUG_ENTER("tp_add_connection"); + + add_global_thread(thd); + mysql_mutex_unlock(&LOCK_thread_count); + connection_t *connection= alloc_connection(thd); + if (connection) + { + thd->event_scheduler.data= connection; + + /* Assign connection to a group. */ + thread_group_t *group= + &all_groups[thd->thread_id%group_count]; + + connection->thread_group=group; + + mysql_mutex_lock(&group->mutex); + group->connection_count++; + mysql_mutex_unlock(&group->mutex); + + /* + Add connection to the work queue.Actual logon + will be done by a worker thread. + */ + queue_put(group, connection); + } + else + { + /* Allocation failed */ + threadpool_remove_connection(thd); + } + DBUG_VOID_RETURN; +} + + +/** + Terminate connection. +*/ + +static void connection_abort(connection_t *connection) +{ + DBUG_ENTER("connection_abort"); + thread_group_t *group= connection->thread_group; + + threadpool_remove_connection(connection->thd); + + mysql_mutex_lock(&group->mutex); + group->connection_count--; + mysql_mutex_unlock(&group->mutex); + + my_free(connection); + DBUG_VOID_RETURN; +} + + +/** + MySQL scheduler callback : kill connection +*/ + +void tp_post_kill_notification(THD *thd) +{ + DBUG_ENTER("tp_post_kill_notification"); + if (current_thd == thd || thd->system_thread) + DBUG_VOID_RETURN; + + if (thd->net.vio) + vio_cancel(thd->net.vio, SHUT_RD); + DBUG_VOID_RETURN; +} + +/** + MySQL scheduler callback: wait begin +*/ + +void tp_wait_begin(THD *thd, int type) +{ + DBUG_ENTER("tp_wait_begin"); + DBUG_ASSERT(thd); + DBUG_ASSERT(!(thd->get_command() == COM_BINLOG_DUMP_GTID || + thd->get_command() == COM_BINLOG_DUMP)); + connection_t *connection = (connection_t *)thd->event_scheduler.data; + if (connection) + { + DBUG_ASSERT(!connection->waiting); + connection->waiting= true; + wait_begin(connection->thread_group); + } + DBUG_VOID_RETURN; +} + + +/** + MySQL scheduler callback: wait end +*/ + +void tp_wait_end(THD *thd) +{ + DBUG_ENTER("tp_wait_end"); + DBUG_ASSERT(thd); + + connection_t *connection = (connection_t *)thd->event_scheduler.data; + if (connection) + { + DBUG_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) + { + longlong old= (longlong)pool_timer.next_timeout_check; + my_atomic_cas64((volatile int64*)&pool_timer.next_timeout_check, + &old, abstime); + } + DBUG_VOID_RETURN; +} + + +/** + Set wait timeout for connection. +*/ + +static void set_wait_timeout(connection_t *c) +{ + ulong strict_trx_idle_timeout= 0; + DBUG_ENTER("set_wait_timeout"); + /* + Calculate wait deadline for this connection. + Instead of using microsecond_interval_timer() 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. + */ + + if (strict_trx_idle_timeout && thd_is_transaction_active(c->thd)) + c->abs_wait_timeout= pool_timer.current_microtime + + 1000LL*pool_timer.tick_interval + + 1000000LL * strict_trx_idle_timeout; + else + c->abs_wait_timeout= pool_timer.current_microtime + + 1000LL*pool_timer.tick_interval + + 1000000LL*c->thd->variables.net_wait_timeout; + + 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) +{ + int ret= 0; + int fd = mysql_socket_getfd(c->thd->net.vio->mysql_socket); + + DBUG_ASSERT(c->thread_group == old_group); + + /* Remove connection from the old group. */ + mysql_mutex_lock(&old_group->mutex); + if (c->bound_to_poll_descriptor) + { + io_poll_disassociate_fd(old_group->pollfd,fd); + c->bound_to_poll_descriptor= false; + } + 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. */ + if (!new_group->thread_count) + ret= create_worker(new_group); + mysql_mutex_unlock(&new_group->mutex); + return ret; +} + + +static int start_io(connection_t *connection) +{ + int fd = mysql_socket_getfd(connection->thd->net.vio->mysql_socket); + /* + 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 *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. + */ + 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; + + 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; + + set_wait_timeout(connection); + err= start_io(connection); + +end: + if (err) + connection_abort(connection); + + DBUG_VOID_RETURN; +} + + + +/** + Worker thread's main +*/ + +static void *worker_main(void *param) +{ + + worker_thread_t this_thread; + pthread_detach_this_thread(); + my_thread_init(); + + DBUG_ENTER("worker_main"); + + thread_group_t *thread_group = (thread_group_t *)param; + + /* Init per-thread structure */ + mysql_cond_init(key_worker_cond, &this_thread.cond, NULL); + this_thread.thread_group= thread_group; + this_thread.event_count=0; + + /* Run event loop */ + for(;;) + { + connection_t *connection; + struct timespec ts; + set_timespec(ts,threadpool_idle_timeout); + connection = get_event(&this_thread, thread_group, &ts); + if (!connection) + break; + + thread_group->total_queue_count++; + this_thread.event_count++; + handle_event(connection); + } + + /* Thread shutdown: cleanup per-worker-thread structure. */ + mysql_cond_destroy(&this_thread.cond); + + bool last_thread; /* 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 NULL; +} + + +bool tp_init() +{ + DBUG_ENTER("tp_init"); + threadpool_started= true; + scheduler_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(1); + } +#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE + PSI_register(mutex); + PSI_register(cond); + PSI_register(thread); +#endif + pool_timer.tick_interval= threadpool_stall_limit; + DBUG_RETURN(start_timer(&pool_timer)? 1: 0); +} + + +void tp_end() +{ + DBUG_ENTER("tp_end"); + + if (!threadpool_started) + DBUG_VOID_RETURN; + + stop_timer(&pool_timer); + for(uint i=0; i< array_elements(all_groups); i++) + { + thread_group_close(&all_groups[i]); + } + threadpool_started= false; + DBUG_VOID_RETURN; +} + + +/** Ensure that poll descriptors are created when threadpool_size changes */ + +void tp_set_threadpool_size(uint size) +{ + bool success= true; + if (!threadpool_started) + return; + + 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) +{ + 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() +{ + 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 'extra_port' parameter is set, you can still connect to the database with \ +superuser account (it must be TCP connection using extra_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) +{ + ulonglong now; + static bool msg_written; + + now= microsecond_interval_timer(); + if (pool_block_start == 0) + { + pool_block_start= now; + msg_written = false; + return; + } + + if (now > pool_block_start + BLOCK_MSG_DELAY && !msg_written) + { + if (max_threads_reached) + sql_print_error(MAX_THREADS_REACHED_MSG); + else + sql_print_error(CREATE_THREAD_ERROR_MSG, my_errno); + + 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/sql/threadpool_win.cc b/sql/threadpool_win.cc new file mode 100644 index 00000000000..1dbadcff39d --- /dev/null +++ b/sql/threadpool_win.cc @@ -0,0 +1,763 @@ +/* Copyright (C) 2012 Monty Program Ab + + 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 */ + +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif + +#define _WIN32_WINNT 0x0601 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* + Threadpool API is not available on XP. We still want to compile a single + version on Windows, but use the latest functionality if available. + We cannot use threadpool functionality directly, since executable won't + start on XP and loader will complain about missing symbols. + + We solve using the usual way it is done on Windows, i.e with dynamic loading. + We'll need to load a lot of function, and make this less painful with the + WEAK_SYMBOL macro below +*/ + +/* + WEAK_SYMBOL(return_type, function_name, argument_type1,..,argument_typeN) + + Declare and load function pointer from kernel32. The name of the static + variable that holds the function pointer is my_ + This should be combined with + #define my_ + so that one could use Widows APIs transparently, without worrying whether + they are present in a particular version or not. + + Of course, prior to use of any function there should be a check for correct + Windows version, or check whether function pointer is not NULL. +*/ +#define WEAK_SYMBOL(return_type, function, ...) \ + typedef return_type (WINAPI *pFN_##function)(__VA_ARGS__); \ + static pFN_##function my_##function = (pFN_##function) \ + (GetProcAddress(GetModuleHandle("kernel32"),#function)) + +WEAK_SYMBOL(VOID, CancelThreadpoolIo, PTP_IO); +#define CancelThreadpoolIo my_CancelThreadpoolIo + +WEAK_SYMBOL(VOID, CloseThreadpool, PTP_POOL); +#define CloseThreadpool my_CloseThreadpool + +WEAK_SYMBOL(VOID, CloseThreadpoolIo, PTP_IO); +#define CloseThreadpoolIo my_CloseThreadpoolIo + +WEAK_SYMBOL(VOID, CloseThreadpoolTimer,PTP_TIMER); +#define CloseThreadpoolTimer my_CloseThreadpoolTimer + +WEAK_SYMBOL(VOID, CloseThreadpoolWait,PTP_WAIT); +#define CloseThreadpoolWait my_CloseThreadpoolWait + +WEAK_SYMBOL(PTP_POOL, CreateThreadpool,PVOID); +#define CreateThreadpool my_CreateThreadpool + +WEAK_SYMBOL(PTP_IO, CreateThreadpoolIo, HANDLE, PTP_WIN32_IO_CALLBACK, PVOID , + PTP_CALLBACK_ENVIRON); +#define CreateThreadpoolIo my_CreateThreadpoolIo + +WEAK_SYMBOL(PTP_TIMER, CreateThreadpoolTimer, PTP_TIMER_CALLBACK , + PVOID pv, PTP_CALLBACK_ENVIRON pcbe); +#define CreateThreadpoolTimer my_CreateThreadpoolTimer + +WEAK_SYMBOL(PTP_WAIT, CreateThreadpoolWait, PTP_WAIT_CALLBACK, PVOID, + PTP_CALLBACK_ENVIRON); +#define CreateThreadpoolWait my_CreateThreadpoolWait + +WEAK_SYMBOL(VOID, DisassociateCurrentThreadFromCallback, PTP_CALLBACK_INSTANCE); +#define DisassociateCurrentThreadFromCallback my_DisassociateCurrentThreadFromCallback + +WEAK_SYMBOL(DWORD, FlsAlloc, PFLS_CALLBACK_FUNCTION); +#define FlsAlloc my_FlsAlloc + +WEAK_SYMBOL(PVOID, FlsGetValue, DWORD); +#define FlsGetValue my_FlsGetValue + +WEAK_SYMBOL(BOOL, FlsSetValue, DWORD, PVOID); +#define FlsSetValue my_FlsSetValue + +WEAK_SYMBOL(VOID, SetThreadpoolThreadMaximum, PTP_POOL, DWORD); +#define SetThreadpoolThreadMaximum my_SetThreadpoolThreadMaximum + +WEAK_SYMBOL(BOOL, SetThreadpoolThreadMinimum, PTP_POOL, DWORD); +#define SetThreadpoolThreadMinimum my_SetThreadpoolThreadMinimum + +WEAK_SYMBOL(VOID, SetThreadpoolTimer, PTP_TIMER, PFILETIME,DWORD,DWORD); +#define SetThreadpoolTimer my_SetThreadpoolTimer + +WEAK_SYMBOL(VOID, SetThreadpoolWait, PTP_WAIT,HANDLE,PFILETIME); +#define SetThreadpoolWait my_SetThreadpoolWait + +WEAK_SYMBOL(VOID, StartThreadpoolIo, PTP_IO); +#define StartThreadpoolIo my_StartThreadpoolIo + +WEAK_SYMBOL(VOID, WaitForThreadpoolIoCallbacks,PTP_IO, BOOL); +#define WaitForThreadpoolIoCallbacks my_WaitForThreadpoolIoCallbacks + +WEAK_SYMBOL(VOID, WaitForThreadpoolTimerCallbacks, PTP_TIMER, BOOL); +#define WaitForThreadpoolTimerCallbacks my_WaitForThreadpoolTimerCallbacks + +WEAK_SYMBOL(VOID, WaitForThreadpoolWaitCallbacks, PTP_WAIT, BOOL); +#define WaitForThreadpoolWaitCallbacks my_WaitForThreadpoolWaitCallbacks + +WEAK_SYMBOL(BOOL, SetFileCompletionNotificationModes, HANDLE, UCHAR); +#define SetFileCompletionNotificationModes my_SetFileCompletionNotificationModes + +WEAK_SYMBOL(BOOL, TrySubmitThreadpoolCallback, PTP_SIMPLE_CALLBACK pfns, + PVOID pv,PTP_CALLBACK_ENVIRON pcbe); +#define TrySubmitThreadpoolCallback my_TrySubmitThreadpoolCallback + +WEAK_SYMBOL(PTP_WORK, CreateThreadpoolWork, PTP_WORK_CALLBACK pfnwk, PVOID pv, + PTP_CALLBACK_ENVIRON pcbe); +#define CreateThreadpoolWork my_CreateThreadpoolWork + +WEAK_SYMBOL(VOID, SubmitThreadpoolWork,PTP_WORK pwk); +#define SubmitThreadpoolWork my_SubmitThreadpoolWork + +WEAK_SYMBOL(VOID, CloseThreadpoolWork, PTP_WORK pwk); +#define CloseThreadpoolWork my_CloseThreadpoolWork + +WEAK_SYMBOL(BOOL, CallbackMayRunLong, PTP_CALLBACK_INSTANCE pci); +#define CallbackMayRunLong my_CallbackMayRunLong + +#if _MSC_VER >= 1600 +/* Stack size manipulation available only on Win7+ /declarations in VS10 */ +WEAK_SYMBOL(BOOL, SetThreadpoolStackInformation, PTP_POOL, + PTP_POOL_STACK_INFORMATION); +#define SetThreadpoolStackInformation my_SetThreadpoolStackInformation +#else /* _MSC_VER < 1600 */ +#define SetThreadpoolCallbackPriority(env,prio) +typedef enum _TP_CALLBACK_PRIORITY { + TP_CALLBACK_PRIORITY_HIGH, + TP_CALLBACK_PRIORITY_NORMAL, + TP_CALLBACK_PRIORITY_LOW, + TP_CALLBACK_PRIORITY_INVALID +} TP_CALLBACK_PRIORITY; +#endif + + +/* Log a warning */ +static void tp_log_warning(const char *msg, const char *fct) +{ + sql_print_warning("Threadpool: %s. %s failed (last error %d)",msg, fct, + GetLastError()); +} + + +PTP_POOL pool; +DWORD fls; + +static bool skip_completion_port_on_success = false; + +/* + Threadpool callbacks. + + io_completion_callback - handle client request + timer_callback - handle wait timeout (kill connection) + shm_read_callback, shm_close_callback - shared memory stuff + login_callback - user login (submitted as threadpool work) + +*/ + +static void CALLBACK timer_callback(PTP_CALLBACK_INSTANCE instance, + PVOID context, PTP_TIMER timer); + +static void CALLBACK io_completion_callback(PTP_CALLBACK_INSTANCE instance, + PVOID context, PVOID overlapped, ULONG io_result, ULONG_PTR nbytes, PTP_IO io); + +static void CALLBACK shm_read_callback(PTP_CALLBACK_INSTANCE instance, + PVOID Context, PTP_WAIT wait,TP_WAIT_RESULT wait_result); + +static void CALLBACK shm_close_callback(PTP_CALLBACK_INSTANCE instance, + PVOID Context, PTP_WAIT wait,TP_WAIT_RESULT wait_result); + +static void check_thread_init(); + +/* Get current time as Windows time */ +static ulonglong now() +{ + ulonglong current_time; + GetSystemTimeAsFileTime((PFILETIME)¤t_time); + return current_time; +} + +/* + Connection structure, encapsulates THD + structures for asynchronous + IO and pool. +*/ + +struct connection_t +{ + THD *thd; + HANDLE handle; + OVERLAPPED overlapped; + /* absolute time for wait timeout (as Windows time) */ + volatile ulonglong timeout; + TP_CALLBACK_ENVIRON callback_environ; + PTP_IO io; + PTP_TIMER timer; + PTP_WAIT shm_read; + /* Callback instance, used to inform treadpool about long callbacks */ + PTP_CALLBACK_INSTANCE callback_instance; + bool logged_in; +}; + + +void init_connection(connection_t *connection) +{ + connection->logged_in = false; + connection->handle= 0; + connection->io= 0; + connection->shm_read= 0; + connection->timer= 0; + connection->logged_in = false; + connection->timeout= ULONGLONG_MAX; + connection->callback_instance= 0; + memset(&connection->overlapped, 0, sizeof(OVERLAPPED)); + InitializeThreadpoolEnvironment(&connection->callback_environ); + SetThreadpoolCallbackPool(&connection->callback_environ, pool); + connection->thd = 0; +} + + +int init_io(connection_t *connection, THD *thd) +{ + connection->thd= thd; + Vio *vio = thd->net.vio; + switch(vio->type) + { + case VIO_TYPE_SSL: + case VIO_TYPE_TCPIP: + connection->handle= (HANDLE)vio->sd; + break; + case VIO_TYPE_NAMEDPIPE: + connection->handle= (HANDLE)vio->hPipe; + break; + case VIO_TYPE_SHARED_MEMORY: + connection->shm_read= CreateThreadpoolWait(shm_read_callback, connection, + &connection->callback_environ); + if (!connection->shm_read) + { + tp_log_warning("Allocation failed", "CreateThreadpoolWait"); + return -1; + } + break; + default: + abort(); + } + + if (connection->handle) + { + /* Performance tweaks (s. MSDN documentation)*/ + UCHAR flags= FILE_SKIP_SET_EVENT_ON_HANDLE; + if (skip_completion_port_on_success) + { + flags |= FILE_SKIP_COMPLETION_PORT_ON_SUCCESS; + } + (void)SetFileCompletionNotificationModes(connection->handle, flags); + + /* Assign io completion callback */ + connection->io= CreateThreadpoolIo(connection->handle, + io_completion_callback, connection, &connection->callback_environ); + if(!connection->io) + { + tp_log_warning("Allocation failed", "CreateThreadpoolWait"); + return -1; + } + } + connection->timer= CreateThreadpoolTimer(timer_callback, connection, + &connection->callback_environ); + if (!connection->timer) + { + tp_log_warning("Allocation failed", "CreateThreadpoolWait"); + return -1; + } + + return 0; +} + + +/* + Start asynchronous read +*/ +int start_io(connection_t *connection, PTP_CALLBACK_INSTANCE instance) +{ + /* Start async read */ + DWORD num_bytes = 0; + static char c; + WSABUF buf; + buf.buf= &c; + buf.len= 0; + DWORD flags=0; + DWORD last_error= 0; + + int retval; + Vio *vio= connection->thd->net.vio; + + if (vio->type == VIO_TYPE_SHARED_MEMORY) + { + SetThreadpoolWait(connection->shm_read, vio->event_server_wrote, NULL); + return 0; + } + if (vio->type == VIO_CLOSED) + { + return -1; + } + + DBUG_ASSERT(vio->type == VIO_TYPE_TCPIP || + vio->type == VIO_TYPE_SSL || + vio->type == VIO_TYPE_NAMEDPIPE); + + OVERLAPPED *overlapped= &connection->overlapped; + PTP_IO io= connection->io; + StartThreadpoolIo(io); + + if (vio->type == VIO_TYPE_TCPIP || vio->type == VIO_TYPE_SSL) + { + /* Start async io (sockets). */ + if (WSARecv(vio->sd , &buf, 1, &num_bytes, &flags, + overlapped, NULL) == 0) + { + retval= last_error= 0; + } + else + { + retval= -1; + last_error= WSAGetLastError(); + } + } + else + { + /* Start async io (named pipe) */ + if (ReadFile(vio->hPipe, &c, 0, &num_bytes ,overlapped)) + { + retval= last_error= 0; + } + else + { + retval= -1; + last_error= GetLastError(); + } + } + + if (retval == 0 || last_error == ERROR_MORE_DATA) + { + /* + IO successfully finished (synchronously). + If skip_completion_port_on_success is set, we need to handle it right + here, because completion callback would not be executed by the pool. + */ + if(skip_completion_port_on_success) + { + CancelThreadpoolIo(io); + io_completion_callback(instance, connection, overlapped, last_error, + num_bytes, io); + } + return 0; + } + + if(last_error == ERROR_IO_PENDING) + { + return 0; + } + + /* Some error occured */ + CancelThreadpoolIo(io); + return -1; +} + + +int login(connection_t *connection, PTP_CALLBACK_INSTANCE instance) +{ + if (threadpool_add_connection(connection->thd) == 0 + && init_io(connection, connection->thd) == 0 + && start_io(connection, instance) == 0) + { + return 0; + } + return -1; +} + +/* + Recalculate wait timeout, maybe reset timer. +*/ +void set_wait_timeout(connection_t *connection, ulonglong old_timeout) +{ + ulonglong new_timeout = now() + + 10000000LL*connection->thd->variables.net_wait_timeout; + + if (new_timeout < old_timeout) + { + SetThreadpoolTimer(connection->timer, (PFILETIME) &new_timeout, 0, 1000); + } + connection->timeout = new_timeout; +} + + +/* Connection destructor */ +void destroy_connection(connection_t *connection, PTP_CALLBACK_INSTANCE instance) +{ + if (instance) + DisassociateCurrentThreadFromCallback(instance); + if (connection->io) + { + WaitForThreadpoolIoCallbacks(connection->io, TRUE); + CloseThreadpoolIo(connection->io); + } + + if(connection->shm_read) + { + WaitForThreadpoolWaitCallbacks(connection->shm_read, TRUE); + CloseThreadpoolWait(connection->shm_read); + } + + if(connection->timer) + { + SetThreadpoolTimer(connection->timer, 0, 0, 0); + WaitForThreadpoolTimerCallbacks(connection->timer, TRUE); + CloseThreadpoolTimer(connection->timer); + } + + if (connection->thd) + { + threadpool_remove_connection(connection->thd); + } + + DestroyThreadpoolEnvironment(&connection->callback_environ); +} + + + +/* + This function should be called first whenever a callback is invoked in the + threadpool, does my_thread_init() if not yet done +*/ +extern ulong thread_created; +static void check_thread_init() +{ + if (FlsGetValue(fls) == NULL) + { + FlsSetValue(fls, (void *)1); + thread_created++; + InterlockedIncrement((volatile long *)&tp_stats.num_worker_threads); + } +} + + +/* + Decrement number of threads when a thread exits . + On Windows, FlsAlloc() provides the thread destruction callbacks. +*/ +static VOID WINAPI thread_destructor(void *data) +{ + if(data) + { + InterlockedDecrement((volatile long *)&tp_stats.num_worker_threads); + } +} + + +/* Scheduler callback : init */ +bool tp_init(void) +{ + fls= FlsAlloc(thread_destructor); + pool= CreateThreadpool(NULL); + if(!pool) + { + sql_print_error("Can't create threadpool. " + "CreateThreadpool() failed with %d. Likely cause is memory pressure", + GetLastError()); + exit(1); + } + + if (threadpool_max_threads) + { + SetThreadpoolThreadMaximum(pool,threadpool_max_threads); + } + + if (threadpool_min_threads) + { + if (!SetThreadpoolThreadMinimum(pool, threadpool_min_threads)) + { + tp_log_warning( "Can't set threadpool minimum threads", + "SetThreadpoolThreadMinimum"); + } + } + + /* + Control stack size (OS must be Win7 or later, plus corresponding SDK) + */ +#if _MSC_VER >=1600 + if (SetThreadpoolStackInformation) + { + TP_POOL_STACK_INFORMATION stackinfo; + stackinfo.StackCommit = 0; + stackinfo.StackReserve = (SIZE_T)my_thread_stack_size; + if (!SetThreadpoolStackInformation(pool, &stackinfo)) + { + tp_log_warning("Can't set threadpool stack size", + "SetThreadpoolStackInformation"); + } + } +#endif + + return 0; +} + + +/** + Scheduler callback : Destroy the scheduler. +*/ +void tp_end(void) +{ + if(pool) + { + SetThreadpoolThreadMaximum(pool, 0); + CloseThreadpool(pool); + } +} + +/** + Notify pool about connection being killed. +*/ +void tp_post_kill_notification(THD *thd) +{ + if (current_thd == thd) + return; /* There is nothing to do.*/ + + if (thd->system_thread) + return; /* Will crash if we attempt to kill system thread. */ + + Vio *vio= thd->net.vio; + + vio_shutdown(vio, SD_BOTH); + +} + +/* + Handle read completion/notification. +*/ +static VOID CALLBACK io_completion_callback(PTP_CALLBACK_INSTANCE instance, + PVOID context, PVOID overlapped, ULONG io_result, ULONG_PTR nbytes, PTP_IO io) +{ + if(instance) + { + check_thread_init(); + } + + connection_t *connection = (connection_t*)context; + + if (io_result != ERROR_SUCCESS) + goto error; + + THD *thd= connection->thd; + ulonglong old_timeout = connection->timeout; + connection->timeout = ULONGLONG_MAX; + connection->callback_instance= instance; + if (threadpool_process_request(connection->thd)) + goto error; + + set_wait_timeout(connection, old_timeout); + if(start_io(connection, instance)) + goto error; + + return; + +error: + /* Some error has occured. */ + + destroy_connection(connection, instance); + free(connection); +} + + +/* Simple callback for login */ +static void CALLBACK login_callback(PTP_CALLBACK_INSTANCE instance, + PVOID context, PTP_WORK work) +{ + if(instance) + { + check_thread_init(); + } + + connection_t *connection =(connection_t *)context; + if (login(connection, instance) != 0) + { + destroy_connection(connection, instance); + free(connection); + } +} + +/* + Timer callback. + Invoked when connection times out (wait_timeout) +*/ +static VOID CALLBACK timer_callback(PTP_CALLBACK_INSTANCE instance, + PVOID parameter, PTP_TIMER timer) +{ + check_thread_init(); + + connection_t *con= (connection_t*)parameter; + ulonglong timeout= con->timeout; + + if (timeout <= now()) + { + con->thd->killed = KILL_CONNECTION; + if(con->thd->net.vio) + vio_shutdown(con->thd->net.vio, SD_BOTH); + } + else if(timeout != ULONGLONG_MAX) + { + /* + Reset timer. + There is a tiny possibility of a race condition, since the value of timeout + could have changed to smaller value in the thread doing io callback. + + Given the relative unimportance of the wait timeout, we accept race + condition. + */ + SetThreadpoolTimer(timer, (PFILETIME)&timeout, 0, 1000); + } +} + + +/* + Shared memory read callback. + Invoked when read event is set on connection. +*/ +static void CALLBACK shm_read_callback(PTP_CALLBACK_INSTANCE instance, + PVOID context, PTP_WAIT wait,TP_WAIT_RESULT wait_result) +{ + connection_t *con= (connection_t *)context; + /* Disarm wait. */ + SetThreadpoolWait(wait, NULL, NULL); + + /* + This is an autoreset event, and one wakeup is eaten already by threadpool, + and the current state is "not set". Thus we need to reset the event again, + or vio_read will hang. + */ + HANDLE h = con->thd->net.vio->event_server_wrote; + SetEvent(h); + io_completion_callback(instance, context, NULL, 0, 0 , 0); +} + + +/* + Notify the thread pool about a new connection. + NOTE: LOCK_thread_count is locked on entry. This function must unlock it. +*/ +void tp_add_connection(THD *thd) +{ + threads.append(thd); + mysql_mutex_unlock(&LOCK_thread_count); + + connection_t *con = (connection_t *)malloc(sizeof(connection_t)); + if(!con) + { + tp_log_warning("Allocation failed", "tp_add_connection"); + threadpool_remove_connection(thd); + return; + } + + init_connection(con); + con->thd= thd; + thd->event_scheduler.data= con; + + /* Try to login asynchronously, using threads in the pool */ + PTP_WORK wrk = CreateThreadpoolWork(login_callback,con, &con->callback_environ); + if (wrk) + { + SubmitThreadpoolWork(wrk); + CloseThreadpoolWork(wrk); + } + else + { + /* Likely memory pressure */ + login_callback(NULL, con, NULL); /* deletes connection if something goes wrong */ + } +} + + +/** + Sets the number of idle threads the thread pool maintains in anticipation of new + requests. +*/ +void tp_set_min_threads(uint val) +{ + if (pool) + SetThreadpoolThreadMinimum(pool, val); +} + +void tp_set_max_threads(uint val) +{ + if (pool) + SetThreadpoolThreadMaximum(pool, val); +} + +void tp_wait_begin(THD *thd, int type) +{ + DBUG_ASSERT(thd); + + /* + Signal to the threadpool whenever callback can run long. Currently, binlog + waits are a good candidate, its waits are really long + */ + if (type == THD_WAIT_BINLOG) + { + connection_t *connection= (connection_t *)thd->event_scheduler.data; + if(connection && connection->callback_instance) + { + CallbackMayRunLong(connection->callback_instance); + /* + Reset instance, to avoid calling CallbackMayRunLong twice within + the same callback (it is an error according to docs). + */ + connection->callback_instance= 0; + } + } +} + +void tp_wait_end(THD *thd) +{ + /* Do we need to do anything ? */ +} + + +/** + Number of idle threads in pool. + This info is not available in Windows implementation, + thus function always returns 0. +*/ +int tp_get_idle_thread_count() +{ + return 0; +} + diff --git a/vio/vio.c b/vio/vio.c index 1381b30b113..6e1715ed788 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -51,6 +51,14 @@ static my_bool has_no_data(Vio *vio MY_ATTRIBUTE((unused))) return FALSE; } +#ifdef _WIN32 +my_bool vio_shared_memory_has_data(Vio *vio) +{ + return (vio->shared_memory_remain > 0); +} + +#endif + /* * Helper to fill most of the Vio* with defaults. */ @@ -85,6 +93,7 @@ static void vio_init(Vio *vio, enum enum_vio_type type, vio->should_retry =vio_should_retry; vio->was_timeout =vio_was_timeout; vio->vioshutdown =vio_shutdown_pipe; + vio->viocancel =vio_cancel_pipe; vio->peer_addr =vio_peer_addr; vio->io_wait =no_io_wait; vio->is_connected =vio_is_connected_pipe; @@ -104,10 +113,11 @@ static void vio_init(Vio *vio, enum enum_vio_type type, vio->should_retry =vio_should_retry; vio->was_timeout =vio_was_timeout; vio->vioshutdown =vio_shutdown_shared_memory; + vio->viocancel =vio_cancel_shared_memory; vio->peer_addr =vio_peer_addr; vio->io_wait =no_io_wait; vio->is_connected =vio_is_connected_shared_memory; - vio->has_data =has_no_data; + vio->has_data =vio_shared_memory_has_data; DBUG_VOID_RETURN; } #endif @@ -123,6 +133,7 @@ static void vio_init(Vio *vio, enum enum_vio_type type, vio->should_retry =vio_should_retry; vio->was_timeout =vio_was_timeout; vio->vioshutdown =vio_ssl_shutdown; + vio->viocancel =vio_cancel; vio->peer_addr =vio_peer_addr; vio->io_wait =vio_io_wait; vio->is_connected =vio_is_connected; @@ -140,6 +151,7 @@ static void vio_init(Vio *vio, enum enum_vio_type type, vio->should_retry =vio_should_retry; vio->was_timeout =vio_was_timeout; vio->vioshutdown =vio_shutdown; + vio->viocancel =vio_cancel; vio->peer_addr =vio_peer_addr; vio->io_wait =vio_io_wait; vio->is_connected =vio_is_connected; diff --git a/vio/vio_priv.h b/vio/vio_priv.h index 51f68ee95c9..6016dcaec81 100644 --- a/vio/vio_priv.h +++ b/vio/vio_priv.h @@ -30,6 +30,7 @@ size_t vio_read_pipe(Vio *vio, uchar * buf, size_t size); size_t vio_write_pipe(Vio *vio, const uchar * buf, size_t size); my_bool vio_is_connected_pipe(Vio *vio); int vio_shutdown_pipe(Vio * vio); +int vio_cancel_pipe(Vio * vio, int how); #endif #ifdef HAVE_SMEM @@ -38,6 +39,7 @@ size_t vio_write_shared_memory(Vio *vio, const uchar * buf, size_t size); my_bool vio_is_connected_shared_memory(Vio *vio); int vio_shutdown_shared_memory(Vio * vio); void vio_delete_shared_memory(Vio *vio); +int vio_cancel_shared_memory(Vio * vio, int how); #endif my_bool vio_buff_has_data(Vio *vio); diff --git a/vio/viopipe.c b/vio/viopipe.c index ad94814023b..eea59e452b1 100644 --- a/vio/viopipe.c +++ b/vio/viopipe.c @@ -118,5 +118,17 @@ int vio_shutdown_pipe(Vio *vio) DBUG_RETURN(ret); } +int vio_cancel_pipe(Vio *vio, int how) +{ + DBUG_ENTER("vio_cancel_pipe"); + + CancelIo(vio->hPipe); + CloseHandle(vio->overlapped.hEvent); + DisconnectNamedPipe(vio->hPipe); + + vio->inactive= TRUE; + DBUG_RETURN(0); +} + #endif diff --git a/vio/vioshm.c b/vio/vioshm.c index 48fca38f590..0b7e0d30aae 100644 --- a/vio/vioshm.c +++ b/vio/vioshm.c @@ -222,5 +222,21 @@ int vio_shutdown_shared_memory(Vio * vio) DBUG_RETURN(0); } +int vio_cancel_shared_memory(Vio * vio, int how) +{ + DBUG_ENTER("vio_cancel_shared_memory"); + if (vio->inactive == FALSE) + { + /* + Set event_conn_closed for notification of both client and server that + connection is closed + */ + SetEvent(vio->event_conn_closed); + } + + vio->inactive= TRUE; + DBUG_RETURN(0); +} + #endif /* #if defined(_WIN32) && defined(HAVE_SMEM) */ diff --git a/vio/viosocket.c b/vio/viosocket.c index 48998fab53b..0e5fa7e3720 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -29,6 +29,36 @@ # include #endif +/* Network io wait callbacks for threadpool */ +static void (*before_io_wait)(void)= 0; +static void (*after_io_wait)(void)= 0; + +/* Wait callback macros (both performance schema and threadpool */ +#define START_SOCKET_WAIT(locker, state_ptr, sock, which, timeout) \ +do \ +{ \ + MYSQL_START_SOCKET_WAIT(locker, state_ptr, sock, \ + which, 0); \ + if (timeout && before_io_wait) \ + before_io_wait(); \ +} while(0) + +#define END_SOCKET_WAIT(locker, timeout) \ +do \ +{ \ + MYSQL_END_SOCKET_WAIT(locker, 0); \ + if (timeout && after_io_wait) \ + after_io_wait(); \ +} while(0) + +void vio_set_wait_callback(void (*before_wait)(void), + void (*after_wait)(void)) +{ + before_io_wait= before_wait; + after_io_wait= after_wait; +} + + int vio_errno(Vio *vio MY_ATTRIBUTE((unused))) { /* These transport types are not Winsock based. */ @@ -205,6 +235,48 @@ size_t vio_write(Vio *vio, const uchar* buf, size_t size) DBUG_RETURN(ret); } +#ifdef _WIN32 +static void CALLBACK cancel_io_apc(ULONG_PTR data) +{ + CancelIo((HANDLE)data); +} + +/* + Cancel IO on Windows. + + On XP, issue CancelIo as asynchronous procedure call to the thread that started + IO. On Vista+, simpler cancelation is done with CancelIoEx. +*/ +int cancel_io(HANDLE handle, DWORD thread_id) +{ + static BOOL (WINAPI *fp_CancelIoEx) (HANDLE, OVERLAPPED *); + static volatile int first_time= 1; + int rc; + HANDLE thread_handle; + + if (first_time) + { + /* Try to load CancelIoEx using GetProcAddress */ + InterlockedCompareExchangePointer((volatile void *)&fp_CancelIoEx, + GetProcAddress(GetModuleHandle("kernel32"), "CancelIoEx"), NULL); + first_time =0; + } + + if (fp_CancelIoEx) + { + return fp_CancelIoEx(handle, NULL)? 0 :-1; + } + + thread_handle= OpenThread(THREAD_SET_CONTEXT, FALSE, thread_id); + if (thread_handle) + { + rc= QueueUserAPC(cancel_io_apc, thread_handle, (ULONG_PTR)handle); + CloseHandle(thread_handle); + } + return rc; +} +#endif + //WL#4896: Not covered static int vio_set_blocking(Vio *vio, my_bool status) { @@ -427,6 +499,29 @@ int vio_shutdown(Vio * vio) DBUG_RETURN(r); } +int vio_cancel(Vio * vio, int how) +{ + int r= 0; + DBUG_ENTER("vio_cancel"); + + if (vio->inactive == FALSE) + { + DBUG_ASSERT(vio->type == VIO_TYPE_TCPIP || + vio->type == VIO_TYPE_SOCKET || + vio->type == VIO_TYPE_SSL); + + DBUG_ASSERT(mysql_socket_getfd(vio->mysql_socket) >= 0); + if (mysql_socket_shutdown(vio->mysql_socket, how)) + r= -1; +#ifdef _WIN32 + /* Cancel possible IO in progres (shutdown does not do that on Windows) */ + (void) cancel_io((HANDLE)vio->mysql_socket, vio->thread_id); +#endif + } + + DBUG_RETURN(r); +} + const char *vio_description(Vio * vio) { @@ -762,7 +857,8 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout) break; } - MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket, PSI_SOCKET_SELECT, 0); + START_SOCKET_WAIT(locker, &state, vio->mysql_socket, + PSI_SOCKET_SELECT, timeout); /* Wait for the I/O event and return early in case of @@ -786,7 +882,7 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout) break; } - MYSQL_END_SOCKET_WAIT(locker, 0); + END_SOCKET_WAIT(locker, timeout); DBUG_RETURN(ret); } @@ -833,13 +929,14 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout) break; } - MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket, PSI_SOCKET_SELECT, 0); + START_SOCKET_WAIT(locker, &state, vio->mysql_socket, + PSI_SOCKET_SELECT, timeout); /* The first argument is ignored on Windows. */ ret= select(fd + 1, &readfds, &writefds, &exceptfds, (timeout >= 0) ? &tm : NULL); - MYSQL_END_SOCKET_WAIT(locker, 0); + END_SOCKET_WAIT(locker, timeout); /* Set error code to indicate a timeout error. */ if (ret == 0)