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