Skip to content

Commit ffc5239

Browse files
committed
MDEV-37619 The forced use of THD accessors hurts InnoDB performance
Let us access some data members of THD directly, instead of invoking non-inline accessor functions. Note: my_thread_id will be used instead of the potentially narrower ulong data type. Also, let us remove some functions from sql_class.cc that were only being used by InnoDB or RocksDB, for no reason. RocksDB always had access to the internals of THD.
1 parent f609dbd commit ffc5239

File tree

19 files changed

+125
-232
lines changed

19 files changed

+125
-232
lines changed

sql/sql_class.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5272,16 +5272,6 @@ extern "C" void thd_decrement_pending_ops(void *thd_)
52725272
}
52735273

52745274

5275-
unsigned long long thd_get_query_id(const MYSQL_THD thd)
5276-
{
5277-
return((unsigned long long)thd->query_id);
5278-
}
5279-
5280-
void thd_clear_error(MYSQL_THD thd)
5281-
{
5282-
thd->clear_error();
5283-
}
5284-
52855275
extern "C" const struct charset_info_st *thd_charset(MYSQL_THD thd)
52865276
{
52875277
return(thd->charset());
@@ -5683,12 +5673,6 @@ extern "C" int thd_binlog_format(const MYSQL_THD thd)
56835673
return BINLOG_FORMAT_UNSPEC;
56845674
}
56855675

5686-
extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all)
5687-
{
5688-
DBUG_ASSERT(thd);
5689-
thd->mark_transaction_to_rollback(all);
5690-
}
5691-
56925676
extern "C" bool thd_binlog_filter_ok(const MYSQL_THD thd)
56935677
{
56945678
return binlog_filter->db_ok(thd->db.str);

storage/innobase/dict/dict0crea.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Database object creation
2424
Created 1/8/1996 Heikki Tuuri
2525
*******************************************************/
2626

27+
#define MYSQL_SERVER
2728
#include "dict0crea.h"
2829
#include "btr0pcur.h"
2930
#ifdef BTR_CUR_HASH_ADAPT
@@ -45,7 +46,7 @@ Created 1/8/1996 Heikki Tuuri
4546
#include "fts0priv.h"
4647
#include "srv0start.h"
4748
#include "log.h"
48-
#include "ha_innodb.h"
49+
#include "sql_class.h"
4950

5051
/*****************************************************************//**
5152
Based on a table object, this function builds the entry to be inserted
@@ -1757,7 +1758,7 @@ dict_create_add_foreigns_to_dictionary(
17571758
return DB_ERROR;
17581759
}
17591760

1760-
bool strict_mode = thd_is_strict_mode(trx->mysql_thd);
1761+
bool strict_mode = trx->mysql_thd->is_strict_mode();
17611762
for (auto fk : local_fk_set)
17621763
if (strict_mode && !fk->check_fk_constraint_valid())
17631764
return DB_CANNOT_ADD_CONSTRAINT;

storage/innobase/dict/dict0dict.cc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Data dictionary system
2525
Created 1/8/1996 Heikki Tuuri
2626
***********************************************************************/
2727

28+
#define MYSQL_SERVER
2829
#include <my_config.h>
2930
#include <string>
3031

@@ -38,7 +39,6 @@ Created 1/8/1996 Heikki Tuuri
3839
#include <algorithm>
3940
#include "sql_class.h"
4041
#include "sql_table.h"
41-
#include <mysql/service_thd_mdl.h>
4242

4343
#include "btr0btr.h"
4444
#include "btr0cur.h"
@@ -524,10 +524,8 @@ dict_index_get_nth_field_pos(
524524

525525
void mdl_release(THD *thd, MDL_ticket *mdl) noexcept
526526
{
527-
if (!thd || !mdl);
528-
else if (MDL_context *mdl_context= static_cast<MDL_context*>
529-
(thd_mdl_context(thd)))
530-
mdl_context->release_lock(mdl);
527+
if (thd && mdl)
528+
thd->mdl_context.release_lock(mdl);
531529
}
532530

533531
/** Parse the table file name into table name and database name.
@@ -787,7 +785,6 @@ dict_acquire_mdl_shared(dict_table_t *table,
787785
if (!table || !mdl)
788786
return table;
789787

790-
MDL_context *mdl_context= static_cast<MDL_context*>(thd_mdl_context(thd));
791788
size_t db_len;
792789

793790
if (trylock)
@@ -805,9 +802,7 @@ dict_acquire_mdl_shared(dict_table_t *table,
805802
if (db_len == 0)
806803
return table; /* InnoDB system tables are not covered by MDL */
807804

808-
return mdl_context
809-
? dict_acquire_mdl_shared<trylock>(table, mdl_context, mdl, table_op)
810-
: nullptr;
805+
return dict_acquire_mdl_shared<trylock>(table, &thd->mdl_context, mdl, table_op);
811806
}
812807

813808
template dict_table_t* dict_acquire_mdl_shared<false>
@@ -1100,9 +1095,7 @@ bool dict_stats::open(THD *thd) noexcept
11001095
ut_ad(!index_stats);
11011096
ut_ad(!mdl_context);
11021097

1103-
mdl_context= static_cast<MDL_context*>(thd_mdl_context(thd));
1104-
if (!mdl_context)
1105-
return true;
1098+
mdl_context= &thd->mdl_context;
11061099
/* FIXME: use compatible type, and maybe remove this parameter altogether! */
11071100
const double timeout= double(global_system_variables.lock_wait_timeout);
11081101
MDL_request request;
@@ -3442,7 +3435,7 @@ dict_foreign_parse_drop_constraints(
34423435

34433436
ut_a(trx->mysql_thd);
34443437

3445-
cs = thd_charset(trx->mysql_thd);
3438+
cs = trx->mysql_thd->charset();
34463439

34473440
*n = 0;
34483441

storage/innobase/eval/eval0eval.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Created 12/29/1997 Heikki Tuuri
2626
*******************************************************/
2727

2828
#include "eval0eval.h"
29+
#include "pars0grm.h"
2930
#include "data0data.h"
3031
#include "row0sel.h"
3132
#include "rem0cmp.h"

0 commit comments

Comments
 (0)