Skip to content

Commit 3c1593d

Browse files
author
Dmitry Lenev
committed
WL#8356 "Improve scalability by not acquiring unnecessary locks for internal temp tables".
Do not initialize THR_LOCK and THR_LOCK_DATA structs for internal temporary tables using Heap SE. These structs are not used for such tables anyway. OTOH initialization of THR_LOCK structure requires acquisition of global THR_LOCK_lock mutex. This patch solves the problem with THR_LOCK_lock mutex popping up as a scalability bottleneck in 1-table Sysbench SELECT_DISTINCT/InnoDB test.
1 parent f4c37f7 commit 3c1593d

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

storage/heap/ha_heap.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ THR_LOCK_DATA **ha_heap::store_lock(THD *thd,
583583
THR_LOCK_DATA **to,
584584
enum thr_lock_type lock_type)
585585
{
586+
/*
587+
This method should not be called for internal temporary tables
588+
as they don't have properly initialized THR_LOCK and THR_LOCK_DATA
589+
structures.
590+
*/
591+
DBUG_ASSERT(!internal_table);
586592
if (lock_type != TL_IGNORE && file->lock.type == TL_UNLOCK)
587593
file->lock.type=lock_type;
588594
*to++= &file->lock;

storage/heap/hp_create.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -195,7 +195,13 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
195195
my_free(share);
196196
goto err;
197197
}
198-
thr_lock_init(&share->lock);
198+
/*
199+
Do not initialize THR_LOCK object for internal temporary tables.
200+
It is not needed for such tables. Calling thr_lock_init() can
201+
cause scalability issues since it acquires global lock.
202+
*/
203+
if (!create_info->internal_table)
204+
thr_lock_init(&share->lock);
199205
mysql_mutex_init(hp_key_mutex_HP_SHARE_intern_lock,
200206
&share->intern_lock, MY_MUTEX_INIT_FAST);
201207
if (!create_info->internal_table)
@@ -299,10 +305,12 @@ void heap_drop_table(HP_INFO *info)
299305

300306
void hp_free(HP_SHARE *share)
301307
{
302-
if (share->open_list.data) /* If not internal table */
308+
my_bool not_internal_table= (share->open_list.data != NULL);
309+
if (not_internal_table) /* If not internal table */
303310
heap_share_list= list_delete(heap_share_list, &share->open_list);
304311
hp_clear(share); /* Remove blocks from memory */
305-
thr_lock_delete(&share->lock);
312+
if (not_internal_table)
313+
thr_lock_delete(&share->lock);
306314
mysql_mutex_destroy(&share->intern_lock);
307315
my_free(share->name);
308316
my_free(share);

storage/heap/hp_open.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -38,7 +38,13 @@ HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
3838
DBUG_RETURN(0);
3939
}
4040
share->open_count++;
41-
thr_lock_data_init(&share->lock,&info->lock,NULL);
41+
/*
42+
Don't initialize THR_LOCK_DATA for internal temporary tables as it
43+
is not used for them anyway (and THR_LOCK is not initialized for them
44+
too).
45+
*/
46+
if (share->open_list.data != NULL)
47+
thr_lock_data_init(&share->lock, &info->lock, NULL);
4248
info->s= share;
4349
info->lastkey= (uchar*) (info + 1);
4450
info->recbuf= (uchar*) (info->lastkey + share->max_key_length);

0 commit comments

Comments
 (0)