mirror of
https://github.com/MariaDB/server.git
synced 2025-10-19 06:02:12 +02:00

This task loads the stats of the tables that are used in a query, from the trace into the optimizer. This feature is also controlled by optimizer_record_context, and is not enabled by default. The stats such as num_of_records present in the table, indexes if present then their names, along with the average number of records_per_key with in each index are loaded from the trace. Additionally, stats from range analysis i.e. ranges, and the corresponding number of records are also loaded from the trace. The trace context which is in JSON format is firstly set into the session variable optimizer_trace_stored_context. Later, when a user issues a query, the contents of optimizer_trace_stored_context variable is parsed and an in memory representation is build using the class Optimizer_Trace_Stored_Context_Extractor. This class is then used by the optimizer to update and save original values of the tables, indexes, and range stats in the methods "set_statistics_for_table()" of sql_statistics.cc, and "check_quick_select()" of opt_range.cc. After the query gets finished, the statistics that were updated in the optimizer are restored back to the saved original values. The entry point for parsing the json structure is in "mysql_execute_command()" of sql_parse.cc, and similarly exit point i.e. to restore the saved stats of the optimizer is at the end of the same method.
76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
/*
|
|
Copyright (c) 2025, MariaDB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335
|
|
USA */
|
|
|
|
#ifndef SQL_JSON_LIB
|
|
#define SQL_JSON_LIB
|
|
|
|
/*
|
|
A syntax sugar interface to json_string_t
|
|
*/
|
|
class Json_string
|
|
{
|
|
json_string_t str;
|
|
|
|
public:
|
|
explicit Json_string(const char *name)
|
|
{
|
|
json_string_set_str(&str, (const uchar *) name,
|
|
(const uchar *) name + strlen(name));
|
|
json_string_set_cs(&str, system_charset_info);
|
|
}
|
|
json_string_t *get() { return &str; }
|
|
};
|
|
|
|
/*
|
|
This [partially] saves the JSON parser state and then can rollback the parser
|
|
to it.
|
|
|
|
The goal of this is to be able to make multiple json_key_matches() calls:
|
|
|
|
Json_saved_parser_state save(je);
|
|
if (json_key_matches(je, KEY_NAME_1)) {
|
|
...
|
|
return;
|
|
}
|
|
save.restore_to(je);
|
|
if (json_key_matches(je, KEY_NAME_2)) {
|
|
...
|
|
}
|
|
|
|
This allows one to parse JSON objects where [optional] members come in any
|
|
order.
|
|
*/
|
|
class Json_saved_parser_state
|
|
{
|
|
const uchar *c_str;
|
|
my_wc_t c_next;
|
|
int state;
|
|
|
|
public:
|
|
explicit Json_saved_parser_state(const json_engine_t *je)
|
|
: c_str(je->s.c_str), c_next(je->s.c_next), state(je->state)
|
|
{
|
|
}
|
|
void restore_to(json_engine_t *je)
|
|
{
|
|
je->s.c_str= c_str;
|
|
je->s.c_next= c_next;
|
|
je->state= state;
|
|
}
|
|
};
|
|
|
|
#endif
|