Skip to content

Commit b0443f4

Browse files
author
Venkatesh Duggirala
committed
Bug#18684222 CURRENT_THD CALLS CAN BE MINIMIZED IN
ACCESS::CREATE_THD()/DROP_THD FUNCTIONS Problem: Current_thd is costly operation and it is getting called in Rpl_info_table_access:create_thd/drop_thd functions many times and it can be avoided. Analysis: In case of RPL_INFO_REPOSITORY=TABLE, Server try to open and close repository table. In the process of opening and closing the table, there are few calls to costly macro current_thd which can be avoided by changing the logic little. Fix: Replacing save_current_thd logic with 'thd_created' (bool) variable.
1 parent ed244b7 commit b0443f4

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

sql/rpl_info_table_access.cc

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2010, 2014, 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
@@ -162,7 +162,7 @@ bool Rpl_info_table_access::close_table(THD *thd, TABLE* table,
162162
*/
163163
ha_commit_trans(thd, FALSE, TRUE);
164164
}
165-
if (saved_current_thd != current_thd)
165+
if (thd_created)
166166
{
167167
if (error)
168168
ha_rollback_trans(thd, TRUE);
@@ -441,19 +441,17 @@ bool Rpl_info_table_access::store_info_values(uint max_num_field, Field **fields
441441
*/
442442
THD *Rpl_info_table_access::create_thd()
443443
{
444-
THD *thd= NULL;
445-
saved_current_thd= current_thd;
444+
THD *thd= current_thd;
446445

447-
if (!current_thd)
446+
if (!thd)
448447
{
449448
thd= new THD;
450449
thd->thread_stack= (char*) &thd;
451450
thd->store_globals();
452451
thd->security_ctx->skip_grants();
453452
thd->system_thread= SYSTEM_THREAD_INFO_REPOSITORY;
453+
thd_created= true;
454454
}
455-
else
456-
thd= current_thd;
457455

458456
return(thd);
459457
}
@@ -472,10 +470,11 @@ bool Rpl_info_table_access::drop_thd(THD *thd)
472470
{
473471
DBUG_ENTER("Rpl_info::drop_thd");
474472

475-
if (saved_current_thd != current_thd)
473+
if (thd_created)
476474
{
477475
delete thd;
478476
my_pthread_setspecific_ptr(THR_THD, NULL);
477+
thd_created= false;
479478
}
480479

481480
DBUG_RETURN(FALSE);

sql/rpl_info_table_access.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2010, 2014, 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
@@ -28,7 +28,7 @@ enum enum_return_id { FOUND_ID= 1, NOT_FOUND_ID, ERROR_ID };
2828
class Rpl_info_table_access
2929
{
3030
public:
31-
Rpl_info_table_access() { };
31+
Rpl_info_table_access(): thd_created(false) { };
3232
virtual ~Rpl_info_table_access() { };
3333

3434
bool open_table(THD* thd, const LEX_STRING dbstr, const LEX_STRING tbstr,
@@ -47,7 +47,7 @@ class Rpl_info_table_access
4747
bool drop_thd(THD* thd);
4848

4949
private:
50-
THD *saved_current_thd;
50+
bool thd_created;
5151

5252
Rpl_info_table_access& operator=(const Rpl_info_table_access& info);
5353
Rpl_info_table_access(const Rpl_info_table_access& info);

0 commit comments

Comments
 (0)