WL#8505: Re-implement the query rewrite plugin APIs as an Audit plugin event class
Affects: Server-5.7
—
Status: Complete
To take advantage of the more performant infrastructure the audit API provides, re-do the query rewrite plugin API as an Audit API event class.
* NF1: Get rid of the current query rewrite plugin API implementation (post-parse and pre-parse plugin types) * NF2: Revert the changes that support the NF1 plugin types from general plugin functions like e.g. plugin_add etc and global structures like THD etc., including the fix for BUG#76509. * FR3: Implement a new audit API event class with 2 audit events (pre- and post- parse) together with the accompanying parameter sets to pass the data needed in and out of the plugins * FR4: convert all the current query rewrite plugins to audit log plugins that subscribe to the FR3 audit event class * FR5: make sure the current tests for the query rewrite plugins work as they were working before (with minimal changes) and add new tests as needed.
== WHY == The Audit API provides additional infrastructure compared to the bare bones plugin handling APIs (plugin_add/plugin_del/plugin_lock_by_name). The following is a description of what this additional infrastructure is. It is mostly a per-session set of plugin locks (a.k.a. plugin references, resulting from plugin_lock_*) and a event class mask denoting what type of plugins are already locked for the session. This means that if there are repetitive calls to these audit API event classes for the duration of the session the global list of loaded plugins will not be consulted and hence no performance impact will be inflicted. The references are released when the session is over. One can still call UNLOAD PLUGIN on audit plugins that are referenced in this way by existing sessions. This will put the plugin in "UNLOADING" state and with the release of the last reference to it it will be unloaded. == HOW == * Add in include/mysql/plugin_audit.h: +/* + AUDIT CLASS : PRE PARSE + + PRE PARSE events occur before parsing has commenced. +*/ + +#define MYSQL_AUDIT_PRE_PARSE_CLASS 2 +#define MYSQL_AUDIT_PRE_PARSE_CLASSMASK (1 << MYSQL_AUDIT_PRE_PARSE_CLASS) + +struct mysql_event_pre_parse +{ + unsigned int event_subclass; + int *flags; + const char *query; + size_t query_length; + char **rewritten_query; + size_t *rewritten_query_length; +}; + + +/* + AUDIT CLASS : POST PARSE + + POST PARSE events occur after parsing has concluded. +*/ + +#define MYSQL_AUDIT_POST_PARSE_CLASS 3 +#define MYSQL_AUDIT_POST_PARSE_CLASSMASK (1 << MYSQL_AUDIT_POST_PARSE_CLASS) + +struct mysql_event_post_parse +{ + unsigned int event_subclass; + int *flags; +}; * Remove include/mysql/plugin_query_rewrite.h * Dispose of num_[pre|post]_parse_plugins globals * Change query_rewrite.cc tio use mysql_audit_notify() instead of the old plugin hooks/plugin_foreach/etc. * Use the proper plugin intialization/deinitialization sequence instead of abusing it as the old API was doing. * dispose of the per-plugin type actions introduced in plugin_add/plugin_del like e.g.: if (plugin->plugin->type == MYSQL_REWRITE_*) ...
See the attached diffs.
Copyright (c) 2000, 2024, Oracle Corporation and/or its affiliates. All rights reserved.