MySQL 8.0.29
Source Code Documentation
pfs_variable.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2022, 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
148using std::string;
149
150typedef std::vector<SHOW_VAR> Status_var_array;
151
152/* Number of system variable elements to preallocate. */
153#define SYSTEM_VARIABLE_PREALLOC 200
155
156/* Global array of all server and plugin-defined status variables. */
158extern bool status_vars_inited;
159static const uint SYSVAR_MEMROOT_BLOCK_SIZE = 4096;
160
162
163class Find_THD_Impl;
166
167/**
168 System variable derived from sys_var object.
169*/
171 public:
173 System_variable(THD *target_thd, const SHOW_VAR *show_var,
174 enum_var_type query_scope);
175 System_variable(THD *target_thd, const SHOW_VAR *show_var);
176
177 bool is_null() const { return !m_initialized; }
178
179 public:
180 const char *m_name;
199
200 private:
202 void init(THD *thd, const SHOW_VAR *show_var, enum_var_type query_scope);
203 void init(THD *thd, const SHOW_VAR *show_var);
204};
205
206/**
207 Status variable derived from @c SHOW_VAR.
208*/
210 public:
212 : m_name(nullptr),
213 m_name_length(0),
218 m_initialized(false) {}
219
220 Status_variable(const SHOW_VAR *show_var, System_status_var *status_array,
221 enum_var_type query_scope);
222
223 bool is_null() const { return !m_initialized; }
224
225 public:
226 const char *m_name;
233
234 private:
236 void init(const SHOW_VAR *show_var, System_status_var *status_array,
237 enum_var_type query_scope);
238};
239
240/**
241 Get and lock a validated @c THD from the thread manager.
242*/
244 public:
246 explicit Find_THD_variable(THD *unsafe_thd) : m_unsafe_thd(unsafe_thd) {}
247
248 bool operator()(THD *thd) override;
249 void set_unsafe_thd(THD *unsafe_thd) { m_unsafe_thd = unsafe_thd; }
250
251 private:
253};
254
255/**
256 Base class for a system or status variable cache.
257*/
258template <class Var_type>
260 public:
262
263 explicit PFS_variable_cache(bool external_init);
264
265 virtual ~PFS_variable_cache() = 0;
266
267 /**
268 Build array of SHOW_VARs from the external variable source.
269 Filter using session scope.
270 */
272
273 /**
274 Build array of SHOW_VARs suitable for aggregation by user, host or account.
275 Filter using session scope.
276 */
278
279 /**
280 Build cache of GLOBAL system or status variables.
281 Aggregate across threads if applicable.
282 */
284
285 /**
286 Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
287 */
289
290 /**
291 Build cache of SESSION variables for a non-instrumented thread.
292 */
294
295 /**
296 Build cache of SESSION variables for an instrumented thread.
297 */
298 int materialize_session(PFS_thread *pfs_thread, bool use_mem_root = false);
299
300 /**
301 Cache a single SESSION variable for an instrumented thread.
302 */
303 int materialize_session(PFS_thread *pfs_thread, uint index);
304
305 /**
306 Build cache of SESSION status variables for a user.
307 */
309
310 /**
311 Build cache of SESSION status variables for a host.
312 */
314
315 /**
316 Build cache of SESSION status variables for an account.
317 */
319
320 /**
321 True if variables have been materialized.
322 */
323 bool is_materialized(void) { return m_materialized; }
324
325 /**
326 True if variables have been materialized for given THD.
327 */
328 bool is_materialized(THD *unsafe_thd) {
329 return (unsafe_thd == m_unsafe_thd && m_materialized);
330 }
331
332 /**
333 True if variables have been materialized for given PFS_thread.
334 */
335 bool is_materialized(PFS_thread *pfs_thread) {
336 return (pfs_thread == m_pfs_thread && m_materialized);
337 }
338
339 /**
340 True if variables have been materialized for given PFS_user.
341 */
342 bool is_materialized(PFS_user *pfs_user) {
343 return (static_cast<PFS_client *>(pfs_user) == m_pfs_client &&
345 }
346
347 /**
348 True if variables have been materialized for given PFS_host.
349 */
350 bool is_materialized(PFS_host *pfs_host) {
351 return (static_cast<PFS_client *>(pfs_host) == m_pfs_client &&
353 }
354
355 /**
356 True if variables have been materialized for given PFS_account.
357 */
358 bool is_materialized(PFS_account *pfs_account) {
359 return (static_cast<PFS_client *>(pfs_account) == m_pfs_client &&
361 }
362
363 /**
364 True if variables have been materialized for given PFS_user/host/account.
365 */
366 bool is_materialized(PFS_client *pfs_client) {
367 return (static_cast<PFS_client *>(pfs_client) == m_pfs_client &&
369 }
370
371 /**
372 Get a validated THD from the thread manager. Execute callback function while
373 inside of the thread manager locks.
374 */
377
378 /**
379 Get a single variable from the cache.
380 Get the first element in the cache by default.
381 */
382 const Var_type *get(uint index = 0) const {
383 if (index >= m_cache.size()) {
384 return nullptr;
385 }
386
387 const Var_type *p = &m_cache.at(index);
388 return p;
389 }
390
391 /**
392 Number of elements in the cache.
393 */
394 uint size() { return (uint)m_cache.size(); }
395
396 private:
397 virtual bool do_initialize_global(void) { return true; }
398 virtual bool do_initialize_session(void) { return true; }
399 virtual int do_materialize_global(void) { return 1; }
400 virtual int do_materialize_all(THD *) { return 1; }
401 virtual int do_materialize_session(THD *) { return 1; }
402 virtual int do_materialize_session(PFS_thread *) { return 1; }
403 virtual int do_materialize_session(PFS_thread *, uint) { return 1; }
404
405 protected:
406 /* Validated THD */
408
409 /* Unvalidated THD */
411
412 /* Current THD */
414
415 /* Current PFS_thread. */
417
418 /* Current PFS_user, host or account. */
420
421 /* Callback for thread iterator. */
423
424 /* Cache of materialized variables. */
426
427 /* True when list of SHOW_VAR is complete. */
429
430 /*
431 True if the SHOW_VAR array must be initialized externally from the
432 materialization step, such as with aggregations and queries by thread.
433 */
435
436 /* True when cache is complete. */
438
439 /* Array of status variables to be materialized. Last element must be null. */
441
442 /* Array of system variable descriptors. */
444
445 /* Version of global hash/array. Changes when vars added/removed. */
447
448 /* Query scope: GLOBAL or SESSION. */
450
451 /* True if temporary mem_root should be used for materialization. */
453
454 /* True if summarizing across users, hosts or accounts. */
456};
457
458/**
459 Destructor.
460*/
461template <class Var_type>
463
464/**
465 Get a validated THD from the thread manager. Execute callback function while
466 while inside the thread manager lock.
467*/
468template <class Var_type>
470 if (unsafe_thd == nullptr) {
471 /*
472 May happen, precisely because the pointer is unsafe
473 (THD just disconnected for example).
474 No need to walk Global_THD_manager for that.
475 */
476 return THD_ptr{nullptr};
477 }
478
479 m_thd_finder.set_unsafe_thd(unsafe_thd);
480 return Global_THD_manager::get_instance()->find_thd(&m_thd_finder);
481}
482
483template <class Var_type>
485 assert(pfs_thread != nullptr);
486 return get_THD(pfs_thread->m_thd);
487}
488
489/**
490 Build array of SHOW_VARs from external source of system or status variables.
491 Filter using session scope.
492*/
493template <class Var_type>
495 if (m_initialized) {
496 return false;
497 }
498
499 return do_initialize_session();
500}
501
502/**
503 Build array of SHOW_VARs suitable for aggregation by user, host or account.
504 Filter using session scope.
505*/
506template <class Var_type>
508 if (m_initialized) {
509 return false;
510 }
511
512 /* Requires aggregation by user, host or account. */
513 m_aggregate = true;
514
515 return do_initialize_session();
516}
517
518/**
519 Build cache of all GLOBAL variables.
520*/
521template <class Var_type>
523 if (is_materialized()) {
524 return 0;
525 }
526
527 return do_materialize_global();
528}
529
530/**
531 Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
532*/
533template <class Var_type>
535 if (!unsafe_thd) {
536 return 1;
537 }
538
539 if (is_materialized(unsafe_thd)) {
540 return 0;
541 }
542
543 return do_materialize_all(unsafe_thd);
544}
545
546/**
547 Build cache of SESSION variables for a non-instrumented thread.
548*/
549template <class Var_type>
551 if (!unsafe_thd) {
552 return 1;
553 }
554
555 if (is_materialized(unsafe_thd)) {
556 return 0;
557 }
558
559 return do_materialize_session(unsafe_thd);
560}
561
562/**
563 Build cache of SESSION variables for a thread.
564*/
565template <class Var_type>
567 bool use_mem_root) {
568 if (!pfs_thread) {
569 return 1;
570 }
571
572 if (is_materialized(pfs_thread)) {
573 return 0;
574 }
575
576 if (!pfs_thread->m_lock.is_populated() || pfs_thread->m_thd == nullptr) {
577 return 1;
578 }
579
580 m_use_mem_root = use_mem_root;
581
582 return do_materialize_session(pfs_thread);
583}
584
585/**
586 Materialize a single variable for a thread.
587*/
588template <class Var_type>
590 uint index) {
591 /* No check for is_materialized(). */
592
593 if (!pfs_thread) {
594 return 1;
595 }
596
597 if (!pfs_thread->m_lock.is_populated() || pfs_thread->m_thd == nullptr) {
598 return 1;
599 }
600
601 return do_materialize_session(pfs_thread, index);
602}
603
604/**
605 System variable cache.
606*/
607class PFS_system_variable_cache : public PFS_variable_cache<System_variable> {
608 public:
609 explicit PFS_system_variable_cache(bool external_init);
610 bool match_scope(int scope);
613
614 private:
615 bool do_initialize_session(void) override;
616
617 /* Global */
618 int do_materialize_global(void) override;
619 /* Session - THD */
620 int do_materialize_session(THD *thd) override;
621 /* Session - PFS_thread */
622 int do_materialize_session(PFS_thread *thread) override;
623 /* Single variable - PFS_thread */
624 int do_materialize_session(PFS_thread *pfs_thread, uint index) override;
625
626 /* Temporary mem_root to use for materialization. */
628 /* Pointer to THD::mem_root. */
630 /* Save THD::mem_root. */
632 /* Pointer to temporary mem_root. */
634 /* Allocate and/or assign temporary mem_root. */
635 void set_mem_root(void);
636 /* Mark all memory blocks as free in temporary mem_root. */
637 void clear_mem_root(void);
638 /* Free mem_root memory. */
639 void free_mem_root(void);
640
641 protected:
642 /* Build SHOW_var array. */
643 bool init_show_var_array(enum_var_type scope, bool strict);
644 /* Global and Session - THD */
645 int do_materialize_all(THD *thd) override;
646};
647
648/**
649 System variable info cache.
650*/
652 public:
653 explicit PFS_system_variable_info_cache(bool external_init)
654 : PFS_system_variable_cache(external_init) {}
656
657 private:
658 /* Global and Session - THD */
659 int do_materialize_all(THD *thd) override;
660};
661
662/**
663 Persisted variables cache.
664*/
666 public:
667 explicit PFS_system_persisted_variables_cache(bool external_init)
668 : PFS_system_variable_cache(external_init) {}
670
671 private:
672 /* Global and Session - THD */
673 int do_materialize_all(THD *thd) override;
674};
675
676/**
677 Status variable cache
678*/
679class PFS_status_variable_cache : public PFS_variable_cache<Status_variable> {
680 public:
681 explicit PFS_status_variable_cache(bool external_init);
682
683 int materialize_user(PFS_user *pfs_user);
684 int materialize_host(PFS_host *pfs_host);
685 int materialize_account(PFS_account *pfs_account);
686
688
689 protected:
690 /* Get PFS_user, account or host associated with a PFS_thread. Implemented by
691 * table class. */
692 virtual PFS_client *get_pfs(PFS_thread *) { return nullptr; }
693
694 /* True if query is a SHOW command. */
696
697 private:
698 bool do_initialize_session(void) override;
699
700 int do_materialize_global(void) override;
701 /* Global and Session - THD */
702 int do_materialize_all(THD *thd) override;
703 int do_materialize_session(THD *thd) override;
704 int do_materialize_session(PFS_thread *thread) override;
705 int do_materialize_session(PFS_thread *, uint) override { return 0; }
706 int do_materialize_client(PFS_client *pfs_client);
707
708 /* Callback to sum user, host or account status variables. */
709 void (*m_sum_client_status)(PFS_client *pfs_client,
710 System_status_var *status_totals);
711
712 /* Build SHOW_VAR array from external source. */
713 bool init_show_var_array(enum_var_type scope, bool strict);
714
715 /* Recursively expand nested SHOW_VAR arrays. */
716 void expand_show_var_array(const SHOW_VAR *show_var_array, const char *prefix,
717 bool strict);
718
719 /* Exclude unwanted variables from the query. */
720 bool filter_show_var(const SHOW_VAR *show_var, bool strict);
721
722 /* Check the variable scope against the query scope. */
723 bool match_scope(SHOW_SCOPE variable_scope, bool strict);
724
725 /* Exclude specific status variables by name or prefix. */
726 bool filter_by_name(const SHOW_VAR *show_var);
727
728 /* Check if a variable has an aggregatable type. */
729 bool can_aggregate(enum_mysql_show_type variable_type);
730
731 /* Build status variable name with prefix. Return in the buffer provided. */
732 char *make_show_var_name(const char *prefix, const char *name, char *name_buf,
733 size_t buf_len);
734
735 /* Build status variable name with prefix. Return copy of the string. */
736 char *make_show_var_name(const char *prefix, const char *name);
737
738 /* For the current THD, use initial_status_vars taken from before the query
739 * start. */
741
742 /* Build the list of status variables from SHOW_VAR array. */
743 void manifest(THD *thd, const SHOW_VAR *show_var_array,
744 System_status_var *status_var_array, const char *prefix,
745 bool nested_array, bool strict);
746};
747
748/* Callback functions to sum status variables for a given user, host or account.
749 */
750void sum_user_status(PFS_client *pfs_user, System_status_var *status_totals);
751void sum_host_status(PFS_client *pfs_host, System_status_var *status_totals);
752void sum_account_status(PFS_client *pfs_account,
753 System_status_var *status_totals);
754
755/* Warnings issued if the global system or status variables change mid-query. */
756void system_variable_warning(void);
757void status_variable_warning(void);
758
759#endif
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:243
THD * m_unsafe_thd
Definition: pfs_variable.h:252
void set_unsafe_thd(THD *unsafe_thd)
Definition: pfs_variable.h:249
Find_THD_variable()
Definition: pfs_variable.h:245
Find_THD_variable(THD *unsafe_thd)
Definition: pfs_variable.h:246
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:210
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:317
Status variable cache.
Definition: pfs_variable.h:679
int do_materialize_client(PFS_client *pfs_client)
Build cache of SESSION status variables using the status values provided.
Definition: pfs_variable.cc:1358
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:1070
bool filter_by_name(const SHOW_VAR *show_var)
Definition: pfs_variable.cc:932
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:1221
bool m_show_command
Definition: pfs_variable.h:695
int materialize_host(PFS_host *pfs_host)
Build cache of SESSION status variables for a host.
Definition: pfs_variable.cc:858
bool do_initialize_session(void) override
Build an internal SHOW_VAR array from the external status variable array.
Definition: pfs_variable.cc:1135
int do_materialize_global(void) override
Build cache for GLOBAL status variables using values totaled from all threads.
Definition: pfs_variable.cc:1169
int do_materialize_session(THD *thd) override
Build SESSION status variable cache using values for a non-instrumented thread.
Definition: pfs_variable.cc:1268
bool can_aggregate(enum_mysql_show_type variable_type)
Check that the variable type is aggregatable.
Definition: pfs_variable.cc:953
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:1098
void(* m_sum_client_status)(PFS_client *pfs_client, System_status_var *status_totals)
Definition: pfs_variable.h:709
int do_materialize_session(PFS_thread *, uint) override
Definition: pfs_variable.h:705
PFS_status_variable_cache(bool external_init)
CLASS PFS_status_variable_cache.
Definition: pfs_variable.cc:826
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:1000
int materialize_account(PFS_account *pfs_account)
Build cache of SESSION status variables for an account.
Definition: pfs_variable.cc:879
int materialize_user(PFS_user *pfs_user)
Build cache of SESSION status variables for a user.
Definition: pfs_variable.cc:837
virtual PFS_client * get_pfs(PFS_thread *)
Definition: pfs_variable.h:692
void manifest(THD *thd, const SHOW_VAR *show_var_array, System_status_var *status_var_array, const char *prefix, bool nested_array, bool strict)
Definition: pfs_variable.cc:1399
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:1026
System_status_var * set_status_vars(void)
For the current THD, use initial_status_vars taken from before the query start.
Definition: pfs_variable.cc:1154
bool match_scope(SHOW_SCOPE variable_scope, bool strict)
Compare status variable scope to desired scope.
Definition: pfs_variable.cc:902
ulonglong get_status_array_version(void)
Definition: pfs_variable.h:687
Persisted variables cache.
Definition: pfs_variable.h:665
int do_materialize_all(THD *thd) override
CLASS PFS_system_persisted_variables_cache.
Definition: pfs_variable.cc:504
~PFS_system_persisted_variables_cache() override=default
PFS_system_persisted_variables_cache(bool external_init)
Definition: pfs_variable.h:667
System variable cache.
Definition: pfs_variable.h:607
ulonglong get_sysvar_hash_version(void)
Definition: pfs_variable.h:611
int do_materialize_session(THD *thd) override
Build a SESSION system variable cache for a THD.
Definition: pfs_variable.cc:395
int do_materialize_global(void) override
Build a GLOBAL system variable cache.
Definition: pfs_variable.cc:159
MEM_ROOT m_mem_sysvar
Definition: pfs_variable.h:627
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:89
MEM_ROOT * m_mem_sysvar_ptr
Definition: pfs_variable.h:633
MEM_ROOT ** m_mem_thd
Definition: pfs_variable.h:629
PFS_system_variable_cache(bool external_init)
Definition: pfs_variable.cc:79
~PFS_system_variable_cache() override
Definition: pfs_variable.h:612
int do_materialize_all(THD *thd) override
Build a GLOBAL and SESSION system variable cache.
Definition: pfs_variable.cc:198
MEM_ROOT * m_mem_thd_save
Definition: pfs_variable.h:631
void set_mem_root(void)
Allocate and assign mem_root for system variable materialization.
Definition: pfs_variable.cc:248
void clear_mem_root(void)
Mark memory blocks in the temporary mem_root as free.
Definition: pfs_variable.cc:262
bool match_scope(int scope)
Match system variable scope to desired scope.
Definition: pfs_variable.cc:135
bool do_initialize_session(void) override
Build an array of SHOW_VARs from the system variable hash.
Definition: pfs_variable.cc:121
void free_mem_root(void)
Free the temporary mem_root.
Definition: pfs_variable.cc:275
System variable info cache.
Definition: pfs_variable.h:651
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:653
~PFS_system_variable_info_cache() override=default
Base class for a system or status variable cache.
Definition: pfs_variable.h:259
virtual int do_materialize_session(PFS_thread *)
Definition: pfs_variable.h:402
THD_ptr get_THD(THD *thd)
Get a validated THD from the thread manager.
Definition: pfs_variable.h:469
bool m_materialized
Definition: pfs_variable.h:437
PFS_client * m_pfs_client
Definition: pfs_variable.h:419
THD * m_unsafe_thd
Definition: pfs_variable.h:410
bool is_materialized(PFS_client *pfs_client)
True if variables have been materialized for given PFS_user/host/account.
Definition: pfs_variable.h:366
virtual int do_materialize_session(THD *)
Definition: pfs_variable.h:401
ulonglong m_version
Definition: pfs_variable.h:446
virtual int do_materialize_all(THD *)
Definition: pfs_variable.h:400
virtual bool do_initialize_session(void)
Definition: pfs_variable.h:398
PFS_thread * m_pfs_thread
Definition: pfs_variable.h:416
bool m_external_init
Definition: pfs_variable.h:434
int materialize_session(PFS_thread *pfs_thread, uint index)
Cache a single SESSION variable for an instrumented thread.
Definition: pfs_variable.h:589
bool is_materialized(PFS_user *pfs_user)
True if variables have been materialized for given PFS_user.
Definition: pfs_variable.h:342
bool is_materialized(PFS_thread *pfs_thread)
True if variables have been materialized for given PFS_thread.
Definition: pfs_variable.h:335
bool m_use_mem_root
Definition: pfs_variable.h:452
Variable_array m_cache
Definition: pfs_variable.h:425
int materialize_session(THD *thd)
Build cache of SESSION variables for a non-instrumented thread.
Definition: pfs_variable.h:550
THD_ptr get_THD(PFS_thread *pfs_thread)
Definition: pfs_variable.h:484
PFS_variable_cache(bool external_init)
Definition: pfs_variable.cc:61
THD * m_current_thd
Definition: pfs_variable.h:413
int materialize_user(PFS_user *pfs_user)
Build cache of SESSION status variables for a user.
bool is_materialized(void)
True if variables have been materialized.
Definition: pfs_variable.h:323
Prealloced_array< Var_type, SYSTEM_VARIABLE_PREALLOC > Variable_array
Definition: pfs_variable.h:261
uint size()
Number of elements in the cache.
Definition: pfs_variable.h:394
virtual int do_materialize_session(PFS_thread *, uint)
Definition: pfs_variable.h:403
int materialize_global()
Build cache of GLOBAL system or status variables.
Definition: pfs_variable.h:522
Show_var_array m_show_var_array
Definition: pfs_variable.h:440
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:566
THD * m_safe_thd
Definition: pfs_variable.h:407
virtual ~PFS_variable_cache()=0
Destructor.
bool initialize_session(void)
Build array of SHOW_VARs from the external variable source.
Definition: pfs_variable.h:494
bool is_materialized(PFS_host *pfs_host)
True if variables have been materialized for given PFS_host.
Definition: pfs_variable.h:350
const Var_type * get(uint index=0) const
Get a single variable from the cache.
Definition: pfs_variable.h:382
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:358
virtual bool do_initialize_global(void)
Definition: pfs_variable.h:397
virtual int do_materialize_global(void)
Definition: pfs_variable.h:399
Find_THD_variable m_thd_finder
Definition: pfs_variable.h:422
bool m_initialized
Definition: pfs_variable.h:428
System_variable_tracker::Array m_sys_var_tracker_array
Definition: pfs_variable.h:443
bool initialize_client_session(void)
Build array of SHOW_VARs suitable for aggregation by user, host or account.
Definition: pfs_variable.h:507
enum_var_type m_query_scope
Definition: pfs_variable.h:449
bool is_materialized(THD *unsafe_thd)
True if variables have been materialized for given THD.
Definition: pfs_variable.h:328
int materialize_account(PFS_account *pfs_account)
Build cache of SESSION status variables for an account.
bool m_aggregate
Definition: pfs_variable.h:455
int materialize_all(THD *thd)
Build cache of GLOBAL and SESSION variables for a non-instrumented thread.
Definition: pfs_variable.h:534
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:209
bool m_initialized
Definition: pfs_variable.h:235
bool is_null() const
Definition: pfs_variable.h:223
size_t m_name_length
Definition: pfs_variable.h:227
Status_variable()
Definition: pfs_variable.h:211
void init(const SHOW_VAR *show_var, System_status_var *status_array, enum_var_type query_scope)
Resolve status value, convert to string.
Definition: pfs_variable.cc:1484
size_t m_value_length
Definition: pfs_variable.h:229
char m_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:228
SHOW_SCOPE m_scope
Definition: pfs_variable.h:231
const CHARSET_INFO * m_charset
Definition: pfs_variable.h:232
const char * m_name
Definition: pfs_variable.h:226
SHOW_TYPE m_type
Definition: pfs_variable.h:230
System variable derived from sys_var object.
Definition: pfs_variable.h:170
size_t m_value_length
Definition: pfs_variable.h:183
size_t m_path_length
Definition: pfs_variable.h:189
char m_set_user_str[USERNAME_LENGTH]
Definition: pfs_variable.h:195
char m_set_host_str[HOSTNAME_LENGTH]
Definition: pfs_variable.h:197
bool m_initialized
Definition: pfs_variable.h:201
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:682
char m_min_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:190
const char * m_name
Definition: pfs_variable.h:180
size_t m_set_host_str_length
Definition: pfs_variable.h:198
int m_scope
Definition: pfs_variable.h:185
char m_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:182
bool is_null() const
Definition: pfs_variable.h:177
char m_max_value_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:192
enum_mysql_show_type m_type
Definition: pfs_variable.h:184
enum_variable_source m_source
Definition: pfs_variable.h:187
size_t m_name_length
Definition: pfs_variable.h:181
size_t m_min_value_length
Definition: pfs_variable.h:191
ulonglong m_set_time
Definition: pfs_variable.h:194
char m_path_str[SHOW_VAR_FUNC_BUFF_SIZE+1]
Definition: pfs_variable.h:188
const CHARSET_INFO * m_charset
Definition: pfs_variable.h:186
System_variable()
CLASS System_variable.
Definition: pfs_variable.cc:601
size_t m_set_user_str_length
Definition: pfs_variable.h:196
size_t m_max_value_length
Definition: pfs_variable.h:193
This class encapsulates THD instance, controls access to the actual THD.
Definition: mysqld_thd_manager.h:95
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:945
const char * p
Definition: ctype-mb.cc:1236
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
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
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:1525
bool status_vars_inited
Definition: sql_show.cc:3103
Status_var_array all_status_vars
void sum_user_status(PFS_client *pfs_user, System_status_var *status_totals)
Definition: pfs_variable.cc:1514
static const uint SYSVAR_MEMROOT_BLOCK_SIZE
Definition: pfs_variable.h:159
void sum_account_status(PFS_client *pfs_account, System_status_var *status_totals)
Definition: pfs_variable.cc:1537
Prealloced_array< SHOW_VAR, SYSTEM_VARIABLE_PREALLOC > Show_var_array
Definition: pfs_variable.h:154
PFS_connection_slice PFS_client
Definition: pfs_variable.h:164
void status_variable_warning(void)
Warning issued if the global status variable array changes during a query.
Definition: pfs_variable.cc:1571
std::vector< SHOW_VAR > Status_var_array
Definition: pfs_variable.h:150
mysql_mutex_t LOCK_plugin_delete
Definition: sql_plugin.cc:436
void system_variable_warning(void)
Warning issued if the version of the system variable hash table changes during a query.
Definition: pfs_variable.cc:1560
"public" interface to sys_var - server configuration variables.
enum enum_mysql_show_type SHOW_TYPE
Definition: set_var.h:72
enum enum_mysql_show_scope SHOW_SCOPE
Definition: set_var.h:73
enum_var_type
Definition: set_var.h:89
std::vector< SHOW_VAR > Status_var_array
Definition: sql_show.cc:3100
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:354
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:62
Instrumented thread implementation.
Definition: pfs_instr.h:372
pfs_lock m_lock
Internal lock.
Definition: pfs_instr.h:456
THD * m_thd
Definition: pfs_instr.h:643
Per user statistics.
Definition: pfs_user.h:61
SHOW STATUS Server status variable.
Definition: status_var.h:78
Per thread status variables.
Definition: system_variables.h:467
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
bool is_populated(void)
Returns true if the record contains values that can be read.
Definition: pfs_lock.h:186
enum_variable_source
This enum values define how system variables are set.
Definition: system_variable_source_type.h:32
unsigned int uint
Definition: uca-dump.cc:29