golden hour
/usr/include/mysql/server/private
⬆️ Go Up
Upload
File/Folder
Size
Actions
aria_backup.h
1.51 KB
Del
OK
assume_aligned.h
2.29 KB
Del
OK
atomic
-
Del
OK
authors.h
9.9 KB
Del
OK
backup.h
1.21 KB
Del
OK
bounded_queue.h
6.67 KB
Del
OK
client_settings.h
1.89 KB
Del
OK
compat56.h
2.23 KB
Del
OK
config.h
14.18 KB
Del
OK
contributors.h
4.76 KB
Del
OK
create_options.h
4.42 KB
Del
OK
custom_conf.h
1.06 KB
Del
OK
datadict.h
1.53 KB
Del
OK
debug_sync.h
2 KB
Del
OK
derived_handler.h
2.32 KB
Del
OK
derror.h
980 B
Del
OK
des_key_file.h
1.21 KB
Del
OK
discover.h
1.53 KB
Del
OK
dur_prop.h
1.06 KB
Del
OK
embedded_priv.h
1.62 KB
Del
OK
event_data_objects.h
4.09 KB
Del
OK
event_db_repository.h
3.56 KB
Del
OK
event_parse_data.h
2.83 KB
Del
OK
event_queue.h
3.36 KB
Del
OK
event_scheduler.h
3.21 KB
Del
OK
events.h
4.59 KB
Del
OK
field.h
211.96 KB
Del
OK
field_comp.h
1.15 KB
Del
OK
filesort.h
6.67 KB
Del
OK
filesort_utils.h
8 KB
Del
OK
ft_global.h
3.04 KB
Del
OK
gcalc_slicescan.h
16.87 KB
Del
OK
gcalc_tools.h
11.62 KB
Del
OK
grant.h
2.69 KB
Del
OK
group_by_handler.h
3.45 KB
Del
OK
gstream.h
2.38 KB
Del
OK
ha_partition.h
62.22 KB
Del
OK
ha_sequence.h
5.94 KB
Del
OK
handle_connections_win.h
884 B
Del
OK
handler.h
188.39 KB
Del
OK
hash.h
4.34 KB
Del
OK
hash_filo.h
5.55 KB
Del
OK
heap.h
9.2 KB
Del
OK
hostname.h
5.29 KB
Del
OK
ilist.h
6.85 KB
Del
OK
init.h
852 B
Del
OK
innodb_priv.h
1.29 KB
Del
OK
item.h
263.12 KB
Del
OK
item_cmpfunc.h
128.01 KB
Del
OK
item_create.h
11.22 KB
Del
OK
item_func.h
124.59 KB
Del
OK
item_geofunc.h
34.69 KB
Del
OK
item_jsonfunc.h
19.8 KB
Del
OK
item_row.h
5.43 KB
Del
OK
item_strfunc.h
64.55 KB
Del
OK
item_subselect.h
56.19 KB
Del
OK
item_sum.h
69.2 KB
Del
OK
item_timefunc.h
57.85 KB
Del
OK
item_vers.h
3.79 KB
Del
OK
item_windowfunc.h
32.61 KB
Del
OK
item_xmlfunc.h
4.36 KB
Del
OK
key.h
2 KB
Del
OK
keycaches.h
1.95 KB
Del
OK
lex.h
28.9 KB
Del
OK
lex_ident.h
2.07 KB
Del
OK
lex_string.h
3.97 KB
Del
OK
lex_symbol.h
1.29 KB
Del
OK
lf.h
6.31 KB
Del
OK
lock.h
2.15 KB
Del
OK
log.h
44.46 KB
Del
OK
log_event.h
178.94 KB
Del
OK
log_event_data_type.h
1.85 KB
Del
OK
log_event_old.h
19.32 KB
Del
OK
log_slow.h
1.98 KB
Del
OK
maria.h
5.73 KB
Del
OK
mariadb.h
1.25 KB
Del
OK
mdl.h
36.78 KB
Del
OK
mem_root_array.h
6.94 KB
Del
OK
message.h
1.17 KB
Del
OK
multi_range_read.h
22.58 KB
Del
OK
my_alarm.h
2.37 KB
Del
OK
my_apc.h
4.62 KB
Del
OK
my_atomic.h
7.11 KB
Del
OK
my_atomic_wrapper.h
2.92 KB
Del
OK
my_base.h
26.5 KB
Del
OK
my_bit.h
6.05 KB
Del
OK
my_bitmap.h
5.22 KB
Del
OK
my_check_opt.h
2.56 KB
Del
OK
my_compare.h
10.93 KB
Del
OK
my_context.h
6.59 KB
Del
OK
my_counter.h
1.68 KB
Del
OK
my_cpu.h
4.85 KB
Del
OK
my_crypt.h
904 B
Del
OK
my_decimal.h
13.43 KB
Del
OK
my_default.h
1.84 KB
Del
OK
my_handler_errors.h
4.74 KB
Del
OK
my_json_writer.h
17.9 KB
Del
OK
my_libwrap.h
1.16 KB
Del
OK
my_md5.h
1.45 KB
Del
OK
my_minidump.h
848 B
Del
OK
my_nosys.h
1.4 KB
Del
OK
my_rdtsc.h
8.15 KB
Del
OK
my_rnd.h
1.04 KB
Del
OK
my_service_manager.h
1.47 KB
Del
OK
my_stack_alloc.h
6.2 KB
Del
OK
my_stacktrace.h
3.14 KB
Del
OK
my_time.h
10.22 KB
Del
OK
my_tree.h
3.9 KB
Del
OK
my_uctype.h
67.9 KB
Del
OK
my_user.h
1.1 KB
Del
OK
myisam.h
17.11 KB
Del
OK
myisamchk.h
4.61 KB
Del
OK
myisammrg.h
4.78 KB
Del
OK
myisampack.h
14.58 KB
Del
OK
mysql_async.h
1.77 KB
Del
OK
mysqld.h
38.7 KB
Del
OK
mysqld_default_groups.h
204 B
Del
OK
mysqld_suffix.h
1.17 KB
Del
OK
mysys_err.h
2.95 KB
Del
OK
nt_servc.h
2.94 KB
Del
OK
opt_range.h
57.58 KB
Del
OK
opt_subselect.h
14.21 KB
Del
OK
opt_trace.h
8.11 KB
Del
OK
opt_trace_context.h
3.21 KB
Del
OK
parse_file.h
4.11 KB
Del
OK
partition_element.h
5.09 KB
Del
OK
partition_info.h
18.85 KB
Del
OK
password.h
1.14 KB
Del
OK
pfs_file_provider.h
3.08 KB
Del
OK
pfs_idle_provider.h
1.35 KB
Del
OK
pfs_memory_provider.h
1.59 KB
Del
OK
pfs_metadata_provider.h
1.85 KB
Del
OK
pfs_socket_provider.h
2.21 KB
Del
OK
pfs_stage_provider.h
1.52 KB
Del
OK
pfs_statement_provider.h
4.25 KB
Del
OK
pfs_table_provider.h
2.56 KB
Del
OK
pfs_thread_provider.h
5.43 KB
Del
OK
pfs_transaction_provider.h
2.78 KB
Del
OK
privilege.h
27.9 KB
Del
OK
probes_mysql.h
973 B
Del
OK
probes_mysql_dtrace.h
32.23 KB
Del
OK
probes_mysql_nodtrace.h
4.89 KB
Del
OK
procedure.h
6.57 KB
Del
OK
protocol.h
12.32 KB
Del
OK
proxy_protocol.h
548 B
Del
OK
queues.h
3.46 KB
Del
OK
records.h
3.03 KB
Del
OK
repl_failsafe.h
1.55 KB
Del
OK
replication.h
15.73 KB
Del
OK
rijndael.h
1.67 KB
Del
OK
rowid_filter.h
15.13 KB
Del
OK
rpl_constants.h
3.28 KB
Del
OK
rpl_filter.h
4.43 KB
Del
OK
rpl_gtid.h
13.31 KB
Del
OK
rpl_injector.h
9.43 KB
Del
OK
rpl_mi.h
13.65 KB
Del
OK
rpl_parallel.h
13.57 KB
Del
OK
rpl_record.h
1.55 KB
Del
OK
rpl_record_old.h
1.37 KB
Del
OK
rpl_reporting.h
2.96 KB
Del
OK
rpl_rli.h
31.8 KB
Del
OK
rpl_tblmap.h
3.1 KB
Del
OK
rpl_utility.h
9.4 KB
Del
OK
scheduler.h
2.99 KB
Del
OK
scope.h
1.76 KB
Del
OK
select_handler.h
2.18 KB
Del
OK
semisync.h
2.23 KB
Del
OK
semisync_master.h
22.7 KB
Del
OK
semisync_master_ack_receiver.h
5.73 KB
Del
OK
semisync_slave.h
3.47 KB
Del
OK
service_versions.h
2 KB
Del
OK
session_tracker.h
13.96 KB
Del
OK
set_var.h
16.1 KB
Del
OK
slave.h
11.99 KB
Del
OK
source_revision.h
67 B
Del
OK
sp.h
22.02 KB
Del
OK
sp_cache.h
2 KB
Del
OK
sp_head.h
63.05 KB
Del
OK
sp_pcontext.h
24.31 KB
Del
OK
sp_rcontext.h
14 KB
Del
OK
span.h
3.84 KB
Del
OK
spatial.h
21.82 KB
Del
OK
sql_acl.h
13.8 KB
Del
OK
sql_admin.h
2.78 KB
Del
OK
sql_alloc.h
1.83 KB
Del
OK
sql_alter.h
11.86 KB
Del
OK
sql_analyse.h
11.23 KB
Del
OK
sql_analyze_stmt.h
11.48 KB
Del
OK
sql_array.h
6.79 KB
Del
OK
sql_audit.h
13.62 KB
Del
OK
sql_base.h
24.83 KB
Del
OK
sql_basic_types.h
9.28 KB
Del
OK
sql_binlog.h
895 B
Del
OK
sql_bitmap.h
7.66 KB
Del
OK
sql_bootstrap.h
1.63 KB
Del
OK
sql_cache.h
21.15 KB
Del
OK
sql_callback.h
1.51 KB
Del
OK
sql_class.h
250.08 KB
Del
OK
sql_cmd.h
9.13 KB
Del
OK
sql_connect.h
3.99 KB
Del
OK
sql_const.h
10.94 KB
Del
OK
sql_crypt.h
1.4 KB
Del
OK
sql_cte.h
16.15 KB
Del
OK
sql_cursor.h
2.26 KB
Del
OK
sql_db.h
2.16 KB
Del
OK
sql_debug.h
4.65 KB
Del
OK
sql_delete.h
1.31 KB
Del
OK
sql_derived.h
1.26 KB
Del
OK
sql_digest.h
3.73 KB
Del
OK
sql_digest_stream.h
1.53 KB
Del
OK
sql_do.h
954 B
Del
OK
sql_error.h
38.12 KB
Del
OK
sql_explain.h
27.1 KB
Del
OK
sql_expression_cache.h
4.26 KB
Del
OK
sql_get_diagnostics.h
7.68 KB
Del
OK
sql_handler.h
2.84 KB
Del
OK
sql_help.h
920 B
Del
OK
sql_hset.h
3.56 KB
Del
OK
sql_i_s.h
7.97 KB
Del
OK
sql_insert.h
2.39 KB
Del
OK
sql_join_cache.h
47.44 KB
Del
OK
sql_lex.h
166.31 KB
Del
OK
sql_lifo_buffer.h
9.45 KB
Del
OK
sql_limit.h
2.38 KB
Del
OK
sql_list.h
21.56 KB
Del
OK
sql_load.h
1.25 KB
Del
OK
sql_locale.h
2.64 KB
Del
OK
sql_manager.h
960 B
Del
OK
sql_mode.h
6.58 KB
Del
OK
sql_parse.h
8.26 KB
Del
OK
sql_partition.h
11.75 KB
Del
OK
sql_partition_admin.h
5.8 KB
Del
OK
sql_plist.h
7.55 KB
Del
OK
sql_plugin.h
7.39 KB
Del
OK
sql_plugin_compat.h
2.18 KB
Del
OK
sql_prepare.h
11.14 KB
Del
OK
sql_priv.h
17.67 KB
Del
OK
sql_profile.h
7.63 KB
Del
OK
sql_reload.h
1.01 KB
Del
OK
sql_rename.h
982 B
Del
OK
sql_repl.h
2.96 KB
Del
OK
sql_schema.h
3.23 KB
Del
OK
sql_select.h
86.56 KB
Del
OK
sql_sequence.h
5.06 KB
Del
OK
sql_servers.h
1.74 KB
Del
OK
sql_show.h
9.39 KB
Del
OK
sql_signal.h
3.28 KB
Del
OK
sql_sort.h
21.39 KB
Del
OK
sql_statistics.h
11.96 KB
Del
OK
sql_string.h
36.43 KB
Del
OK
sql_table.h
11.07 KB
Del
OK
sql_tablespace.h
956 B
Del
OK
sql_test.h
1.55 KB
Del
OK
sql_time.h
8.18 KB
Del
OK
sql_trigger.h
10.76 KB
Del
OK
sql_truncate.h
2.03 KB
Del
OK
sql_tvc.h
2.36 KB
Del
OK
sql_type.h
286 KB
Del
OK
sql_type_geom.h
18.53 KB
Del
OK
sql_type_int.h
9.73 KB
Del
OK
sql_type_json.h
6 KB
Del
OK
sql_type_real.h
1.23 KB
Del
OK
sql_type_string.h
1.59 KB
Del
OK
sql_udf.h
4.74 KB
Del
OK
sql_union.h
1.04 KB
Del
OK
sql_update.h
1.88 KB
Del
OK
sql_view.h
2.33 KB
Del
OK
sql_window.h
6.65 KB
Del
OK
ssl_compat.h
3.07 KB
Del
OK
strfunc.h
2.22 KB
Del
OK
structs.h
25.13 KB
Del
OK
sys_vars_shared.h
2.67 KB
Del
OK
t_ctype.h
5.51 KB
Del
OK
table.h
112.29 KB
Del
OK
table_cache.h
4.13 KB
Del
OK
thr_alarm.h
2.87 KB
Del
OK
thr_lock.h
6.7 KB
Del
OK
thr_malloc.h
1.17 KB
Del
OK
thr_timer.h
1.53 KB
Del
OK
thread_cache.h
5.77 KB
Del
OK
thread_pool_priv.h
4 KB
Del
OK
threadpool.h
4.51 KB
Del
OK
threadpool_generic.h
3.83 KB
Del
OK
transaction.h
1.43 KB
Del
OK
tzfile.h
4.9 KB
Del
OK
tztime.h
3.32 KB
Del
OK
uniques.h
4.1 KB
Del
OK
unireg.h
7.43 KB
Del
OK
vers_string.h
2.47 KB
Del
OK
violite.h
9.71 KB
Del
OK
waiting_threads.h
4.43 KB
Del
OK
welcome_copyright_notice.h
1.19 KB
Del
OK
win_tzname_data.h
6.35 KB
Del
OK
winservice.h
1.17 KB
Del
OK
wqueue.h
1.53 KB
Del
OK
wsrep.h
3.23 KB
Del
OK
wsrep_applier.h
2.64 KB
Del
OK
wsrep_binlog.h
3.36 KB
Del
OK
wsrep_client_service.h
2.5 KB
Del
OK
wsrep_client_state.h
1.53 KB
Del
OK
wsrep_condition_variable.h
1.45 KB
Del
OK
wsrep_high_priority_service.h
4.8 KB
Del
OK
wsrep_mutex.h
1.19 KB
Del
OK
wsrep_mysqld.h
19.88 KB
Del
OK
wsrep_mysqld_c.h
1.2 KB
Del
OK
wsrep_on.h
1.68 KB
Del
OK
wsrep_priv.h
1.6 KB
Del
OK
wsrep_schema.h
4.54 KB
Del
OK
wsrep_server_service.h
3.55 KB
Del
OK
wsrep_server_state.h
2.23 KB
Del
OK
wsrep_sst.h
3.86 KB
Del
OK
wsrep_storage_service.h
1.77 KB
Del
OK
wsrep_thd.h
10.58 KB
Del
OK
wsrep_trans_observer.h
17.81 KB
Del
OK
wsrep_types.h
997 B
Del
OK
wsrep_utils.h
9.07 KB
Del
OK
wsrep_var.h
4.17 KB
Del
OK
wsrep_xid.h
1.42 KB
Del
OK
xa.h
1.69 KB
Del
OK
Edit: my_json_writer.h
/* Copyright (C) 2014 SkySQL Ab, MariaDB Corporation Ab 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 JSON_WRITER_INCLUDED #define JSON_WRITER_INCLUDED #include "my_base.h" #if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) || defined ENABLED_JSON_WRITER_CONSISTENCY_CHECKS #include <set> #include <stack> #include <string> #include <vector> #endif #ifdef JSON_WRITER_UNIT_TEST #include "sql_string.h" // Also, mock objects are defined in my_json_writer-t.cc #define VALIDITY_ASSERT(x) if (!(x)) this->invalid_json= true; #else #include "sql_select.h" #define VALIDITY_ASSERT(x) DBUG_ASSERT(x) #endif #include <type_traits> class Opt_trace_stmt; class Opt_trace_context; class Json_writer; struct TABLE_LIST; /* Single_line_formatting_helper is used by Json_writer to do better formatting of JSON documents. The idea is to catch arrays that can be printed on one line: arrayName : [ "boo", 123, 456 ] and actually print them on one line. Arrrays that occupy too much space on the line, or have nested members cannot be printed on one line. We hook into JSON printing functions and try to detect the pattern. While detecting the pattern, we will accumulate "boo", 123, 456 as strings. Then, - either the pattern is broken, and we print the elements out, - or the pattern lasts till the end of the array, and we print the array on one line. */ class Single_line_formatting_helper { enum enum_state { INACTIVE, ADD_MEMBER, IN_ARRAY, DISABLED }; /* This works like a finite automaton. state=DISABLED means the helper is disabled - all on_XXX functions will return false (which means "not handled") and do nothing. +->-+ | v INACTIVE ---> ADD_MEMBER ---> IN_ARRAY--->-+ ^ | +------------------<--------------------+ For other states: INACTIVE - initial state, we have nothing. ADD_MEMBER - add_member() was called, the buffer has "member_name\0". IN_ARRAY - start_array() was called. */ enum enum_state state; enum { MAX_LINE_LEN= 80 }; char buffer[80]; /* The data in the buffer is located between buffer[0] and buf_ptr */ char *buf_ptr; uint line_len; Json_writer *owner; public: Single_line_formatting_helper() : state(INACTIVE), buf_ptr(buffer) {} void init(Json_writer *owner_arg) { owner= owner_arg; } bool on_add_member(const char *name, size_t len); bool on_start_array(); bool on_end_array(); void on_start_object(); // on_end_object() is not needed. bool on_add_str(const char *str, size_t num_bytes); /* Returns true if the helper is flushing its buffer and is probably making calls back to its Json_writer. (The Json_writer uses this function to avoid re-doing the processing that it has already done before making a call to fmt_helper) */ bool is_making_writer_calls() const { return state == DISABLED; } private: void flush_on_one_line(); void disable_and_flush(); }; /* Something that looks like class String, but has an internal limit of how many bytes one can append to it. Bytes that were truncated due to the size limitation are counted. */ class String_with_limit { public: String_with_limit() : size_limit(SIZE_T_MAX), truncated_len(0) { str.length(0); } size_t get_truncated_bytes() const { return truncated_len; } size_t get_size_limit() { return size_limit; } void set_size_limit(size_t limit_arg) { // Setting size limit to be shorter than length will not have the desired // effect DBUG_ASSERT(str.length() < size_limit); size_limit= limit_arg; } void append(const char *s, size_t size) { if (str.length() + size <= size_limit) { // Whole string can be added, just do it str.append(s, size); } else { // We cannot add the whole string if (str.length() < size_limit) { // But we can still add something size_t bytes_to_add = size_limit - str.length(); str.append(s, bytes_to_add); truncated_len += size - bytes_to_add; } else truncated_len += size; } } void append(const char *s) { append(s, strlen(s)); } void append(char c) { if (str.length() + 1 > size_limit) truncated_len++; else str.append(c); } const String *get_string() { return &str; } size_t length() { return str.length(); } private: String str; // str must not get longer than this many bytes. size_t size_limit; // How many bytes were truncated from the string size_t truncated_len; }; /* A class to write well-formed JSON documents. The documents are also formatted for human readability. */ class Json_writer { #if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) /* In debug mode, Json_writer will fail and assertion if one attempts to produce an invalid JSON document (e.g. JSON array having named elements). */ std::vector<bool> named_items_expectation; bool named_item_expected() const; bool got_name; #ifdef JSON_WRITER_UNIT_TEST public: // When compiled for unit test, creating invalid JSON will set this to true // instead of an assertion. bool invalid_json= false; #endif #endif public: /* Add a member. We must be in an object. */ Json_writer& add_member(const char *name); Json_writer& add_member(const char *name, size_t len); /* Add atomic values */ void add_str(const char* val); void add_str(const char* val, size_t num_bytes); void add_str(const String &str); void add_str(Item *item); void add_table_name(const JOIN_TAB *tab); void add_table_name(const TABLE* table); void add_ll(longlong val); void add_ull(ulonglong val); void add_size(longlong val); void add_double(double val); void add_bool(bool val); void add_null(); private: void add_unquoted_str(const char* val); void add_unquoted_str(const char* val, size_t len); bool on_add_str(const char *str, size_t num_bytes); void on_start_object(); public: /* Start a child object */ void start_object(); void start_array(); void end_object(); void end_array(); /* One can set a limit of how large a JSON document should be. Writes beyond that size will be counted, but will not be collected. */ void set_size_limit(size_t mem_size) { output.set_size_limit(mem_size); } size_t get_truncated_bytes() { return output.get_truncated_bytes(); } Json_writer() : #if !defined(NDEBUG) || defined(JSON_WRITER_UNIT_TEST) got_name(false), #endif indent_level(0), document_start(true), element_started(false), first_child(true) { fmt_helper.init(this); } private: // TODO: a stack of (name, bool is_object_or_array) elements. int indent_level; enum { INDENT_SIZE = 2 }; friend class Single_line_formatting_helper; friend class Json_writer_nesting_guard; bool document_start; bool element_started; bool first_child; Single_line_formatting_helper fmt_helper; void append_indent(); void start_element(); void start_sub_element(); public: String_with_limit output; }; /* A class to add values to Json_writer_object and Json_writer_array */ class Json_value_helper { Json_writer* writer; public: void init(Json_writer *my_writer) { writer= my_writer; } void add_str(const char* val) { writer->add_str(val); } void add_str(const char* val, size_t length) { writer->add_str(val, length); } void add_str(const String &str) { writer->add_str(str.ptr(), str.length()); } void add_str(const LEX_CSTRING &str) { writer->add_str(str.str, str.length); } void add_str(Item *item) { writer->add_str(item); } void add_ll(longlong val) { writer->add_ll(val); } void add_size(longlong val) { writer->add_size(val); } void add_double(double val) { writer->add_double(val); } void add_bool(bool val) { writer->add_bool(val); } void add_null() { writer->add_null(); } void add_table_name(const JOIN_TAB *tab) { writer->add_table_name(tab); } void add_table_name(const TABLE* table) { writer->add_table_name(table); } }; /* A common base for Json_writer_object and Json_writer_array */ class Json_writer_struct { Json_writer_struct(const Json_writer_struct&)= delete; Json_writer_struct& operator=(const Json_writer_struct&)= delete; #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS static thread_local std::vector<bool> named_items_expectation; #endif protected: Json_writer* my_writer; Json_value_helper context; /* Tells when a json_writer_struct has been closed or not */ bool closed; explicit Json_writer_struct(Json_writer *writer) : my_writer(writer) { context.init(my_writer); closed= false; #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS named_items_expectation.push_back(expect_named_children); #endif } explicit Json_writer_struct(THD *thd) : Json_writer_struct(thd->opt_trace.get_current_json()) { } public: #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS virtual ~Json_writer_struct() { named_items_expectation.pop_back(); } #else virtual ~Json_writer_struct() = default; #endif bool trace_started() const { return my_writer != 0; } #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS bool named_item_expected() const { return named_items_expectation.size() > 1 && *(named_items_expectation.rbegin() + 1); } #endif }; /* RAII-based class to start/end writing a JSON object into the JSON document There is "ignore mode": one can initialize Json_writer_object with a NULL Json_writer argument, and then all its calls will do nothing. This is used by optimizer trace which can be enabled or disabled. */ class Json_writer_object : public Json_writer_struct { private: void add_member(const char *name) { my_writer->add_member(name); } public: explicit Json_writer_object(Json_writer* writer, const char *str= nullptr) : Json_writer_struct(writer) { #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS DBUG_ASSERT(named_item_expected()); #endif if (unlikely(my_writer)) { if (str) my_writer->add_member(str); my_writer->start_object(); } } explicit Json_writer_object(THD* thd, const char *str= nullptr) : Json_writer_object(thd->opt_trace.get_current_json(), str) { } ~Json_writer_object() { if (my_writer && !closed) my_writer->end_object(); closed= TRUE; } Json_writer_object& add(const char *name, bool value) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); context.add_bool(value); } return *this; } Json_writer_object& add(const char *name, ulonglong value) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); my_writer->add_ull(value); } return *this; } template<class IntT, typename= typename ::std::enable_if<std::is_integral<IntT>::value>::type > Json_writer_object& add(const char *name, IntT value) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); context.add_ll(value); } return *this; } Json_writer_object& add(const char *name, double value) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); context.add_double(value); } return *this; } Json_writer_object& add(const char *name, const char *value) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); context.add_str(value); } return *this; } Json_writer_object& add(const char *name, const char *value, size_t num_bytes) { add_member(name); context.add_str(value, num_bytes); return *this; } Json_writer_object& add(const char *name, const LEX_CSTRING &value) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); context.add_str(value.str, value.length); } return *this; } Json_writer_object& add(const char *name, Item *value) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); context.add_str(value); } return *this; } Json_writer_object& add_null(const char*name) { DBUG_ASSERT(!closed); if (my_writer) { add_member(name); context.add_null(); } return *this; } Json_writer_object& add_table_name(const JOIN_TAB *tab) { DBUG_ASSERT(!closed); if (my_writer) { add_member("table"); context.add_table_name(tab); } return *this; } Json_writer_object& add_table_name(const TABLE *table) { DBUG_ASSERT(!closed); if (my_writer) { add_member("table"); context.add_table_name(table); } return *this; } Json_writer_object& add_select_number(uint select_number) { DBUG_ASSERT(!closed); if (my_writer) { add_member("select_id"); if (unlikely(select_number >= INT_MAX)) context.add_str("fake"); else context.add_ll(static_cast<longlong>(select_number)); } return *this; } void end() { DBUG_ASSERT(!closed); if (unlikely(my_writer)) my_writer->end_object(); closed= TRUE; } }; /* RAII-based class to start/end writing a JSON array into the JSON document There is "ignore mode": one can initialize Json_writer_array with a NULL Json_writer argument, and then all its calls will do nothing. This is used by optimizer trace which can be enabled or disabled. */ class Json_writer_array : public Json_writer_struct { public: explicit Json_writer_array(Json_writer *writer, const char *str= nullptr) : Json_writer_struct(writer) { #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS DBUG_ASSERT(!named_item_expected()); #endif if (unlikely(my_writer)) { if (str) my_writer->add_member(str); my_writer->start_array(); } } explicit Json_writer_array(THD *thd, const char *str= nullptr) : Json_writer_array(thd->opt_trace.get_current_json(), str) { } ~Json_writer_array() { if (unlikely(my_writer && !closed)) { my_writer->end_array(); closed= TRUE; } } void end() { DBUG_ASSERT(!closed); if (unlikely(my_writer)) my_writer->end_array(); closed= TRUE; } Json_writer_array& add(bool value) { DBUG_ASSERT(!closed); if (my_writer) context.add_bool(value); return *this; } Json_writer_array& add(ulonglong value) { DBUG_ASSERT(!closed); if (my_writer) context.add_ll(static_cast<longlong>(value)); return *this; } Json_writer_array& add(longlong value) { DBUG_ASSERT(!closed); if (my_writer) context.add_ll(value); return *this; } Json_writer_array& add(double value) { DBUG_ASSERT(!closed); if (my_writer) context.add_double(value); return *this; } #ifndef _WIN64 Json_writer_array& add(size_t value) { DBUG_ASSERT(!closed); if (my_writer) context.add_ll(static_cast<longlong>(value)); return *this; } #endif Json_writer_array& add(const char *value) { DBUG_ASSERT(!closed); if (my_writer) context.add_str(value); return *this; } Json_writer_array& add(const char *value, size_t num_bytes) { DBUG_ASSERT(!closed); if (my_writer) context.add_str(value, num_bytes); return *this; } Json_writer_array& add(const LEX_CSTRING &value) { DBUG_ASSERT(!closed); if (my_writer) context.add_str(value.str, value.length); return *this; } Json_writer_array& add(Item *value) { DBUG_ASSERT(!closed); if (my_writer) context.add_str(value); return *this; } Json_writer_array& add_null() { DBUG_ASSERT(!closed); if (my_writer) context.add_null(); return *this; } Json_writer_array& add_table_name(const JOIN_TAB *tab) { DBUG_ASSERT(!closed); if (my_writer) context.add_table_name(tab); return *this; } Json_writer_array& add_table_name(const TABLE *table) { DBUG_ASSERT(!closed); if (my_writer) context.add_table_name(table); return *this; } }; /* RAII-based class to disable writing into the JSON document The tracing is disabled as soon as the object is created. The destuctor is called as soon as we exit the scope of the object and the tracing is enabled back. */ class Json_writer_temp_disable { public: Json_writer_temp_disable(THD *thd_arg); ~Json_writer_temp_disable(); THD *thd; }; /* RAII-based helper class to detect incorrect use of Json_writer. The idea is that a function typically must leave Json_writer at the same identation level as it was when it was invoked. Leaving it at a different level typically means we forgot to close an object or an array So, here is a way to guard void foo(Json_writer *writer) { Json_writer_nesting_guard(writer); .. do something with writer // at the end of the function, ~Json_writer_nesting_guard() is called // and it makes sure that the nesting is the same as when the function was // entered. } */ class Json_writer_nesting_guard { #ifdef DBUG_OFF public: Json_writer_nesting_guard(Json_writer *) {} #else Json_writer* writer; int indent_level; public: Json_writer_nesting_guard(Json_writer *writer_arg) : writer(writer_arg), indent_level(writer->indent_level) {} ~Json_writer_nesting_guard() { DBUG_ASSERT(indent_level == writer->indent_level); } #endif }; #endif
Save