Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/my_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,20 @@ typedef uint64 my_thread_id;
*/
#define MY_THREAD_ID_MAX UINT32_MAX

#ifdef _WIN32
#define MAX_THREAD_NAME 256
#elif defined(__linux__)
#define MAX_THREAD_NAME 16
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
#define MAX_THREAD_NAME 19
#include <pthread_np.h>
#elif defined(__apple_build_version__)
#include <sys/proc_info.h>
#define MAX_THREAD_NAME MAXTHREADNAMESIZE
Comment on lines +634 to +636
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The macro __apple_build_version__ is specific to Apple's Clang compiler. If MariaDB is compiled on macOS using a different compiler (such as GCC or upstream Clang), this macro will not be defined, and the build will fall back to the default MAX_THREAD_NAME 16 instead of using MAXTHREADNAMESIZE (which is 64). Using the standard platform macro __APPLE__ is more robust.

#elif defined(__APPLE__)
#include <sys/proc_info.h>
#define MAX_THREAD_NAME MAXTHREADNAMESIZE

#else
#define MAX_THREAD_NAME 16
#endif

extern void my_threadattr_global_init(void);
extern my_bool my_thread_global_init(void);
extern void my_thread_set_name(const char *);
Expand Down
1 change: 1 addition & 0 deletions libmysqld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/mf_iocache.cc ../sql/my_decimal.cc
../sql/net_serv.cc ../sql/opt_range.cc
../sql/opt_group_by_cardinality.cc
../sql/sql_parallel_workers.cc
../sql/opt_rewrite_date_cmp.cc
../sql/opt_rewrite_remove_casefold.cc
../sql/opt_sargable_left.cc
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/main/mysqld--help.result
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,9 @@ The following specify which files/extra groups are read (specified before remain
Cost of checking the row against the WHERE clause.
Increasing this will have the optimizer to prefer plans
with less row combinations
--parallel-worker-threads=#
Number of worker threads available for parallel query
execution. 0 means parallel execution is disabled
--path=name Comma-separated list of schema names that defines the
search order for stored routines
--performance-schema
Expand Down Expand Up @@ -2004,6 +2007,7 @@ optimizer-trace
optimizer-trace-max-mem-size 1048576
optimizer-use-condition-selectivity 4
optimizer-where-cost 0.032
parallel-worker-threads 0
path CURRENT_SCHEMA
performance-schema FALSE
performance-schema-accounts-size -1
Expand Down
84 changes: 84 additions & 0 deletions mysql-test/main/parallel_query.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
SET DEBUG_SYNC='RESET';
#
# MDEV-39492 Parallel Query: Study how to create worker threads
#
create table t1 select seq from seq_1_to_2;
set session parallel_worker_threads=3;
# we should currently see 3 warnings;
select SQL_BUFFER_RESULT seq from t1;
seq
1
2
1
2
1
2
set session parallel_worker_threads=10;
select SQL_BUFFER_RESULT seq from t1;
seq
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
set session parallel_worker_threads=0;
connect killee, localhost, root, , ;
# check that kill query on a parallel worker is passed to the manager
connection killee;
set session parallel_worker_threads=3;
SET @save_dbug= @@global.debug_dbug;
SET GLOBAL debug_dbug = "+d,pwt_worker_pause_before_signal";
select SQL_BUFFER_RESULT seq from t1;;
# now use the default connection to view/kill the thread group executing
# the parallel work
connection default;
SET DEBUG_SYNC='now WAIT_FOR pwt_worker_paused';
# wait for all 3 workers to hit our debug sync point
# then have a look at what is in our process list without thread ID
select USER, DB, STATE, SUBSTRING(INFO, 1, 32)
from information_schema.processlist
where (INFO regexp '.*parallel worker.*' or
STATE regexp '.*parallel worker.*') and
NOT INFO regexp '.*information_schema\.processlist.*';
USER DB STATE SUBSTRING(INFO, 1, 32)
root test debug sync point: now Parallel Worker 3 For Thread ID
root test debug sync point: now Parallel Worker 2 For Thread ID
root test debug sync point: now Parallel Worker 1 For Thread ID
root test Reading data from parallel workers select SQL_BUFFER_RESULT seq fro
kill query ID;
# signal our workers to continue execution
SET DEBUG_SYNC = "now SIGNAL pwt_worker_continue";
# then wait for the manager thread to clean up and go back to sleep
# review error message on --reap
connection killee;
ERROR 70100: Query execution was interrupted
SET DEBUG_SYNC = "RESET";
# save as above, but kill a worker with a simple kill and see the
# connection drop
select SQL_BUFFER_RESULT seq from t1;;
connection default;
SET DEBUG_SYNC='now WAIT_FOR pwt_worker_paused';
kill ID;
SET DEBUG_SYNC = "now SIGNAL pwt_worker_continue";
connection killee;
ERROR 70100: Query execution was interrupted
# killee connection now dead, confirmed below
connection default;
drop table t1;
SET GLOBAL debug_dbug = @save_dbug;
SET DEBUG_SYNC = "RESET";
108 changes: 108 additions & 0 deletions mysql-test/main/parallel_query.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# Test KILL and KILL QUERY statements.
#

-- source include/count_sessions.inc
-- source include/not_embedded.inc
# this will be used in the future -- source include/have_innodb.inc
-- source include/have_sequence.inc
--source include/have_debug.inc
--source include/have_debug_sync.inc
SET DEBUG_SYNC='RESET';

--disable_service_connection

--echo #
--echo # MDEV-39492 Parallel Query: Study how to create worker threads
--echo #

create table t1 select seq from seq_1_to_2;

set session parallel_worker_threads=3;
--echo # we should currently see 3 warnings;
select SQL_BUFFER_RESULT seq from t1;

set session parallel_worker_threads=10;
select SQL_BUFFER_RESULT seq from t1;

set session parallel_worker_threads=0;
connect (killee, localhost, root, , );

--echo # check that kill query on a parallel worker is passed to the manager

--connection killee
let $id= `select connection_id()`;
set session parallel_worker_threads=3;

# worker THDs don't inherit session vars, we are using a debug_sync_set_action
# to pause execution in our worker threads just after they have done something

SET @save_dbug= @@global.debug_dbug;
SET GLOBAL debug_dbug = "+d,pwt_worker_pause_before_signal";

--send select SQL_BUFFER_RESULT seq from t1;
--echo # now use the default connection to view/kill the thread group executing
--echo # the parallel work
--connection default
SET DEBUG_SYNC='now WAIT_FOR pwt_worker_paused';
let $name= "Parallel Worker 1 For Thread ID $id";
let $killID= `SELECT @kid:=ID from information_schema.processlist
where info like $name limit 1`;
--echo # wait for all 3 workers to hit our debug sync point
let $wait_condition=
select count(*) = 3 from information_schema.processlist
where state like 'debug sync%' and info like '%Thread ID $id';
--source include/wait_condition.inc
--echo # then have a look at what is in our process list without thread ID
select USER, DB, STATE, SUBSTRING(INFO, 1, 32)
from information_schema.processlist
where (INFO regexp '.*parallel worker.*' or
STATE regexp '.*parallel worker.*') and
NOT INFO regexp '.*information_schema\.processlist.*';
--replace_result $killID ID
eval kill query $killID;
--echo # signal our workers to continue execution
SET DEBUG_SYNC = "now SIGNAL pwt_worker_continue";
--echo # then wait for the manager thread to clean up and go back to sleep
let $wait_condition=
select count(*) = 1 from information_schema.processlist
where command = 'Sleep' and id = $id;
--source include/wait_condition.inc
#select * from information_schema.processlist;
--echo # review error message on --reap
--connection killee
--error ER_QUERY_INTERRUPTED
reap;

SET DEBUG_SYNC = "RESET";

--echo # save as above, but kill a worker with a simple kill and see the
--echo # connection drop

--send select SQL_BUFFER_RESULT seq from t1;
connection default;
SET DEBUG_SYNC='now WAIT_FOR pwt_worker_paused';
let $name= "Parallel Worker 1 For Thread ID $id";
let $killID= `SELECT @kid:=ID from information_schema.processlist
where info like $name limit 1`;
--replace_result $killID ID
eval kill $killID;
SET DEBUG_SYNC = "now SIGNAL pwt_worker_continue";
let $wait_condition=
select count(*) = 0 from information_schema.processlist
where command = 'Sleep' and id = $id;
--source include/wait_condition.inc
connection killee;
--disable_warnings
--error ER_QUERY_INTERRUPTED
reap;

--echo # killee connection now dead, confirmed below

connection default;

drop table t1;
SET GLOBAL debug_dbug = @save_dbug;
SET DEBUG_SYNC = "RESET";

--source include/wait_until_count_sessions.inc
54 changes: 54 additions & 0 deletions mysql-test/main/parallel_query_excluded.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
SET @save_optimizer_trace= @@optimizer_trace;
SET optimizer_trace='enabled=on';
CREATE TABLE t_plain (a INT);
INSERT INTO t_plain VALUES (1),(2),(3);
CREATE TABLE t_blob (a INT, b BLOB);
INSERT INTO t_blob VALUES (1,'x'),(2,'y'),(3,'z');
CREATE TABLE t_text (a INT, b TEXT);
INSERT INTO t_text VALUES (1,'x'),(2,'y'),(3,'z');
CREATE TABLE t_m1 (a INT) ENGINE=MyISAM;
INSERT INTO t_m1 VALUES (1),(2),(3);
CREATE TABLE t_m2 (a INT) ENGINE=MyISAM;
INSERT INTO t_m2 VALUES (4),(5),(6);
CREATE TABLE t_merge (a INT) ENGINE=MERGE UNION=(t_m1,t_m2) INSERT_METHOD=LAST;
CREATE TABLE t_ft (a INT, b VARCHAR(64), FULLTEXT(b)) ENGINE=MyISAM;
INSERT INTO t_ft VALUES (1,'alpha beta'),(2,'gamma delta'),(3,'epsilon zeta');
set session parallel_worker_threads=2;
# plain table: chosen for parallel scan (expect 1)
SELECT a FROM t_plain;
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;
chosen_for_parallel_scan
1
# BLOB column present: excluded, not chosen (expect 0)
SELECT a FROM t_blob;
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;
chosen_for_parallel_scan
0
# TEXT column present: excluded, not chosen (expect 0)
SELECT a FROM t_text;
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;
chosen_for_parallel_scan
0
# MERGE engine: excluded, not chosen (expect 0)
SELECT a FROM t_merge;
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;
chosen_for_parallel_scan
0
# fulltext-searched (MATCH in select list): excluded, not chosen (expect 0)
SELECT a, MATCH(b) AGAINST('alpha') FROM t_ft;
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;
chosen_for_parallel_scan
0
DROP TABLE t_plain, t_blob, t_text, t_merge, t_m1, t_m2, t_ft;
SET optimizer_trace= @save_optimizer_trace;
set session parallel_worker_threads=default;
80 changes: 80 additions & 0 deletions mysql-test/main/parallel_query_excluded.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#
# MDEV-39492 Parallel Query: tables that cannot be shipped row-by-row through a
# worker batch table are excluded from parallel worker scan.
#
# JOIN::choose_parallel_scan() records the table picked for the parallel scan
# in the optimizer trace as "chosen_for_parallel_scan". An ordinary table is
# chosen; a table is rejected by the use_parallel_scan gate when it has a
# BLOB/TEXT (blob-backed) column, uses the MERGE engine, or is fulltext-searched
# (a MATCH ... AGAINST refers to it). We assert presence/absence of that trace
# key (1/0) rather than the temporary row-multiplication behaviour.
#
--source include/not_embedded.inc

SET @save_optimizer_trace= @@optimizer_trace;
SET optimizer_trace='enabled=on';

CREATE TABLE t_plain (a INT);
INSERT INTO t_plain VALUES (1),(2),(3);
CREATE TABLE t_blob (a INT, b BLOB);
INSERT INTO t_blob VALUES (1,'x'),(2,'y'),(3,'z');
CREATE TABLE t_text (a INT, b TEXT);
INSERT INTO t_text VALUES (1,'x'),(2,'y'),(3,'z');

# MERGE table over two MyISAM children
CREATE TABLE t_m1 (a INT) ENGINE=MyISAM;
INSERT INTO t_m1 VALUES (1),(2),(3);
CREATE TABLE t_m2 (a INT) ENGINE=MyISAM;
INSERT INTO t_m2 VALUES (4),(5),(6);
CREATE TABLE t_merge (a INT) ENGINE=MERGE UNION=(t_m1,t_m2) INSERT_METHOD=LAST;

# fulltext: MATCH in the select list keeps a full table scan and marks the
# table fulltext-searched
CREATE TABLE t_ft (a INT, b VARCHAR(64), FULLTEXT(b)) ENGINE=MyISAM;
INSERT INTO t_ft VALUES (1,'alpha beta'),(2,'gamma delta'),(3,'epsilon zeta');

set session parallel_worker_threads=2;

--echo # plain table: chosen for parallel scan (expect 1)
--disable_result_log
SELECT a FROM t_plain;
--enable_result_log
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;

--echo # BLOB column present: excluded, not chosen (expect 0)
--disable_result_log
SELECT a FROM t_blob;
--enable_result_log
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;

--echo # TEXT column present: excluded, not chosen (expect 0)
--disable_result_log
SELECT a FROM t_text;
--enable_result_log
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;

--echo # MERGE engine: excluded, not chosen (expect 0)
--disable_result_log
SELECT a FROM t_merge;
--enable_result_log
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;

--echo # fulltext-searched (MATCH in select list): excluded, not chosen (expect 0)
--disable_result_log
SELECT a, MATCH(b) AGAINST('alpha') FROM t_ft;
--enable_result_log
SELECT JSON_EXTRACT(trace, '$**.chosen_for_parallel_scan') IS NOT NULL
AS chosen_for_parallel_scan
FROM information_schema.optimizer_trace;

DROP TABLE t_plain, t_blob, t_text, t_merge, t_m1, t_m2, t_ft;
SET optimizer_trace= @save_optimizer_trace;
set session parallel_worker_threads=default;
Loading
Loading