Skip to content

Commit 32be7df

Browse files
committed
Return to original stage after mysql_lock_tables
Stage "Filling schema table" is now properly shown in 'show processlist' mysys/mf_keycache.c: Simple cleanup with more comments sql/lock.cc: Return to original stage after mysql_lock_tables Made 'Table lock' as a true stage sql/sql_show.cc: Restore original stage after get_schema_tables_result
1 parent c11a054 commit 32be7df

File tree

5 files changed

+38
-19
lines changed

5 files changed

+38
-19
lines changed

mysys/mf_keycache.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,11 +1020,11 @@ void end_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, my_bool cleanup)
10201020
*/
10211021

10221022
static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
1023-
struct st_my_thread_var *thread)
1023+
struct st_my_thread_var *thread)
10241024
{
10251025
struct st_my_thread_var *last;
1026-
10271026
DBUG_ASSERT(!thread->next && !thread->prev);
1027+
10281028
if (! (last= wqueue->last_thread))
10291029
{
10301030
/* Queue is empty */
@@ -1033,10 +1033,15 @@ static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
10331033
}
10341034
else
10351035
{
1036-
thread->prev= last->next->prev;
1037-
last->next->prev= &thread->next;
1038-
thread->next= last->next;
1039-
last->next= thread;
1036+
DBUG_ASSERT(last->next->prev == &last->next);
1037+
/* Add backlink to previous element */
1038+
thread->prev= last->next->prev;
1039+
/* Fix first in list to point backwords to current */
1040+
last->next->prev= &thread->next;
1041+
/* Next should point to the first element in list */
1042+
thread->next= last->next;
1043+
/* Fix old element to point to new one */
1044+
last->next= thread;
10401045
}
10411046
wqueue->last_thread= thread;
10421047
}
@@ -1057,17 +1062,22 @@ static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
10571062
*/
10581063

10591064
static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
1060-
struct st_my_thread_var *thread)
1065+
struct st_my_thread_var *thread)
10611066
{
10621067
KEYCACHE_DBUG_PRINT("unlink_from_queue", ("thread %ld", thread->id));
10631068
DBUG_ASSERT(thread->next && thread->prev);
1069+
10641070
if (thread->next == thread)
1071+
{
10651072
/* The queue contains only one member */
10661073
wqueue->last_thread= NULL;
1074+
}
10671075
else
10681076
{
1077+
/* Remove current element from list */
10691078
thread->next->prev= thread->prev;
1070-
*thread->prev=thread->next;
1079+
*thread->prev= thread->next;
1080+
/* If first element, change list pointer to point to previous element */
10711081
if (wqueue->last_thread == thread)
10721082
wqueue->last_thread= STRUCT_PTR(struct st_my_thread_var, next,
10731083
thread->prev);
@@ -1111,10 +1121,10 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
11111121
{
11121122
struct st_my_thread_var *last;
11131123
struct st_my_thread_var *thread= my_thread_var;
1114-
1115-
/* Add to queue. */
11161124
DBUG_ASSERT(!thread->next);
11171125
DBUG_ASSERT(!thread->prev); /* Not required, but must be true anyway. */
1126+
1127+
/* Add to queue. */
11181128
if (! (last= wqueue->last_thread))
11191129
thread->next= thread;
11201130
else
@@ -1125,7 +1135,7 @@ static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
11251135
wqueue->last_thread= thread;
11261136

11271137
/*
1128-
Wait until thread is removed from queue by the signalling thread.
1138+
Wait until thread is removed from queue by the signaling thread.
11291139
The loop protects against stray signals.
11301140
*/
11311141
do
@@ -1163,10 +1173,11 @@ static void release_whole_queue(KEYCACHE_WQUEUE *wqueue)
11631173
if (!(last= wqueue->last_thread))
11641174
return;
11651175

1166-
next= last->next;
1176+
next= last->next; /* First (oldest) element */
11671177
do
11681178
{
11691179
thread=next;
1180+
DBUG_ASSERT(thread);
11701181
KEYCACHE_DBUG_PRINT("release_whole_queue: signal",
11711182
("thread %ld", thread->id));
11721183
/* Signal the thread. */

sql/lock.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,16 @@ bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, uint flags)
301301
int rc= 1;
302302
ulong timeout= (flags & MYSQL_LOCK_IGNORE_TIMEOUT) ?
303303
LONG_TIMEOUT : thd->variables.lock_wait_timeout;
304-
304+
PSI_stage_info org_stage;
305305
DBUG_ENTER("mysql_lock_tables(sql_lock)");
306306

307-
THD_STAGE_INFO(thd, stage_system_lock);
307+
thd->enter_stage(&stage_system_lock, &org_stage, __func__, __FILE__,
308+
__LINE__);
308309
if (sql_lock->table_count && lock_external(thd, sql_lock->table,
309310
sql_lock->table_count))
310311
goto end;
311312

312-
thd_proc_info(thd, "Table lock");
313+
THD_STAGE_INFO(thd, stage_table_lock);
313314

314315
/* Copy the lock data array. thr_multi_lock() reorders its contents. */
315316
memmove(sql_lock->locks + sql_lock->lock_count, sql_lock->locks,
@@ -323,7 +324,7 @@ bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, uint flags)
323324
(void) unlock_external(thd, sql_lock->table, sql_lock->table_count);
324325

325326
end:
326-
THD_STAGE_INFO(thd, stage_after_table_lock);
327+
THD_STAGE_INFO(thd, org_stage);
327328

328329
if (thd->killed)
329330
{

sql/mysqld.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9458,6 +9458,8 @@ PSI_stage_info stage_sql_thd_waiting_until_delay= { 0, "Waiting until MASTER_DEL
94589458
PSI_stage_info stage_storing_result_in_query_cache= { 0, "storing result in query cache", 0};
94599459
PSI_stage_info stage_storing_row_into_queue= { 0, "storing row into queue", 0};
94609460
PSI_stage_info stage_system_lock= { 0, "System lock", 0};
9461+
PSI_stage_info stage_table_lock= { 0, "Table lock", 0};
9462+
PSI_stage_info stage_filling_schema_table= { 0, "Filling schema table", 0};
94619463
PSI_stage_info stage_update= { 0, "update", 0};
94629464
PSI_stage_info stage_updating= { 0, "updating", 0};
94639465
PSI_stage_info stage_updating_main_table= { 0, "updating main table", 0};
@@ -9591,6 +9593,8 @@ PSI_stage_info *all_server_stages[]=
95919593
& stage_storing_result_in_query_cache,
95929594
& stage_storing_row_into_queue,
95939595
& stage_system_lock,
9596+
& stage_table_lock,
9597+
& stage_filling_schema_table,
95949598
& stage_update,
95959599
& stage_updating,
95969600
& stage_updating_main_table,

sql/mysqld.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ extern PSI_stage_info stage_statistics;
413413
extern PSI_stage_info stage_storing_result_in_query_cache;
414414
extern PSI_stage_info stage_storing_row_into_queue;
415415
extern PSI_stage_info stage_system_lock;
416+
extern PSI_stage_info stage_table_lock;
417+
extern PSI_stage_info stage_filling_schema_table;
416418
extern PSI_stage_info stage_update;
417419
extern PSI_stage_info stage_updating;
418420
extern PSI_stage_info stage_updating_main_table;

sql/sql_show.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8081,12 +8081,13 @@ bool get_schema_tables_result(JOIN *join,
80818081
THD *thd= join->thd;
80828082
LEX *lex= thd->lex;
80838083
bool result= 0;
8084-
const char *old_proc_info;
8084+
PSI_stage_info org_stage;
80858085
DBUG_ENTER("get_schema_tables_result");
80868086

80878087
Warnings_only_error_handler err_handler;
80888088
thd->push_internal_handler(&err_handler);
8089-
old_proc_info= thd_proc_info(thd, "Filling schema table");
8089+
thd->enter_stage(&stage_filling_schema_table, &org_stage, __func__, __FILE__,
8090+
__LINE__);
80908091

80918092
JOIN_TAB *tab;
80928093
for (tab= first_linear_tab(join, WITHOUT_BUSH_ROOTS, WITH_CONST_TABLES);
@@ -8190,7 +8191,7 @@ bool get_schema_tables_result(JOIN *join,
81908191
}
81918192
else if (result)
81928193
my_error(ER_UNKNOWN_ERROR, MYF(0));
8193-
thd_proc_info(thd, old_proc_info);
8194+
THD_STAGE_INFO(thd, org_stage);
81948195
DBUG_RETURN(result);
81958196
}
81968197

0 commit comments

Comments
 (0)