Skip to content

Commit 5f4db47

Browse files
committed
Bug#24930129: REDUCE NUMBER OF DICTIONARY CACHE LOOKUPS
Move acquire() calls higher in call hierarchy to reduce number of acquire() calls. Pass const dd object references or pointers instead of object name strings. Part 1: Do this for schemas, events and stored routines.
1 parent ad4a343 commit 5f4db47

18 files changed

+472
-589
lines changed

mysql-test/r/dd_debug.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ SET GLOBAL DEBUG= '-d, fail_while_acquiring_dd_object';
6161
# 1.3b No schema found during drop.
6262
SET DEBUG= '+d, pretend_no_schema_in_drop_schema';
6363
DROP SCHEMA s1;
64-
ERROR 42000: Unknown database 's1'
64+
ERROR HY000: Can't drop database 's1'; database doesn't exist
6565
SET DEBUG= '-d, pretend_no_schema_in_drop_schema';
6666
# 1.3c Fail while dropping dd object during drop.
6767
SET DEBUG= '+d, fail_while_dropping_dd_object';

mysql-test/t/dd_debug.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ SET GLOBAL DEBUG= '-d, fail_while_acquiring_dd_object';
9393
--echo # 1.3b No schema found during drop.
9494

9595
SET DEBUG= '+d, pretend_no_schema_in_drop_schema';
96-
--error ER_BAD_DB_ERROR
96+
--error ER_DB_DROP_EXISTS
9797
DROP SCHEMA s1;
9898
SET DEBUG= '-d, pretend_no_schema_in_drop_schema';
9999

sql/dd/cache/dictionary_client.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,42 @@ class Dictionary_client
648648
const typename T::cache_partition_type** object);
649649

650650

651+
/**
652+
Retrieve an object by its schema- and object name.
653+
654+
This function returns a cloned object that can be modified.
655+
656+
@note We will acquire an IX-lock on the schema name unless we already
657+
have one. This is needed for proper synchronization with schema
658+
DDL in cases where the table does not exist, and where the
659+
indirect synchronization based on table names therefore will not
660+
apply.
661+
662+
@note This is a variant of the method above asking for an object of type
663+
T, and hence using T's functions for updating name keys etc.
664+
This function, however, returns the instance pointed to as type
665+
T::cache_partition_type to ease handling of various subtypes
666+
of the same base type.
667+
668+
@todo TODO: We should change the MDL acquisition (see above) for a more
669+
long term solution.
670+
671+
@tparam T Dictionary object type.
672+
@param schema_name Name of the schema containing the object.
673+
@param object_name Name of the object.
674+
@param [out] object Dictionary object, if present; otherwise NULL.
675+
676+
@retval false No error.
677+
@retval true Error (from handling a cache miss, or from
678+
failing to get an MDL lock).
679+
*/
680+
681+
template <typename T>
682+
bool acquire_for_modification(const String_type &schema_name,
683+
const String_type &object_name,
684+
typename T::cache_partition_type** object);
685+
686+
651687
/**
652688
Retrieve a table object by its se private id.
653689

sql/dd/dd_event.cc

Lines changed: 19 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2017, 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
@@ -32,7 +32,6 @@
3232
#include "sql_lex.h"
3333
#include "sql_string.h"
3434
#include "system_variables.h"
35-
#include "transaction.h" // trans_commit
3635
#include "tztime.h" // Time_zone
3736

3837

@@ -258,29 +257,6 @@ static Event::enum_interval_field get_enum_interval_field(
258257
}
259258

260259

261-
bool
262-
event_exists(dd::cache::Dictionary_client *dd_client,
263-
const String_type &schema_name,
264-
const String_type &event_name,
265-
bool *exists)
266-
{
267-
DBUG_ENTER("dd::event_exists");
268-
DBUG_ASSERT(exists);
269-
270-
const dd::Event *event_ptr= nullptr;
271-
dd::cache::Dictionary_client::Auto_releaser releaser(dd_client);
272-
if (dd_client->acquire(schema_name, event_name, &event_ptr))
273-
{
274-
// Error is reported by the dictionary subsystem.
275-
DBUG_RETURN(true);
276-
}
277-
278-
*exists= event_ptr != nullptr;
279-
280-
DBUG_RETURN(false);
281-
}
282-
283-
284260
/**
285261
Set Event attributes.
286262
@@ -387,7 +363,7 @@ static void set_event_attributes(THD *thd, Event *event,
387363

388364

389365
bool create_event(THD *thd,
390-
const String_type &schema_name,
366+
const Schema &schema,
391367
const String_type &event_name,
392368
const String_type &event_body,
393369
const String_type &event_body_utf8,
@@ -396,143 +372,55 @@ bool create_event(THD *thd,
396372
{
397373
DBUG_ENTER("dd::create_event");
398374

399-
dd::cache::Dictionary_client *client= thd->dd_client();
400-
dd::cache::Dictionary_client::Auto_releaser releaser(client);
401-
const dd::Schema *sch_obj= nullptr;
402-
403-
// Acquire schema object.
404-
if (client->acquire(schema_name, &sch_obj))
405-
{
406-
// Error is reported by the dictionary subsystem.
407-
DBUG_RETURN(true);
408-
}
409-
if (sch_obj == nullptr)
410-
{
411-
my_error(ER_BAD_DB_ERROR, MYF(0), schema_name.c_str());
412-
DBUG_RETURN(true);
413-
}
414-
415-
std::unique_ptr<dd::Event> event(sch_obj->create_event(thd));
375+
std::unique_ptr<dd::Event> event(schema.create_event(thd));
416376

417377
// Set Event attributes.
418378
set_event_attributes(thd, event.get(), event_name, event_body,
419379
event_body_utf8, definer, event_data, false);
420380

421-
if (client->store(event.get()))
422-
{
423-
trans_rollback_stmt(thd);
424-
// Full rollback we have THD::transaction_rollback_request.
425-
trans_rollback(thd);
426-
DBUG_RETURN(true);
427-
}
428-
429-
DBUG_RETURN(trans_commit_stmt(thd) || trans_commit(thd));
381+
DBUG_RETURN(thd->dd_client()->store(event.get()));
430382
}
431383

432384

433-
bool update_event(THD *thd, const Event *event,
434-
const String_type &new_db_name,
385+
bool update_event(THD *thd, Event *event,
386+
const dd::Schema *new_schema,
435387
const String_type &new_event_name,
436388
const String_type &new_event_body,
437389
const String_type &new_event_body_utf8,
438390
const LEX_USER *definer,
439391
Event_parse_data *event_data)
440392
{
441393
DBUG_ENTER("dd::update_event");
442-
DBUG_ASSERT(event != nullptr);
443-
444-
dd::cache::Dictionary_client *client= thd->dd_client();
445-
dd::cache::Dictionary_client::Auto_releaser releaser(client);
446-
447-
Event *new_event= nullptr;
448-
if (client->acquire_for_modification(event->id(), &new_event))
449-
DBUG_RETURN(true);
450394

451395
// Check whether alter event was given dates that are in the past.
452-
if (event_data->check_dates(thd, static_cast<int>(new_event->on_completion())))
396+
if (event_data->check_dates(thd, static_cast<int>(event->on_completion())))
453397
DBUG_RETURN(true);
454398

455399
// Update Schema Id if there is a dbname change.
456-
if (new_db_name != "")
457-
{
458-
const dd::Schema *to_sch_ptr;
459-
if (client->acquire(new_db_name, &to_sch_ptr))
460-
DBUG_RETURN(true);
461-
462-
if (to_sch_ptr == nullptr)
463-
{
464-
my_error(ER_BAD_DB_ERROR, MYF(0), new_db_name.c_str());
465-
DBUG_RETURN(true);
466-
}
467-
468-
new_event->set_schema_id(to_sch_ptr->id());
469-
}
400+
if (new_schema != nullptr)
401+
event->set_schema_id(new_schema->id());
470402

471403
// Set the altered event attributes.
472-
set_event_attributes(thd, new_event,
404+
set_event_attributes(thd, event,
473405
new_event_name != "" ? new_event_name : event->name(),
474406
new_event_body, new_event_body_utf8, definer,
475407
event_data, true);
476408

477-
if (client->update(new_event))
478-
{
479-
trans_rollback_stmt(thd);
480-
// Full rollback we have THD::transaction_rollback_request.
481-
trans_rollback(thd);
482-
DBUG_RETURN(true);
483-
}
484-
485-
DBUG_RETURN(trans_commit_stmt(thd) || trans_commit(thd));
409+
DBUG_RETURN(thd->dd_client()->update(event));
486410
}
487411

488-
bool update_event_time_and_status(THD *thd, const Event *event,
489-
my_time_t last_executed, ulonglong status)
490-
{
491-
DBUG_ENTER("dd::update_event_time_fields");
492-
493-
DBUG_ASSERT(event != nullptr);
494-
495-
dd::cache::Dictionary_client *client= thd->dd_client();
496-
dd::cache::Dictionary_client::Auto_releaser releaser(client);
497-
498-
Event *new_event= nullptr;
499-
if (client->acquire_for_modification(event->id(), &new_event))
500-
DBUG_RETURN(true);
501-
502-
new_event->set_event_status_null(false);
503-
new_event->set_event_status(get_enum_event_status(status));
504-
new_event->set_last_executed_null(false);
505-
new_event->set_last_executed(last_executed);
506412

507-
if (client->update(new_event))
508-
{
509-
trans_rollback_stmt(thd);
510-
// Full rollback in case we have THD::transaction_rollback_request.
511-
trans_rollback(thd);
512-
DBUG_RETURN(true);
513-
}
514-
515-
DBUG_RETURN(trans_commit_stmt(thd) || trans_commit(thd));
516-
}
517-
518-
519-
bool drop_event(THD *thd, const Event *event)
413+
bool update_event_time_and_status(THD *thd, Event *event,
414+
my_time_t last_executed, ulonglong status)
520415
{
521-
DBUG_ENTER("dd::drop_event");
522-
523-
DBUG_ASSERT(event != nullptr);
524-
525-
Disable_gtid_state_update_guard disabler(thd);
416+
DBUG_ENTER("dd::update_event_time_and_status");
526417

527-
if (thd->dd_client()->drop(event))
528-
{
529-
trans_rollback_stmt(thd);
530-
// Full rollback in case we have THD::transaction_rollback_request.
531-
trans_rollback(thd);
532-
DBUG_RETURN(true);
533-
}
418+
event->set_event_status_null(false);
419+
event->set_event_status(get_enum_event_status(status));
420+
event->set_last_executed_null(false);
421+
event->set_last_executed(last_executed);
534422

535-
DBUG_RETURN(trans_commit_stmt(thd) || trans_commit(thd));
423+
DBUG_RETURN(thd->dd_client()->update(event));
536424
}
537425

538426
} // namespace dd

sql/dd/dd_event.h

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using sql_mode_t= ulonglong;
3131

3232
namespace dd
3333
{
34+
class Schema;
3435
namespace cache
3536
{
3637
class Dictionary_client;
@@ -67,27 +68,11 @@ int get_old_on_completion(Event::enum_on_completion on_completion);
6768
*/
6869
interval_type get_old_interval_type(Event::enum_interval_field interval_field);
6970

70-
/**
71-
Check if an event exists under a schema.
72-
73-
@param dd_client Dictionary client
74-
@param schema_name Schema name of the event object name.
75-
@param name The event name to search for.
76-
@param [out] exists Value set to true if the object is found else false.
77-
78-
@retval true Failure (error has been reported).
79-
@retval false Success.
80-
*/
81-
bool event_exists(dd::cache::Dictionary_client *dd_client,
82-
const String_type &schema_name,
83-
const String_type &name,
84-
bool *exists);
85-
8671
/**
8772
Create an event object and commit it to DD Table Events.
8873
8974
@param thd Thread handle
90-
@param schema_name Database name
75+
@param schema Schema object.
9176
@param event_name Event name
9277
@param event_body Event body.
9378
@param event_body_utf8 Event body in utf8 format.
@@ -97,7 +82,7 @@ bool event_exists(dd::cache::Dictionary_client *dd_client,
9782
@retval true Event creation failed.
9883
@retval false Event creation succeeded.
9984
*/
100-
bool create_event(THD *thd, const String_type &schema_name,
85+
bool create_event(THD *thd, const Schema &schema,
10186
const String_type &event_name, const String_type &event_body,
10287
const String_type &event_body_utf8, const LEX_USER *definer,
10388
Event_parse_data *event_data);
@@ -108,7 +93,7 @@ bool create_event(THD *thd, const String_type &schema_name,
10893
10994
@param thd Thread handle
11095
@param event Event to update.
111-
@param new_db_name Updated db name.
96+
@param new_schema New Schema or nullptr if the schema does not change.
11297
@param new_event_name Updated Event name.
11398
@param new_event_body Updated Event body.
11499
@param new_event_body_utf8 Updated Event body in utf8 format.
@@ -118,8 +103,8 @@ bool create_event(THD *thd, const String_type &schema_name,
118103
@retval true Event updation failed.
119104
@retval false Event updation succeeded.
120105
*/
121-
bool update_event(THD *thd, const Event *event,
122-
const String_type &new_db_name,
106+
bool update_event(THD *thd, Event *event,
107+
const dd::Schema *new_schema,
123108
const String_type &new_event_name,
124109
const String_type &new_event_body,
125110
const String_type &new_event_body_utf8,
@@ -137,19 +122,9 @@ bool update_event(THD *thd, const Event *event,
137122
@retval true true if update failed.
138123
@retval false false if update succeeded.
139124
*/
140-
bool update_event_time_and_status(THD *thd, const Event *event,
125+
bool update_event_time_and_status(THD *thd, Event *event,
141126
my_time_t last_executed,
142127
ulonglong status);
143128

144-
/**
145-
Drop an Event from event metadata table.
146-
147-
@param thd Thread handle.
148-
@param event Event to be droppped.
149-
150-
@retval true if event drop failed.
151-
@retval false if event drop succeeded.
152-
*/
153-
bool drop_event(THD *thd, const Event *event);
154129
} // namespace dd
155130
#endif // DD_EVENT_INCLUDED

0 commit comments

Comments
 (0)