MySQL 9.1.0
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 m_value_str[0] = '\0';
219 }
220
221 Status_variable(const SHOW_VAR *show_var, System_status_var *vars,
222 enum_var_type query_scope);
223
224 bool is_null() const { return !m_initialized; }
225
226 public:
227 const char *m_name;
234
235 private:
237 void init(const SHOW_VAR *show_var, System_status_var *vars,
238 enum_var_type query_scope);
239};
240
241/**
242 Get and lock a validated @c THD from the thread manager.
243*/
245 public:
247 explicit Find_THD_variable(THD *unsafe_thd) : m_unsafe_thd(unsafe_thd) {}
248
249 bool operator()(THD *thd) override;
250 void set_unsafe_thd(THD *unsafe_thd) { m_unsafe_thd = unsafe_thd; }
251
252 private:
254};
255
256/**
257 Base class for a system or status variable cache.
258*/
259template <class Var_type>
261 public:
263
264 explicit PFS_variable_cache(bool external_init);
265
266 virtual ~PFS_variable_cache() = 0;
267
268 /**
269 Build array of SHOW_VARs from the external variable source.
270 Filter using session scope.
271 */
273
274 /**
275 Build array of SHOW_VARs suitable for aggregation by user, host or account.
276 Filter using session scope.
277 */
279
280 /**
281 Build cache of GLOBAL system or status variables.
282 Aggregate across threads if applicable.
283 */
285
286 /**
287 Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
288 */
290
291 /**
292 Build cache of SESSION variables for a non-instrumented thread.
293 */
295
296 /**
297 Build cache of SESSION variables for an instrumented thread.
298 */
299 int materialize_session(PFS_thread *pfs_thread, bool use_mem_root = false);
300
301 /**
302 Cache a single SESSION variable for an instrumented thread.
303 */
304 int materialize_session(PFS_thread *pfs_thread, uint index);
305
306 /**
307 Build cache of SESSION status variables for a user.
308 */
310
311 /**
312 Build cache of SESSION status variables for a host.
313 */
315
316 /**
317 Build cache of SESSION status variables for an account.
318 */
320
321 /**
322 True if variables have been materialized.
323 */
325
326 /**
327 True if variables have been materialized for given THD.
328 */
329 bool is_materialized(THD *unsafe_thd) {
330 return (unsafe_thd == m_unsafe_thd && m_materialized);
331 }
332
333 /**
334 True if variables have been materialized for given PFS_thread.
335 */
336 bool is_materialized(PFS_thread *pfs_thread) {
337 return (pfs_thread == m_pfs_thread && m_materialized);
338 }
339
340 /**
341 True if variables have been materialized for given PFS_user.
342 */
343 bool is_materialized(PFS_user *pfs_user) {
344 return (static_cast<PFS_client *>(pfs_user) == m_pfs_client &&
346 }
347
348 /**
349 True if variables have been materialized for given PFS_host.
350 */
351 bool is_materialized(PFS_host *pfs_host) {
352 return (static_cast<PFS_client *>(pfs_host) == m_pfs_client &&
354 }
355
356 /**
357 True if variables have been materialized for given PFS_account.
358 */
359 bool is_materialized(PFS_account *pfs_account) {
360 return (static_cast<PFS_client *>(pfs_account) == m_pfs_client &&
362 }
363
364 /**
365 True if variables have been materialized for given PFS_user/host/account.
366 */
367 bool is_materialized(PFS_client *pfs_client) {
368 return (static_cast<PFS_client *>(pfs_client) == m_pfs_client &&
370 }
371
372 /**
373 Get a validated THD from the thread manager. Execute callback function while
374 inside of the thread manager locks.
375 */
378
379 /**
380 Get a single variable from the cache.
381 Get the first element in the cache by default.
382 */
383 const Var_type *get(uint index = 0) const {
384 if (index >= m_cache.size()) {
385 return nullptr;
386 }
387
388 const Var_type *p = &m_cache.at(index);
389 return p;
390 }
391
392 /**
393 Number of elements in the cache.
394 */
395 uint size() { return (uint)m_cache.size(); }
396
397 private:
398 virtual bool do_initialize_global() { return true; }
399 virtual bool do_initialize_session() { return true; }
400 virtual int do_materialize_global() { return 1; }
401 virtual int do_materialize_all(THD *) { return 1; }
402 virtual int do_materialize_session(THD *) { return 1; }
403 virtual int do_materialize_session(PFS_thread *) { return 1; }
404 virtual int do_materialize_session(PFS_thread *, uint) { return 1; }
405
406 protected:
407 /* Validated THD */
409
410 /* Unvalidated THD */
412
413 /* Current THD */
415
416 /* Current PFS_thread. */
418
419 /* Current PFS_user, host or account. */
421
422 /* Callback for thread iterator. */
424
425 /* Cache of materialized variables. */
427
428 /* True when list of SHOW_VAR is complete. */
430
431 /*
432 True if the SHOW_VAR array must be initialized externally from the
433 materialization step, such as with aggregations and queries by thread.
434 */
436
437 /* True when cache is complete. */
439
440 /* Array of status variables to be materialized. Last element must be null. */
442
443 /* Array of system variable descriptors. */
445
446 /* Version of global hash/array. Changes when vars added/removed. */
448
449 /* Query scope: GLOBAL or SESSION. */
451
452 /* True if temporary mem_root should be used for materialization. */
454
455 /* True if summarizing across users, hosts or accounts. */
457};
458
459/**
460 Destructor.
461*/
462template <class Var_type>
464
465/**
466 Get a validated THD from the thread manager. Execute callback function while
467 while inside the thread manager lock.
468*/
469template <class Var_type>
471 if (unsafe_thd == nullptr) {
472 /*
473 May happen, precisely because the pointer is unsafe
474 (THD just disconnected for example).
475 No need to walk Global_THD_manager for that.
476 */
477 return THD_ptr{nullptr};
478 }
479
480 m_thd_finder.set_unsafe_thd(unsafe_thd);
481 return Global_THD_manager::get_instance()->find_thd(&m_thd_finder);
482}
483
484template <class Var_type>
486 assert(pfs_thread != nullptr);
487 return get_THD(pfs_thread->m_thd);
488}
489
490/**
491 Build array of SHOW_VARs from external source of system or status variables.
492 Filter using session scope.
493*/
494template <class Var_type>
496 if (m_initialized) {
497 return false;
498 }
499
500 return do_initialize_session();
501}
502
503/**
504 Build array of SHOW_VARs suitable for aggregation by user, host or account.
505 Filter using session scope.
506*/
507template <class Var_type>
509 if (m_initialized) {
510 return false;
511 }
512
513 /* Requires aggregation by user, host or account. */
514 m_aggregate = true;
515
516 return do_initialize_session();
517}
518
519/**
520 Build cache of all GLOBAL variables.
521*/
522template <class Var_type>
524 if (is_materialized()) {
525 return 0;
526 }
527
528 return do_materialize_global();
529}
530
531/**
532 Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
533*/
534template <class Var_type>
536 if (!unsafe_thd) {
537 return 1;
538 }
539
540 if (is_materialized(unsafe_thd)) {
541 return 0;
542 }
543
544 return do_materialize_all(unsafe_thd);
545}
546
547/**
548 Build cache of SESSION variables for a non-instrumented thread.
549*/
550template <class Var_type>
552 if (!unsafe_thd) {
553 return 1;
554 }
555
556 if (is_materialized(unsafe_thd)) {
557 return 0;
558 }
559
560 return do_materialize_session(unsafe_thd);
561}
562
563/**
564 Build cache of SESSION variables for a thread.
565*/
566template <class Var_type>
568 bool use_mem_root) {
569 if (!pfs_thread) {
570 return 1;
571 }
572
573 if (is_materialized(pfs_thread)) {
574 return 0;
575 }
576
577 if (!pfs_thread->m_lock.is_populated() || pfs_thread->m_thd == nullptr) {
578 return 1;
579 }
580
581 m_use_mem_root = use_mem_root;
582
583 return do_materialize_session(pfs_thread);
584}
585
586/**
587 Materialize a single variable for a thread.
588*/
589template <class Var_type>
591 uint index) {
592 /* No check for is_materialized(). */
593
594 if (!pfs_thread) {
595 return 1;
596 }
597
598 if (!pfs_thread->m_lock.is_populated() || pfs_thread->m_thd == nullptr) {
599 return 1;
600 }
601
602 return do_materialize_session(pfs_thread, index);
603}
604
605/**
606 System variable cache.
607*/
608class PFS_system_variable_cache : public PFS_variable_cache<System_variable> {
609 public:
610 explicit PFS_system_variable_cache(bool external_init);
611 bool match_scope(int scope);
614
615 private:
616 bool do_initialize_session() override;
617
618 /* Global */
619 int do_materialize_global() override;
620 /* Session - THD */
621 int do_materialize_session(THD *thd) override;
622 /* Session - PFS_thread */
623 int do_materialize_session(PFS_thread *thread) override;
624 /* Single variable - PFS_thread */
625 int do_materialize_session(PFS_thread *pfs_thread, uint index) override;
626
627 /* Temporary mem_root to use for materialization. */
629 /* Pointer to THD::mem_root. */
631 /* Save THD::mem_root. */
633 /* Pointer to temporary mem_root. */
635 /* Allocate and/or assign temporary mem_root. */
636 void set_mem_root();
637 /* Mark all memory blocks as free in temporary mem_root. */
638 void clear_mem_root();
639 /* Free mem_root memory. */
640 void free_mem_root();
641
642 protected:
643 /* Build SHOW_var array. */
644 bool init_show_var_array(enum_var_type scope, bool strict);
645 /* Global and Session - THD */
646 int do_materialize_all(THD *thd) override;
647};
648
649/**
650 System variable info cache.
651*/
653 public:
654 explicit PFS_system_variable_info_cache(bool external_init)
655 : PFS_system_variable_cache(external_init) {}
657
658 private:
659 /* Global and Session - THD */
660 int do_materialize_all(THD *thd) override;
661};
662
663/**
664 Persisted variables cache.
665*/
667 public:
668 explicit PFS_system_persisted_variables_cache(bool external_init)
669 : PFS_system_variable_cache(external_init) {}
671
672 private:
673 /* Global and Session - THD */
674 int do_materialize_all(THD *thd) override;
675};
676
677/**
678 Status variable cache
679*/
680class PFS_status_variable_cache : public PFS_variable_cache<Status_variable> {
681 public:
682 explicit PFS_status_variable_cache(bool external_init);
683
684 int materialize_user(PFS_user *pfs_user);
685 int materialize_host(PFS_host *pfs_host);
686 int materialize_account(PFS_account *pfs_account);
687
689
690 protected:
691 /* Get PFS_user, account or host associated with a PFS_thread. Implemented by
692 * table class. */
693 virtual PFS_client *get_pfs(PFS_thread *) { return nullptr; }
694
695 /* True if query is a SHOW command. */
697
698 private:
699 bool do_initialize_session() override;
700
701 int do_materialize_global() override;
702 /* Global and Session - THD */
703 int do_materialize_all(THD *thd) override;
704 int do_materialize_session(THD *thd) override;
705 int do_materialize_session(PFS_thread *thread) override;
706 int do_materialize_session(PFS_thread *, uint) override { return 0; }
707 int do_materialize_client(PFS_client *pfs_client);
708
709 /* Callback to sum user, host or account status variables. */
710 void (*m_sum_client_status)(PFS_client *pfs_client,
711 System_status_var *status_totals);
712
713 /* Build SHOW_VAR array from external source. */
714 bool init_show_var_array(enum_var_type scope, bool strict);
715
716 /* Recursively expand nested SHOW_VAR arrays. */
717 void expand_show_var_array(const SHOW_VAR *show_var_array, const char *prefix,
718 bool strict);
719
720 /* Exclude unwanted variables from the query. */
721 bool filter_show_var(const SHOW_VAR *show_var, bool strict);
722
723 /* Check the variable scope against the query scope. */
724 bool match_scope(SHOW_SCOPE variable_scope, bool strict);
725
726 /* Exclude specific status variables by name or prefix. */
727 bool filter_by_name(const SHOW_VAR *show_var);
728
729 /* Check if a variable has an aggregatable type. */
730 bool can_aggregate(enum_mysql_show_type variable_type);
731
732 /* Build status variable name with prefix. Return in the buffer provided. */
733 char *make_show_var_name(const char *prefix, const char *name, char *name_buf,
734 size_t buf_len);
735
736 /* Build status variable name with prefix. Return copy of the string. */
737 char *make_show_var_name(const char *prefix, const char *name);
738
739 /* For the current THD, use initial_status_vars taken from before the query
740 * start. */
742
743 /* Build the list of status variables from SHOW_VAR array. */
744 void manifest(THD *thd, const SHOW_VAR *show_var_array,
745 System_status_var *vars, const char *prefix, bool nested_array,
746 bool strict);
747};
748
749/* Callback functions to sum status variables for a given user, host or account.
750 */
751void sum_user_status(PFS_client *pfs_user, System_status_var *status_totals);
752void sum_host_status(PFS_client *pfs_host, System_status_var *status_totals);
753void sum_account_status(PFS_client *pfs_account,
754 System_status_var *status_totals);
755
756/* Warnings issued if the global system or status variables change mid-query. */
759
760#endif
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
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:244
THD * m_unsafe_thd
Definition: pfs_variable.h:253
void set_unsafe_thd(THD *unsafe_thd)
Definition: pfs_variable.h:250
Find_THD_variable()
Definition: pfs_variable.h:246
Find_THD_variable(THD *unsafe_thd)
Definition: pfs_variable.h:247
bool operator()(THD *thd) override
Override this operator to provide implementation to find specific thd.
Definition: pfs_variable.cc:55
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:335
Status variable cache.
Definition: pfs_variable.h:680
int do_materialize_client(PFS_client *pfs_client)
Build cache of SESSION status variables using the status values provided.
Definition: pfs_variable.cc:1349
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:1061
bool filter_by_name(const SHOW_VAR *show_var)
Definition: pfs_variable.cc:928
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:1212
bool m_show_command
Definition: pfs_variable.h:696
int materialize_host(PFS_host *pfs_host)
Build cache of SESSION status variables for a host.
Definition: pfs_variable.cc:860
bool do_initialize_session() override
Build an internal SHOW_VAR array from the external status variable array.
Definition: pfs_variable.cc:1126
int do_materialize_session(THD *thd) override
Build SESSION status variable cache using values for a non-instrumented thread.
Definition: pfs_variable.cc:1259
bool can_aggregate(enum_mysql_show_type variable_type)
Check that the variable type is aggregatable.
Definition: pfs_variable.cc:949
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:1089
void(* m_sum_client_status)(PFS_client *pfs_client, System_status_var *status_totals)
Definition: pfs_variable.h:710
int do_materialize_session(PFS_thread *, uint) override
Definition: pfs_variable.h:706
PFS_status_variable_cache(bool external_init)
CLASS PFS_status_variable_cache.
Definition: pfs_variable.cc:828
void manifest(THD *thd, const SHOW_VAR *show_var_array, System_status_var *vars, const char *prefix, bool nested_array, bool strict)
Definition: pfs_variable.cc:1390
ulonglong get_status_array_version()
Definition: pfs_variable.h:688
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:994
int materialize_account(PFS_account *pfs_account)
Build cache of SESSION status variables for an account.
Definition: pfs_variable.cc:881
int materialize_user(PFS_user *pfs_user)
Build cache of SESSION status variables for a user.
Definition: pfs_variable.cc:839
virtual PFS_client * get_pfs(PFS_thread *)
Definition: pfs_variable.h:693
int do_materialize_global() override
Build cache for GLOBAL status variables using values totaled from all threads.
Definition: pfs_variable.cc:1160
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:1020
bool match_scope(SHOW_SCOPE variable_scope, bool strict)
Compare status variable scope to desired scope.
Definition: pfs_variable.cc:904
System_status_var * set_status_vars()
For the current THD, use initial_status_vars taken from before the query start.
Definition: pfs_variable.cc:1145
Persisted variables cache.
Definition: pfs_variable.h:666
int do_materialize_all(THD *thd) override
CLASS PFS_system_persisted_variables_cache.
Definition: pfs_variable.cc:505
~PFS_system_persisted_variables_cache() override=default
PFS_system_persisted_variables_cache(bool external_init)
Definition: pfs_variable.h:668
System variable cache.
Definition: pfs_variable.h:608
int do_materialize_session(THD *thd) override
Build a SESSION system variable cache for a THD.
Definition: pfs_variable.cc:393
void set_mem_root()
Allocate and assign mem_root for system variable materialization.
Definition: pfs_variable.cc:242
MEM_ROOT m_mem_sysvar
Definition: pfs_variable.h:628
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:634
MEM_ROOT ** m_mem_thd
Definition: pfs_variable.h:630
void free_mem_root()
Free the temporary mem_root.
Definition: pfs_variable.cc:269
PFS_system_variable_cache(bool external_init)
Definition: pfs_variable.cc:78
~PFS_system_variable_cache() override
Definition: pfs_variable.h:613
ulonglong get_sysvar_hash_version()
Definition: pfs_variable.h:612
int do_materialize_all(THD *thd) override
Build a GLOBAL and SESSION system variable cache.
Definition: pfs_variable.cc:191
MEM_ROOT * m_mem_thd_save
Definition: pfs_variable.h:632
int do_materialize_global() override
Build a GLOBAL system variable cache.
Definition: pfs_variable.cc:151
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:256
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:652
int do_materialize_all(THD *thd) override
CLASS PFS_system_variable_info_cache.
Definition: pfs_variable.cc:451
PFS_system_variable_info_cache(bool external_init)
Definition: pfs_variable.h:654
~PFS_system_variable_info_cache() override=default
Base class for a system or status variable cache.
Definition: pfs_variable.h:260
virtual int do_materialize_session(PFS_thread *)
Definition: pfs_variable.h:403
THD_ptr get_THD(THD *thd)
Get a validated THD from the thread manager.
Definition: pfs_variable.h:470
bool is_materialized()
True if variables have been materialized.
Definition: pfs_variable.h:324
bool m_materialized
Definition: pfs_variable.h:438
PFS_client * m_pfs_client
Definition: pfs_variable.h:420
bool initialize_session()
Build array of SHOW_VARs from the external variable source.
Definition: pfs_variable.h:495
THD * m_unsafe_thd
Definition: pfs_variable.h:411
bool is_materialized(PFS_client *pfs_client)
True if variables have been materialized for given PFS_user/host/account.
Definition: pfs_variable.h:367
virtual int do_materialize_session(THD *)
Definition: pfs_variable.h:402
virtual int do_materialize_global()
Definition: pfs_variable.h:400
ulonglong m_version
Definition: pfs_variable.h:447
virtual int do_materialize_all(THD *)
Definition: pfs_variable.h:401
bool initialize_client_session()
Build array of SHOW_VARs suitable for aggregation by user, host or account.
Definition: pfs_variable.h:508
PFS_thread * m_pfs_thread
Definition: pfs_variable.h:417
bool m_external_init
Definition: pfs_variable.h:435
int materialize_session(PFS_thread *pfs_thread, uint index)
Cache a single SESSION variable for an instrumented thread.
Definition: pfs_variable.h:590
bool is_materialized(PFS_user *pfs_user)
True if variables have been materialized for given PFS_user.
Definition: pfs_variable.h:343
bool is_materialized(PFS_thread *pfs_thread)
True if variables have been materialized for given PFS_thread.
Definition: pfs_variable.h:336
bool m_use_mem_root
Definition: pfs_variable.h:453
Variable_array m_cache
Definition: pfs_variable.h:426
int materialize_session(THD *thd)
Build cache of SESSION variables for a non-instrumented thread.
Definition: pfs_variable.h:551
THD_ptr get_THD(PFS_thread *pfs_thread)
Definition: pfs_variable.h:485
PFS_variable_cache(bool external_init)
Definition: pfs_variable.cc:61
THD * m_current_thd
Definition: pfs_variable.h:414
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:262
uint size()
Number of elements in the cache.
Definition: pfs_variable.h:395
virtual int do_materialize_session(PFS_thread *, uint)
Definition: pfs_variable.h:404
int materialize_global()
Build cache of GLOBAL system or status variables.
Definition: pfs_variable.h:523
Show_var_array m_show_var_array
Definition: pfs_variable.h:441
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:567
THD * m_safe_thd
Definition: pfs_variable.h:408
virtual ~PFS_variable_cache()=0
Destructor.
virtual bool do_initialize_session()
Definition: pfs_variable.h:399
bool is_materialized(PFS_host *pfs_host)
True if variables have been materialized for given PFS_host.
Definition: pfs_variable.h:351
const Var_type * get(uint index=0) const
Get a single variable from the cache.
Definition: pfs_variable.h:383
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:359
Find_THD_variable m_thd_finder
Definition: pfs_variable.h:423
bool m_initialized
Definition: pfs_variable.h:429
System_variable_tracker::Array m_sys_var_tracker_array
Definition: pfs_variable.h:444
enum_var_type m_query_scope
Definition: pfs_variable.h:450
bool is_materialized(THD *unsafe_thd)
True if variables have been materialized for given THD.
Definition: pfs_variable.h:329
int materialize_account(PFS_account *pfs_account)
Build cache of SESSION status variables for an account.
bool m_aggregate
Definition: pfs_variable.h:456
virtual bool do_initialize_global()
Definition: pfs_variable.h:398
int materialize_all(THD *thd)
Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
Definition: pfs_variable.h:535
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:236
bool is_null() const
Definition: pfs_variable.h:224
size_t m_name_length
Definition: pfs_variable.h:228
Status_variable()
Definition: pfs_variable.h:210
size_t m_value_length
Definition: pfs_variable.h:230
char m_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:229
SHOW_SCOPE m_scope
Definition: pfs_variable.h:232
const CHARSET_INFO * m_charset
Definition: pfs_variable.h:233
const char * m_name
Definition: pfs_variable.h:227
SHOW_TYPE m_type
Definition: pfs_variable.h:231
void init(const SHOW_VAR *show_var, System_status_var *vars, enum_var_type query_scope)
Resolve status value, convert to string.
Definition: pfs_variable.cc:1476
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:684
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:603
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:36
const char * p
Definition: ctype-mb.cc:1225
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
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:1515
bool status_vars_inited
Definition: sql_show.cc:3250
Status_var_array all_status_vars
void sum_user_status(PFS_client *pfs_user, System_status_var *status_totals)
Definition: pfs_variable.cc:1504
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:1561
void system_variable_warning()
Warning issued if the version of the system variable hash table changes during a query.
Definition: pfs_variable.cc:1550
void sum_account_status(PFS_client *pfs_account, System_status_var *status_totals)
Definition: pfs_variable.cc:1527
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:439
"public" interface to sys_var - server configuration variables.
enum enum_mysql_show_type SHOW_TYPE
Definition: set_var.h:75
enum enum_mysql_show_scope SHOW_SCOPE
Definition: set_var.h:76
enum_var_type
Definition: set_var.h:92
std::vector< SHOW_VAR > Status_var_array
Definition: sql_show.cc:3247
case opt name
Definition: sslopt-case.h:29
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:421
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:375
pfs_lock m_lock
Internal lock.
Definition: pfs_instr.h:459
THD * m_thd
Definition: pfs_instr.h:646
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:525
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