MySQL 8.0.40
Source Code Documentation
pfs_variable.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef PFS_VARIABLE_H
26#define PFS_VARIABLE_H
27
28/**
29 @file storage/perfschema/pfs_variable.h
30 Performance schema system and status variables (declarations).
31*/
32
33/**
34 OVERVIEW
35 --------
36 Status and system variables are implemented differently in the server, but the
37 steps to process them in the Performance Schema are essentially the same:
38
39 1. INITIALIZE - Build or acquire a sorted list of variables to use for input.
40 Use the SHOW_VAR struct as an intermediate format common to system, status
41 and user vars:
42
43 SHOW_VAR
44 Name - Text string
45 Value - Pointer to memory location, function, sub array structure
46 Type - Scalar, function, or sub array
47 Scope - SESSION, GLOBAL, BOTH
48
49 Steps:
50 - Register the server's internal buffer with the class. Acquire locks
51 if necessary, then scan the contents of the input buffer.
52 - For system variables, convert each element to SHOW_VAR format, store in
53 a temporary array.
54 - For status variables, copy existing global status array into a local
55 array that can be used without locks. Expand nested sub arrays, indicated
56 by a type of SHOW_ARRAY.
57
58 2. MATERIALIZE - Convert the list of SHOW_VAR variables to string format,
59 store in a local cache:
60 - Resolve each variable according to the type.
61 - Recursively process unexpanded nested arrays and callback functions.
62 - Aggregate values across threads for global status.
63 - Convert numeric values to a string.
64 - Prefix variable name with the plugin name.
65
66 3. OUTPUT - Iterate the cache for the SHOW command or table query.
67
68 CLASS OVERVIEW
69 --------------
70 1. System_variable - A materialized system variable
71 2. Status_variable - A materialized status variable
72 3. PFS_variable_cache - Base class that defines the interface for the
73 operations above.
74 public
75 init_show_var_array() - Build SHOW_VAR list of variables for processing
76 materialize_global() - Materialize global variables, aggregate across
77 sessions
78 materialize_session() - Materialize variables for a given PFS_thread or
79 THD
80 materialize_user() - Materialize variables for a user, aggregate
81 across related threads.
82 materialize_host() - Materialize variables for a host, aggregate
83 across related threads.
84 materialize_account() - Materialize variables for a account, aggregate
85 across related threads.
86 private
87 m_show_var_array - Prealloc_array of SHOW_VARs for input to
88 Materialize
89 m_cache - Prealloc_array of materialized variables for
90 output
91 do_materialize_global() - Implementation of materialize_global()
92 do_materialize_session() - Implementation of materialize_session()
93 do_materialize_client() - Implementation of
94 materialize_user/host/account()
95
96 4. PFS_system_variable_cache - System variable implementation of
97 PFS_variable_cache
98 5. PFS_status_variable_cache - Status variable implementation of
99 PFS_variable_cache
100 6. Find_THD_variable - Used by the thread manager to find and lock a
101 THD.
102
103 GLOSSARY
104 --------
105 Status variable - Server or plugin status counter. Not dynamic.
106 System variable - Server or plugin configuration variable. Usually dynamic.
107 GLOBAL scope - Associated with the server, no context at thread level.
108 SESSION scope - Associated with a connection or thread, but no global
109 context.
110 BOTH scope - Globally defined but applies at the session level.
111 Initialize - Build list of variables in SHOW_VAR format.
112 Materialize - Convert variables in SHOW_VAR list to string, cache for
113 output.
114 Manifest - Substep of Materialize. Resolve variable values according to
115 type. This includes SHOW_FUNC types which are resolved by
116 executing a callback function (possibly recursively), and
117 SHOW_ARRAY types that expand into nested sub arrays.
118 LOCK PRIORITIES
119 ---------------
120 System Variables
121 LOCK_plugin_delete (block plugin delete)
122 LOCK_system_variables_hash
123 LOCK_thd_data (block THD delete)
124 LOCK_thd_sysvar (block system variable updates,
125 alloc_and_copy_thd_dynamic_variables)
126 LOCK_global_system_variables (very briefly held)
127
128 Status Variables
129 LOCK_status
130 LOCK_thd_data (block THD delete)
131*/
132
133#include "my_inttypes.h"
134/* Iteration on THD from the sql layer. */
136
137#define PFS_VAR
138#include <assert.h>
139#include <stddef.h>
140#include <sys/types.h>
141#include <string>
142
143#include "sql/set_var.h"
148
149typedef std::vector<SHOW_VAR> Status_var_array;
150
151/* Number of system variable elements to preallocate. */
152#define SYSTEM_VARIABLE_PREALLOC 200
154
155/* Global array of all server and plugin-defined status variables. */
157extern bool status_vars_inited;
158static const uint SYSVAR_MEMROOT_BLOCK_SIZE = 4096;
159
161
162class Find_THD_Impl;
165
166/**
167 System variable derived from sys_var object.
168*/
170 public:
172 System_variable(THD *target_thd, const SHOW_VAR *show_var,
173 enum_var_type query_scope);
174 System_variable(THD *target_thd, const SHOW_VAR *show_var);
175
176 bool is_null() const { return !m_initialized; }
177
178 public:
179 const char *m_name;
198
199 private:
201 void init(THD *thd, const SHOW_VAR *show_var, enum_var_type query_scope);
202 void init(THD *thd, const SHOW_VAR *show_var);
203};
204
205/**
206 Status variable derived from @c SHOW_VAR.
207*/
209 public:
211 : m_name(nullptr),
212 m_name_length(0),
217 m_initialized(false) {}
218
220 enum_var_type query_scope);
221
222 bool is_null() const { return !m_initialized; }
223
224 public:
225 const char *m_name;
232
233 private:
235 void init(const SHOW_VAR *show_var, System_status_var *status_vars,
236 enum_var_type query_scope);
237};
238
239/**
240 Get and lock a validated @c THD from the thread manager.
241*/
243 public:
245 explicit Find_THD_variable(THD *unsafe_thd) : m_unsafe_thd(unsafe_thd) {}
246
247 bool operator()(THD *thd) override;
248 void set_unsafe_thd(THD *unsafe_thd) { m_unsafe_thd = unsafe_thd; }
249
250 private:
252};
253
254/**
255 Base class for a system or status variable cache.
256*/
257template <class Var_type>
259 public:
261
262 explicit PFS_variable_cache(bool external_init);
263
264 virtual ~PFS_variable_cache() = 0;
265
266 /**
267 Build array of SHOW_VARs from the external variable source.
268 Filter using session scope.
269 */
271
272 /**
273 Build array of SHOW_VARs suitable for aggregation by user, host or account.
274 Filter using session scope.
275 */
277
278 /**
279 Build cache of GLOBAL system or status variables.
280 Aggregate across threads if applicable.
281 */
283
284 /**
285 Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
286 */
288
289 /**
290 Build cache of SESSION variables for a non-instrumented thread.
291 */
293
294 /**
295 Build cache of SESSION variables for an instrumented thread.
296 */
297 int materialize_session(PFS_thread *pfs_thread, bool use_mem_root = false);
298
299 /**
300 Cache a single SESSION variable for an instrumented thread.
301 */
302 int materialize_session(PFS_thread *pfs_thread, uint index);
303
304 /**
305 Build cache of SESSION status variables for a user.
306 */
308
309 /**
310 Build cache of SESSION status variables for a host.
311 */
313
314 /**
315 Build cache of SESSION status variables for an account.
316 */
318
319 /**
320 True if variables have been materialized.
321 */
323
324 /**
325 True if variables have been materialized for given THD.
326 */
327 bool is_materialized(THD *unsafe_thd) {
328 return (unsafe_thd == m_unsafe_thd && m_materialized);
329 }
330
331 /**
332 True if variables have been materialized for given PFS_thread.
333 */
334 bool is_materialized(PFS_thread *pfs_thread) {
335 return (pfs_thread == m_pfs_thread && m_materialized);
336 }
337
338 /**
339 True if variables have been materialized for given PFS_user.
340 */
341 bool is_materialized(PFS_user *pfs_user) {
342 return (static_cast<PFS_client *>(pfs_user) == m_pfs_client &&
344 }
345
346 /**
347 True if variables have been materialized for given PFS_host.
348 */
349 bool is_materialized(PFS_host *pfs_host) {
350 return (static_cast<PFS_client *>(pfs_host) == m_pfs_client &&
352 }
353
354 /**
355 True if variables have been materialized for given PFS_account.
356 */
357 bool is_materialized(PFS_account *pfs_account) {
358 return (static_cast<PFS_client *>(pfs_account) == m_pfs_client &&
360 }
361
362 /**
363 True if variables have been materialized for given PFS_user/host/account.
364 */
365 bool is_materialized(PFS_client *pfs_client) {
366 return (static_cast<PFS_client *>(pfs_client) == m_pfs_client &&
368 }
369
370 /**
371 Get a validated THD from the thread manager. Execute callback function while
372 inside of the thread manager locks.
373 */
376
377 /**
378 Get a single variable from the cache.
379 Get the first element in the cache by default.
380 */
381 const Var_type *get(uint index = 0) const {
382 if (index >= m_cache.size()) {
383 return nullptr;
384 }
385
386 const Var_type *p = &m_cache.at(index);
387 return p;
388 }
389
390 /**
391 Number of elements in the cache.
392 */
393 uint size() { return (uint)m_cache.size(); }
394
395 private:
396 virtual bool do_initialize_global() { return true; }
397 virtual bool do_initialize_session() { return true; }
398 virtual int do_materialize_global() { return 1; }
399 virtual int do_materialize_all(THD *) { return 1; }
400 virtual int do_materialize_session(THD *) { return 1; }
401 virtual int do_materialize_session(PFS_thread *) { return 1; }
402 virtual int do_materialize_session(PFS_thread *, uint) { return 1; }
403
404 protected:
405 /* Validated THD */
407
408 /* Unvalidated THD */
410
411 /* Current THD */
413
414 /* Current PFS_thread. */
416
417 /* Current PFS_user, host or account. */
419
420 /* Callback for thread iterator. */
422
423 /* Cache of materialized variables. */
425
426 /* True when list of SHOW_VAR is complete. */
428
429 /*
430 True if the SHOW_VAR array must be initialized externally from the
431 materialization step, such as with aggregations and queries by thread.
432 */
434
435 /* True when cache is complete. */
437
438 /* Array of status variables to be materialized. Last element must be null. */
440
441 /* Array of system variable descriptors. */
443
444 /* Version of global hash/array. Changes when vars added/removed. */
446
447 /* Query scope: GLOBAL or SESSION. */
449
450 /* True if temporary mem_root should be used for materialization. */
452
453 /* True if summarizing across users, hosts or accounts. */
455};
456
457/**
458 Destructor.
459*/
460template <class Var_type>
462
463/**
464 Get a validated THD from the thread manager. Execute callback function while
465 while inside the thread manager lock.
466*/
467template <class Var_type>
469 if (unsafe_thd == nullptr) {
470 /*
471 May happen, precisely because the pointer is unsafe
472 (THD just disconnected for example).
473 No need to walk Global_THD_manager for that.
474 */
475 return THD_ptr{nullptr};
476 }
477
478 m_thd_finder.set_unsafe_thd(unsafe_thd);
479 return Global_THD_manager::get_instance()->find_thd(&m_thd_finder);
480}
481
482template <class Var_type>
484 assert(pfs_thread != nullptr);
485 return get_THD(pfs_thread->m_thd);
486}
487
488/**
489 Build array of SHOW_VARs from external source of system or status variables.
490 Filter using session scope.
491*/
492template <class Var_type>
494 if (m_initialized) {
495 return false;
496 }
497
498 return do_initialize_session();
499}
500
501/**
502 Build array of SHOW_VARs suitable for aggregation by user, host or account.
503 Filter using session scope.
504*/
505template <class Var_type>
507 if (m_initialized) {
508 return false;
509 }
510
511 /* Requires aggregation by user, host or account. */
512 m_aggregate = true;
513
514 return do_initialize_session();
515}
516
517/**
518 Build cache of all GLOBAL variables.
519*/
520template <class Var_type>
522 if (is_materialized()) {
523 return 0;
524 }
525
526 return do_materialize_global();
527}
528
529/**
530 Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
531*/
532template <class Var_type>
534 if (!unsafe_thd) {
535 return 1;
536 }
537
538 if (is_materialized(unsafe_thd)) {
539 return 0;
540 }
541
542 return do_materialize_all(unsafe_thd);
543}
544
545/**
546 Build cache of SESSION variables for a non-instrumented thread.
547*/
548template <class Var_type>
550 if (!unsafe_thd) {
551 return 1;
552 }
553
554 if (is_materialized(unsafe_thd)) {
555 return 0;
556 }
557
558 return do_materialize_session(unsafe_thd);
559}
560
561/**
562 Build cache of SESSION variables for a thread.
563*/
564template <class Var_type>
566 bool use_mem_root) {
567 if (!pfs_thread) {
568 return 1;
569 }
570
571 if (is_materialized(pfs_thread)) {
572 return 0;
573 }
574
575 if (!pfs_thread->m_lock.is_populated() || pfs_thread->m_thd == nullptr) {
576 return 1;
577 }
578
579 m_use_mem_root = use_mem_root;
580
581 return do_materialize_session(pfs_thread);
582}
583
584/**
585 Materialize a single variable for a thread.
586*/
587template <class Var_type>
589 uint index) {
590 /* No check for is_materialized(). */
591
592 if (!pfs_thread) {
593 return 1;
594 }
595
596 if (!pfs_thread->m_lock.is_populated() || pfs_thread->m_thd == nullptr) {
597 return 1;
598 }
599
600 return do_materialize_session(pfs_thread, index);
601}
602
603/**
604 System variable cache.
605*/
606class PFS_system_variable_cache : public PFS_variable_cache<System_variable> {
607 public:
608 explicit PFS_system_variable_cache(bool external_init);
609 bool match_scope(int scope);
612
613 private:
614 bool do_initialize_session() override;
615
616 /* Global */
617 int do_materialize_global() override;
618 /* Session - THD */
619 int do_materialize_session(THD *thd) override;
620 /* Session - PFS_thread */
621 int do_materialize_session(PFS_thread *thread) override;
622 /* Single variable - PFS_thread */
623 int do_materialize_session(PFS_thread *pfs_thread, uint index) override;
624
625 /* Temporary mem_root to use for materialization. */
627 /* Pointer to THD::mem_root. */
629 /* Save THD::mem_root. */
631 /* Pointer to temporary mem_root. */
633 /* Allocate and/or assign temporary mem_root. */
634 void set_mem_root();
635 /* Mark all memory blocks as free in temporary mem_root. */
636 void clear_mem_root();
637 /* Free mem_root memory. */
638 void free_mem_root();
639
640 protected:
641 /* Build SHOW_var array. */
642 bool init_show_var_array(enum_var_type scope, bool strict);
643 /* Global and Session - THD */
644 int do_materialize_all(THD *thd) override;
645};
646
647/**
648 System variable info cache.
649*/
651 public:
652 explicit PFS_system_variable_info_cache(bool external_init)
653 : PFS_system_variable_cache(external_init) {}
655
656 private:
657 /* Global and Session - THD */
658 int do_materialize_all(THD *thd) override;
659};
660
661/**
662 Persisted variables cache.
663*/
665 public:
666 explicit PFS_system_persisted_variables_cache(bool external_init)
667 : PFS_system_variable_cache(external_init) {}
669
670 private:
671 /* Global and Session - THD */
672 int do_materialize_all(THD *thd) override;
673};
674
675/**
676 Status variable cache
677*/
678class PFS_status_variable_cache : public PFS_variable_cache<Status_variable> {
679 public:
680 explicit PFS_status_variable_cache(bool external_init);
681
682 int materialize_user(PFS_user *pfs_user);
683 int materialize_host(PFS_host *pfs_host);
684 int materialize_account(PFS_account *pfs_account);
685
687
688 protected:
689 /* Get PFS_user, account or host associated with a PFS_thread. Implemented by
690 * table class. */
691 virtual PFS_client *get_pfs(PFS_thread *) { return nullptr; }
692
693 /* True if query is a SHOW command. */
695
696 private:
697 bool do_initialize_session() override;
698
699 int do_materialize_global() override;
700 /* Global and Session - THD */
701 int do_materialize_all(THD *thd) override;
702 int do_materialize_session(THD *thd) override;
703 int do_materialize_session(PFS_thread *thread) override;
704 int do_materialize_session(PFS_thread *, uint) override { return 0; }
705 int do_materialize_client(PFS_client *pfs_client);
706
707 /* Callback to sum user, host or account status variables. */
708 void (*m_sum_client_status)(PFS_client *pfs_client,
709 System_status_var *status_totals);
710
711 /* Build SHOW_VAR array from external source. */
712 bool init_show_var_array(enum_var_type scope, bool strict);
713
714 /* Recursively expand nested SHOW_VAR arrays. */
715 void expand_show_var_array(const SHOW_VAR *show_var_array, const char *prefix,
716 bool strict);
717
718 /* Exclude unwanted variables from the query. */
719 bool filter_show_var(const SHOW_VAR *show_var, bool strict);
720
721 /* Check the variable scope against the query scope. */
722 bool match_scope(SHOW_SCOPE variable_scope, bool strict);
723
724 /* Exclude specific status variables by name or prefix. */
725 bool filter_by_name(const SHOW_VAR *show_var);
726
727 /* Check if a variable has an aggregatable type. */
728 bool can_aggregate(enum_mysql_show_type variable_type);
729
730 /* Build status variable name with prefix. Return in the buffer provided. */
731 char *make_show_var_name(const char *prefix, const char *name, char *name_buf,
732 size_t buf_len);
733
734 /* Build status variable name with prefix. Return copy of the string. */
735 char *make_show_var_name(const char *prefix, const char *name);
736
737 /* For the current THD, use initial_status_vars taken from before the query
738 * start. */
740
741 /* Build the list of status variables from SHOW_VAR array. */
742 void manifest(THD *thd, const SHOW_VAR *show_var_array,
743 System_status_var *status_vars, const char *prefix,
744 bool nested_array, bool strict);
745};
746
747/* Callback functions to sum status variables for a given user, host or account.
748 */
749void sum_user_status(PFS_client *pfs_user, System_status_var *status_totals);
750void sum_host_status(PFS_client *pfs_host, System_status_var *status_totals);
751void sum_account_status(PFS_client *pfs_account,
752 System_status_var *status_totals);
753
754/* Warnings issued if the global system or status variables change mid-query. */
757
758#endif
Base class to find specific thd from the thd list.
Definition: mysqld_thd_manager.h:64
Get and lock a validated THD from the thread manager.
Definition: pfs_variable.h:242
THD * m_unsafe_thd
Definition: pfs_variable.h:251
void set_unsafe_thd(THD *unsafe_thd)
Definition: pfs_variable.h:248
Find_THD_variable()
Definition: pfs_variable.h:244
Find_THD_variable(THD *unsafe_thd)
Definition: pfs_variable.h:245
bool operator()(THD *thd) override
Override this operator to provide implementation to find specific thd.
Definition: pfs_variable.cc:53
static Global_THD_manager * get_instance()
Retrieves singleton instance.
Definition: mysqld_thd_manager.h:213
THD_ptr find_thd(Find_THD_Impl *func)
Returns a THD_ptr containing first THD for which operator() returns true.
Definition: mysqld_thd_manager.cc:321
Status variable cache.
Definition: pfs_variable.h:678
int do_materialize_client(PFS_client *pfs_client)
Build cache of SESSION status variables using the status values provided.
Definition: pfs_variable.cc:1365
void expand_show_var_array(const SHOW_VAR *show_var_array, const char *prefix, bool strict)
Expand a nested sub array of status variables, indicated by a type of SHOW_ARRAY.
Definition: pfs_variable.cc:1074
bool filter_by_name(const SHOW_VAR *show_var)
Definition: pfs_variable.cc:939
int do_materialize_all(THD *thd) override
Build GLOBAL and SESSION status variable cache using values for a non-instrumented thread.
Definition: pfs_variable.cc:1225
bool m_show_command
Definition: pfs_variable.h:694
int materialize_host(PFS_host *pfs_host)
Build cache of SESSION status variables for a host.
Definition: pfs_variable.cc:865
bool do_initialize_session() override
Build an internal SHOW_VAR array from the external status variable array.
Definition: pfs_variable.cc:1139
int do_materialize_session(THD *thd) override
Build SESSION status variable cache using values for a non-instrumented thread.
Definition: pfs_variable.cc:1273
bool can_aggregate(enum_mysql_show_type variable_type)
Check that the variable type is aggregatable.
Definition: pfs_variable.cc:960
char * make_show_var_name(const char *prefix, const char *name, char *name_buf, size_t buf_len)
Build the complete status variable name, with prefix.
Definition: pfs_variable.cc:1102
void(* m_sum_client_status)(PFS_client *pfs_client, System_status_var *status_totals)
Definition: pfs_variable.h:708
int do_materialize_session(PFS_thread *, uint) override
Definition: pfs_variable.h:704
PFS_status_variable_cache(bool external_init)
CLASS PFS_status_variable_cache.
Definition: pfs_variable.cc:833
ulonglong get_status_array_version()
Definition: pfs_variable.h:686
void manifest(THD *thd, const SHOW_VAR *show_var_array, System_status_var *status_vars, const char *prefix, bool nested_array, bool strict)
Definition: pfs_variable.cc:1406
bool filter_show_var(const SHOW_VAR *show_var, bool strict)
Check if a status variable should be excluded from the query.
Definition: pfs_variable.cc:1007
int materialize_account(PFS_account *pfs_account)
Build cache of SESSION status variables for an account.
Definition: pfs_variable.cc:886
int materialize_user(PFS_user *pfs_user)
Build cache of SESSION status variables for a user.
Definition: pfs_variable.cc:844
virtual PFS_client * get_pfs(PFS_thread *)
Definition: pfs_variable.h:691
int do_materialize_global() override
Build cache for GLOBAL status variables using values totaled from all threads.
Definition: pfs_variable.cc:1173
bool init_show_var_array(enum_var_type scope, bool strict)
Build an array of SHOW_VARs from the global status array.
Definition: pfs_variable.cc:1033
bool match_scope(SHOW_SCOPE variable_scope, bool strict)
Compare status variable scope to desired scope.
Definition: pfs_variable.cc:909
System_status_var * set_status_vars()
For the current THD, use initial_status_vars taken from before the query start.
Definition: pfs_variable.cc:1158
Persisted variables cache.
Definition: pfs_variable.h:664
int do_materialize_all(THD *thd) override
CLASS PFS_system_persisted_variables_cache.
Definition: pfs_variable.cc:510
~PFS_system_persisted_variables_cache() override=default
PFS_system_persisted_variables_cache(bool external_init)
Definition: pfs_variable.h:666
System variable cache.
Definition: pfs_variable.h:606
int do_materialize_session(THD *thd) override
Build a SESSION system variable cache for a THD.
Definition: pfs_variable.cc:398
void set_mem_root()
Allocate and assign mem_root for system variable materialization.
Definition: pfs_variable.cc:247
MEM_ROOT m_mem_sysvar
Definition: pfs_variable.h:626
bool init_show_var_array(enum_var_type scope, bool strict)
Build a sorted list of all system variables from the system variable hash.
Definition: pfs_variable.cc:87
MEM_ROOT * m_mem_sysvar_ptr
Definition: pfs_variable.h:632
MEM_ROOT ** m_mem_thd
Definition: pfs_variable.h:628
void free_mem_root()
Free the temporary mem_root.
Definition: pfs_variable.cc:274
PFS_system_variable_cache(bool external_init)
Definition: pfs_variable.cc:77
~PFS_system_variable_cache() override
Definition: pfs_variable.h:611
ulonglong get_sysvar_hash_version()
Definition: pfs_variable.h:610
int do_materialize_all(THD *thd) override
Build a GLOBAL and SESSION system variable cache.
Definition: pfs_variable.cc:196
MEM_ROOT * m_mem_thd_save
Definition: pfs_variable.h:630
int do_materialize_global() override
Build a GLOBAL system variable cache.
Definition: pfs_variable.cc:156
bool match_scope(int scope)
Match system variable scope to desired scope.
Definition: pfs_variable.cc:132
void clear_mem_root()
Mark memory blocks in the temporary mem_root as free.
Definition: pfs_variable.cc:261
bool do_initialize_session() override
Build an array of SHOW_VARs from the system variable hash.
Definition: pfs_variable.cc:118
System variable info cache.
Definition: pfs_variable.h:650
int do_materialize_all(THD *thd) override
CLASS PFS_system_variable_info_cache.
Definition: pfs_variable.cc:456
PFS_system_variable_info_cache(bool external_init)
Definition: pfs_variable.h:652
~PFS_system_variable_info_cache() override=default
Base class for a system or status variable cache.
Definition: pfs_variable.h:258
virtual int do_materialize_session(PFS_thread *)
Definition: pfs_variable.h:401
THD_ptr get_THD(THD *thd)
Get a validated THD from the thread manager.
Definition: pfs_variable.h:468
bool is_materialized()
True if variables have been materialized.
Definition: pfs_variable.h:322
bool m_materialized
Definition: pfs_variable.h:436
PFS_client * m_pfs_client
Definition: pfs_variable.h:418
bool initialize_session()
Build array of SHOW_VARs from the external variable source.
Definition: pfs_variable.h:493
THD * m_unsafe_thd
Definition: pfs_variable.h:409
bool is_materialized(PFS_client *pfs_client)
True if variables have been materialized for given PFS_user/host/account.
Definition: pfs_variable.h:365
virtual int do_materialize_session(THD *)
Definition: pfs_variable.h:400
virtual int do_materialize_global()
Definition: pfs_variable.h:398
ulonglong m_version
Definition: pfs_variable.h:445
virtual int do_materialize_all(THD *)
Definition: pfs_variable.h:399
bool initialize_client_session()
Build array of SHOW_VARs suitable for aggregation by user, host or account.
Definition: pfs_variable.h:506
PFS_thread * m_pfs_thread
Definition: pfs_variable.h:415
bool m_external_init
Definition: pfs_variable.h:433
int materialize_session(PFS_thread *pfs_thread, uint index)
Cache a single SESSION variable for an instrumented thread.
Definition: pfs_variable.h:588
bool is_materialized(PFS_user *pfs_user)
True if variables have been materialized for given PFS_user.
Definition: pfs_variable.h:341
bool is_materialized(PFS_thread *pfs_thread)
True if variables have been materialized for given PFS_thread.
Definition: pfs_variable.h:334
bool m_use_mem_root
Definition: pfs_variable.h:451
Variable_array m_cache
Definition: pfs_variable.h:424
int materialize_session(THD *thd)
Build cache of SESSION variables for a non-instrumented thread.
Definition: pfs_variable.h:549
THD_ptr get_THD(PFS_thread *pfs_thread)
Definition: pfs_variable.h:483
PFS_variable_cache(bool external_init)
Definition: pfs_variable.cc:59
THD * m_current_thd
Definition: pfs_variable.h:412
int materialize_user(PFS_user *pfs_user)
Build cache of SESSION status variables for a user.
Prealloced_array< Var_type, SYSTEM_VARIABLE_PREALLOC > Variable_array
Definition: pfs_variable.h:260
uint size()
Number of elements in the cache.
Definition: pfs_variable.h:393
virtual int do_materialize_session(PFS_thread *, uint)
Definition: pfs_variable.h:402
int materialize_global()
Build cache of GLOBAL system or status variables.
Definition: pfs_variable.h:521
Show_var_array m_show_var_array
Definition: pfs_variable.h:439
int materialize_session(PFS_thread *pfs_thread, bool use_mem_root=false)
Build cache of SESSION variables for an instrumented thread.
Definition: pfs_variable.h:565
THD * m_safe_thd
Definition: pfs_variable.h:406
virtual ~PFS_variable_cache()=0
Destructor.
virtual bool do_initialize_session()
Definition: pfs_variable.h:397
bool is_materialized(PFS_host *pfs_host)
True if variables have been materialized for given PFS_host.
Definition: pfs_variable.h:349
const Var_type * get(uint index=0) const
Get a single variable from the cache.
Definition: pfs_variable.h:381
int materialize_host(PFS_host *pfs_host)
Build cache of SESSION status variables for a host.
bool is_materialized(PFS_account *pfs_account)
True if variables have been materialized for given PFS_account.
Definition: pfs_variable.h:357
Find_THD_variable m_thd_finder
Definition: pfs_variable.h:421
bool m_initialized
Definition: pfs_variable.h:427
System_variable_tracker::Array m_sys_var_tracker_array
Definition: pfs_variable.h:442
enum_var_type m_query_scope
Definition: pfs_variable.h:448
bool is_materialized(THD *unsafe_thd)
True if variables have been materialized for given THD.
Definition: pfs_variable.h:327
int materialize_account(PFS_account *pfs_account)
Build cache of SESSION status variables for an account.
bool m_aggregate
Definition: pfs_variable.h:454
virtual bool do_initialize_global()
Definition: pfs_variable.h:396
int materialize_all(THD *thd)
Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
Definition: pfs_variable.h:533
Element_type & at(size_t n)
Definition: prealloced_array.h:231
size_t size() const
Definition: prealloced_array.h:227
Status variable derived from SHOW_VAR.
Definition: pfs_variable.h:208
bool m_initialized
Definition: pfs_variable.h:234
bool is_null() const
Definition: pfs_variable.h:222
size_t m_name_length
Definition: pfs_variable.h:226
Status_variable()
Definition: pfs_variable.h:210
size_t m_value_length
Definition: pfs_variable.h:228
char m_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:227
SHOW_SCOPE m_scope
Definition: pfs_variable.h:230
void init(const SHOW_VAR *show_var, System_status_var *status_vars, enum_var_type query_scope)
Resolve status value, convert to string.
Definition: pfs_variable.cc:1492
const CHARSET_INFO * m_charset
Definition: pfs_variable.h:231
const char * m_name
Definition: pfs_variable.h:225
SHOW_TYPE m_type
Definition: pfs_variable.h:229
System variable derived from sys_var object.
Definition: pfs_variable.h:169
size_t m_value_length
Definition: pfs_variable.h:182
size_t m_path_length
Definition: pfs_variable.h:188
char m_set_user_str[USERNAME_LENGTH]
Definition: pfs_variable.h:194
char m_set_host_str[HOSTNAME_LENGTH]
Definition: pfs_variable.h:196
bool m_initialized
Definition: pfs_variable.h:200
void init(THD *thd, const SHOW_VAR *show_var, enum_var_type query_scope)
Get sys_var value from global or local source then convert to string.
Definition: pfs_variable.cc:689
char m_min_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:189
const char * m_name
Definition: pfs_variable.h:179
size_t m_set_host_str_length
Definition: pfs_variable.h:197
int m_scope
Definition: pfs_variable.h:184
char m_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:181
bool is_null() const
Definition: pfs_variable.h:176
char m_max_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:191
enum_mysql_show_type m_type
Definition: pfs_variable.h:183
enum_variable_source m_source
Definition: pfs_variable.h:186
size_t m_name_length
Definition: pfs_variable.h:180
size_t m_min_value_length
Definition: pfs_variable.h:190
ulonglong m_set_time
Definition: pfs_variable.h:193
char m_path_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:187
const CHARSET_INFO * m_charset
Definition: pfs_variable.h:185
System_variable()
CLASS System_variable.
Definition: pfs_variable.cc:608
size_t m_set_user_str_length
Definition: pfs_variable.h:195
size_t m_max_value_length
Definition: pfs_variable.h:192
This class encapsulates THD instance, controls access to the actual THD.
Definition: mysqld_thd_manager.h:98
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
const char * p
Definition: ctype-mb.cc:1237
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
static constexpr int HOSTNAME_LENGTH
Definition: my_hostname.h:43
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
#define USERNAME_LENGTH
Definition: mysql_com.h:69
SHOW_VAR status_vars[]
Definition: mysqld.cc:9662
Performance schema account (declarations).
Performance schema host (declarations).
Performance schema instruments (declarations).
Performance schema user (declarations).
void sum_host_status(PFS_client *pfs_host, System_status_var *status_totals)
Definition: pfs_variable.cc:1533
bool status_vars_inited
Definition: sql_show.cc:3246
Status_var_array all_status_vars
void sum_user_status(PFS_client *pfs_user, System_status_var *status_totals)
Definition: pfs_variable.cc:1522
static const uint SYSVAR_MEMROOT_BLOCK_SIZE
Definition: pfs_variable.h:158
void status_variable_warning()
Warning issued if the global status variable array changes during a query.
Definition: pfs_variable.cc:1579
void system_variable_warning()
Warning issued if the version of the system variable hash table changes during a query.
Definition: pfs_variable.cc:1568
void sum_account_status(PFS_client *pfs_account, System_status_var *status_totals)
Definition: pfs_variable.cc:1545
Prealloced_array< SHOW_VAR, SYSTEM_VARIABLE_PREALLOC > Show_var_array
Definition: pfs_variable.h:153
PFS_connection_slice PFS_client
Definition: pfs_variable.h:163
std::vector< SHOW_VAR > Status_var_array
Definition: pfs_variable.h:149
mysql_mutex_t LOCK_plugin_delete
Definition: sql_plugin.cc:437
"public" interface to sys_var - server configuration variables.
enum enum_mysql_show_type SHOW_TYPE
Definition: set_var.h:73
enum enum_mysql_show_scope SHOW_SCOPE
Definition: set_var.h:74
enum_var_type
Definition: set_var.h:90
std::vector< SHOW_VAR > Status_var_array
Definition: sql_show.cc:3243
case opt name
Definition: sslopt-case.h:33
enum_mysql_show_type
Declarations for SHOW STATUS support in plugins.
Definition: status_var.h:30
@ SHOW_UNDEF
Definition: status_var.h:31
#define SHOW_VAR_FUNC_BUFF_SIZE
Definition: status_var.h:87
@ SHOW_SCOPE_UNDEF
Definition: status_var.h:69
Definition: m_ctype.h:385
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Per account statistics.
Definition: pfs_account.h:67
A connection slice, an arbitrary grouping of several connections.
Definition: pfs_con_slice.h:54
Per host statistics.
Definition: pfs_host.h:64
Instrumented thread implementation.
Definition: pfs_instr.h:373
pfs_lock m_lock
Internal lock.
Definition: pfs_instr.h:457
THD * m_thd
Definition: pfs_instr.h:644
Per user statistics.
Definition: pfs_user.h:63
SHOW STATUS Server status variable.
Definition: status_var.h:79
Per thread status variables.
Definition: system_variables.h:511
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
bool is_populated()
Returns true if the record contains values that can be read.
Definition: pfs_lock.h:189
enum_variable_source
This enum values define how system variables are set.
Definition: system_variable_source_type.h:33
unsigned int uint
Definition: uca9-dump.cc:75