MDEV-9077 add sys_schema from https://github.com/mysql/mysql-sys
This commit is contained in:
parent
7c5c6fa65c
commit
4bac804c90
1
scripts/sys_schema/.gitignore
vendored
Normal file
1
scripts/sys_schema/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
gen/
|
339
scripts/sys_schema/COPYING
Normal file
339
scripts/sys_schema/COPYING
Normal file
@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
14
scripts/sys_schema/LICENSE
Normal file
14
scripts/sys_schema/LICENSE
Normal file
@ -0,0 +1,14 @@
|
||||
Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
218
scripts/sys_schema/NEWS.md
Normal file
218
scripts/sys_schema/NEWS.md
Normal file
@ -0,0 +1,218 @@
|
||||
# Change history for the MySQL sys schema
|
||||
|
||||
## 1.5.1 (07/07/16)
|
||||
|
||||
### Improvements
|
||||
|
||||
* A `quote_identifier` function was added, which can be used to properly backtick identifier names
|
||||
* The `Tls_version` column was added to the output from the `mysql.slave_master_info` table, from the `diagnostics` procedure (backported from 5.7 upstream change)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* MySQL Bug #77853 / Oracle Bug #21512106 - The `format_path` function did not consider directory boundaries when comparing variables to paths - it now does. Also fixed to no longer translate backslashes within Windows paths to forward slash
|
||||
* Oracle Bug #21663578 - Fixed an instability within the sysschema.v_schema_tables_with_full_table_scans test
|
||||
* Oracle Bug #21970078 - The host_summary view could fail with a division by zero error
|
||||
* MySQL Bug #78874 / Oracle Bug #22066096 - The `ps_setup_show_enabled` procedure showed all rows for the `performance_schema.setup_objects` table, rather than only those that are enabled
|
||||
* MySQL Bug #80569 / Oracle Bug #22848110 - The `max_latency` column for the `host_summary_by_statement_latency` view incorrectly showed the SUM of latency
|
||||
* MySQL Bug #80833 / Oracle Bug #22988461 - The `pages_hashed` and `pages_old` columns within the `innodb_buffer_stats_by_schema` and `innodb_buffer_stats_by_table` views were calculated incorrectly (**Contributed by Tsubasa Tanaka**)
|
||||
* MySQL Bug #78823 / Oracle Bug #22011361 - The `create_synonym_db` procedure failed when using reserved words as the synonym name (this change also introduced the `quote_identifier` function mentioned above **Contriubuted by Paul Dubois**)
|
||||
* MySQL Bug #81564 / Oracle Bug #23335880 - The `ps_setup_show_enabled` and `ps_setup_show_disabled` procedures were fixed to:
|
||||
** Show `user@host` instead of `host@user` for accounts
|
||||
** Fixed the column header for `disabled_users` within `ps_setup_show_disabled`
|
||||
** Explicitly ordered all output for test stability
|
||||
** Show disabled users for 5.7.6+
|
||||
* Oracle Bug #21970806 - The `sysschema.fn_ps_thread_trx_info` test was unstable
|
||||
* Oracle Bug #23621189 - The `ps_trace_statement_digest` procedure ran EXPLAIN incorrectly in certain cases (such as on a SHOW statement, no query being specified, or not having a full qualified table), the procedure now catches these issues and ignores them
|
||||
|
||||
## 1.5.0 (11/09/15)
|
||||
|
||||
### Improvements
|
||||
|
||||
* The `format_bytes` function now shows no decimal places when outputting a simple bytes value
|
||||
* The `processlist`/`x$processlist` views where improved, changes include:
|
||||
* The `pid` and `program_name` of the connection are shown, if set within the `performance_schema.session_connect_attrs` table (**Contributed by Daniël van Eeden**)
|
||||
* Issue #50 - The current statement progress is reported via the new stage progress reporting within Performance Schema stages within 5.7 (such as ALTER TABLE progress reporting)
|
||||
* Issue #60 - A new `statement_latency` column was added to all versions, which reports the current statement latency with picosecond precision from the `performance_schema.events_statements_current` table, when enabled
|
||||
* Some transaction information was exposed, with the `trx_latency` (for the current or last transaction depending on `trx_state`), `trx_state` (ACTIVE, COMMITTED, ROLLED BACK), and `trx_autocommit` (YES/NO) columns
|
||||
* A new `metrics` view has been added. On 5.7 this provides a union view of the performance_schema.global_status and information_schema.innodb_metrics tables, along with P_S memory and the current time, as a single metrics output. On 5.6 it provides a union view of the information_schema.global_status and information_schema.innodb_metrics tables, along with the current time. (**Contributed by Jesper Wisborg Krogh**)
|
||||
* New `session`/`x$session` views have been added, which give the same output as the `processlist` view counterparts, but filtered to only show foreground connections (**Contributed by Morgan Tocker**)
|
||||
* A new `session_ssl_status` view was added, which shows the SSL version, ciper and session resuse statistics for each connection (**Contributed by Daniël van Eeden**)
|
||||
* A new `schema_auto_increment_columns` view was added, that shows statistics on each auto_incrment within the instance, including the `auto_increment_ratio`, so you can easily monitor how full specific auto_increment columns are (**Contributed by Shlomi Noach**)
|
||||
* A new `schema_redundant_indexes` view was added, that shows indexes made redundant (or duplicated) by other more dominant indexes. Also includes the the helper view `x$schema_flattened_keys`. (**Contributed by Shlomi Noach**)
|
||||
* New `schema_table_lock_waits`/`x$schema_table_lock_waits` views have been added, which show any sessions that are waiting for table level metadata locks, and the sessions that are blocking them. Resolves Git Issue #57, inspired by the suggestion from Daniël van Eeden
|
||||
* The `innodb_lock_waits` view had the following columns added to it, following a manually merged contribution from Shlomi Noach for a similar view
|
||||
* `wait_age_secs` - the current row lock wait time in seconds
|
||||
* `sql_kill_blocking_query` - the "KILL QUERY <connection_id>" command to run to kill the blocking session current statement
|
||||
* `sql_kill_blocking_connection` - the "KILL <connection_id" command to run to kill the blocking session
|
||||
* A new `table_exists` procedure was added, which checks for the existence of table, and if it exists, returns the type (BASE TABLE, VIEW, TEMPORARY) (**Contributed by Jesper Wisborg Krogh**)
|
||||
* A new `execute_prepared_stmt()` procedure was added, which takes a SQL statement as an input variable and executes it as a prepared statement (**Contributed by Jesper Wisborg Krogh**)
|
||||
* A new `statement_performance_analyzer()` procedure was added, that allows reporting on the statements that are have been running over snapshot periods (**Contributed by Jesper Wisborg Krogh**)
|
||||
* A new `diagnostics()` procedure was added, which creates a large diagnostics report based upon most of the new instrumentation now available, computed over a configurable number of snapshot intervals (**Contributed by Jesper Wisborg Krogh**)
|
||||
* A 5.7 specific `ps_trace_thread()` procedure was added, which now shows the hierarchy of transactions and stored routines, as well as statements, stages and waits, if enabled
|
||||
* Added a new `ps_thread_account()` stored function, that returns the "user@host" account for a given Performance Schema thread id
|
||||
* Added a new `ps_thread_trx_info()` stored function which outputs, for a given thread id, the transactions, and statements that those transactions have executed, as a JSON object
|
||||
* Added new `list_add()` and `list_drop()` stored functions, that take a string csv list, and either add or remove items from that list respectively. Can be used to easily update variables that take such lists, like `sql_mode`.
|
||||
* The `ps_thread_id` stored function now returns the thread id for the current connection if NULL is passed for the in_connection_id parameter
|
||||
* Added a new `version_major()` stored function, which returns the major version of MySQL Server (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Added a new `version_minor()` stored function, which returns the minor (release series) version of MySQL Server (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Added a new `version_patch()` stored function, which returns the patch release version of MySQL Server (**Contributed by Jesper Wisborg Krogh**)
|
||||
* The `ps_is_account_enabled` function was updated to take a VARCHAR(32) user input on 5.7, as a part of WL#2284
|
||||
* The generate_sql_file.sh script had a number of improvements:
|
||||
* Generated files are now output in to a "gen" directory, that is ignored by git
|
||||
* Added using a new default "mysql.sys@localhost" user (that has the account locked) for the MySQL 5.7+ integration as the DEFINER for all objects
|
||||
* Added a warning to the top of the generated integration file to also submit changes to the sys project
|
||||
* Improved the the option of skipping binary logs, so that all routines can load as well - those that used SET sql_log_bin will now select a warning when being used instead of setting the option
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Git Issue #51 - Fixed the `generate_sql_file.sh` script to also replace the definer in the before_setup.sql output
|
||||
* Git Issue #52 - Removed apostrophe from the `format_statement` function comment because TOAD no likey
|
||||
* Git Issue #56 - Installation failed on 5.6 with ONLY_FULL_GROUP_BY enabled
|
||||
* Git Issue #76 - Fixes for the new show_compatibility_56 variable. 5.7 versions of the `format_path()` function and `ps_check_lost_instrumentation` view were added, that use performance_schema.global_status/global_variables instead of information_schema.global_status/global_variables
|
||||
* Git Issue #79 - Fixed grammar within `statements_with_runtimes_in_95th_percentile` view descriptions
|
||||
* Oracle Bug #21484593 / Oracle Bug #21281955 - The `format_path()` function incorrectly took and returned a VARCHAR(260) instead of VARCHAR(512) (as the underlying is exposed as in Performance Schema) causing sporadic test failures
|
||||
* Oracle Bug #21550271 - Fixed the `ps_setup_reset_to_default` for 5.7 with the addition of the new `history` column on the `performance_schema.setup_actors` table
|
||||
* Oracle Bug #21550054 - It is possible that the views can show data that overflows when aggregating very large values, reset all statistics before each test to ensure no overflows
|
||||
* Oracle Bug #21647101 - Fixed the `ps_is_instrument_default_enabed` and `ps_is_instrument_default_timed` to take in to account the new instruments added within 5.7
|
||||
* MySQL Bug #77848 - Added the missing ps_setup_instruments_cleanup.inc
|
||||
* Fixed the `ps_setup_reset_to_default()` procedure to also set the new `ENABLED` column within `performance_schema.setup_actors` within 5.7
|
||||
* The `user_summary_by_file_io`/`x$user_summary_by_file_io` and `host_summary_by_file_io`/`x$host_summary_by_file_io` tables were incorrectly aggregating all wait events, not just `wait/io/file/%`
|
||||
|
||||
### Implementation Details
|
||||
|
||||
* Tests were improved via 5.7 integration
|
||||
* Template files were added for stored procedures and functions
|
||||
* Improved the sys_config_cleanup.inc procedure in tests to be able to reset the sys_config table completely (including the set_by column to NULL). The triggers can now be set to not update the column by setting the @sys.ignore_sys_config_triggers user variable to true
|
||||
|
||||
## 1.4.0 (09/03/2015)
|
||||
|
||||
### Backwards Incompatible Changes
|
||||
|
||||
* The `memory_global_by_current_allocated` views were renamed to `memory_global_by_current_bytes` for consistency with the other memory views
|
||||
* The `ps_setup_enable_consumers` procedure was renamed to `ps_setup_disable_consumer` for naming consistency (everything is now singular, not plural)
|
||||
* The `format_time` function displayed values in minutes incorrectly, it now rounds to minutes, and uses an 'm' suffix, like the rest of the units
|
||||
|
||||
### Improvements
|
||||
|
||||
* The beginnings of a mysql-test suite have been added
|
||||
* The `innodb_lock_waits`/`x$innodb_lock_waits` views were improved (**Contributions by both Jesper Wisborg Krogh and Mark Matthews**)
|
||||
* Added the `wait_started`, `wait_age`, `waiting_trx_started` `waiting_trx_age`, `waiting_trx_rows_locked` and `waiting_trx_rows_modified` columns for waiting transactions
|
||||
* Added the `blocking_trx_started`, `blocking_trx_age`, `blocking_trx_rows_locked` and `blocking_trx_rows_modified` for blocking transactions
|
||||
* Order the result set so the oldest lock waits are first
|
||||
* The `waiting_table` and `waiting_index` were always the same as the `blocking_table` and `blocking_index`. So the blocking_% columns have been removed and the waiting_% columns have been renamed to locked_%
|
||||
* The `waiting_lock_type` and `blocking_lock_type` were also always the same. So these were removed and replaced with a single `locked_type` column
|
||||
* Renamed the `waiting_thread` and `blocking_thread` to `waiting_pid` and `blocking_pid` respectively to avoid confusion with the threads from the Performance Schema.
|
||||
* Added the `sys_get_config` function, used to get configuration parameters from the `sys_config` table - primarily from other sys objects, but can be used individually (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Add an option to generate_sql_file.sh to generate a mysql_install_db / mysqld --initialize format friendly file
|
||||
* Added the `ps_is_thread_instrumented` function, to check whether a specified thread is instrumented within Performance Schema
|
||||
* Added the `ps_is_consumer_enabled` function, to check whether a specified consumer is enabled within Performance Schema (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Added some further replacements to the `format_path` function (`slave_load_tmpdir`, `innodb_data_home_dir`, `innodb_log_group_home_dir` and `innodb_undo_directory`)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* The 5.6 `host_summary` and `x$host_summary` views incorrectly had the column with `COUNT(DISTINCT accounts.user)` named `unique_hosts` instead of `unique_users` (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Both the `format_time` and `format_bytes` took a BIGINT as input, and output VARCHAR, but BIGINT could be too small for aggregated values for the inputs. Now both functions both use TEXT as their input (Issue #34, Issue #38)
|
||||
* The `format_time` function displayed values in minutes incorrectly, it now rounds to minutes, and uses an 'm' suffix, like the rest of the units
|
||||
* The `sys_config` related triggers had no DEFINER clause set
|
||||
* The `ps_setup_disable_thread` procedure always disabled the current thread and was ignoring the connection id given as an argument (**Contributed by Jesper Wisborg Krogh**)
|
||||
* The `ps_trace_thread` procedure had an incorrect calculation of how long the procedure has been running (**Contributed by Jesper Wisborg Krogh**)
|
||||
|
||||
### Implementation Details
|
||||
|
||||
Various changes were made to allow better generation of integration sql files:
|
||||
|
||||
* The formatting for all comments has been standardized on -- line comments. C-style /* comments */ have been removed
|
||||
* Issue #35 had one instance of this resolved in this release (**Contributed by Joe Grasse**), but the entire code base has now been done
|
||||
* Each object has been created within it's own file. No longer do x$ views live with their non-x$ counterparts
|
||||
* DELIMITERs were standardized to $$
|
||||
|
||||
## 1.3.0 (23/10/2014)
|
||||
|
||||
### Improvements
|
||||
|
||||
* Added an `innodb_lock_waits` set of views, showing each thread that is waiting on a lock within InnoDB, and the blocking thread lock information (**Contributed by Jesper Wisborg Krogh**)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fixed broken `host_summary_by_stages` views, broken with a last minute change before the 1.2.0 release that went unnoticed (facepalm)
|
||||
|
||||
## 1.2.0 (22/10/2014)
|
||||
|
||||
### Backwards Incompatible Changes
|
||||
|
||||
* The `host_summary_by_stages` and `user_summary_by_stages` `wait_sum` and `wait_avg` columns were renamed to `total_latency` and `avg_latency` respectively, for consistency.
|
||||
* The `host_summary_by_file_io_type` and `user_summary_by_file_io_type `latency` column was renamed to `total_latency`, for consistency.
|
||||
|
||||
### Improvements
|
||||
|
||||
* Made the truncation length for the `format_statement` view configurable
|
||||
* This includes adding a new persistent `sys_config` table to store the new variable - `statement_truncate_len` - see the README for usage
|
||||
* Added `total_latency` to the `schema_tables_with_full_table_scans` view, and added an x$ counterpart
|
||||
* Added `innodb_buffer_free` to the `schema_table_statistics_with_buffer` view, to summarize how much free space is allocated per table in the buffer pool
|
||||
* The `schema_unused_indexes` view now ignores indexes named `PRIMARY` (primary keys)
|
||||
* Added `rows_affected` and `rows_affected_avg` stats to the `statement_analysis` views
|
||||
* The `statements_with_full_table_scans` view now ignores any SQL that starts with `SHOW`
|
||||
* Added a script, `generate_sql_file.sh`, that can be used to generate a single SQL file, also allowing substitution of the MySQL user to use, and/or whether the `SET sql_log_bin ...` statements should be omitted.
|
||||
* This is useful for those using RDS, where the root@localhost user is not accessible, and sql_log_bin is disabled (Issue #5)
|
||||
* Added a set of `memory_by_thread_by_current_bytes` views, that summarize memory usage per thread with MySQL 5.7's memory instrumentation
|
||||
* Improved each of the host specific views to return aggregate values for `background` threads, instead of ignoring them, in the same way as the user summary views
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Added the missing `memory_by_host` view for MySQL 5.7
|
||||
* Added missing space for hour notation within the `format_time` function
|
||||
* Fixed views affected by MySQL 5.7 ONLY_FULL_GROUP_BY and functional dependency changes
|
||||
|
||||
## 1.1.0 (04/09/2014)
|
||||
|
||||
### Improvements
|
||||
|
||||
* Added host summary views, which have the same structure as the user summary views, but aggregated by host instead (**Contributed by Arnaud Adant**)
|
||||
* `host_summary`
|
||||
* `host_summary_by_file_io_type`
|
||||
* `host_summary_by_file_io`
|
||||
* `host_summary_by_statement_type`
|
||||
* `host_summary_by_statement_latency`
|
||||
* `host_summary_by_stages`
|
||||
* `waits_by_host_by_latency`
|
||||
|
||||
* Added functions which return instruments are either enabled, or timed by default (#15) (**Contributed by Jesper Wisborg Krogh**)
|
||||
* `ps_is_instrument_default_enabled`
|
||||
* `ps_is_instrument_default_timed`
|
||||
|
||||
* Added a `ps_thread_id` function, which returns the thread_id value exposed within performance_schema for the current connection (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Improved each of the user specific views to return aggregate values for `background` threads, instead of ignoring them (**Contributed by Joe Grasse**)
|
||||
* Optimized the `schema_table_statistics` and `schema_table_statistics_with_buffer` views, to use a new view that will get materialized (`x$ps_schema_table_statistics_io`), along with the changes to the RETURN types for `extract_schema_from_file_name` and `extract_table_from_file_name`, this results in a significant performance improvement - in one test changing the run time from 14 minutes to 20 seconds. (**Conceived by Roy Lyseng, Mark Leith and Jesper Wisborg Krogh, implemented and contributed by Jesper Wisborg Krogh**)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Removed unintentially committed sys_56_rds.sql file (See Issue #5, which is still outstanding)
|
||||
* Fixed the `ps_trace_statement_digest` and `ps_trace_thread` procedures to properly set sql_log_bin, and reset the thread INSTRUMENTED value correctly (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Removed various sql_log_bin disabling from other procedures that no longer require it - DML against the performance_schema data is no longer replicated (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Fixed EXPLAIN within `ps_trace_statement_digest` procedure (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Fixed the datatype for the `thd_id` variable within the `ps_thread_stack` procedure (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Fixed datatypes used for temporary tables within the `ps_trace_statement_digest` procedure (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Fixed the RETURN datatype `extract_schema_from_file_name` and `extract_table_from_file_name` to return a VARCHAR(64) (**Contributed by Jesper Wisborg Krogh**)
|
||||
* Added events_transactions_current to the default enabled consumers in 5.7 (#25)
|
||||
|
||||
## 1.0.1 (23/05/2014)
|
||||
|
||||
### Improvements
|
||||
|
||||
* Added procedures to enable / disable Performance Schema consumers. (**Contributed by the MySQL QA Team**)
|
||||
* `ps_setup_disable_consumers(<LIKE string>)` allows disabling any consumers matching the LIKE string.
|
||||
* `ps_setup_enable_consumers(<LIKE string>)` allows enabling any consumers matching the LIKE string.
|
||||
|
||||
* Added procedures to show both enabled and disbled consumers or instruments individually, these are more useful for tooling than the `ps_setup_show_enabled`/`ps_setup_show_disabled` procedures which show all configuration in multiple result sets. (**Contributed by the MySQL QA Team**)
|
||||
* `ps_setup_show_disabled_consumers` shows only disabled consumers.
|
||||
* `ps_setup_show_disabled_instruments` shows only disabled instruments.
|
||||
* `ps_setup_show_enabled_consumers` shows only enabled consumers.
|
||||
* `ps_setup_show_enabled_instruments` shows only enabled instruments.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Running the installation scripts sometimes failed because of the comment format. (#1) (**Contributed by Joe Grasse**)
|
||||
* Some views did not work with the ERROR_FOR_DIVISION_BY_ZERO SQL mode. (#6) (**Contributed by Joe Grasse**)
|
||||
* On Windows the `ps_thread_stack()` stored function failed to escape file path backslashes correctly within the JSON output.
|
||||
|
||||
## 1.0.0 (11/04/2014)
|
5486
scripts/sys_schema/README.md
Normal file
5486
scripts/sys_schema/README.md
Normal file
File diff suppressed because it is too large
Load Diff
16
scripts/sys_schema/after_setup.sql
Normal file
16
scripts/sys_schema/after_setup.sql
Normal file
@ -0,0 +1,16 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
SET @@sql_log_bin = @sql_log_bin;
|
22
scripts/sys_schema/before_setup.sql
Normal file
22
scripts/sys_schema/before_setup.sql
Normal file
@ -0,0 +1,22 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
SET NAMES utf8;
|
||||
SET @sql_log_bin = @@sql_log_bin;
|
||||
SET sql_log_bin = 0;
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS sys DEFAULT CHARACTER SET utf8;
|
||||
|
||||
USE sys;
|
@ -0,0 +1,66 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS extract_schema_from_file_name;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION extract_schema_from_file_name (
|
||||
path VARCHAR(512)
|
||||
)
|
||||
RETURNS VARCHAR(64)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a raw file path, and attempts to extract the schema name from it.
|
||||
|
||||
Useful for when interacting with Performance Schema data
|
||||
concerning IO statistics, for example.
|
||||
|
||||
Currently relies on the fact that a table data file will be within a
|
||||
specified database directory (will not work with partitions or tables
|
||||
that specify an individual DATA_DIRECTORY).
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
path (VARCHAR(512)):
|
||||
The full file path to a data file to extract the schema name from.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
VARCHAR(64)
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');
|
||||
+----------------------------------------------------------------------------+
|
||||
| sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |
|
||||
+----------------------------------------------------------------------------+
|
||||
| employees |
|
||||
+----------------------------------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
RETURN LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -2), '/', 1), 64);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,62 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS extract_table_from_file_name;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION extract_table_from_file_name (
|
||||
path VARCHAR(512)
|
||||
)
|
||||
RETURNS VARCHAR(64)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a raw file path, and extracts the table name from it.
|
||||
|
||||
Useful for when interacting with Performance Schema data
|
||||
concerning IO statistics, for example.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
path (VARCHAR(512)):
|
||||
The full file path to a data file to extract the table name from.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
VARCHAR(64)
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');
|
||||
+---------------------------------------------------------------------------+
|
||||
| sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |
|
||||
+---------------------------------------------------------------------------+
|
||||
| employee |
|
||||
+---------------------------------------------------------------------------+
|
||||
1 row in set (0.02 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
RETURN LEFT(SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -1), '@0024', '$'), '.', 1), 64);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
84
scripts/sys_schema/functions/format_bytes.sql
Normal file
84
scripts/sys_schema/functions/format_bytes.sql
Normal file
@ -0,0 +1,84 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS format_bytes;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION format_bytes (
|
||||
-- We feed in and return TEXT here, as aggregates of
|
||||
-- bytes can return numbers larger than BIGINT UNSIGNED
|
||||
bytes TEXT
|
||||
)
|
||||
RETURNS TEXT
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a raw bytes value, and converts it to a human readable format.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
bytes (TEXT):
|
||||
A raw bytes value.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TEXT
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.format_bytes(2348723492723746) AS size;
|
||||
+----------+
|
||||
| size |
|
||||
+----------+
|
||||
| 2.09 PiB |
|
||||
+----------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> SELECT sys.format_bytes(2348723492723) AS size;
|
||||
+----------+
|
||||
| size |
|
||||
+----------+
|
||||
| 2.14 TiB |
|
||||
+----------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> SELECT sys.format_bytes(23487234) AS size;
|
||||
+-----------+
|
||||
| size |
|
||||
+-----------+
|
||||
| 22.40 MiB |
|
||||
+-----------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
IF bytes IS NULL THEN RETURN NULL;
|
||||
ELSEIF bytes >= 1125899906842624 THEN RETURN CONCAT(ROUND(bytes / 1125899906842624, 2), ' PiB');
|
||||
ELSEIF bytes >= 1099511627776 THEN RETURN CONCAT(ROUND(bytes / 1099511627776, 2), ' TiB');
|
||||
ELSEIF bytes >= 1073741824 THEN RETURN CONCAT(ROUND(bytes / 1073741824, 2), ' GiB');
|
||||
ELSEIF bytes >= 1048576 THEN RETURN CONCAT(ROUND(bytes / 1048576, 2), ' MiB');
|
||||
ELSEIF bytes >= 1024 THEN RETURN CONCAT(ROUND(bytes / 1024, 2), ' KiB');
|
||||
ELSE RETURN CONCAT(ROUND(bytes, 0), ' bytes');
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
108
scripts/sys_schema/functions/format_path.sql
Normal file
108
scripts/sys_schema/functions/format_path.sql
Normal file
@ -0,0 +1,108 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS format_path;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION format_path (
|
||||
in_path VARCHAR(512)
|
||||
)
|
||||
RETURNS VARCHAR(512) CHARSET UTF8
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a raw path value, and strips out the datadir or tmpdir
|
||||
replacing with @@datadir and @@tmpdir respectively.
|
||||
|
||||
Also normalizes the paths across operating systems, so backslashes
|
||||
on Windows are converted to forward slashes
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
path (VARCHAR(512)):
|
||||
The raw file path value to format.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
VARCHAR(512) CHARSET UTF8
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> select @@datadir;
|
||||
+-----------------------------------------------+
|
||||
| @@datadir |
|
||||
+-----------------------------------------------+
|
||||
| /Users/mark/sandboxes/SmallTree/AMaster/data/ |
|
||||
+-----------------------------------------------+
|
||||
1 row in set (0.06 sec)
|
||||
|
||||
mysql> select format_path(\'/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD\') AS path;
|
||||
+--------------------------+
|
||||
| path |
|
||||
+--------------------------+
|
||||
| @@datadir/mysql/proc.MYD |
|
||||
+--------------------------+
|
||||
1 row in set (0.03 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
DECLARE v_path VARCHAR(512);
|
||||
DECLARE v_undo_dir VARCHAR(1024);
|
||||
|
||||
DECLARE path_separator CHAR(1) DEFAULT '/';
|
||||
|
||||
IF @@global.version_compile_os LIKE 'win%' THEN
|
||||
SET path_separator = '\\';
|
||||
END IF;
|
||||
|
||||
-- OSX hides /private/ in variables, but Performance Schema does not
|
||||
IF in_path LIKE '/private/%' THEN
|
||||
SET v_path = REPLACE(in_path, '/private', '');
|
||||
ELSE
|
||||
SET v_path = in_path;
|
||||
END IF;
|
||||
|
||||
-- @@global.innodb_undo_directory is only set when separate undo logs are used
|
||||
SET v_undo_dir = IFNULL((SELECT VARIABLE_VALUE FROM information_schema.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'innodb_undo_directory'), '');
|
||||
|
||||
IF v_path IS NULL THEN
|
||||
RETURN NULL;
|
||||
ELSEIF v_path LIKE CONCAT(@@global.datadir, IF(SUBSTRING(@@global.datadir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.datadir, CONCAT('@@datadir', IF(SUBSTRING(@@global.datadir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.tmpdir, IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.tmpdir, CONCAT('@@tmpdir', IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.slave_load_tmpdir, IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.slave_load_tmpdir, CONCAT('@@slave_load_tmpdir', IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.innodb_data_home_dir, IF(SUBSTRING(@@global.innodb_data_home_dir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.innodb_data_home_dir, CONCAT('@@innodb_data_home_dir', IF(SUBSTRING(@@global.innodb_data_home_dir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.innodb_log_group_home_dir, IF(SUBSTRING(@@global.innodb_log_group_home_dir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.innodb_log_group_home_dir, CONCAT('@@innodb_log_group_home_dir', IF(SUBSTRING(@@global.innodb_log_group_home_dir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(v_undo_dir, IF(SUBSTRING(v_undo_dir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, v_undo_dir, CONCAT('@@innodb_undo_directory', IF(SUBSTRING(v_undo_dir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.basedir, IF(SUBSTRING(@@global.basedir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.basedir, CONCAT('@@basedir', IF(SUBSTRING(@@global.basedir, -1) = path_separator, path_separator, '')));
|
||||
END IF;
|
||||
|
||||
RETURN v_path;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
108
scripts/sys_schema/functions/format_path_57.sql
Normal file
108
scripts/sys_schema/functions/format_path_57.sql
Normal file
@ -0,0 +1,108 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS format_path;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION format_path (
|
||||
in_path VARCHAR(512)
|
||||
)
|
||||
RETURNS VARCHAR(512) CHARSET UTF8
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a raw path value, and strips out the datadir or tmpdir
|
||||
replacing with @@datadir and @@tmpdir respectively.
|
||||
|
||||
Also normalizes the paths across operating systems, so backslashes
|
||||
on Windows are converted to forward slashes
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
path (VARCHAR(512)):
|
||||
The raw file path value to format.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
VARCHAR(512) CHARSET UTF8
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> select @@datadir;
|
||||
+-----------------------------------------------+
|
||||
| @@datadir |
|
||||
+-----------------------------------------------+
|
||||
| /Users/mark/sandboxes/SmallTree/AMaster/data/ |
|
||||
+-----------------------------------------------+
|
||||
1 row in set (0.06 sec)
|
||||
|
||||
mysql> select format_path(\'/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD\') AS path;
|
||||
+--------------------------+
|
||||
| path |
|
||||
+--------------------------+
|
||||
| @@datadir/mysql/proc.MYD |
|
||||
+--------------------------+
|
||||
1 row in set (0.03 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
DECLARE v_path VARCHAR(512);
|
||||
DECLARE v_undo_dir VARCHAR(1024);
|
||||
|
||||
DECLARE path_separator CHAR(1) DEFAULT '/';
|
||||
|
||||
IF @@global.version_compile_os LIKE 'win%' THEN
|
||||
SET path_separator = '\\';
|
||||
END IF;
|
||||
|
||||
-- OSX hides /private/ in variables, but Performance Schema does not
|
||||
IF in_path LIKE '/private/%' THEN
|
||||
SET v_path = REPLACE(in_path, '/private', '');
|
||||
ELSE
|
||||
SET v_path = in_path;
|
||||
END IF;
|
||||
|
||||
-- @@global.innodb_undo_directory is only set when separate undo logs are used
|
||||
SET v_undo_dir = IFNULL((SELECT VARIABLE_VALUE FROM performance_schema.global_variables WHERE VARIABLE_NAME = 'innodb_undo_directory'), '');
|
||||
|
||||
IF v_path IS NULL THEN
|
||||
RETURN NULL;
|
||||
ELSEIF v_path LIKE CONCAT(@@global.datadir, IF(SUBSTRING(@@global.datadir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.datadir, CONCAT('@@datadir', IF(SUBSTRING(@@global.datadir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.tmpdir, IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.tmpdir, CONCAT('@@tmpdir', IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.slave_load_tmpdir, IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.slave_load_tmpdir, CONCAT('@@slave_load_tmpdir', IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.innodb_data_home_dir, IF(SUBSTRING(@@global.innodb_data_home_dir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.innodb_data_home_dir, CONCAT('@@innodb_data_home_dir', IF(SUBSTRING(@@global.innodb_data_home_dir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.innodb_log_group_home_dir, IF(SUBSTRING(@@global.innodb_log_group_home_dir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.innodb_log_group_home_dir, CONCAT('@@innodb_log_group_home_dir', IF(SUBSTRING(@@global.innodb_log_group_home_dir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(v_undo_dir, IF(SUBSTRING(v_undo_dir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, v_undo_dir, CONCAT('@@innodb_undo_directory', IF(SUBSTRING(v_undo_dir, -1) = path_separator, path_separator, '')));
|
||||
ELSEIF v_path LIKE CONCAT(@@global.basedir, IF(SUBSTRING(@@global.basedir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN
|
||||
SET v_path = REPLACE(v_path, @@global.basedir, CONCAT('@@basedir', IF(SUBSTRING(@@global.basedir, -1) = path_separator, path_separator, '')));
|
||||
END IF;
|
||||
|
||||
RETURN v_path;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
81
scripts/sys_schema/functions/format_statement.sql
Normal file
81
scripts/sys_schema/functions/format_statement.sql
Normal file
@ -0,0 +1,81 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS format_statement;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION format_statement (
|
||||
statement LONGTEXT
|
||||
)
|
||||
RETURNS LONGTEXT
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Formats a normalized statement, truncating it if it is > 64 characters long by default.
|
||||
|
||||
To configure the length to truncate the statement to by default, update the `statement_truncate_len`
|
||||
variable with `sys_config` table to a different value. Alternatively, to change it just for just
|
||||
your particular session, use `SET @sys.statement_truncate_len := <some new value>`.
|
||||
|
||||
Useful for printing statement related data from Performance Schema from
|
||||
the command line.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
statement (LONGTEXT):
|
||||
The statement to format.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
LONGTEXT
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.format_statement(digest_text)
|
||||
-> FROM performance_schema.events_statements_summary_by_digest
|
||||
-> ORDER by sum_timer_wait DESC limit 5;
|
||||
+-------------------------------------------------------------------+
|
||||
| sys.format_statement(digest_text) |
|
||||
+-------------------------------------------------------------------+
|
||||
| CREATE SQL SECURITY INVOKER VI ... KE ? AND `variable_value` > ? |
|
||||
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `esc` . ... |
|
||||
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `sys` . ... |
|
||||
| CREATE SQL SECURITY INVOKER VI ... , `compressed_size` ) ) DESC |
|
||||
| CREATE SQL SECURITY INVOKER VI ... LIKE ? ORDER BY `timer_start` |
|
||||
+-------------------------------------------------------------------+
|
||||
5 rows in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
-- Check if we have the configured length, if not, init it
|
||||
IF @sys.statement_truncate_len IS NULL THEN
|
||||
SET @sys.statement_truncate_len = sys_get_config('statement_truncate_len', 64);
|
||||
END IF;
|
||||
|
||||
IF CHAR_LENGTH(statement) > @sys.statement_truncate_len THEN
|
||||
RETURN REPLACE(CONCAT(LEFT(statement, (@sys.statement_truncate_len/2)-2), ' ... ', RIGHT(statement, (@sys.statement_truncate_len/2)-2)), '\n', ' ');
|
||||
ELSE
|
||||
RETURN REPLACE(statement, '\n', ' ');
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
91
scripts/sys_schema/functions/format_time.sql
Normal file
91
scripts/sys_schema/functions/format_time.sql
Normal file
@ -0,0 +1,91 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS format_time;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION format_time (
|
||||
-- We feed in and return TEXT here, as aggregates of
|
||||
-- picoseconds can return numbers larger than BIGINT UNSIGNED
|
||||
picoseconds TEXT
|
||||
)
|
||||
RETURNS TEXT CHARSET UTF8
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a raw picoseconds value, and converts it to a human readable form.
|
||||
|
||||
Picoseconds are the precision that all latency values are printed in
|
||||
within Performance Schema, however are not user friendly when wanting
|
||||
to scan output from the command line.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
picoseconds (TEXT):
|
||||
The raw picoseconds value to convert.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TEXT
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> select format_time(342342342342345);
|
||||
+------------------------------+
|
||||
| format_time(342342342342345) |
|
||||
+------------------------------+
|
||||
| 00:05:42 |
|
||||
+------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> select format_time(342342342);
|
||||
+------------------------+
|
||||
| format_time(342342342) |
|
||||
+------------------------+
|
||||
| 342.34 us |
|
||||
+------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> select format_time(34234);
|
||||
+--------------------+
|
||||
| format_time(34234) |
|
||||
+--------------------+
|
||||
| 34.23 ns |
|
||||
+--------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
IF picoseconds IS NULL THEN RETURN NULL;
|
||||
ELSEIF picoseconds >= 604800000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 604800000000000000, 2), ' w');
|
||||
ELSEIF picoseconds >= 86400000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 86400000000000000, 2), ' d');
|
||||
ELSEIF picoseconds >= 3600000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 3600000000000000, 2), ' h');
|
||||
ELSEIF picoseconds >= 60000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 60000000000000, 2), ' m');
|
||||
ELSEIF picoseconds >= 1000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000000, 2), ' s');
|
||||
ELSEIF picoseconds >= 1000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000, 2), ' ms');
|
||||
ELSEIF picoseconds >= 1000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000, 2), ' us');
|
||||
ELSEIF picoseconds >= 1000 THEN RETURN CONCAT(ROUND(picoseconds / 1000, 2), ' ns');
|
||||
ELSE RETURN CONCAT(picoseconds, ' ps');
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
90
scripts/sys_schema/functions/list_add.sql
Normal file
90
scripts/sys_schema/functions/list_add.sql
Normal file
@ -0,0 +1,90 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS list_add;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION list_add (
|
||||
in_list TEXT,
|
||||
in_add_value TEXT
|
||||
)
|
||||
RETURNS TEXT
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a list, and a value to add to the list, and returns the resulting list.
|
||||
|
||||
Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_list (TEXT):
|
||||
The comma separated list to add a value to
|
||||
|
||||
in_add_value (TEXT):
|
||||
The value to add to the input list
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TEXT
|
||||
|
||||
Example
|
||||
--------
|
||||
|
||||
mysql> select @@sql_mode;
|
||||
+-----------------------------------------------------------------------------------+
|
||||
| @@sql_mode |
|
||||
+-----------------------------------------------------------------------------------+
|
||||
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
|
||||
+-----------------------------------------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> set sql_mode = sys.list_add(@@sql_mode, ''ANSI_QUOTES'');
|
||||
Query OK, 0 rows affected (0.06 sec)
|
||||
|
||||
mysql> select @@sql_mode;
|
||||
+-----------------------------------------------------------------------------------------------+
|
||||
| @@sql_mode |
|
||||
+-----------------------------------------------------------------------------------------------+
|
||||
| ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
|
||||
+-----------------------------------------------------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
CONTAINS SQL
|
||||
BEGIN
|
||||
|
||||
IF (in_add_value IS NULL) THEN
|
||||
SIGNAL SQLSTATE '02200'
|
||||
SET MESSAGE_TEXT = 'Function sys.list_add: in_add_value input variable should not be NULL',
|
||||
MYSQL_ERRNO = 1138;
|
||||
END IF;
|
||||
|
||||
IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN
|
||||
-- return the new value as a single value list
|
||||
RETURN in_add_value;
|
||||
END IF;
|
||||
|
||||
RETURN (SELECT CONCAT(TRIM(BOTH ',' FROM TRIM(in_list)), ',', in_add_value));
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
91
scripts/sys_schema/functions/list_drop.sql
Normal file
91
scripts/sys_schema/functions/list_drop.sql
Normal file
@ -0,0 +1,91 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS list_drop;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION list_drop (
|
||||
in_list TEXT,
|
||||
in_drop_value TEXT
|
||||
)
|
||||
RETURNS TEXT
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a list, and a value to attempt to remove from the list, and returns the resulting list.
|
||||
|
||||
Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_list (TEXT):
|
||||
The comma separated list to drop a value from
|
||||
|
||||
in_drop_value (TEXT):
|
||||
The value to drop from the input list
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TEXT
|
||||
|
||||
Example
|
||||
--------
|
||||
|
||||
mysql> select @@sql_mode;
|
||||
+-----------------------------------------------------------------------------------------------+
|
||||
| @@sql_mode |
|
||||
+-----------------------------------------------------------------------------------------------+
|
||||
| ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
|
||||
+-----------------------------------------------------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> set sql_mode = sys.list_drop(@@sql_mode, ''ONLY_FULL_GROUP_BY'');
|
||||
Query OK, 0 rows affected (0.03 sec)
|
||||
|
||||
mysql> select @@sql_mode;
|
||||
+----------------------------------------------------------------------------+
|
||||
| @@sql_mode |
|
||||
+----------------------------------------------------------------------------+
|
||||
| ANSI_QUOTES,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
|
||||
+----------------------------------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
CONTAINS SQL
|
||||
BEGIN
|
||||
|
||||
IF (in_drop_value IS NULL) THEN
|
||||
SIGNAL SQLSTATE '02200'
|
||||
SET MESSAGE_TEXT = 'Function sys.list_drop: in_drop_value input variable should not be NULL',
|
||||
MYSQL_ERRNO = 1138;
|
||||
END IF;
|
||||
|
||||
IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN
|
||||
-- return the list as it was passed in
|
||||
RETURN in_list;
|
||||
END IF;
|
||||
|
||||
-- ensure that leading / trailing commas are remove, support values with either spaces or not between commas
|
||||
RETURN (SELECT TRIM(BOTH ',' FROM REPLACE(REPLACE(CONCAT(',', in_list), CONCAT(',', in_drop_value), ''), CONCAT(', ', in_drop_value), '')));
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
69
scripts/sys_schema/functions/ps_is_account_enabled.sql
Normal file
69
scripts/sys_schema/functions/ps_is_account_enabled.sql
Normal file
@ -0,0 +1,69 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_is_account_enabled;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_account_enabled (
|
||||
in_host VARCHAR(60),
|
||||
in_user VARCHAR(16)
|
||||
)
|
||||
RETURNS ENUM('YES', 'NO')
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Determines whether instrumentation of an account is enabled
|
||||
within Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_host VARCHAR(60):
|
||||
The hostname of the account to check.
|
||||
in_user (VARCHAR(16)):
|
||||
The username of the account to check.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
ENUM(\'YES\', \'NO\', \'PARTIAL\')
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.ps_is_account_enabled(\'localhost\', \'root\');
|
||||
+------------------------------------------------+
|
||||
| sys.ps_is_account_enabled(\'localhost\', \'root\') |
|
||||
+------------------------------------------------+
|
||||
| YES |
|
||||
+------------------------------------------------+
|
||||
1 row in set (0.01 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
RETURN IF(EXISTS(SELECT 1
|
||||
FROM performance_schema.setup_actors
|
||||
WHERE (`HOST` = '%' OR in_host LIKE `HOST`)
|
||||
AND (`USER` = '%' OR `USER` = in_user)
|
||||
),
|
||||
'YES', 'NO'
|
||||
);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
70
scripts/sys_schema/functions/ps_is_account_enabled_57.sql
Normal file
70
scripts/sys_schema/functions/ps_is_account_enabled_57.sql
Normal file
@ -0,0 +1,70 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_is_account_enabled;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_account_enabled (
|
||||
in_host VARCHAR(60),
|
||||
in_user VARCHAR(32)
|
||||
)
|
||||
RETURNS ENUM('YES', 'NO')
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Determines whether instrumentation of an account is enabled
|
||||
within Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_host VARCHAR(60):
|
||||
The hostname of the account to check.
|
||||
in_user VARCHAR(32):
|
||||
The username of the account to check.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
ENUM(\'YES\', \'NO\', \'PARTIAL\')
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.ps_is_account_enabled(\'localhost\', \'root\');
|
||||
+------------------------------------------------+
|
||||
| sys.ps_is_account_enabled(\'localhost\', \'root\') |
|
||||
+------------------------------------------------+
|
||||
| YES |
|
||||
+------------------------------------------------+
|
||||
1 row in set (0.01 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
RETURN IF(EXISTS(SELECT 1
|
||||
FROM performance_schema.setup_actors
|
||||
WHERE (`HOST` = '%' OR in_host LIKE `HOST`)
|
||||
AND (`USER` = '%' OR `USER` = in_user)
|
||||
AND (`ENABLED` = 'YES')
|
||||
),
|
||||
'YES', 'NO'
|
||||
);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
76
scripts/sys_schema/functions/ps_is_consumer_enabled.sql
Normal file
76
scripts/sys_schema/functions/ps_is_consumer_enabled.sql
Normal file
@ -0,0 +1,76 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_is_consumer_enabled;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_consumer_enabled (
|
||||
in_consumer varchar(64)
|
||||
)
|
||||
RETURNS enum('YES', 'NO')
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Determines whether a consumer is enabled (taking the consumer hierarchy into consideration)
|
||||
within the Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_consumer VARCHAR(64):
|
||||
The name of the consumer to check.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
ENUM(\'YES\', \'NO\')
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.ps_is_consumer_enabled(\'events_stages_history\');
|
||||
+-----------------------------------------------------+
|
||||
| sys.ps_is_consumer_enabled(\'events_stages_history\') |
|
||||
+-----------------------------------------------------+
|
||||
| NO |
|
||||
+-----------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
RETURN (
|
||||
SELECT (CASE
|
||||
WHEN c.NAME = 'global_instrumentation' THEN c.ENABLED
|
||||
WHEN c.NAME = 'thread_instrumentation' THEN IF(cg.ENABLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO')
|
||||
WHEN c.NAME LIKE '%\_digest' THEN IF(cg.ENABLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO')
|
||||
WHEN c.NAME LIKE '%\_current' THEN IF(cg.ENABLED = 'YES' AND ct.ENABLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO')
|
||||
ELSE IF(cg.ENABLED = 'YES' AND ct.ENABLED = 'YES' AND c.ENABLED = 'YES'
|
||||
AND ( SELECT cc.ENABLED FROM performance_schema.setup_consumers cc WHERE NAME = CONCAT(SUBSTRING_INDEX(c.NAME, '_', 2), '_current')
|
||||
) = 'YES', 'YES', 'NO')
|
||||
END) AS IsEnabled
|
||||
FROM performance_schema.setup_consumers c
|
||||
INNER JOIN performance_schema.setup_consumers cg
|
||||
INNER JOIN performance_schema.setup_consumers ct
|
||||
WHERE cg.NAME = 'global_instrumentation'
|
||||
AND ct.NAME = 'thread_instrumentation'
|
||||
AND c.NAME = in_consumer
|
||||
);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,76 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_is_instrument_default_enabled;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_instrument_default_enabled (
|
||||
in_instrument VARCHAR(128)
|
||||
)
|
||||
RETURNS ENUM('YES', 'NO')
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Returns whether an instrument is enabled by default in this version of MySQL.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_instrument VARCHAR(128):
|
||||
The instrument to check.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
ENUM(\'YES\', \'NO\')
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.ps_is_instrument_default_enabled(\'statement/sql/select\');
|
||||
+--------------------------------------------------------------+
|
||||
| sys.ps_is_instrument_default_enabled(\'statement/sql/select\') |
|
||||
+--------------------------------------------------------------+
|
||||
| YES |
|
||||
+--------------------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_enabled ENUM('YES', 'NO');
|
||||
|
||||
-- Currently the same in all versions
|
||||
SET v_enabled = IF(in_instrument LIKE 'wait/io/file/%'
|
||||
OR in_instrument LIKE 'wait/io/table/%'
|
||||
OR in_instrument LIKE 'statement/%'
|
||||
OR in_instrument LIKE 'memory/performance_schema/%'
|
||||
OR in_instrument IN ('wait/lock/table/sql/handler', 'idle')
|
||||
/*!50707
|
||||
OR in_instrument LIKE 'stage/innodb/%'
|
||||
OR in_instrument = 'stage/sql/copy to tmp table'
|
||||
*/
|
||||
,
|
||||
'YES',
|
||||
'NO'
|
||||
);
|
||||
|
||||
RETURN v_enabled;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,75 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_is_instrument_default_timed;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_instrument_default_timed (
|
||||
in_instrument VARCHAR(128)
|
||||
)
|
||||
RETURNS ENUM('YES', 'NO')
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Returns whether an instrument is timed by default in this version of MySQL.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_instrument VARCHAR(128):
|
||||
The instrument to check.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
ENUM(\'YES\', \'NO\')
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.ps_is_instrument_default_timed(\'statement/sql/select\');
|
||||
+------------------------------------------------------------+
|
||||
| sys.ps_is_instrument_default_timed(\'statement/sql/select\') |
|
||||
+------------------------------------------------------------+
|
||||
| YES |
|
||||
+------------------------------------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_timed ENUM('YES', 'NO');
|
||||
|
||||
-- Currently the same in all versions
|
||||
SET v_timed = IF(in_instrument LIKE 'wait/io/file/%'
|
||||
OR in_instrument LIKE 'wait/io/table/%'
|
||||
OR in_instrument LIKE 'statement/%'
|
||||
OR in_instrument IN ('wait/lock/table/sql/handler', 'idle')
|
||||
/*!50707
|
||||
OR in_instrument LIKE 'stage/innodb/%'
|
||||
OR in_instrument = 'stage/sql/copy to tmp table'
|
||||
*/
|
||||
,
|
||||
'YES',
|
||||
'NO'
|
||||
);
|
||||
|
||||
RETURN v_timed;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
72
scripts/sys_schema/functions/ps_is_thread_instrumented.sql
Normal file
72
scripts/sys_schema/functions/ps_is_thread_instrumented.sql
Normal file
@ -0,0 +1,72 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_is_thread_instrumented;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_thread_instrumented (
|
||||
in_connection_id BIGINT UNSIGNED
|
||||
) RETURNS ENUM('YES', 'NO', 'UNKNOWN')
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Checks whether the provided connection id is instrumented within Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_connection_id (BIGINT UNSIGNED):
|
||||
The id of the connection to check.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
ENUM(\'YES\', \'NO\', \'UNKNOWN\')
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.ps_is_thread_instrumented(CONNECTION_ID());
|
||||
+------------------------------------------------+
|
||||
| sys.ps_is_thread_instrumented(CONNECTION_ID()) |
|
||||
+------------------------------------------------+
|
||||
| YES |
|
||||
+------------------------------------------------+
|
||||
'
|
||||
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_enabled ENUM('YES', 'NO', 'UNKNOWN');
|
||||
|
||||
IF (in_connection_id IS NULL) THEN
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
|
||||
SELECT INSTRUMENTED INTO v_enabled
|
||||
FROM performance_schema.threads
|
||||
WHERE PROCESSLIST_ID = in_connection_id;
|
||||
|
||||
IF (v_enabled IS NULL) THEN
|
||||
RETURN 'UNKNOWN';
|
||||
ELSE
|
||||
RETURN v_enabled;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
71
scripts/sys_schema/functions/ps_thread_account.sql
Normal file
71
scripts/sys_schema/functions/ps_thread_account.sql
Normal file
@ -0,0 +1,71 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_thread_account;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_account (
|
||||
in_thread_id BIGINT UNSIGNED
|
||||
) RETURNS TEXT
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Return the user@host account for the given Performance Schema thread id.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_thread_id (BIGINT UNSIGNED):
|
||||
The id of the thread to return the account for.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> select thread_id, processlist_user, processlist_host from performance_schema.threads where type = ''foreground'';
|
||||
+-----------+------------------+------------------+
|
||||
| thread_id | processlist_user | processlist_host |
|
||||
+-----------+------------------+------------------+
|
||||
| 23 | NULL | NULL |
|
||||
| 30 | root | localhost |
|
||||
| 31 | msandbox | localhost |
|
||||
| 32 | msandbox | localhost |
|
||||
+-----------+------------------+------------------+
|
||||
4 rows in set (0.00 sec)
|
||||
|
||||
mysql> select sys.ps_thread_account(31);
|
||||
+---------------------------+
|
||||
| sys.ps_thread_account(31) |
|
||||
+---------------------------+
|
||||
| msandbox@localhost |
|
||||
+---------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
RETURN (SELECT IF(
|
||||
type = 'FOREGROUND',
|
||||
CONCAT(processlist_user, '@', processlist_host),
|
||||
type
|
||||
) AS account
|
||||
FROM `performance_schema`.`threads`
|
||||
WHERE thread_id = in_thread_id);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
66
scripts/sys_schema/functions/ps_thread_id.sql
Normal file
66
scripts/sys_schema/functions/ps_thread_id.sql
Normal file
@ -0,0 +1,66 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_thread_id;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_id (
|
||||
in_connection_id BIGINT UNSIGNED
|
||||
) RETURNS BIGINT UNSIGNED
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Return the Performance Schema THREAD_ID for the specified connection ID.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_connection_id (BIGINT UNSIGNED):
|
||||
The id of the connection to return the thread id for. If NULL, the current
|
||||
connection thread id is returned.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.ps_thread_id(79);
|
||||
+----------------------+
|
||||
| sys.ps_thread_id(79) |
|
||||
+----------------------+
|
||||
| 98 |
|
||||
+----------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> SELECT sys.ps_thread_id(CONNECTION_ID());
|
||||
+-----------------------------------+
|
||||
| sys.ps_thread_id(CONNECTION_ID()) |
|
||||
+-----------------------------------+
|
||||
| 98 |
|
||||
+-----------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
RETURN (SELECT THREAD_ID
|
||||
FROM `performance_schema`.`threads`
|
||||
WHERE PROCESSLIST_ID = IFNULL(in_connection_id, CONNECTION_ID())
|
||||
);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
171
scripts/sys_schema/functions/ps_thread_stack.sql
Normal file
171
scripts/sys_schema/functions/ps_thread_stack.sql
Normal file
@ -0,0 +1,171 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_thread_stack;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_stack (
|
||||
thd_id BIGINT UNSIGNED,
|
||||
debug BOOLEAN
|
||||
)
|
||||
RETURNS LONGTEXT CHARSET latin1
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Outputs a JSON formatted stack of all statements, stages and events
|
||||
within Performance Schema for the specified thread.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
thd_id (BIGINT UNSIGNED):
|
||||
The id of the thread to trace. This should match the thread_id
|
||||
column from the performance_schema.threads table.
|
||||
in_verbose (BOOLEAN):
|
||||
Include file:lineno information in the events.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
(line separation added for output)
|
||||
|
||||
mysql> SELECT sys.ps_thread_stack(37, FALSE) AS thread_stack\\G
|
||||
*************************** 1. row ***************************
|
||||
thread_stack: {"rankdir": "LR","nodesep": "0.10","stack_created": "2014-02-19 13:39:03",
|
||||
"mysql_version": "5.7.3-m13","mysql_user": "root@localhost","events":
|
||||
[{"nesting_event_id": "0", "event_id": "10", "timer_wait": 256.35, "event_info":
|
||||
"sql/select", "wait_info": "select @@version_comment limit 1\\nerrors: 0\\nwarnings: 0\\nlock time:
|
||||
...
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
|
||||
DECLARE json_objects LONGTEXT;
|
||||
|
||||
/*!50602
|
||||
-- Do not track the current thread, it will kill the stack
|
||||
UPDATE performance_schema.threads
|
||||
SET instrumented = 'NO'
|
||||
WHERE processlist_id = CONNECTION_ID();
|
||||
*/
|
||||
|
||||
SET SESSION group_concat_max_len=@@global.max_allowed_packet;
|
||||
|
||||
-- Select the entire stack of events
|
||||
SELECT GROUP_CONCAT(CONCAT( '{'
|
||||
, CONCAT_WS( ', '
|
||||
, CONCAT('"nesting_event_id": "', IF(nesting_event_id IS NULL, '0', nesting_event_id), '"')
|
||||
, CONCAT('"event_id": "', event_id, '"')
|
||||
-- Convert from picoseconds to microseconds
|
||||
, CONCAT( '"timer_wait": ', ROUND(timer_wait/1000000, 2))
|
||||
, CONCAT( '"event_info": "'
|
||||
, CASE
|
||||
WHEN event_name NOT LIKE 'wait/io%' THEN REPLACE(SUBSTRING_INDEX(event_name, '/', -2), '\\', '\\\\')
|
||||
WHEN event_name NOT LIKE 'wait/io/file%' OR event_name NOT LIKE 'wait/io/socket%' THEN REPLACE(SUBSTRING_INDEX(event_name, '/', -4), '\\', '\\\\')
|
||||
ELSE event_name
|
||||
END
|
||||
, '"'
|
||||
)
|
||||
-- Always dump the extra wait information gathered for statements
|
||||
, CONCAT( '"wait_info": "', IFNULL(wait_info, ''), '"')
|
||||
-- If debug is enabled, add the file:lineno information for waits
|
||||
, CONCAT( '"source": "', IF(true AND event_name LIKE 'wait%', IFNULL(wait_info, ''), ''), '"')
|
||||
-- Depending on the type of event, name it appropriately
|
||||
, CASE
|
||||
WHEN event_name LIKE 'wait/io/file%' THEN '"event_type": "io/file"'
|
||||
WHEN event_name LIKE 'wait/io/table%' THEN '"event_type": "io/table"'
|
||||
WHEN event_name LIKE 'wait/io/socket%' THEN '"event_type": "io/socket"'
|
||||
WHEN event_name LIKE 'wait/synch/mutex%' THEN '"event_type": "synch/mutex"'
|
||||
WHEN event_name LIKE 'wait/synch/cond%' THEN '"event_type": "synch/cond"'
|
||||
WHEN event_name LIKE 'wait/synch/rwlock%' THEN '"event_type": "synch/rwlock"'
|
||||
WHEN event_name LIKE 'wait/lock%' THEN '"event_type": "lock"'
|
||||
WHEN event_name LIKE 'statement/%' THEN '"event_type": "stmt"'
|
||||
WHEN event_name LIKE 'stage/%' THEN '"event_type": "stage"'
|
||||
WHEN event_name LIKE '%idle%' THEN '"event_type": "idle"'
|
||||
ELSE ''
|
||||
END
|
||||
)
|
||||
, '}'
|
||||
)
|
||||
ORDER BY event_id ASC SEPARATOR ',') event
|
||||
INTO json_objects
|
||||
FROM (
|
||||
/*!50600
|
||||
-- Select all statements, with the extra tracing information available
|
||||
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,
|
||||
CONCAT(sql_text, '\\n',
|
||||
'errors: ', errors, '\\n',
|
||||
'warnings: ', warnings, '\\n',
|
||||
'lock time: ', ROUND(lock_time/1000000, 2),'us\\n',
|
||||
'rows affected: ', rows_affected, '\\n',
|
||||
'rows sent: ', rows_sent, '\\n',
|
||||
'rows examined: ', rows_examined, '\\n',
|
||||
'tmp tables: ', created_tmp_tables, '\\n',
|
||||
'tmp disk tables: ', created_tmp_disk_tables, '\\n',
|
||||
'select scan: ', select_scan, '\\n',
|
||||
'select full join: ', select_full_join, '\\n',
|
||||
'select full range join: ', select_full_range_join, '\\n',
|
||||
'select range: ', select_range, '\\n',
|
||||
'select range check: ', select_range_check, '\\n',
|
||||
'sort merge passes: ', sort_merge_passes, '\\n',
|
||||
'sort rows: ', sort_rows, '\\n',
|
||||
'sort range: ', sort_range, '\\n',
|
||||
'sort scan: ', sort_scan, '\\n',
|
||||
'no index used: ', IF(no_index_used, 'TRUE', 'FALSE'), '\\n',
|
||||
'no good index used: ', IF(no_good_index_used, 'TRUE', 'FALSE'), '\\n'
|
||||
) AS wait_info
|
||||
FROM performance_schema.events_statements_history_long WHERE thread_id = thd_id)
|
||||
UNION
|
||||
-- Select all stages
|
||||
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info
|
||||
FROM performance_schema.events_stages_history_long WHERE thread_id = thd_id)
|
||||
UNION */
|
||||
-- Select all events, adding information appropriate to the event
|
||||
(SELECT thread_id, event_id,
|
||||
CONCAT(event_name ,
|
||||
IF(event_name NOT LIKE 'wait/synch/mutex%', IFNULL(CONCAT(' - ', operation), ''), ''),
|
||||
IF(number_of_bytes IS NOT NULL, CONCAT(' ', number_of_bytes, ' bytes'), ''),
|
||||
IF(event_name LIKE 'wait/io/file%', '\\n', ''),
|
||||
IF(object_schema IS NOT NULL, CONCAT('\\nObject: ', object_schema, '.'), ''),
|
||||
IF(object_name IS NOT NULL,
|
||||
IF (event_name LIKE 'wait/io/socket%',
|
||||
-- Print the socket if used, else the IP:port as reported
|
||||
CONCAT(IF (object_name LIKE ':0%', @@socket, object_name)),
|
||||
object_name),
|
||||
''),
|
||||
/*!50600 IF(index_name IS NOT NULL, CONCAT(' Index: ', index_name), ''),*/'\\n'
|
||||
) AS event_name,
|
||||
timer_wait, timer_start, nesting_event_id, source AS wait_info
|
||||
FROM performance_schema.events_waits_history_long WHERE thread_id = thd_id)) events
|
||||
ORDER BY event_id;
|
||||
|
||||
RETURN CONCAT('{',
|
||||
CONCAT_WS(',',
|
||||
'"rankdir": "LR"',
|
||||
'"nodesep": "0.10"',
|
||||
CONCAT('"stack_created": "', NOW(), '"'),
|
||||
CONCAT('"mysql_version": "', VERSION(), '"'),
|
||||
CONCAT('"mysql_user": "', CURRENT_USER(), '"'),
|
||||
CONCAT('"events": [', IFNULL(json_objects,''), ']')
|
||||
),
|
||||
'}');
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
233
scripts/sys_schema/functions/ps_thread_trx_info.sql
Normal file
233
scripts/sys_schema/functions/ps_thread_trx_info.sql
Normal file
@ -0,0 +1,233 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS ps_thread_trx_info;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_trx_info (
|
||||
in_thread_id BIGINT UNSIGNED
|
||||
) RETURNS LONGTEXT
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Returns a JSON object with info on the given threads current transaction,
|
||||
and the statements it has already executed, derived from the
|
||||
performance_schema.events_transactions_current and
|
||||
performance_schema.events_statements_history tables (so the consumers
|
||||
for these also have to be enabled within Performance Schema to get full
|
||||
data in the object).
|
||||
|
||||
When the output exceeds the default truncation length (65535), a JSON error
|
||||
object is returned, such as:
|
||||
|
||||
{ "error": "Trx info truncated: Row 6 was cut by GROUP_CONCAT()" }
|
||||
|
||||
Similar error objects are returned for other warnings/and exceptions raised
|
||||
when calling the function.
|
||||
|
||||
The max length of the output of this function can be controlled with the
|
||||
ps_thread_trx_info.max_length variable set via sys_config, or the
|
||||
@sys.ps_thread_trx_info.max_length user variable, as appropriate.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_thread_id (BIGINT UNSIGNED):
|
||||
The id of the thread to return the transaction info for.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
SELECT sys.ps_thread_trx_info(48)\\G
|
||||
*************************** 1. row ***************************
|
||||
sys.ps_thread_trx_info(48): [
|
||||
{
|
||||
"time": "790.70 us",
|
||||
"state": "COMMITTED",
|
||||
"mode": "READ WRITE",
|
||||
"autocommitted": "NO",
|
||||
"gtid": "AUTOMATIC",
|
||||
"isolation": "REPEATABLE READ",
|
||||
"statements_executed": [
|
||||
{
|
||||
"sql_text": "INSERT INTO info VALUES (1, \'foo\')",
|
||||
"time": "471.02 us",
|
||||
"schema": "trx",
|
||||
"rows_examined": 0,
|
||||
"rows_affected": 1,
|
||||
"rows_sent": 0,
|
||||
"tmp_tables": 0,
|
||||
"tmp_disk_tables": 0,
|
||||
"sort_rows": 0,
|
||||
"sort_merge_passes": 0
|
||||
},
|
||||
{
|
||||
"sql_text": "COMMIT",
|
||||
"time": "254.42 us",
|
||||
"schema": "trx",
|
||||
"rows_examined": 0,
|
||||
"rows_affected": 0,
|
||||
"rows_sent": 0,
|
||||
"tmp_tables": 0,
|
||||
"tmp_disk_tables": 0,
|
||||
"sort_rows": 0,
|
||||
"sort_merge_passes": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"time": "426.20 us",
|
||||
"state": "COMMITTED",
|
||||
"mode": "READ WRITE",
|
||||
"autocommitted": "NO",
|
||||
"gtid": "AUTOMATIC",
|
||||
"isolation": "REPEATABLE READ",
|
||||
"statements_executed": [
|
||||
{
|
||||
"sql_text": "INSERT INTO info VALUES (2, \'bar\')",
|
||||
"time": "107.33 us",
|
||||
"schema": "trx",
|
||||
"rows_examined": 0,
|
||||
"rows_affected": 1,
|
||||
"rows_sent": 0,
|
||||
"tmp_tables": 0,
|
||||
"tmp_disk_tables": 0,
|
||||
"sort_rows": 0,
|
||||
"sort_merge_passes": 0
|
||||
},
|
||||
{
|
||||
"sql_text": "COMMIT",
|
||||
"time": "213.23 us",
|
||||
"schema": "trx",
|
||||
"rows_examined": 0,
|
||||
"rows_affected": 0,
|
||||
"rows_sent": 0,
|
||||
"tmp_tables": 0,
|
||||
"tmp_disk_tables": 0,
|
||||
"sort_rows": 0,
|
||||
"sort_merge_passes": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
1 row in set (0.03 sec)
|
||||
'
|
||||
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_output LONGTEXT DEFAULT '{}';
|
||||
DECLARE v_msg_text TEXT DEFAULT '';
|
||||
DECLARE v_signal_msg TEXT DEFAULT '';
|
||||
DECLARE v_mysql_errno INT;
|
||||
DECLARE v_max_output_len BIGINT;
|
||||
-- Capture warnings/errors such as group_concat truncation
|
||||
-- and report as JSON error objects
|
||||
DECLARE EXIT HANDLER FOR SQLWARNING, SQLEXCEPTION
|
||||
BEGIN
|
||||
GET DIAGNOSTICS CONDITION 1
|
||||
v_msg_text = MESSAGE_TEXT,
|
||||
v_mysql_errno = MYSQL_ERRNO;
|
||||
|
||||
IF v_mysql_errno = 1260 THEN
|
||||
SET v_signal_msg = CONCAT('{ "error": "Trx info truncated: ', v_msg_text, '" }');
|
||||
ELSE
|
||||
SET v_signal_msg = CONCAT('{ "error": "', v_msg_text, '" }');
|
||||
END IF;
|
||||
|
||||
RETURN v_signal_msg;
|
||||
END;
|
||||
|
||||
-- Set configuration options
|
||||
IF (@sys.ps_thread_trx_info.max_length IS NULL) THEN
|
||||
SET @sys.ps_thread_trx_info.max_length = sys.sys_get_config('ps_thread_trx_info.max_length', 65535);
|
||||
END IF;
|
||||
|
||||
IF (@sys.ps_thread_trx_info.max_length != @@session.group_concat_max_len) THEN
|
||||
SET @old_group_concat_max_len = @@session.group_concat_max_len;
|
||||
-- Convert to int value for the SET, and give some surrounding space
|
||||
SET v_max_output_len = (@sys.ps_thread_trx_info.max_length - 5);
|
||||
SET SESSION group_concat_max_len = v_max_output_len;
|
||||
END IF;
|
||||
|
||||
SET v_output = (
|
||||
SELECT CONCAT('[', IFNULL(GROUP_CONCAT(trx_info ORDER BY event_id), ''), '\n]') AS trx_info
|
||||
FROM (SELECT trxi.thread_id,
|
||||
trxi.event_id,
|
||||
GROUP_CONCAT(
|
||||
IFNULL(
|
||||
CONCAT('\n {\n',
|
||||
' "time": "', IFNULL(sys.format_time(trxi.timer_wait), ''), '",\n',
|
||||
' "state": "', IFNULL(trxi.state, ''), '",\n',
|
||||
' "mode": "', IFNULL(trxi.access_mode, ''), '",\n',
|
||||
' "autocommitted": "', IFNULL(trxi.autocommit, ''), '",\n',
|
||||
' "gtid": "', IFNULL(trxi.gtid, ''), '",\n',
|
||||
' "isolation": "', IFNULL(trxi.isolation_level, ''), '",\n',
|
||||
' "statements_executed": [', IFNULL(s.stmts, ''), IF(s.stmts IS NULL, ' ]\n', '\n ]\n'),
|
||||
' }'
|
||||
),
|
||||
'')
|
||||
ORDER BY event_id) AS trx_info
|
||||
|
||||
FROM (
|
||||
(SELECT thread_id, event_id, timer_wait, state,access_mode, autocommit, gtid, isolation_level
|
||||
FROM performance_schema.events_transactions_current
|
||||
WHERE thread_id = in_thread_id
|
||||
AND end_event_id IS NULL)
|
||||
UNION
|
||||
(SELECT thread_id, event_id, timer_wait, state,access_mode, autocommit, gtid, isolation_level
|
||||
FROM performance_schema.events_transactions_history
|
||||
WHERE thread_id = in_thread_id)
|
||||
) AS trxi
|
||||
LEFT JOIN (SELECT thread_id,
|
||||
nesting_event_id,
|
||||
GROUP_CONCAT(
|
||||
IFNULL(
|
||||
CONCAT('\n {\n',
|
||||
' "sql_text": "', IFNULL(sys.format_statement(REPLACE(sql_text, '\\', '\\\\')), ''), '",\n',
|
||||
' "time": "', IFNULL(sys.format_time(timer_wait), ''), '",\n',
|
||||
' "schema": "', IFNULL(current_schema, ''), '",\n',
|
||||
' "rows_examined": ', IFNULL(rows_examined, ''), ',\n',
|
||||
' "rows_affected": ', IFNULL(rows_affected, ''), ',\n',
|
||||
' "rows_sent": ', IFNULL(rows_sent, ''), ',\n',
|
||||
' "tmp_tables": ', IFNULL(created_tmp_tables, ''), ',\n',
|
||||
' "tmp_disk_tables": ', IFNULL(created_tmp_disk_tables, ''), ',\n',
|
||||
' "sort_rows": ', IFNULL(sort_rows, ''), ',\n',
|
||||
' "sort_merge_passes": ', IFNULL(sort_merge_passes, ''), '\n',
|
||||
' }'), '') ORDER BY event_id) AS stmts
|
||||
FROM performance_schema.events_statements_history
|
||||
WHERE sql_text IS NOT NULL
|
||||
AND thread_id = in_thread_id
|
||||
GROUP BY thread_id, nesting_event_id
|
||||
) AS s
|
||||
ON trxi.thread_id = s.thread_id
|
||||
AND trxi.event_id = s.nesting_event_id
|
||||
WHERE trxi.thread_id = in_thread_id
|
||||
GROUP BY trxi.thread_id, trxi.event_id
|
||||
) trxs
|
||||
GROUP BY thread_id
|
||||
);
|
||||
|
||||
IF (@old_group_concat_max_len IS NOT NULL) THEN
|
||||
SET SESSION group_concat_max_len = @old_group_concat_max_len;
|
||||
END IF;
|
||||
|
||||
RETURN v_output;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
71
scripts/sys_schema/functions/quote_identifier.sql
Normal file
71
scripts/sys_schema/functions/quote_identifier.sql
Normal file
@ -0,0 +1,71 @@
|
||||
-- Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS quote_identifier;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
-- https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
|
||||
-- Maximum supported length for any of the current identifiers in 5.7.5+ is 256 characters.
|
||||
-- Before that, user variables could have any length.
|
||||
--
|
||||
-- Based on Paul Dubois' suggestion in Bug #78823/Bug #22011361.
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION quote_identifier(in_identifier TEXT)
|
||||
RETURNS TEXT CHARSET UTF8
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes an unquoted identifier (schema name, table name, etc.) and
|
||||
returns the identifier quoted with backticks.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_identifier (TEXT):
|
||||
The identifier to quote.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TEXT
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT sys.quote_identifier(''my_identifier'') AS Identifier;
|
||||
+-----------------+
|
||||
| Identifier |
|
||||
+-----------------+
|
||||
| `my_identifier` |
|
||||
+-----------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> SELECT sys.quote_identifier(''my`idenfier'') AS Identifier;
|
||||
+----------------+
|
||||
| Identifier |
|
||||
+----------------+
|
||||
| `my``idenfier` |
|
||||
+----------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
RETURN CONCAT('`', REPLACE(in_identifier, '`', '``'), '`');
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
98
scripts/sys_schema/functions/sys_get_config.sql
Normal file
98
scripts/sys_schema/functions/sys_get_config.sql
Normal file
@ -0,0 +1,98 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS sys_get_config;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION sys_get_config (
|
||||
in_variable_name VARCHAR(128),
|
||||
in_default_value VARCHAR(128)
|
||||
)
|
||||
RETURNS VARCHAR(128)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Returns the value for the requested variable using the following logic:
|
||||
|
||||
1. If the option exists in sys.sys_config return the value from there.
|
||||
2. Else fall back on the provided default value.
|
||||
|
||||
Notes for using sys_get_config():
|
||||
|
||||
* If the default value argument to sys_get_config() is NULL and case 2. is reached, NULL is returned.
|
||||
It is then expected that the caller is able to handle NULL for the given configuration option.
|
||||
* The convention is to name the user variables @sys.<name of variable>. It is <name of variable> that
|
||||
is stored in the sys_config table and is what is expected as the argument to sys_get_config().
|
||||
* If you want to check whether the configuration option has already been set and if not assign with
|
||||
the return value of sys_get_config() you can use IFNULL(...) (see example below). However this should
|
||||
not be done inside a loop (e.g. for each row in a result set) as for repeated calls where assignment
|
||||
is only needed in the first iteration using IFNULL(...) is expected to be significantly slower than
|
||||
using an IF (...) THEN ... END IF; block (see example below).
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_variable_name (VARCHAR(128)):
|
||||
The name of the config option to return the value for.
|
||||
|
||||
in_default_value (VARCHAR(128)):
|
||||
The default value to return if the variable does not exist in sys.sys_config.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
VARCHAR(128)
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
-- Get the configuration value from sys.sys_config falling back on 128 if the option is not present in the table.
|
||||
mysql> SELECT sys.sys_get_config(''statement_truncate_len'', 128) AS Value;
|
||||
+-------+
|
||||
| Value |
|
||||
+-------+
|
||||
| 64 |
|
||||
+-------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
-- Check whether the option is already set, if not assign - IFNULL(...) one liner example.
|
||||
mysql> SET @sys.statement_truncate_len = IFNULL(@sys.statement_truncate_len, sys.sys_get_config(''statement_truncate_len'', 64));
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
-- Check whether the option is already set, if not assign - IF ... THEN ... END IF example.
|
||||
IF (@sys.statement_truncate_len IS NULL) THEN
|
||||
SET @sys.statement_truncate_len = sys.sys_get_config(''statement_truncate_len'', 64);
|
||||
END IF;
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_value VARCHAR(128) DEFAULT NULL;
|
||||
|
||||
-- Check if we have the variable in the sys.sys_config table
|
||||
SET v_value = (SELECT value FROM sys.sys_config WHERE variable = in_variable_name);
|
||||
|
||||
-- Protection against the variable not existing in sys_config
|
||||
IF (v_value IS NULL) THEN
|
||||
SET v_value = in_default_value;
|
||||
END IF;
|
||||
|
||||
RETURN v_value;
|
||||
END $$
|
||||
|
||||
DELIMITER ;
|
51
scripts/sys_schema/functions/version_major.sql
Normal file
51
scripts/sys_schema/functions/version_major.sql
Normal file
@ -0,0 +1,51 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS version_major;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION version_major ()
|
||||
RETURNS TINYINT UNSIGNED
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Returns the major version of MySQL Server.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TINYINT UNSIGNED
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT VERSION(), sys.version_major();
|
||||
+--------------------------------------+---------------------+
|
||||
| VERSION() | sys.version_major() |
|
||||
+--------------------------------------+---------------------+
|
||||
| 5.7.9-enterprise-commercial-advanced | 5 |
|
||||
+--------------------------------------+---------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 1);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
51
scripts/sys_schema/functions/version_minor.sql
Normal file
51
scripts/sys_schema/functions/version_minor.sql
Normal file
@ -0,0 +1,51 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS version_minor;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION version_minor ()
|
||||
RETURNS TINYINT UNSIGNED
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Returns the minor (release series) version of MySQL Server.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TINYINT UNSIGNED
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT VERSION(), sys.server_minor();
|
||||
+--------------------------------------+---------------------+
|
||||
| VERSION() | sys.version_minor() |
|
||||
+--------------------------------------+---------------------+
|
||||
| 5.7.9-enterprise-commercial-advanced | 7 |
|
||||
+--------------------------------------+---------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 2), '.', -1);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
51
scripts/sys_schema/functions/version_patch.sql
Normal file
51
scripts/sys_schema/functions/version_patch.sql
Normal file
@ -0,0 +1,51 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS version_patch;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION version_patch ()
|
||||
RETURNS TINYINT UNSIGNED
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Returns the patch release version of MySQL Server.
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
TINYINT UNSIGNED
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SELECT VERSION(), sys.version_patch();
|
||||
+--------------------------------------+---------------------+
|
||||
| VERSION() | sys.version_patch() |
|
||||
+--------------------------------------+---------------------+
|
||||
| 5.7.9-enterprise-commercial-advanced | 9 |
|
||||
+--------------------------------------+---------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', -1);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
239
scripts/sys_schema/generate_sql_file.sh
Normal file
239
scripts/sys_schema/generate_sql_file.sh
Normal file
@ -0,0 +1,239 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
OS=`uname`
|
||||
SYSDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
GENDIR=$SYSDIR/gen
|
||||
PWD=$( pwd )
|
||||
|
||||
# Grab the current sys version
|
||||
SYSVERSIONTMP=`cat views/version.sql | grep 'AS sys_version' | awk '{print $2}'`
|
||||
SYSVERSION=`echo "${SYSVERSIONTMP//\'}"`
|
||||
|
||||
MYSQLUSER="'root'@'localhost'"
|
||||
|
||||
if [ $OS == "Darwin" ] ;
|
||||
then
|
||||
SED_R="sed -E"
|
||||
else
|
||||
SED_R="sed -r"
|
||||
fi
|
||||
|
||||
USAGE="
|
||||
Options:
|
||||
================
|
||||
|
||||
v: The version of MySQL to build the sys schema for, either '56' or '57'
|
||||
|
||||
b: Whether to omit any lines that deal with sql_log_bin (useful for RDS)
|
||||
|
||||
m: Whether to generate a mysql_install_db / mysqld --initialize formatted file
|
||||
|
||||
u: The user to set as the owner of the objects (useful for RDS)
|
||||
|
||||
Examples:
|
||||
================
|
||||
|
||||
Generate a MySQL 5.7 SQL file that uses the 'mark'@'localhost' user:
|
||||
|
||||
$0 -v 57 -u \"'mark'@'localhost'\"
|
||||
|
||||
Generate a MySQL 5.6 SQL file for RDS:
|
||||
|
||||
$0 -v 56 -b -u CURRENT_USER
|
||||
|
||||
Generate a MySQL 5.7 initialize / bootstrap file:
|
||||
|
||||
$0 -v 57 -m
|
||||
"
|
||||
|
||||
# Grab options
|
||||
while getopts ":v:bhmu:" opt; do
|
||||
case $opt in
|
||||
b)
|
||||
SKIPBINLOG=true
|
||||
;;
|
||||
h)
|
||||
echo $"$USAGE"
|
||||
exit 0
|
||||
;;
|
||||
m)
|
||||
MYSQLCOMPAT=true
|
||||
# Bundled mysql expects the mysql.sys user to be used
|
||||
MYSQLUSER="'mysql.sys'@'localhost'"
|
||||
;;
|
||||
u)
|
||||
if [ -z "$MYSQLCOMPAT" ] ;
|
||||
then
|
||||
MYSQLUSER="${OPTARG}"
|
||||
fi
|
||||
;;
|
||||
v)
|
||||
if [ $OPTARG == "56" ] || [ $OPTARG == "57" ] ;
|
||||
then
|
||||
MYSQLVERSION=$OPTARG
|
||||
else
|
||||
echo "Invalid -v option, please run again with either '-v 56' or '-v 57'"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
echo $"$USAGE"
|
||||
exit 1
|
||||
;;
|
||||
:)
|
||||
echo "Option -$OPTARG requires an argument." >&2
|
||||
echo $"$USAGE"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check required options
|
||||
if [[ -z "$MYSQLVERSION" ]] ;
|
||||
then
|
||||
echo " -v (MySQL Version) parameter required, please run again with either '-v 56' or '-v 57'"
|
||||
echo $"$USAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create the gen directory
|
||||
if [[ ! -d $GENDIR ]] ;
|
||||
then
|
||||
mkdir $GENDIR
|
||||
fi
|
||||
|
||||
# Create output file name
|
||||
if [[ ! -z "$MYSQLCOMPAT" ]] ;
|
||||
then
|
||||
OUTPUTFILE="mysql_sys_schema.sql"
|
||||
else
|
||||
OUTPUTFILE="sys_${SYSVERSION}_${MYSQLVERSION}_inline.sql"
|
||||
fi
|
||||
|
||||
# Create the initial output file
|
||||
if [[ ! -z "$MYSQLCOMPAT" ]] ;
|
||||
then
|
||||
# Pre-process all the files in a copied temp directory
|
||||
if [[ ! -d $GENDIR/tmpgen ]] ;
|
||||
then
|
||||
mkdir $GENDIR/tmpgen
|
||||
fi
|
||||
cd $GENDIR/tmpgen
|
||||
rm -rf *
|
||||
cp -r $SYSDIR/after_setup.sql $SYSDIR/tables $SYSDIR/triggers $SYSDIR/functions $SYSDIR/views $SYSDIR/procedures .
|
||||
|
||||
# Switch user if requested
|
||||
# Remove individual copyrights
|
||||
# Replace newlines in COMMENTs with literal \n
|
||||
# Drop added trailing \n <sad panda>
|
||||
# Remove DELIMITER commands
|
||||
# Replace $$ delimiter with ;
|
||||
# Remove leading spaces
|
||||
# Remove -- line comments *after removing leading spaces*
|
||||
for file in `find . -name '*.sql'`; do
|
||||
# The 5.6 MEM/WB integration should still use the root@localhost user
|
||||
if [ ! $MYSQLVERSION == "56" ] ;
|
||||
then
|
||||
sed -i -e "s/'root'@'localhost'/$MYSQLUSER/g" $file
|
||||
fi
|
||||
sed -i -e "/Copyright/,/51 Franklin St/d" $file
|
||||
sed -i -e "/^ *COMMENT/,/^ *'/{G;s/\n/\\\n/g;}" $file
|
||||
sed -i -e "s/ '\\\n/ '/g" $file
|
||||
sed -i -e "/^DELIMITER/d" $file
|
||||
sed -i -e "s/\\$\\$/;/g" $file
|
||||
sed -i -e "s/^ *//g" $file
|
||||
sed -i -e "/^--/d" $file
|
||||
done
|
||||
|
||||
# Start the output file from a non-removed copyright file
|
||||
sed -e "s/^/-- /" $SYSDIR/LICENSE > $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
echo "--" >> $OUTPUTFILE
|
||||
echo "-- WARNING: THIS IS A GENERATED FILE, CHANGES NEED TO BE MADE ON THE UPSTREAM MYSQL-SYS REPOSITORY AS WELL" >> $OUTPUTFILE
|
||||
echo "-- PLEASE SUBMIT A PULL REQUEST TO https://github.com/mysql/mysql-sys" >> $OUTPUTFILE
|
||||
echo "--" >> $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
|
||||
# Add the expected user
|
||||
# Note this currently only works with 5.7 mysql.user structure
|
||||
if [ ! $MYSQLVERSION == "56" ] ;
|
||||
then
|
||||
echo "REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',CURRENT_TIMESTAMP,NULL,'Y');" >> $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
echo "REPLACE INTO mysql.db VALUES ('localhost','sys','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y');" >> $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
echo "REPLACE INTO mysql.tables_priv VALUES ('localhost','sys','mysql.sys','sys_config','root@localhost', CURRENT_TIMESTAMP, 'Select', '');" >> $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
echo "FLUSH PRIVILEGES;" >> $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
fi
|
||||
|
||||
# Put in the contents of before_setup.sql, though don't collapse lines
|
||||
sed -e "/sql_log_bin/d;s/'root'@'localhost'/$MYSQLUSER/g;/Copyright/,/51 Franklin St/d" $SYSDIR/before_setup.sql >> $OUTPUTFILE
|
||||
|
||||
# Add the rest of the files in install file order, removing new lines along the way
|
||||
cat "$SYSDIR/sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | grep -v before_setup | grep -v after_setup | $SED_R 's .{8} ' | sed 's/^/./' > "./sys_$MYSQLVERSION.sql"
|
||||
while read file; do
|
||||
# First try and get a DROP command
|
||||
grep -E '(^DROP PROCEDURE|^DROP FUNCTION|^DROP TRIGGER)' $file >> $OUTPUTFILE
|
||||
# And remove any that may exist (but keep DROP TEMPORARY TABLE)
|
||||
sed -i -e "/^DROP PROCEDURE/d;/^DROP FUNCTION/d;/^DROP TRIGGER/d" $file
|
||||
echo "" >> $OUTPUTFILE
|
||||
# Then collapse the rest of the file
|
||||
cat $file | tr '\n' ' ' >> $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
echo "" >> $OUTPUTFILE
|
||||
done < "./sys_$MYSQLVERSION.sql"
|
||||
|
||||
# Does essentially nothing right now, but may in future
|
||||
sed -e "/Copyright/,/51 Franklin St/d;/sql_log_bin/d" $SYSDIR/after_setup.sql >> $OUTPUTFILE
|
||||
|
||||
# Remove final leading and trailing spaces
|
||||
sed -i '' -e "s/^ *//g" $OUTPUTFILE
|
||||
sed -i '' -e "s/[ \t]*$//g" $OUTPUTFILE
|
||||
# Remove more than one empty line
|
||||
sed -i '' -e "/^$/N;/^\n$/D" $OUTPUTFILE
|
||||
|
||||
mv $OUTPUTFILE $GENDIR/
|
||||
cd $GENDIR/
|
||||
rm -rf $GENDIR/tmpgen
|
||||
else
|
||||
sed -e "s/^/-- /" $SYSDIR/LICENSE > $GENDIR/$OUTPUTFILE
|
||||
cat "$SYSDIR/sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | $SED_R 's .{8} ' | sed "s/^/$(echo $SYSDIR | sed -e 's/[]\/$*.^|[]/\\&/g')/g" \
|
||||
| xargs sed -e "/Copyright/,/51 Franklin St/d;s/'root'@'localhost'/$MYSQLUSER/g" >> $GENDIR/$OUTPUTFILE
|
||||
fi
|
||||
|
||||
# Check if sql_log_bin lines should be removed
|
||||
if [[ ! -z "$SKIPBINLOG" ]] ;
|
||||
then
|
||||
LOGWARNING="WARNING: Using a routine that could cause binary log events, but disabling of binary logging has been removed"
|
||||
sed -i '' -e "s/^[ \s]*SET sql_log_bin = 0/SELECT \"$LOGWARNING\"/g" $GENDIR/$OUTPUTFILE
|
||||
sed -i '' -e "s/\sSET sql_log_bin = @log_bin;/SET @log_bin = NULL;/g" $GENDIR/$OUTPUTFILE
|
||||
SKIPBINLOG="disabled"
|
||||
else
|
||||
SKIPBINLOG="enabled"
|
||||
fi
|
||||
|
||||
cd $PWD
|
||||
|
||||
# Print summary
|
||||
echo $"
|
||||
Wrote file: $GENDIR/$OUTPUTFILE
|
||||
Object Definer: $MYSQLUSER
|
||||
sql_log_bin: $SKIPBINLOG
|
||||
"
|
173
scripts/sys_schema/procedures/create_synonym_db.sql
Normal file
173
scripts/sys_schema/procedures/create_synonym_db.sql
Normal file
@ -0,0 +1,173 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS create_synonym_db;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE create_synonym_db (
|
||||
IN in_db_name VARCHAR(64),
|
||||
IN in_synonym VARCHAR(64)
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes a source database name and synonym name, and then creates the
|
||||
synonym database with views that point to all of the tables within
|
||||
the source database.
|
||||
|
||||
Useful for creating a "ps" synonym for "performance_schema",
|
||||
or "is" instead of "information_schema", for example.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_db_name (VARCHAR(64)):
|
||||
The database name that you would like to create a synonym for.
|
||||
in_synonym (VARCHAR(64)):
|
||||
The database synonym name.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> SHOW DATABASES;
|
||||
+--------------------+
|
||||
| Database |
|
||||
+--------------------+
|
||||
| information_schema |
|
||||
| mysql |
|
||||
| performance_schema |
|
||||
| sys |
|
||||
| test |
|
||||
+--------------------+
|
||||
5 rows in set (0.00 sec)
|
||||
|
||||
mysql> CALL sys.create_synonym_db(\'performance_schema\', \'ps\');
|
||||
+---------------------------------------+
|
||||
| summary |
|
||||
+---------------------------------------+
|
||||
| Created 74 views in the `ps` database |
|
||||
+---------------------------------------+
|
||||
1 row in set (8.57 sec)
|
||||
|
||||
Query OK, 0 rows affected (8.57 sec)
|
||||
|
||||
mysql> SHOW DATABASES;
|
||||
+--------------------+
|
||||
| Database |
|
||||
+--------------------+
|
||||
| information_schema |
|
||||
| mysql |
|
||||
| performance_schema |
|
||||
| ps |
|
||||
| sys |
|
||||
| test |
|
||||
+--------------------+
|
||||
6 rows in set (0.00 sec)
|
||||
|
||||
mysql> SHOW FULL TABLES FROM ps;
|
||||
+------------------------------------------------------+------------+
|
||||
| Tables_in_ps | Table_type |
|
||||
+------------------------------------------------------+------------+
|
||||
| accounts | VIEW |
|
||||
| cond_instances | VIEW |
|
||||
| events_stages_current | VIEW |
|
||||
| events_stages_history | VIEW |
|
||||
...
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_done bool DEFAULT FALSE;
|
||||
DECLARE v_db_name_check VARCHAR(64);
|
||||
DECLARE v_db_err_msg TEXT;
|
||||
DECLARE v_table VARCHAR(64);
|
||||
DECLARE v_views_created INT DEFAULT 0;
|
||||
|
||||
DECLARE db_doesnt_exist CONDITION FOR SQLSTATE '42000';
|
||||
DECLARE db_name_exists CONDITION FOR SQLSTATE 'HY000';
|
||||
|
||||
DECLARE c_table_names CURSOR FOR
|
||||
SELECT TABLE_NAME
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = in_db_name;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
|
||||
|
||||
-- Check if the source database exists
|
||||
SELECT SCHEMA_NAME INTO v_db_name_check
|
||||
FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = in_db_name;
|
||||
|
||||
IF v_db_name_check IS NULL THEN
|
||||
SET v_db_err_msg = CONCAT('Unknown database ', in_db_name);
|
||||
SIGNAL SQLSTATE 'HY000'
|
||||
SET MESSAGE_TEXT = v_db_err_msg;
|
||||
END IF;
|
||||
|
||||
-- Check if a database of the synonym name already exists
|
||||
SELECT SCHEMA_NAME INTO v_db_name_check
|
||||
FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = in_synonym;
|
||||
|
||||
IF v_db_name_check = in_synonym THEN
|
||||
SET v_db_err_msg = CONCAT('Can\'t create database ', in_synonym, '; database exists');
|
||||
SIGNAL SQLSTATE 'HY000'
|
||||
SET MESSAGE_TEXT = v_db_err_msg;
|
||||
END IF;
|
||||
|
||||
-- All good, create the database and views
|
||||
SET @create_db_stmt := CONCAT('CREATE DATABASE ', sys.quote_identifier(in_synonym));
|
||||
PREPARE create_db_stmt FROM @create_db_stmt;
|
||||
EXECUTE create_db_stmt;
|
||||
DEALLOCATE PREPARE create_db_stmt;
|
||||
|
||||
SET v_done = FALSE;
|
||||
OPEN c_table_names;
|
||||
c_table_names: LOOP
|
||||
FETCH c_table_names INTO v_table;
|
||||
IF v_done THEN
|
||||
LEAVE c_table_names;
|
||||
END IF;
|
||||
|
||||
SET @create_view_stmt = CONCAT(
|
||||
'CREATE SQL SECURITY INVOKER VIEW ',
|
||||
sys.quote_identifier(in_synonym),
|
||||
'.',
|
||||
sys.quote_identifier(v_table),
|
||||
' AS SELECT * FROM ',
|
||||
sys.quote_identifier(in_db_name),
|
||||
'.',
|
||||
sys.quote_identifier(v_table)
|
||||
);
|
||||
PREPARE create_view_stmt FROM @create_view_stmt;
|
||||
EXECUTE create_view_stmt;
|
||||
DEALLOCATE PREPARE create_view_stmt;
|
||||
|
||||
SET v_views_created = v_views_created + 1;
|
||||
END LOOP;
|
||||
CLOSE c_table_names;
|
||||
|
||||
SELECT CONCAT(
|
||||
'Created ', v_views_created, ' view',
|
||||
IF(v_views_created != 1, 's', ''), ' in the ',
|
||||
sys.quote_identifier(in_synonym), ' database'
|
||||
) AS summary;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
1118
scripts/sys_schema/procedures/diagnostics.sql
Normal file
1118
scripts/sys_schema/procedures/diagnostics.sql
Normal file
File diff suppressed because it is too large
Load Diff
89
scripts/sys_schema/procedures/execute_prepared_stmt.sql
Normal file
89
scripts/sys_schema/procedures/execute_prepared_stmt.sql
Normal file
@ -0,0 +1,89 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS execute_prepared_stmt;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE execute_prepared_stmt (
|
||||
IN in_query longtext CHARACTER SET UTF8
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Takes the query in the argument and executes it using a prepared statement. The prepared statement is deallocated,
|
||||
so the procedure is mainly useful for executing one off dynamically created queries.
|
||||
|
||||
The sys_execute_prepared_stmt prepared statement name is used for the query and is required not to exist.
|
||||
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_query (longtext CHARACTER SET UTF8):
|
||||
The query to execute.
|
||||
|
||||
|
||||
Configuration Options
|
||||
----------------------
|
||||
|
||||
sys.debug
|
||||
Whether to provide debugging output.
|
||||
Default is ''OFF''. Set to ''ON'' to include.
|
||||
|
||||
|
||||
Example
|
||||
--------
|
||||
|
||||
mysql> CALL sys.execute_prepared_stmt(''SELECT * FROM sys.sys_config'');
|
||||
+------------------------+-------+---------------------+--------+
|
||||
| variable | value | set_time | set_by |
|
||||
+------------------------+-------+---------------------+--------+
|
||||
| statement_truncate_len | 64 | 2015-06-30 13:06:00 | NULL |
|
||||
+------------------------+-------+---------------------+--------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
-- Set configuration options
|
||||
IF (@sys.debug IS NULL) THEN
|
||||
SET @sys.debug = sys.sys_get_config('debug', 'OFF');
|
||||
END IF;
|
||||
|
||||
-- Verify the query exists
|
||||
-- The shortest possible query is "DO 1"
|
||||
IF (in_query IS NULL OR LENGTH(in_query) < 4) THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = "The @sys.execute_prepared_stmt.sql must contain a query";
|
||||
END IF;
|
||||
|
||||
SET @sys.execute_prepared_stmt.sql = in_query;
|
||||
|
||||
IF (@sys.debug = 'ON') THEN
|
||||
SELECT @sys.execute_prepared_stmt.sql AS 'Debug';
|
||||
END IF;
|
||||
PREPARE sys_execute_prepared_stmt FROM @sys.execute_prepared_stmt.sql;
|
||||
EXECUTE sys_execute_prepared_stmt;
|
||||
DEALLOCATE PREPARE sys_execute_prepared_stmt;
|
||||
|
||||
SET @sys.execute_prepared_stmt.sql = NULL;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,54 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_disable_background_threads;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_background_threads ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Disable all background thread instrumentation within Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_background_threads();
|
||||
+--------------------------------+
|
||||
| summary |
|
||||
+--------------------------------+
|
||||
| Disabled 18 background threads |
|
||||
+--------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.threads
|
||||
SET instrumented = 'NO'
|
||||
WHERE type = 'BACKGROUND';
|
||||
|
||||
SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' background thread', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
70
scripts/sys_schema/procedures/ps_setup_disable_consumer.sql
Normal file
70
scripts/sys_schema/procedures/ps_setup_disable_consumer.sql
Normal file
@ -0,0 +1,70 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_disable_consumer;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_consumer (
|
||||
IN consumer VARCHAR(128)
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Disables consumers within Performance Schema
|
||||
matching the input pattern.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
consumer (VARCHAR(128)):
|
||||
A LIKE pattern match (using "%consumer%") of consumers to disable
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
To disable all consumers:
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_consumer(\'\');
|
||||
+--------------------------+
|
||||
| summary |
|
||||
+--------------------------+
|
||||
| Disabled 15 consumers |
|
||||
+--------------------------+
|
||||
1 row in set (0.02 sec)
|
||||
|
||||
To disable just the event_stage consumers:
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_comsumers(\'stage\');
|
||||
+------------------------+
|
||||
| summary |
|
||||
+------------------------+
|
||||
| Disabled 3 consumers |
|
||||
+------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.setup_consumers
|
||||
SET enabled = 'NO'
|
||||
WHERE name LIKE CONCAT('%', consumer, '%');
|
||||
|
||||
SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' consumer', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,80 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_disable_instrument;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_instrument (
|
||||
IN in_pattern VARCHAR(128)
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Disables instruments within Performance Schema
|
||||
matching the input pattern.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_pattern (VARCHAR(128)):
|
||||
A LIKE pattern match (using "%in_pattern%") of events to disable
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
To disable all mutex instruments:
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_instrument(\'wait/synch/mutex\');
|
||||
+--------------------------+
|
||||
| summary |
|
||||
+--------------------------+
|
||||
| Disabled 155 instruments |
|
||||
+--------------------------+
|
||||
1 row in set (0.02 sec)
|
||||
|
||||
To disable just a specific TCP/IP based network IO instrument:
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_instrument(\'wait/io/socket/sql/server_tcpip_socket\');
|
||||
+------------------------+
|
||||
| summary |
|
||||
+------------------------+
|
||||
| Disabled 1 instruments |
|
||||
+------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
To disable all instruments:
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_instrument(\'\');
|
||||
+--------------------------+
|
||||
| summary |
|
||||
+--------------------------+
|
||||
| Disabled 547 instruments |
|
||||
+--------------------------+
|
||||
1 row in set (0.01 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.setup_instruments
|
||||
SET enabled = 'NO', timed = 'NO'
|
||||
WHERE name LIKE CONCAT('%', in_pattern, '%');
|
||||
|
||||
SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' instrument', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
68
scripts/sys_schema/procedures/ps_setup_disable_thread.sql
Normal file
68
scripts/sys_schema/procedures/ps_setup_disable_thread.sql
Normal file
@ -0,0 +1,68 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_disable_thread;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_thread (
|
||||
IN in_connection_id BIGINT
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Disable the given connection/thread in Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_connection_id (BIGINT):
|
||||
The connection ID (PROCESSLIST_ID from performance_schema.threads
|
||||
or the ID shown within SHOW PROCESSLIST)
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_thread(3);
|
||||
+-------------------+
|
||||
| summary |
|
||||
+-------------------+
|
||||
| Disabled 1 thread |
|
||||
+-------------------+
|
||||
1 row in set (0.01 sec)
|
||||
|
||||
To disable the current connection:
|
||||
|
||||
mysql> CALL sys.ps_setup_disable_thread(CONNECTION_ID());
|
||||
+-------------------+
|
||||
| summary |
|
||||
+-------------------+
|
||||
| Disabled 1 thread |
|
||||
+-------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.threads
|
||||
SET instrumented = 'NO'
|
||||
WHERE processlist_id = in_connection_id;
|
||||
|
||||
SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' thread', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,54 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_enable_background_threads;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_background_threads ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Enable all background thread instrumentation within Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_background_threads();
|
||||
+-------------------------------+
|
||||
| summary |
|
||||
+-------------------------------+
|
||||
| Enabled 18 background threads |
|
||||
+-------------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.threads
|
||||
SET instrumented = 'YES'
|
||||
WHERE type = 'BACKGROUND';
|
||||
|
||||
SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' background thread', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
74
scripts/sys_schema/procedures/ps_setup_enable_consumer.sql
Normal file
74
scripts/sys_schema/procedures/ps_setup_enable_consumer.sql
Normal file
@ -0,0 +1,74 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_enable_consumer;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_consumer (
|
||||
IN consumer VARCHAR(128)
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Enables consumers within Performance Schema
|
||||
matching the input pattern.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
consumer (VARCHAR(128)):
|
||||
A LIKE pattern match (using "%consumer%") of consumers to enable
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
To enable all consumers:
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_consumer(\'\');
|
||||
+-------------------------+
|
||||
| summary |
|
||||
+-------------------------+
|
||||
| Enabled 10 consumers |
|
||||
+-------------------------+
|
||||
1 row in set (0.02 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.02 sec)
|
||||
|
||||
To enable just "waits" consumers:
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_consumer(\'waits\');
|
||||
+-----------------------+
|
||||
| summary |
|
||||
+-----------------------+
|
||||
| Enabled 3 consumers |
|
||||
+-----------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.setup_consumers
|
||||
SET enabled = 'YES'
|
||||
WHERE name LIKE CONCAT('%', consumer, '%');
|
||||
|
||||
SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' consumer', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
86
scripts/sys_schema/procedures/ps_setup_enable_instrument.sql
Normal file
86
scripts/sys_schema/procedures/ps_setup_enable_instrument.sql
Normal file
@ -0,0 +1,86 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_enable_instrument;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_instrument (
|
||||
IN in_pattern VARCHAR(128)
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Enables instruments within Performance Schema
|
||||
matching the input pattern.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_pattern (VARCHAR(128)):
|
||||
A LIKE pattern match (using "%in_pattern%") of events to enable
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
To enable all mutex instruments:
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_instrument(\'wait/synch/mutex\');
|
||||
+-------------------------+
|
||||
| summary |
|
||||
+-------------------------+
|
||||
| Enabled 155 instruments |
|
||||
+-------------------------+
|
||||
1 row in set (0.02 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.02 sec)
|
||||
|
||||
To enable just a specific TCP/IP based network IO instrument:
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_instrument(\'wait/io/socket/sql/server_tcpip_socket\');
|
||||
+-----------------------+
|
||||
| summary |
|
||||
+-----------------------+
|
||||
| Enabled 1 instruments |
|
||||
+-----------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
To enable all instruments:
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_instrument(\'\');
|
||||
+-------------------------+
|
||||
| summary |
|
||||
+-------------------------+
|
||||
| Enabled 547 instruments |
|
||||
+-------------------------+
|
||||
1 row in set (0.01 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.01 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.setup_instruments
|
||||
SET enabled = 'YES', timed = 'YES'
|
||||
WHERE name LIKE CONCAT('%', in_pattern, '%');
|
||||
|
||||
SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' instrument', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
68
scripts/sys_schema/procedures/ps_setup_enable_thread.sql
Normal file
68
scripts/sys_schema/procedures/ps_setup_enable_thread.sql
Normal file
@ -0,0 +1,68 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_enable_thread;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_thread (
|
||||
IN in_connection_id BIGINT
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Enable the given connection/thread in Performance Schema.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_connection_id (BIGINT):
|
||||
The connection ID (PROCESSLIST_ID from performance_schema.threads
|
||||
or the ID shown within SHOW PROCESSLIST)
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_thread(3);
|
||||
+------------------+
|
||||
| summary |
|
||||
+------------------+
|
||||
| Enabled 1 thread |
|
||||
+------------------+
|
||||
1 row in set (0.01 sec)
|
||||
|
||||
To enable the current connection:
|
||||
|
||||
mysql> CALL sys.ps_setup_enable_thread(CONNECTION_ID());
|
||||
+------------------+
|
||||
| summary |
|
||||
+------------------+
|
||||
| Enabled 1 thread |
|
||||
+------------------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
UPDATE performance_schema.threads
|
||||
SET instrumented = 'YES'
|
||||
WHERE processlist_id = in_connection_id;
|
||||
|
||||
SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' thread', IF(@rows != 1, 's', '')) AS summary;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
146
scripts/sys_schema/procedures/ps_setup_reload_saved.sql
Normal file
146
scripts/sys_schema/procedures/ps_setup_reload_saved.sql
Normal file
@ -0,0 +1,146 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_reload_saved;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_reload_saved ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Reloads a saved Performance Schema configuration,
|
||||
so that you can alter the setup for debugging purposes,
|
||||
but restore it to a previous state.
|
||||
|
||||
Use the companion procedure - ps_setup_save(), to
|
||||
save a configuration.
|
||||
|
||||
Requires the SUPER privilege for "SET sql_log_bin = 0;".
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_save();
|
||||
Query OK, 0 rows affected (0.08 sec)
|
||||
|
||||
mysql> UPDATE performance_schema.setup_instruments SET enabled = \'YES\', timed = \'YES\';
|
||||
Query OK, 547 rows affected (0.40 sec)
|
||||
Rows matched: 784 Changed: 547 Warnings: 0
|
||||
|
||||
/* Run some tests that need more detailed instrumentation here */
|
||||
|
||||
mysql> CALL sys.ps_setup_reload_saved();
|
||||
Query OK, 0 rows affected (0.32 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_done bool DEFAULT FALSE;
|
||||
DECLARE v_lock_result INT;
|
||||
DECLARE v_lock_used_by BIGINT;
|
||||
DECLARE v_signal_message TEXT;
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
SIGNAL SQLSTATE VALUE '90001'
|
||||
SET MESSAGE_TEXT = 'An error occurred, was sys.ps_setup_save() run before this procedure?';
|
||||
END;
|
||||
|
||||
SET @log_bin := @@sql_log_bin;
|
||||
SET sql_log_bin = 0;
|
||||
|
||||
SELECT IS_USED_LOCK('sys.ps_setup_save') INTO v_lock_used_by;
|
||||
|
||||
IF (v_lock_used_by != CONNECTION_ID()) THEN
|
||||
SET v_signal_message = CONCAT('The sys.ps_setup_save lock is currently owned by ', v_lock_used_by);
|
||||
SIGNAL SQLSTATE VALUE '90002'
|
||||
SET MESSAGE_TEXT = v_signal_message;
|
||||
END IF;
|
||||
|
||||
DELETE FROM performance_schema.setup_actors;
|
||||
INSERT INTO performance_schema.setup_actors SELECT * FROM tmp_setup_actors;
|
||||
|
||||
BEGIN
|
||||
-- Workaround for http://bugs.mysql.com/bug.php?id=70025
|
||||
DECLARE v_name varchar(64);
|
||||
DECLARE v_enabled enum('YES', 'NO');
|
||||
DECLARE c_consumers CURSOR FOR SELECT NAME, ENABLED FROM tmp_setup_consumers;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
|
||||
|
||||
SET v_done = FALSE;
|
||||
OPEN c_consumers;
|
||||
c_consumers_loop: LOOP
|
||||
FETCH c_consumers INTO v_name, v_enabled;
|
||||
IF v_done THEN
|
||||
LEAVE c_consumers_loop;
|
||||
END IF;
|
||||
|
||||
UPDATE performance_schema.setup_consumers
|
||||
SET ENABLED = v_enabled
|
||||
WHERE NAME = v_name;
|
||||
END LOOP;
|
||||
CLOSE c_consumers;
|
||||
END;
|
||||
|
||||
UPDATE performance_schema.setup_instruments
|
||||
INNER JOIN tmp_setup_instruments USING (NAME)
|
||||
SET performance_schema.setup_instruments.ENABLED = tmp_setup_instruments.ENABLED,
|
||||
performance_schema.setup_instruments.TIMED = tmp_setup_instruments.TIMED;
|
||||
BEGIN
|
||||
-- Workaround for http://bugs.mysql.com/bug.php?id=70025
|
||||
DECLARE v_thread_id bigint unsigned;
|
||||
DECLARE v_instrumented enum('YES', 'NO');
|
||||
DECLARE c_threads CURSOR FOR SELECT THREAD_ID, INSTRUMENTED FROM tmp_threads;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
|
||||
|
||||
SET v_done = FALSE;
|
||||
OPEN c_threads;
|
||||
c_threads_loop: LOOP
|
||||
FETCH c_threads INTO v_thread_id, v_instrumented;
|
||||
IF v_done THEN
|
||||
LEAVE c_threads_loop;
|
||||
END IF;
|
||||
|
||||
UPDATE performance_schema.threads
|
||||
SET INSTRUMENTED = v_instrumented
|
||||
WHERE THREAD_ID = v_thread_id;
|
||||
END LOOP;
|
||||
CLOSE c_threads;
|
||||
END;
|
||||
|
||||
UPDATE performance_schema.threads
|
||||
SET INSTRUMENTED = IF(PROCESSLIST_USER IS NOT NULL,
|
||||
sys.ps_is_account_enabled(PROCESSLIST_HOST, PROCESSLIST_USER),
|
||||
'YES')
|
||||
WHERE THREAD_ID NOT IN (SELECT THREAD_ID FROM tmp_threads);
|
||||
|
||||
DROP TEMPORARY TABLE tmp_setup_actors;
|
||||
DROP TEMPORARY TABLE tmp_setup_consumers;
|
||||
DROP TEMPORARY TABLE tmp_setup_instruments;
|
||||
DROP TEMPORARY TABLE tmp_threads;
|
||||
|
||||
SELECT RELEASE_LOCK('sys.ps_setup_save') INTO v_lock_result;
|
||||
|
||||
SET sql_log_bin = @log_bin;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
148
scripts/sys_schema/procedures/ps_setup_reset_to_default.sql
Normal file
148
scripts/sys_schema/procedures/ps_setup_reset_to_default.sql
Normal file
@ -0,0 +1,148 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_reset_to_default;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_reset_to_default (
|
||||
IN in_verbose BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Resets the Performance Schema setup to the default settings.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_verbose (BOOLEAN):
|
||||
Whether to print each setup stage (including the SQL) whilst running.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_reset_to_default(true)\\G
|
||||
*************************** 1. row ***************************
|
||||
status: Resetting: setup_actors
|
||||
DELETE
|
||||
FROM performance_schema.setup_actors
|
||||
WHERE NOT (HOST = \'%\' AND USER = \'%\' AND ROLE = \'%\')
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
*************************** 1. row ***************************
|
||||
status: Resetting: setup_actors
|
||||
INSERT IGNORE INTO performance_schema.setup_actors
|
||||
VALUES (\'%\', \'%\', \'%\')
|
||||
1 row in set (0.00 sec)
|
||||
...
|
||||
|
||||
mysql> CALL sys.ps_setup_reset_to_default(false)\\G
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
SET @query = 'DELETE
|
||||
FROM performance_schema.setup_actors
|
||||
WHERE NOT (HOST = ''%'' AND USER = ''%'' AND ROLE = ''%'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_actors\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'INSERT IGNORE INTO performance_schema.setup_actors
|
||||
VALUES (''%'', ''%'', ''%'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_actors\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'UPDATE performance_schema.setup_instruments
|
||||
SET ENABLED = sys.ps_is_instrument_default_enabled(NAME),
|
||||
TIMED = sys.ps_is_instrument_default_timed(NAME)';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_instruments\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'UPDATE performance_schema.setup_consumers
|
||||
SET ENABLED = IF(NAME IN (''events_statements_current'', ''global_instrumentation'', ''thread_instrumentation'', ''statements_digest''), ''YES'', ''NO'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_consumers\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'DELETE
|
||||
FROM performance_schema.setup_objects
|
||||
WHERE NOT (OBJECT_TYPE = ''TABLE'' AND OBJECT_NAME = ''%''
|
||||
AND (OBJECT_SCHEMA = ''mysql'' AND ENABLED = ''NO'' AND TIMED = ''NO'' )
|
||||
OR (OBJECT_SCHEMA = ''performance_schema'' AND ENABLED = ''NO'' AND TIMED = ''NO'' )
|
||||
OR (OBJECT_SCHEMA = ''information_schema'' AND ENABLED = ''NO'' AND TIMED = ''NO'' )
|
||||
OR (OBJECT_SCHEMA = ''%'' AND ENABLED = ''YES'' AND TIMED = ''YES''))';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_objects\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'INSERT IGNORE INTO performance_schema.setup_objects
|
||||
VALUES (''TABLE'', ''mysql'' , ''%'', ''NO'' , ''NO'' ),
|
||||
(''TABLE'', ''performance_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''TABLE'', ''information_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''TABLE'', ''%'' , ''%'', ''YES'', ''YES'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_objects\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'UPDATE performance_schema.threads
|
||||
SET INSTRUMENTED = ''YES''';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: threads\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
165
scripts/sys_schema/procedures/ps_setup_reset_to_default_57.sql
Normal file
165
scripts/sys_schema/procedures/ps_setup_reset_to_default_57.sql
Normal file
@ -0,0 +1,165 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_reset_to_default;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_reset_to_default (
|
||||
IN in_verbose BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Resets the Performance Schema setup to the default settings.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_verbose (BOOLEAN):
|
||||
Whether to print each setup stage (including the SQL) whilst running.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_reset_to_default(true)\\G
|
||||
*************************** 1. row ***************************
|
||||
status: Resetting: setup_actors
|
||||
DELETE
|
||||
FROM performance_schema.setup_actors
|
||||
WHERE NOT (HOST = \'%\' AND USER = \'%\' AND ROLE = \'%\')
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
*************************** 1. row ***************************
|
||||
status: Resetting: setup_actors
|
||||
INSERT IGNORE INTO performance_schema.setup_actors
|
||||
VALUES (\'%\', \'%\', \'%\')
|
||||
1 row in set (0.00 sec)
|
||||
...
|
||||
|
||||
mysql> CALL sys.ps_setup_reset_to_default(false)\\G
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
SET @query = 'DELETE
|
||||
FROM performance_schema.setup_actors
|
||||
WHERE NOT (HOST = ''%'' AND USER = ''%'' AND ROLE = ''%'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_actors\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'INSERT IGNORE INTO performance_schema.setup_actors
|
||||
VALUES (''%'', ''%'', ''%'', ''YES'', ''YES'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_actors\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'UPDATE performance_schema.setup_instruments
|
||||
SET ENABLED = sys.ps_is_instrument_default_enabled(NAME),
|
||||
TIMED = sys.ps_is_instrument_default_timed(NAME)';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_instruments\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'UPDATE performance_schema.setup_consumers
|
||||
SET ENABLED = IF(NAME IN (''events_statements_current'', ''events_transactions_current'', ''global_instrumentation'', ''thread_instrumentation'', ''statements_digest''), ''YES'', ''NO'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_consumers\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'DELETE
|
||||
FROM performance_schema.setup_objects
|
||||
WHERE NOT (OBJECT_TYPE IN (''EVENT'', ''FUNCTION'', ''PROCEDURE'', ''TABLE'', ''TRIGGER'') AND OBJECT_NAME = ''%''
|
||||
AND (OBJECT_SCHEMA = ''mysql'' AND ENABLED = ''NO'' AND TIMED = ''NO'' )
|
||||
OR (OBJECT_SCHEMA = ''performance_schema'' AND ENABLED = ''NO'' AND TIMED = ''NO'' )
|
||||
OR (OBJECT_SCHEMA = ''information_schema'' AND ENABLED = ''NO'' AND TIMED = ''NO'' )
|
||||
OR (OBJECT_SCHEMA = ''%'' AND ENABLED = ''YES'' AND TIMED = ''YES''))';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_objects\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'INSERT IGNORE INTO performance_schema.setup_objects
|
||||
VALUES (''EVENT'' , ''mysql'' , ''%'', ''NO'' , ''NO'' ),
|
||||
(''EVENT'' , ''performance_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''EVENT'' , ''information_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''EVENT'' , ''%'' , ''%'', ''YES'', ''YES''),
|
||||
(''FUNCTION'' , ''mysql'' , ''%'', ''NO'' , ''NO'' ),
|
||||
(''FUNCTION'' , ''performance_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''FUNCTION'' , ''information_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''FUNCTION'' , ''%'' , ''%'', ''YES'', ''YES''),
|
||||
(''PROCEDURE'', ''mysql'' , ''%'', ''NO'' , ''NO'' ),
|
||||
(''PROCEDURE'', ''performance_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''PROCEDURE'', ''information_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''PROCEDURE'', ''%'' , ''%'', ''YES'', ''YES''),
|
||||
(''TABLE'' , ''mysql'' , ''%'', ''NO'' , ''NO'' ),
|
||||
(''TABLE'' , ''performance_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''TABLE'' , ''information_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''TABLE'' , ''%'' , ''%'', ''YES'', ''YES''),
|
||||
(''TRIGGER'' , ''mysql'' , ''%'', ''NO'' , ''NO'' ),
|
||||
(''TRIGGER'' , ''performance_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''TRIGGER'' , ''information_schema'', ''%'', ''NO'' , ''NO'' ),
|
||||
(''TRIGGER'' , ''%'' , ''%'', ''YES'', ''YES'')';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: setup_objects\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
|
||||
SET @query = 'UPDATE performance_schema.threads
|
||||
SET INSTRUMENTED = ''YES''';
|
||||
|
||||
IF (in_verbose) THEN
|
||||
SELECT CONCAT('Resetting: threads\n', REPLACE(@query, ' ', '')) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE reset_stmt FROM @query;
|
||||
EXECUTE reset_stmt;
|
||||
DEALLOCATE PREPARE reset_stmt;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
@ -0,0 +1,16 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
SET @@session.sql_mode = @old_sql_mode;
|
@ -0,0 +1,17 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
-- Because of bug 11750980/bug 41686, set the sql_mode to ''
|
||||
SET @old_sql_mode = @@session.sql_mode, @@session.sql_mode = '';
|
100
scripts/sys_schema/procedures/ps_setup_save.sql
Normal file
100
scripts/sys_schema/procedures/ps_setup_save.sql
Normal file
@ -0,0 +1,100 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_save;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_save (
|
||||
IN in_timeout INT
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Saves the current configuration of Performance Schema,
|
||||
so that you can alter the setup for debugging purposes,
|
||||
but restore it to a previous state.
|
||||
|
||||
Use the companion procedure - ps_setup_reload_saved(), to
|
||||
restore the saved config.
|
||||
|
||||
The named lock "sys.ps_setup_save" is taken before the
|
||||
current configuration is saved. If the attempt to get the named
|
||||
lock times out, an error occurs.
|
||||
|
||||
The lock is released after the settings have been restored by
|
||||
calling ps_setup_reload_saved().
|
||||
|
||||
Requires the SUPER privilege for "SET sql_log_bin = 0;".
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_timeout INT
|
||||
The timeout in seconds used when trying to obtain the lock.
|
||||
A negative timeout means infinite timeout.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_save(-1);
|
||||
Query OK, 0 rows affected (0.08 sec)
|
||||
|
||||
mysql> UPDATE performance_schema.setup_instruments
|
||||
-> SET enabled = \'YES\', timed = \'YES\';
|
||||
Query OK, 547 rows affected (0.40 sec)
|
||||
Rows matched: 784 Changed: 547 Warnings: 0
|
||||
|
||||
/* Run some tests that need more detailed instrumentation here */
|
||||
|
||||
mysql> CALL sys.ps_setup_reload_saved();
|
||||
Query OK, 0 rows affected (0.32 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_lock_result INT;
|
||||
|
||||
SET @log_bin := @@sql_log_bin;
|
||||
SET sql_log_bin = 0;
|
||||
|
||||
SELECT GET_LOCK('sys.ps_setup_save', in_timeout) INTO v_lock_result;
|
||||
|
||||
IF v_lock_result THEN
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_setup_actors;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_setup_consumers;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_setup_instruments;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_threads;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_setup_actors LIKE performance_schema.setup_actors;
|
||||
CREATE TEMPORARY TABLE tmp_setup_consumers LIKE performance_schema.setup_consumers;
|
||||
CREATE TEMPORARY TABLE tmp_setup_instruments LIKE performance_schema.setup_instruments;
|
||||
CREATE TEMPORARY TABLE tmp_threads (THREAD_ID bigint unsigned NOT NULL PRIMARY KEY, INSTRUMENTED enum('YES','NO') NOT NULL);
|
||||
|
||||
INSERT INTO tmp_setup_actors SELECT * FROM performance_schema.setup_actors;
|
||||
INSERT INTO tmp_setup_consumers SELECT * FROM performance_schema.setup_consumers;
|
||||
INSERT INTO tmp_setup_instruments SELECT * FROM performance_schema.setup_instruments;
|
||||
INSERT INTO tmp_threads SELECT THREAD_ID, INSTRUMENTED FROM performance_schema.threads;
|
||||
ELSE
|
||||
SIGNAL SQLSTATE VALUE '90000'
|
||||
SET MESSAGE_TEXT = 'Could not lock the sys.ps_setup_save user lock, another thread has a saved configuration';
|
||||
END IF;
|
||||
|
||||
SET sql_log_bin = @log_bin;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
163
scripts/sys_schema/procedures/ps_setup_show_disabled.sql
Normal file
163
scripts/sys_schema/procedures/ps_setup_show_disabled.sql
Normal file
@ -0,0 +1,163 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_show_disabled;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_disabled (
|
||||
IN in_show_instruments BOOLEAN,
|
||||
IN in_show_threads BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Shows all currently disable Performance Schema configuration.
|
||||
|
||||
Disabled users is only available for MySQL 5.7.6 and later.
|
||||
In earlier versions it was only possible to enable users.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_show_instruments (BOOLEAN):
|
||||
Whether to print disabled instruments (can print many items)
|
||||
|
||||
in_show_threads (BOOLEAN):
|
||||
Whether to print disabled threads
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_show_disabled(TRUE, TRUE);
|
||||
+----------------------------+
|
||||
| performance_schema_enabled |
|
||||
+----------------------------+
|
||||
| 1 |
|
||||
+----------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
+--------------------+
|
||||
| disabled_users |
|
||||
+--------------------+
|
||||
| \'mark\'@\'localhost\' |
|
||||
+--------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
+-------------+----------------------+---------+-------+
|
||||
| object_type | objects | enabled | timed |
|
||||
+-------------+----------------------+---------+-------+
|
||||
| EVENT | mysql.% | NO | NO |
|
||||
| EVENT | performance_schema.% | NO | NO |
|
||||
| EVENT | information_schema.% | NO | NO |
|
||||
| FUNCTION | mysql.% | NO | NO |
|
||||
| FUNCTION | performance_schema.% | NO | NO |
|
||||
| FUNCTION | information_schema.% | NO | NO |
|
||||
| PROCEDURE | mysql.% | NO | NO |
|
||||
| PROCEDURE | performance_schema.% | NO | NO |
|
||||
| PROCEDURE | information_schema.% | NO | NO |
|
||||
| TABLE | mysql.% | NO | NO |
|
||||
| TABLE | performance_schema.% | NO | NO |
|
||||
| TABLE | information_schema.% | NO | NO |
|
||||
| TRIGGER | mysql.% | NO | NO |
|
||||
| TRIGGER | performance_schema.% | NO | NO |
|
||||
| TRIGGER | information_schema.% | NO | NO |
|
||||
+-------------+----------------------+---------+-------+
|
||||
15 rows in set (0.00 sec)
|
||||
|
||||
+----------------------------------+
|
||||
| disabled_consumers |
|
||||
+----------------------------------+
|
||||
| events_stages_current |
|
||||
| events_stages_history |
|
||||
| events_stages_history_long |
|
||||
| events_statements_history |
|
||||
| events_statements_history_long |
|
||||
| events_transactions_history |
|
||||
| events_transactions_history_long |
|
||||
| events_waits_current |
|
||||
| events_waits_history |
|
||||
| events_waits_history_long |
|
||||
+----------------------------------+
|
||||
10 rows in set (0.00 sec)
|
||||
|
||||
Empty set (0.00 sec)
|
||||
|
||||
+---------------------------------------------------------------------------------------+-------+
|
||||
| disabled_instruments | timed |
|
||||
+---------------------------------------------------------------------------------------+-------+
|
||||
| wait/synch/mutex/sql/TC_LOG_MMAP::LOCK_tc | NO |
|
||||
| wait/synch/mutex/sql/LOCK_des_key_file | NO |
|
||||
| wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_commit | NO |
|
||||
...
|
||||
| memory/sql/servers_cache | NO |
|
||||
| memory/sql/udf_mem | NO |
|
||||
| wait/lock/metadata/sql/mdl | NO |
|
||||
+---------------------------------------------------------------------------------------+-------+
|
||||
547 rows in set (0.00 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.01 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
SELECT @@performance_schema AS performance_schema_enabled;
|
||||
|
||||
-- In 5.7.6 and later the setup_actors table has an ENABLED column to
|
||||
-- specify whether the actor is enabled. Before that all actors matched
|
||||
-- in the setup_actors table were enabled.
|
||||
-- So only execute the query in 5.7.6+
|
||||
/*!50706
|
||||
SELECT CONCAT('\'', user, '\'@\'', host, '\'') AS disabled_users
|
||||
FROM performance_schema.setup_actors
|
||||
WHERE enabled = 'NO'
|
||||
ORDER BY disabled_users;
|
||||
*/
|
||||
|
||||
SELECT object_type,
|
||||
CONCAT(object_schema, '.', object_name) AS objects,
|
||||
enabled,
|
||||
timed
|
||||
FROM performance_schema.setup_objects
|
||||
WHERE enabled = 'NO'
|
||||
ORDER BY object_type, objects;
|
||||
|
||||
SELECT name AS disabled_consumers
|
||||
FROM performance_schema.setup_consumers
|
||||
WHERE enabled = 'NO'
|
||||
ORDER BY disabled_consumers;
|
||||
|
||||
IF (in_show_threads) THEN
|
||||
SELECT IF(name = 'thread/sql/one_connection',
|
||||
CONCAT(processlist_user, '@', processlist_host),
|
||||
REPLACE(name, 'thread/', '')) AS disabled_threads,
|
||||
TYPE AS thread_type
|
||||
FROM performance_schema.threads
|
||||
WHERE INSTRUMENTED = 'NO'
|
||||
ORDER BY disabled_threads;
|
||||
END IF;
|
||||
|
||||
IF (in_show_instruments) THEN
|
||||
SELECT name AS disabled_instruments,
|
||||
timed
|
||||
FROM performance_schema.setup_instruments
|
||||
WHERE enabled = 'NO'
|
||||
ORDER BY disabled_instruments;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,57 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_show_disabled_consumers;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_disabled_consumers ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Shows all currently disabled consumers.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_show_disabled_consumers();
|
||||
|
||||
+---------------------------+
|
||||
| disabled_consumers |
|
||||
+---------------------------+
|
||||
| events_statements_current |
|
||||
| global_instrumentation |
|
||||
| thread_instrumentation |
|
||||
| statements_digest |
|
||||
+---------------------------+
|
||||
4 rows in set (0.05 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
SELECT name AS disabled_consumers
|
||||
FROM performance_schema.setup_consumers
|
||||
WHERE enabled = 'NO'
|
||||
ORDER BY disabled_consumers;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,47 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_show_disabled_instruments;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_disabled_instruments ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Shows all currently disabled instruments.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_show_disabled_instruments();
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
SELECT name AS disabled_instruments, timed
|
||||
FROM performance_schema.setup_instruments
|
||||
WHERE enabled = 'NO'
|
||||
ORDER BY disabled_instruments;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
166
scripts/sys_schema/procedures/ps_setup_show_enabled.sql
Normal file
166
scripts/sys_schema/procedures/ps_setup_show_enabled.sql
Normal file
@ -0,0 +1,166 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_show_enabled;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_enabled (
|
||||
IN in_show_instruments BOOLEAN,
|
||||
IN in_show_threads BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Shows all currently enabled Performance Schema configuration.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_show_instruments (BOOLEAN):
|
||||
Whether to print enabled instruments (can print many items)
|
||||
|
||||
in_show_threads (BOOLEAN):
|
||||
Whether to print enabled threads
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_show_enabled(TRUE, TRUE);
|
||||
+----------------------------+
|
||||
| performance_schema_enabled |
|
||||
+----------------------------+
|
||||
| 1 |
|
||||
+----------------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
+---------------+
|
||||
| enabled_users |
|
||||
+---------------+
|
||||
| \'%\'@\'%\' |
|
||||
+---------------+
|
||||
1 row in set (0.01 sec)
|
||||
|
||||
+-------------+---------+---------+-------+
|
||||
| object_type | objects | enabled | timed |
|
||||
+-------------+---------+---------+-------+
|
||||
| EVENT | %.% | YES | YES |
|
||||
| FUNCTION | %.% | YES | YES |
|
||||
| PROCEDURE | %.% | YES | YES |
|
||||
| TABLE | %.% | YES | YES |
|
||||
| TRIGGER | %.% | YES | YES |
|
||||
+-------------+---------+---------+-------+
|
||||
5 rows in set (0.01 sec)
|
||||
|
||||
+---------------------------+
|
||||
| enabled_consumers |
|
||||
+---------------------------+
|
||||
| events_statements_current |
|
||||
| global_instrumentation |
|
||||
| thread_instrumentation |
|
||||
| statements_digest |
|
||||
+---------------------------+
|
||||
4 rows in set (0.05 sec)
|
||||
|
||||
+---------------------------------+-------------+
|
||||
| enabled_threads | thread_type |
|
||||
+---------------------------------+-------------+
|
||||
| sql/main | BACKGROUND |
|
||||
| sql/thread_timer_notifier | BACKGROUND |
|
||||
| innodb/io_ibuf_thread | BACKGROUND |
|
||||
| innodb/io_log_thread | BACKGROUND |
|
||||
| innodb/io_read_thread | BACKGROUND |
|
||||
| innodb/io_read_thread | BACKGROUND |
|
||||
| innodb/io_write_thread | BACKGROUND |
|
||||
| innodb/io_write_thread | BACKGROUND |
|
||||
| innodb/page_cleaner_thread | BACKGROUND |
|
||||
| innodb/srv_lock_timeout_thread | BACKGROUND |
|
||||
| innodb/srv_error_monitor_thread | BACKGROUND |
|
||||
| innodb/srv_monitor_thread | BACKGROUND |
|
||||
| innodb/srv_master_thread | BACKGROUND |
|
||||
| innodb/srv_purge_thread | BACKGROUND |
|
||||
| innodb/srv_worker_thread | BACKGROUND |
|
||||
| innodb/srv_worker_thread | BACKGROUND |
|
||||
| innodb/srv_worker_thread | BACKGROUND |
|
||||
| innodb/buf_dump_thread | BACKGROUND |
|
||||
| innodb/dict_stats_thread | BACKGROUND |
|
||||
| sql/signal_handler | BACKGROUND |
|
||||
| sql/compress_gtid_table | FOREGROUND |
|
||||
| root@localhost | FOREGROUND |
|
||||
+---------------------------------+-------------+
|
||||
22 rows in set (0.01 sec)
|
||||
|
||||
+-------------------------------------+-------+
|
||||
| enabled_instruments | timed |
|
||||
+-------------------------------------+-------+
|
||||
| wait/io/file/sql/map | YES |
|
||||
| wait/io/file/sql/binlog | YES |
|
||||
...
|
||||
| statement/com/Error | YES |
|
||||
| statement/com/ | YES |
|
||||
| idle | YES |
|
||||
+-------------------------------------+-------+
|
||||
210 rows in set (0.08 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.89 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
SELECT @@performance_schema AS performance_schema_enabled;
|
||||
|
||||
-- In 5.7.6 and later the setup_actors table has an ENABLED column to
|
||||
-- specify whether the actor is enabled. Before that all actors matched
|
||||
-- in the setup_actors table were enabled.
|
||||
SELECT CONCAT('\'', user, '\'@\'', host, '\'') AS enabled_users
|
||||
FROM performance_schema.setup_actors
|
||||
/*!50706 WHERE enabled = 'YES' */
|
||||
ORDER BY enabled_users;
|
||||
|
||||
SELECT object_type,
|
||||
CONCAT(object_schema, '.', object_name) AS objects,
|
||||
enabled,
|
||||
timed
|
||||
FROM performance_schema.setup_objects
|
||||
WHERE enabled = 'YES'
|
||||
ORDER BY object_type, objects;
|
||||
|
||||
SELECT name AS enabled_consumers
|
||||
FROM performance_schema.setup_consumers
|
||||
WHERE enabled = 'YES'
|
||||
ORDER BY enabled_consumers;
|
||||
|
||||
IF (in_show_threads) THEN
|
||||
SELECT IF(name = 'thread/sql/one_connection',
|
||||
CONCAT(processlist_user, '@', processlist_host),
|
||||
REPLACE(name, 'thread/', '')) AS enabled_threads,
|
||||
TYPE AS thread_type
|
||||
FROM performance_schema.threads
|
||||
WHERE INSTRUMENTED = 'YES'
|
||||
ORDER BY enabled_threads;
|
||||
END IF;
|
||||
|
||||
IF (in_show_instruments) THEN
|
||||
SELECT name AS enabled_instruments,
|
||||
timed
|
||||
FROM performance_schema.setup_instruments
|
||||
WHERE enabled = 'YES'
|
||||
ORDER BY enabled_instruments;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,57 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_show_enabled_consumers;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_enabled_consumers ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Shows all currently enabled consumers.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_show_enabled_consumers();
|
||||
|
||||
+---------------------------+
|
||||
| enabled_consumers |
|
||||
+---------------------------+
|
||||
| events_statements_current |
|
||||
| global_instrumentation |
|
||||
| thread_instrumentation |
|
||||
| statements_digest |
|
||||
+---------------------------+
|
||||
4 rows in set (0.05 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
SELECT name AS enabled_consumers
|
||||
FROM performance_schema.setup_consumers
|
||||
WHERE enabled = 'YES'
|
||||
ORDER BY enabled_consumers;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,47 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_setup_show_enabled_instruments;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_show_enabled_instruments ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Shows all currently enabled instruments.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_setup_show_enabled_instruments();
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
SELECT name AS enabled_instruments, timed
|
||||
FROM performance_schema.setup_instruments
|
||||
WHERE enabled = 'YES'
|
||||
ORDER BY enabled_instruments;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,230 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_statement_avg_latency_histogram;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_statement_avg_latency_histogram ()
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Outputs a textual histogram graph of the average latency values
|
||||
across all normalized queries tracked within the Performance Schema
|
||||
events_statements_summary_by_digest table.
|
||||
|
||||
Can be used to show a very high level picture of what kind of
|
||||
latency distribution statements running within this instance have.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
None.
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_statement_avg_latency_histogram()\\G
|
||||
*************************** 1. row ***************************
|
||||
Performance Schema Statement Digest Average Latency Histogram:
|
||||
|
||||
. = 1 unit
|
||||
* = 2 units
|
||||
# = 3 units
|
||||
|
||||
(0 - 38ms) 240 | ################################################################################
|
||||
(38 - 77ms) 38 | ......................................
|
||||
(77 - 115ms) 3 | ...
|
||||
(115 - 154ms) 62 | *******************************
|
||||
(154 - 192ms) 3 | ...
|
||||
(192 - 231ms) 0 |
|
||||
(231 - 269ms) 0 |
|
||||
(269 - 307ms) 0 |
|
||||
(307 - 346ms) 0 |
|
||||
(346 - 384ms) 1 | .
|
||||
(384 - 423ms) 1 | .
|
||||
(423 - 461ms) 0 |
|
||||
(461 - 499ms) 0 |
|
||||
(499 - 538ms) 0 |
|
||||
(538 - 576ms) 0 |
|
||||
(576 - 615ms) 1 | .
|
||||
|
||||
Total Statements: 350; Buckets: 16; Bucket Size: 38 ms;
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
SELECT CONCAT('\n',
|
||||
'\n . = 1 unit',
|
||||
'\n * = 2 units',
|
||||
'\n # = 3 units\n',
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(0 - ',
|
||||
ROUND((@bucket_size := (SELECT ROUND((MAX(avg_us) - MIN(avg_us)) / (@buckets := 16)) AS size
|
||||
FROM sys.x$ps_digest_avg_latency_distribution)) / (@unit_div := 1000)),
|
||||
(@unit := 'ms'), ')'),
|
||||
REPEAT(' ', (@max_label_size := ((1 + LENGTH(ROUND((@bucket_size * 15) / @unit_div)) + 3 + LENGTH(ROUND(@bucket_size * 16) / @unit_div)) + 1)) - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us <= @bucket_size), 0)),
|
||||
REPEAT(' ', (@max_label_len := (@max_label_size + LENGTH((@total_queries := (SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution)))) + 1) - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < (@one_unit := 40), '.', IF(@count_in_bucket < (@two_unit := 80), '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND(@bucket_size / @unit_div), ' - ', ROUND((@bucket_size * 2) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size AND b1.avg_us <= @bucket_size * 2), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 2) / @unit_div), ' - ', ROUND((@bucket_size * 3) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 2 AND b1.avg_us <= @bucket_size * 3), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 3) / @unit_div), ' - ', ROUND((@bucket_size * 4) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 3 AND b1.avg_us <= @bucket_size * 4), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 4) / @unit_div), ' - ', ROUND((@bucket_size * 5) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 4 AND b1.avg_us <= @bucket_size * 5), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 5) / @unit_div), ' - ', ROUND((@bucket_size * 6) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 5 AND b1.avg_us <= @bucket_size * 6), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 6) / @unit_div), ' - ', ROUND((@bucket_size * 7) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 6 AND b1.avg_us <= @bucket_size * 7), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 7) / @unit_div), ' - ', ROUND((@bucket_size * 8) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 7 AND b1.avg_us <= @bucket_size * 8), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 8) / @unit_div), ' - ', ROUND((@bucket_size * 9) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 8 AND b1.avg_us <= @bucket_size * 9), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 9) / @unit_div), ' - ', ROUND((@bucket_size * 10) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 9 AND b1.avg_us <= @bucket_size * 10), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 10) / @unit_div), ' - ', ROUND((@bucket_size * 11) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 10 AND b1.avg_us <= @bucket_size * 11), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 11) / @unit_div), ' - ', ROUND((@bucket_size * 12) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 11 AND b1.avg_us <= @bucket_size * 12), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 12) / @unit_div), ' - ', ROUND((@bucket_size * 13) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 12 AND b1.avg_us <= @bucket_size * 13), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 13) / @unit_div), ' - ', ROUND((@bucket_size * 14) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 13 AND b1.avg_us <= @bucket_size * 14), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 14) / @unit_div), ' - ', ROUND((@bucket_size * 15) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 14 AND b1.avg_us <= @bucket_size * 15), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 15) / @unit_div), ' - ', ROUND((@bucket_size * 16) / @unit_div), @unit, ')'),
|
||||
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
|
||||
@count_in_bucket := IFNULL((SELECT SUM(cnt)
|
||||
FROM sys.x$ps_digest_avg_latency_distribution AS b1
|
||||
WHERE b1.avg_us > @bucket_size * 15 AND b1.avg_us <= @bucket_size * 16), 0)),
|
||||
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
|
||||
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
|
||||
IF(@count_in_bucket < @one_unit, @count_in_bucket,
|
||||
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
|
||||
|
||||
'\n\n Total Statements: ', @total_queries, '; Buckets: ', @buckets , '; Bucket Size: ', ROUND(@bucket_size / @unit_div) , ' ', @unit, ';\n'
|
||||
|
||||
) AS `Performance Schema Statement Digest Average Latency Histogram`;
|
||||
|
||||
END $$
|
||||
|
||||
DELIMITER ;
|
324
scripts/sys_schema/procedures/ps_trace_statement_digest.sql
Normal file
324
scripts/sys_schema/procedures/ps_trace_statement_digest.sql
Normal file
@ -0,0 +1,324 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_trace_statement_digest;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_trace_statement_digest (
|
||||
IN in_digest VARCHAR(32),
|
||||
IN in_runtime INT,
|
||||
IN in_interval DECIMAL(2,2),
|
||||
IN in_start_fresh BOOLEAN,
|
||||
IN in_auto_enable BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Traces all instrumentation within Performance Schema for a specific
|
||||
Statement Digest.
|
||||
|
||||
When finding a statement of interest within the
|
||||
performance_schema.events_statements_summary_by_digest table, feed
|
||||
the DIGEST MD5 value in to this procedure, set how long to poll for,
|
||||
and at what interval to poll, and it will generate a report of all
|
||||
statistics tracked within Performance Schema for that digest for the
|
||||
interval.
|
||||
|
||||
It will also attempt to generate an EXPLAIN for the longest running
|
||||
example of the digest during the interval. Note this may fail, as:
|
||||
|
||||
* Performance Schema truncates long SQL_TEXT values (and hence the
|
||||
EXPLAIN will fail due to parse errors)
|
||||
* the default schema is sys (so tables that are not fully qualified
|
||||
in the query may not be found)
|
||||
* some queries such as SHOW are not supported in EXPLAIN.
|
||||
|
||||
When the EXPLAIN fails, the error will be ignored and no EXPLAIN
|
||||
output generated.
|
||||
|
||||
Requires the SUPER privilege for "SET sql_log_bin = 0;".
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_digest (VARCHAR(32)):
|
||||
The statement digest identifier you would like to analyze
|
||||
in_runtime (INT):
|
||||
The number of seconds to run analysis for
|
||||
in_interval (DECIMAL(2,2)):
|
||||
The interval (in seconds, may be fractional) at which to try
|
||||
and take snapshots
|
||||
in_start_fresh (BOOLEAN):
|
||||
Whether to TRUNCATE the events_statements_history_long and
|
||||
events_stages_history_long tables before starting
|
||||
in_auto_enable (BOOLEAN):
|
||||
Whether to automatically turn on required consumers
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> call ps_trace_statement_digest(\'891ec6860f98ba46d89dd20b0c03652c\', 10, 0.1, true, true);
|
||||
+--------------------+
|
||||
| SUMMARY STATISTICS |
|
||||
+--------------------+
|
||||
| SUMMARY STATISTICS |
|
||||
+--------------------+
|
||||
1 row in set (9.11 sec)
|
||||
|
||||
+------------+-----------+-----------+-----------+---------------+------------+------------+
|
||||
| executions | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scans |
|
||||
+------------+-----------+-----------+-----------+---------------+------------+------------+
|
||||
| 21 | 4.11 ms | 2.00 ms | 0 | 21 | 0 | 0 |
|
||||
+------------+-----------+-----------+-----------+---------------+------------+------------+
|
||||
1 row in set (9.11 sec)
|
||||
|
||||
+------------------------------------------+-------+-----------+
|
||||
| event_name | count | latency |
|
||||
+------------------------------------------+-------+-----------+
|
||||
| stage/sql/checking query cache for query | 16 | 724.37 us |
|
||||
| stage/sql/statistics | 16 | 546.92 us |
|
||||
| stage/sql/freeing items | 18 | 520.11 us |
|
||||
| stage/sql/init | 51 | 466.80 us |
|
||||
...
|
||||
| stage/sql/cleaning up | 18 | 11.92 us |
|
||||
| stage/sql/executing | 16 | 6.95 us |
|
||||
+------------------------------------------+-------+-----------+
|
||||
17 rows in set (9.12 sec)
|
||||
|
||||
+---------------------------+
|
||||
| LONGEST RUNNING STATEMENT |
|
||||
+---------------------------+
|
||||
| LONGEST RUNNING STATEMENT |
|
||||
+---------------------------+
|
||||
1 row in set (9.16 sec)
|
||||
|
||||
+-----------+-----------+-----------+-----------+---------------+------------+-----------+
|
||||
| thread_id | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scan |
|
||||
+-----------+-----------+-----------+-----------+---------------+------------+-----------+
|
||||
| 166646 | 618.43 us | 1.00 ms | 0 | 1 | 0 | 0 |
|
||||
+-----------+-----------+-----------+-----------+---------------+------------+-----------+
|
||||
1 row in set (9.16 sec)
|
||||
|
||||
// Truncated for clarity...
|
||||
+-----------------------------------------------------------------+
|
||||
| sql_text |
|
||||
+-----------------------------------------------------------------+
|
||||
| select hibeventhe0_.id as id1382_, hibeventhe0_.createdTime ... |
|
||||
+-----------------------------------------------------------------+
|
||||
1 row in set (9.17 sec)
|
||||
|
||||
+------------------------------------------+-----------+
|
||||
| event_name | latency |
|
||||
+------------------------------------------+-----------+
|
||||
| stage/sql/init | 8.61 us |
|
||||
| stage/sql/Waiting for query cache lock | 453.23 us |
|
||||
| stage/sql/init | 331.07 ns |
|
||||
| stage/sql/checking query cache for query | 43.04 us |
|
||||
...
|
||||
| stage/sql/freeing items | 30.46 us |
|
||||
| stage/sql/cleaning up | 662.13 ns |
|
||||
+------------------------------------------+-----------+
|
||||
18 rows in set (9.23 sec)
|
||||
|
||||
+----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+
|
||||
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
||||
+----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+
|
||||
| 1 | SIMPLE | hibeventhe0_ | const | fixedTime | fixedTime | 775 | const,const | 1 | NULL |
|
||||
+----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+
|
||||
1 row in set (9.27 sec)
|
||||
|
||||
Query OK, 0 rows affected (9.28 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
|
||||
DECLARE v_start_fresh BOOLEAN DEFAULT false;
|
||||
DECLARE v_auto_enable BOOLEAN DEFAULT false;
|
||||
DECLARE v_explain BOOLEAN DEFAULT true;
|
||||
DECLARE v_this_thread_enabed ENUM('YES', 'NO');
|
||||
DECLARE v_runtime INT DEFAULT 0;
|
||||
DECLARE v_start INT DEFAULT 0;
|
||||
DECLARE v_found_stmts INT;
|
||||
|
||||
SET @log_bin := @@sql_log_bin;
|
||||
SET sql_log_bin = 0;
|
||||
|
||||
-- Do not track the current thread, it will kill the stack
|
||||
SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();
|
||||
CALL sys.ps_setup_disable_thread(CONNECTION_ID());
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS stmt_trace;
|
||||
CREATE TEMPORARY TABLE stmt_trace (
|
||||
thread_id BIGINT UNSIGNED,
|
||||
timer_start BIGINT UNSIGNED,
|
||||
event_id BIGINT UNSIGNED,
|
||||
sql_text longtext,
|
||||
timer_wait BIGINT UNSIGNED,
|
||||
lock_time BIGINT UNSIGNED,
|
||||
errors BIGINT UNSIGNED,
|
||||
mysql_errno INT,
|
||||
rows_sent BIGINT UNSIGNED,
|
||||
rows_affected BIGINT UNSIGNED,
|
||||
rows_examined BIGINT UNSIGNED,
|
||||
created_tmp_tables BIGINT UNSIGNED,
|
||||
created_tmp_disk_tables BIGINT UNSIGNED,
|
||||
no_index_used BIGINT UNSIGNED,
|
||||
PRIMARY KEY (thread_id, timer_start)
|
||||
);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS stmt_stages;
|
||||
CREATE TEMPORARY TABLE stmt_stages (
|
||||
event_id BIGINT UNSIGNED,
|
||||
stmt_id BIGINT UNSIGNED,
|
||||
event_name VARCHAR(128),
|
||||
timer_wait BIGINT UNSIGNED,
|
||||
PRIMARY KEY (event_id)
|
||||
);
|
||||
|
||||
SET v_start_fresh = in_start_fresh;
|
||||
IF v_start_fresh THEN
|
||||
TRUNCATE TABLE performance_schema.events_statements_history_long;
|
||||
TRUNCATE TABLE performance_schema.events_stages_history_long;
|
||||
END IF;
|
||||
|
||||
SET v_auto_enable = in_auto_enable;
|
||||
IF v_auto_enable THEN
|
||||
CALL sys.ps_setup_save(0);
|
||||
|
||||
UPDATE performance_schema.threads
|
||||
SET INSTRUMENTED = IF(PROCESSLIST_ID IS NOT NULL, 'YES', 'NO');
|
||||
|
||||
-- Only the events_statements_history_long and events_stages_history_long tables and their ancestors are needed
|
||||
UPDATE performance_schema.setup_consumers
|
||||
SET ENABLED = 'YES'
|
||||
WHERE NAME NOT LIKE '%\_history'
|
||||
AND NAME NOT LIKE 'events_wait%'
|
||||
AND NAME NOT LIKE 'events_transactions%'
|
||||
AND NAME <> 'statements_digest';
|
||||
|
||||
UPDATE performance_schema.setup_instruments
|
||||
SET ENABLED = 'YES',
|
||||
TIMED = 'YES'
|
||||
WHERE NAME LIKE 'statement/%' OR NAME LIKE 'stage/%';
|
||||
END IF;
|
||||
|
||||
WHILE v_runtime < in_runtime DO
|
||||
SELECT UNIX_TIMESTAMP() INTO v_start;
|
||||
|
||||
INSERT IGNORE INTO stmt_trace
|
||||
SELECT thread_id, timer_start, event_id, sql_text, timer_wait, lock_time, errors, mysql_errno,
|
||||
rows_sent, rows_affected, rows_examined, created_tmp_tables, created_tmp_disk_tables, no_index_used
|
||||
FROM performance_schema.events_statements_history_long
|
||||
WHERE digest = in_digest;
|
||||
|
||||
INSERT IGNORE INTO stmt_stages
|
||||
SELECT stages.event_id, stmt_trace.event_id,
|
||||
stages.event_name, stages.timer_wait
|
||||
FROM performance_schema.events_stages_history_long AS stages
|
||||
JOIN stmt_trace ON stages.nesting_event_id = stmt_trace.event_id;
|
||||
|
||||
SELECT SLEEP(in_interval) INTO @sleep;
|
||||
SET v_runtime = v_runtime + (UNIX_TIMESTAMP() - v_start);
|
||||
END WHILE;
|
||||
|
||||
SELECT "SUMMARY STATISTICS";
|
||||
|
||||
SELECT COUNT(*) executions,
|
||||
sys.format_time(SUM(timer_wait)) AS exec_time,
|
||||
sys.format_time(SUM(lock_time)) AS lock_time,
|
||||
SUM(rows_sent) AS rows_sent,
|
||||
SUM(rows_affected) AS rows_affected,
|
||||
SUM(rows_examined) AS rows_examined,
|
||||
SUM(created_tmp_tables) AS tmp_tables,
|
||||
SUM(no_index_used) AS full_scans
|
||||
FROM stmt_trace;
|
||||
|
||||
SELECT event_name,
|
||||
COUNT(*) as count,
|
||||
sys.format_time(SUM(timer_wait)) as latency
|
||||
FROM stmt_stages
|
||||
GROUP BY event_name
|
||||
ORDER BY SUM(timer_wait) DESC;
|
||||
|
||||
SELECT "LONGEST RUNNING STATEMENT";
|
||||
|
||||
SELECT thread_id,
|
||||
sys.format_time(timer_wait) AS exec_time,
|
||||
sys.format_time(lock_time) AS lock_time,
|
||||
rows_sent,
|
||||
rows_affected,
|
||||
rows_examined,
|
||||
created_tmp_tables AS tmp_tables,
|
||||
no_index_used AS full_scan
|
||||
FROM stmt_trace
|
||||
ORDER BY timer_wait DESC LIMIT 1;
|
||||
|
||||
SELECT sql_text
|
||||
FROM stmt_trace
|
||||
ORDER BY timer_wait DESC LIMIT 1;
|
||||
|
||||
SELECT sql_text, event_id INTO @sql, @sql_id
|
||||
FROM stmt_trace
|
||||
ORDER BY timer_wait DESC LIMIT 1;
|
||||
|
||||
IF (@sql_id IS NOT NULL) THEN
|
||||
SELECT event_name,
|
||||
sys.format_time(timer_wait) as latency
|
||||
FROM stmt_stages
|
||||
WHERE stmt_id = @sql_id
|
||||
ORDER BY event_id;
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE stmt_trace;
|
||||
DROP TEMPORARY TABLE stmt_stages;
|
||||
|
||||
IF (@sql IS NOT NULL) THEN
|
||||
SET @stmt := CONCAT("EXPLAIN FORMAT=JSON ", @sql);
|
||||
BEGIN
|
||||
-- Not all queries support EXPLAIN, so catch the cases that are
|
||||
-- not supported. Currently that includes cases where the table
|
||||
-- is not fully qualified and is not in the default schema for this
|
||||
-- procedure as it's not possible to change the default schema inside
|
||||
-- a procedure.
|
||||
--
|
||||
-- Errno = 1064: You have an error in your SQL syntax
|
||||
-- Errno = 1146: Table '...' doesn't exist
|
||||
DECLARE CONTINUE HANDLER FOR 1064, 1146 SET v_explain = false;
|
||||
|
||||
PREPARE explain_stmt FROM @stmt;
|
||||
END;
|
||||
|
||||
IF (v_explain) THEN
|
||||
EXECUTE explain_stmt;
|
||||
DEALLOCATE PREPARE explain_stmt;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF v_auto_enable THEN
|
||||
CALL sys.ps_setup_reload_saved();
|
||||
END IF;
|
||||
-- Restore INSTRUMENTED for this thread
|
||||
IF (v_this_thread_enabed = 'YES') THEN
|
||||
CALL sys.ps_setup_enable_thread(CONNECTION_ID());
|
||||
END IF;
|
||||
|
||||
SET sql_log_bin = @log_bin;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
321
scripts/sys_schema/procedures/ps_trace_thread.sql
Normal file
321
scripts/sys_schema/procedures/ps_trace_thread.sql
Normal file
@ -0,0 +1,321 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_trace_thread;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_trace_thread (
|
||||
IN in_thread_id BIGINT UNSIGNED,
|
||||
IN in_outfile VARCHAR(255),
|
||||
IN in_max_runtime DECIMAL(20,2),
|
||||
IN in_interval DECIMAL(20,2),
|
||||
IN in_start_fresh BOOLEAN,
|
||||
IN in_auto_setup BOOLEAN,
|
||||
IN in_debug BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Dumps all data within Performance Schema for an instrumented thread,
|
||||
to create a DOT formatted graph file.
|
||||
|
||||
Each resultset returned from the procedure should be used for a complete graph
|
||||
|
||||
Requires the SUPER privilege for "SET sql_log_bin = 0;".
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_thread_id (BIGINT UNSIGNED):
|
||||
The thread that you would like a stack trace for
|
||||
in_outfile (VARCHAR(255)):
|
||||
The filename the dot file will be written to
|
||||
in_max_runtime (DECIMAL(20,2)):
|
||||
The maximum time to keep collecting data.
|
||||
Use NULL to get the default which is 60 seconds.
|
||||
in_interval (DECIMAL(20,2)):
|
||||
How long to sleep between data collections.
|
||||
Use NULL to get the default which is 1 second.
|
||||
in_start_fresh (BOOLEAN):
|
||||
Whether to reset all Performance Schema data before tracing.
|
||||
in_auto_setup (BOOLEAN):
|
||||
Whether to disable all other threads and enable all consumers/instruments.
|
||||
This will also reset the settings at the end of the run.
|
||||
in_debug (BOOLEAN):
|
||||
Whether you would like to include file:lineno in the graph
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_trace_thread(25, CONCAT(\'/tmp/stack-\', REPLACE(NOW(), \' \', \'-\'), \'.dot\'), NULL, NULL, TRUE, TRUE, TRUE);
|
||||
+-------------------+
|
||||
| summary |
|
||||
+-------------------+
|
||||
| Disabled 1 thread |
|
||||
+-------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
+---------------------------------------------+
|
||||
| Info |
|
||||
+---------------------------------------------+
|
||||
| Data collection starting for THREAD_ID = 25 |
|
||||
+---------------------------------------------+
|
||||
1 row in set (0.03 sec)
|
||||
|
||||
+-----------------------------------------------------------+
|
||||
| Info |
|
||||
+-----------------------------------------------------------+
|
||||
| Stack trace written to /tmp/stack-2014-02-16-21:18:41.dot |
|
||||
+-----------------------------------------------------------+
|
||||
1 row in set (60.07 sec)
|
||||
|
||||
+-------------------------------------------------------------------+
|
||||
| Convert to PDF |
|
||||
+-------------------------------------------------------------------+
|
||||
| dot -Tpdf -o /tmp/stack_25.pdf /tmp/stack-2014-02-16-21:18:41.dot |
|
||||
+-------------------------------------------------------------------+
|
||||
1 row in set (60.07 sec)
|
||||
|
||||
+-------------------------------------------------------------------+
|
||||
| Convert to PNG |
|
||||
+-------------------------------------------------------------------+
|
||||
| dot -Tpng -o /tmp/stack_25.png /tmp/stack-2014-02-16-21:18:41.dot |
|
||||
+-------------------------------------------------------------------+
|
||||
1 row in set (60.07 sec)
|
||||
|
||||
+------------------+
|
||||
| summary |
|
||||
+------------------+
|
||||
| Enabled 1 thread |
|
||||
+------------------+
|
||||
1 row in set (60.32 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_done bool DEFAULT FALSE;
|
||||
DECLARE v_start, v_runtime DECIMAL(20,2) DEFAULT 0.0;
|
||||
DECLARE v_min_event_id bigint unsigned DEFAULT 0;
|
||||
DECLARE v_this_thread_enabed ENUM('YES', 'NO');
|
||||
DECLARE v_event longtext;
|
||||
DECLARE c_stack CURSOR FOR
|
||||
SELECT CONCAT(IF(nesting_event_id IS NOT NULL, CONCAT(nesting_event_id, ' -> '), ''),
|
||||
event_id, '; ', event_id, ' [label="',
|
||||
-- Convert from picoseconds to microseconds
|
||||
'(', sys.format_time(timer_wait), ') ',
|
||||
IF (event_name NOT LIKE 'wait/io%',
|
||||
SUBSTRING_INDEX(event_name, '/', -2),
|
||||
IF (event_name NOT LIKE 'wait/io/file%' OR event_name NOT LIKE 'wait/io/socket%',
|
||||
SUBSTRING_INDEX(event_name, '/', -4),
|
||||
event_name)
|
||||
),
|
||||
-- Always dump the extra wait information gathered for statements
|
||||
IF (event_name LIKE 'statement/%', IFNULL(CONCAT('\\n', wait_info), ''), ''),
|
||||
-- If debug is enabled, add the file:lineno information for waits
|
||||
IF (in_debug AND event_name LIKE 'wait%', wait_info, ''),
|
||||
'", ',
|
||||
-- Depending on the type of event, style appropriately
|
||||
CASE WHEN event_name LIKE 'wait/io/file%' THEN
|
||||
'shape=box, style=filled, color=red'
|
||||
WHEN event_name LIKE 'wait/io/table%' THEN
|
||||
'shape=box, style=filled, color=green'
|
||||
WHEN event_name LIKE 'wait/io/socket%' THEN
|
||||
'shape=box, style=filled, color=yellow'
|
||||
WHEN event_name LIKE 'wait/synch/mutex%' THEN
|
||||
'style=filled, color=lightskyblue'
|
||||
WHEN event_name LIKE 'wait/synch/cond%' THEN
|
||||
'style=filled, color=darkseagreen3'
|
||||
WHEN event_name LIKE 'wait/synch/rwlock%' THEN
|
||||
'style=filled, color=orchid'
|
||||
WHEN event_name LIKE 'wait/lock%' THEN
|
||||
'shape=box, style=filled, color=tan'
|
||||
WHEN event_name LIKE 'statement/%' THEN
|
||||
CONCAT('shape=box, style=bold',
|
||||
-- Style statements depending on COM vs SQL
|
||||
CASE WHEN event_name LIKE 'statement/com/%' THEN
|
||||
' style=filled, color=darkseagreen'
|
||||
ELSE
|
||||
-- Use long query time from the server to
|
||||
-- flag long running statements in red
|
||||
IF((timer_wait/1000000000000) > @@long_query_time,
|
||||
' style=filled, color=red',
|
||||
' style=filled, color=lightblue')
|
||||
END
|
||||
)
|
||||
WHEN event_name LIKE 'stage/%' THEN
|
||||
'style=filled, color=slategray3'
|
||||
-- IDLE events are on their own, call attention to them
|
||||
WHEN event_name LIKE '%idle%' THEN
|
||||
'shape=box, style=filled, color=firebrick3'
|
||||
ELSE '' END,
|
||||
'];\n'
|
||||
) event, event_id
|
||||
FROM (
|
||||
-- Select all statements, with the extra tracing information available
|
||||
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,
|
||||
CONCAT(sql_text, '\\n',
|
||||
'errors: ', errors, '\\n',
|
||||
'warnings: ', warnings, '\\n',
|
||||
'lock time: ', sys.format_time(lock_time),'\\n',
|
||||
'rows affected: ', rows_affected, '\\n',
|
||||
'rows sent: ', rows_sent, '\\n',
|
||||
'rows examined: ', rows_examined, '\\n',
|
||||
'tmp tables: ', created_tmp_tables, '\\n',
|
||||
'tmp disk tables: ', created_tmp_disk_tables, '\\n'
|
||||
'select scan: ', select_scan, '\\n',
|
||||
'select full join: ', select_full_join, '\\n',
|
||||
'select full range join: ', select_full_range_join, '\\n',
|
||||
'select range: ', select_range, '\\n',
|
||||
'select range check: ', select_range_check, '\\n',
|
||||
'sort merge passes: ', sort_merge_passes, '\\n',
|
||||
'sort rows: ', sort_rows, '\\n',
|
||||
'sort range: ', sort_range, '\\n',
|
||||
'sort scan: ', sort_scan, '\\n',
|
||||
'no index used: ', IF(no_index_used, 'TRUE', 'FALSE'), '\\n',
|
||||
'no good index used: ', IF(no_good_index_used, 'TRUE', 'FALSE'), '\\n'
|
||||
) AS wait_info
|
||||
FROM performance_schema.events_statements_history_long
|
||||
WHERE thread_id = in_thread_id AND event_id > v_min_event_id)
|
||||
UNION
|
||||
-- Select all stages
|
||||
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info
|
||||
FROM performance_schema.events_stages_history_long
|
||||
WHERE thread_id = in_thread_id AND event_id > v_min_event_id)
|
||||
UNION
|
||||
-- Select all events, adding information appropriate to the event
|
||||
(SELECT thread_id, event_id,
|
||||
CONCAT(event_name,
|
||||
IF(event_name NOT LIKE 'wait/synch/mutex%', IFNULL(CONCAT(' - ', operation), ''), ''),
|
||||
IF(number_of_bytes IS NOT NULL, CONCAT(' ', number_of_bytes, ' bytes'), ''),
|
||||
IF(event_name LIKE 'wait/io/file%', '\\n', ''),
|
||||
IF(object_schema IS NOT NULL, CONCAT('\\nObject: ', object_schema, '.'), ''),
|
||||
IF(object_name IS NOT NULL,
|
||||
IF (event_name LIKE 'wait/io/socket%',
|
||||
-- Print the socket if used, else the IP:port as reported
|
||||
CONCAT('\\n', IF (object_name LIKE ':0%', @@socket, object_name)),
|
||||
object_name),
|
||||
''
|
||||
),
|
||||
IF(index_name IS NOT NULL, CONCAT(' Index: ', index_name), ''), '\\n'
|
||||
) AS event_name,
|
||||
timer_wait, timer_start, nesting_event_id, source AS wait_info
|
||||
FROM performance_schema.events_waits_history_long
|
||||
WHERE thread_id = in_thread_id AND event_id > v_min_event_id)
|
||||
) events
|
||||
ORDER BY event_id;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
|
||||
|
||||
SET @log_bin := @@sql_log_bin;
|
||||
SET sql_log_bin = 0;
|
||||
|
||||
-- Do not track the current thread, it will kill the stack
|
||||
SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();
|
||||
CALL sys.ps_setup_disable_thread(CONNECTION_ID());
|
||||
|
||||
IF (in_auto_setup) THEN
|
||||
CALL sys.ps_setup_save(0);
|
||||
|
||||
-- Ensure only the thread to create the stack trace for is instrumented and that we instrument everything.
|
||||
DELETE FROM performance_schema.setup_actors;
|
||||
|
||||
UPDATE performance_schema.threads
|
||||
SET INSTRUMENTED = IF(THREAD_ID = in_thread_id, 'YES', 'NO');
|
||||
|
||||
-- only the %_history_long tables and it ancestors are needed
|
||||
UPDATE performance_schema.setup_consumers
|
||||
SET ENABLED = 'YES'
|
||||
WHERE NAME NOT LIKE '%\_history';
|
||||
|
||||
UPDATE performance_schema.setup_instruments
|
||||
SET ENABLED = 'YES',
|
||||
TIMED = 'YES';
|
||||
END IF;
|
||||
|
||||
IF (in_start_fresh) THEN
|
||||
TRUNCATE performance_schema.events_statements_history_long;
|
||||
TRUNCATE performance_schema.events_stages_history_long;
|
||||
TRUNCATE performance_schema.events_waits_history_long;
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_events;
|
||||
CREATE TEMPORARY TABLE tmp_events (
|
||||
event_id bigint unsigned NOT NULL,
|
||||
event longblob,
|
||||
PRIMARY KEY (event_id)
|
||||
);
|
||||
|
||||
-- Print headers for a .dot file
|
||||
INSERT INTO tmp_events VALUES (0, CONCAT('digraph events { rankdir=LR; nodesep=0.10;\n',
|
||||
'// Stack created .....: ', NOW(), '\n',
|
||||
'// MySQL version .....: ', VERSION(), '\n',
|
||||
'// MySQL hostname ....: ', @@hostname, '\n',
|
||||
'// MySQL port ........: ', @@port, '\n',
|
||||
'// MySQL socket ......: ', @@socket, '\n',
|
||||
'// MySQL user ........: ', CURRENT_USER(), '\n'));
|
||||
|
||||
SELECT CONCAT('Data collection starting for THREAD_ID = ', in_thread_id) AS 'Info';
|
||||
|
||||
SET v_min_event_id = 0,
|
||||
v_start = UNIX_TIMESTAMP(),
|
||||
in_interval = IFNULL(in_interval, 1.00),
|
||||
in_max_runtime = IFNULL(in_max_runtime, 60.00);
|
||||
|
||||
WHILE (v_runtime < in_max_runtime
|
||||
AND (SELECT INSTRUMENTED FROM performance_schema.threads WHERE THREAD_ID = in_thread_id) = 'YES') DO
|
||||
SET v_done = FALSE;
|
||||
OPEN c_stack;
|
||||
c_stack_loop: LOOP
|
||||
FETCH c_stack INTO v_event, v_min_event_id;
|
||||
IF v_done THEN
|
||||
LEAVE c_stack_loop;
|
||||
END IF;
|
||||
|
||||
IF (LENGTH(v_event) > 0) THEN
|
||||
INSERT INTO tmp_events VALUES (v_min_event_id, v_event);
|
||||
END IF;
|
||||
END LOOP;
|
||||
CLOSE c_stack;
|
||||
|
||||
SELECT SLEEP(in_interval) INTO @sleep;
|
||||
SET v_runtime = (UNIX_TIMESTAMP() - v_start);
|
||||
END WHILE;
|
||||
|
||||
INSERT INTO tmp_events VALUES (v_min_event_id+1, '}');
|
||||
|
||||
SET @query = CONCAT('SELECT event FROM tmp_events ORDER BY event_id INTO OUTFILE ''', in_outfile, ''' FIELDS ESCAPED BY '''' LINES TERMINATED BY ''''');
|
||||
PREPARE stmt_output FROM @query;
|
||||
EXECUTE stmt_output;
|
||||
DEALLOCATE PREPARE stmt_output;
|
||||
|
||||
SELECT CONCAT('Stack trace written to ', in_outfile) AS 'Info';
|
||||
SELECT CONCAT('dot -Tpdf -o /tmp/stack_', in_thread_id, '.pdf ', in_outfile) AS 'Convert to PDF';
|
||||
SELECT CONCAT('dot -Tpng -o /tmp/stack_', in_thread_id, '.png ', in_outfile) AS 'Convert to PNG';
|
||||
DROP TEMPORARY TABLE tmp_events;
|
||||
|
||||
-- Reset the settings for the performance schema
|
||||
IF (in_auto_setup) THEN
|
||||
CALL sys.ps_setup_reload_saved();
|
||||
END IF;
|
||||
-- Restore INSTRUMENTED for this thread
|
||||
IF (v_this_thread_enabed = 'YES') THEN
|
||||
CALL sys.ps_setup_enable_thread(CONNECTION_ID());
|
||||
END IF;
|
||||
|
||||
SET sql_log_bin = @log_bin;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
340
scripts/sys_schema/procedures/ps_trace_thread_57.sql
Normal file
340
scripts/sys_schema/procedures/ps_trace_thread_57.sql
Normal file
@ -0,0 +1,340 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_trace_thread;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_trace_thread (
|
||||
IN in_thread_id BIGINT UNSIGNED,
|
||||
IN in_outfile VARCHAR(255),
|
||||
IN in_max_runtime DECIMAL(20,2),
|
||||
IN in_interval DECIMAL(20,2),
|
||||
IN in_start_fresh BOOLEAN,
|
||||
IN in_auto_setup BOOLEAN,
|
||||
IN in_debug BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Dumps all data within Performance Schema for an instrumented thread,
|
||||
to create a DOT formatted graph file.
|
||||
|
||||
Each resultset returned from the procedure should be used for a complete graph
|
||||
|
||||
Requires the SUPER privilege for "SET sql_log_bin = 0;".
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_thread_id (BIGINT UNSIGNED):
|
||||
The thread that you would like a stack trace for
|
||||
in_outfile (VARCHAR(255)):
|
||||
The filename the dot file will be written to
|
||||
in_max_runtime (DECIMAL(20,2)):
|
||||
The maximum time to keep collecting data.
|
||||
Use NULL to get the default which is 60 seconds.
|
||||
in_interval (DECIMAL(20,2)):
|
||||
How long to sleep between data collections.
|
||||
Use NULL to get the default which is 1 second.
|
||||
in_start_fresh (BOOLEAN):
|
||||
Whether to reset all Performance Schema data before tracing.
|
||||
in_auto_setup (BOOLEAN):
|
||||
Whether to disable all other threads and enable all consumers/instruments.
|
||||
This will also reset the settings at the end of the run.
|
||||
in_debug (BOOLEAN):
|
||||
Whether you would like to include file:lineno in the graph
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_trace_thread(25, CONCAT(\'/tmp/stack-\', REPLACE(NOW(), \' \', \'-\'), \'.dot\'), NULL, NULL, TRUE, TRUE, TRUE);
|
||||
+-------------------+
|
||||
| summary |
|
||||
+-------------------+
|
||||
| Disabled 1 thread |
|
||||
+-------------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
+---------------------------------------------+
|
||||
| Info |
|
||||
+---------------------------------------------+
|
||||
| Data collection starting for THREAD_ID = 25 |
|
||||
+---------------------------------------------+
|
||||
1 row in set (0.03 sec)
|
||||
|
||||
+-----------------------------------------------------------+
|
||||
| Info |
|
||||
+-----------------------------------------------------------+
|
||||
| Stack trace written to /tmp/stack-2014-02-16-21:18:41.dot |
|
||||
+-----------------------------------------------------------+
|
||||
1 row in set (60.07 sec)
|
||||
|
||||
+-------------------------------------------------------------------+
|
||||
| Convert to PDF |
|
||||
+-------------------------------------------------------------------+
|
||||
| dot -Tpdf -o /tmp/stack_25.pdf /tmp/stack-2014-02-16-21:18:41.dot |
|
||||
+-------------------------------------------------------------------+
|
||||
1 row in set (60.07 sec)
|
||||
|
||||
+-------------------------------------------------------------------+
|
||||
| Convert to PNG |
|
||||
+-------------------------------------------------------------------+
|
||||
| dot -Tpng -o /tmp/stack_25.png /tmp/stack-2014-02-16-21:18:41.dot |
|
||||
+-------------------------------------------------------------------+
|
||||
1 row in set (60.07 sec)
|
||||
|
||||
+------------------+
|
||||
| summary |
|
||||
+------------------+
|
||||
| Enabled 1 thread |
|
||||
+------------------+
|
||||
1 row in set (60.32 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_done bool DEFAULT FALSE;
|
||||
DECLARE v_start, v_runtime DECIMAL(20,2) DEFAULT 0.0;
|
||||
DECLARE v_min_event_id bigint unsigned DEFAULT 0;
|
||||
DECLARE v_this_thread_enabed ENUM('YES', 'NO');
|
||||
DECLARE v_event longtext;
|
||||
DECLARE c_stack CURSOR FOR
|
||||
SELECT CONCAT(IF(nesting_event_id IS NOT NULL, CONCAT(nesting_event_id, ' -> '), ''),
|
||||
event_id, '; ', event_id, ' [label="',
|
||||
-- Convert from picoseconds to microseconds
|
||||
'(', sys.format_time(timer_wait), ') ',
|
||||
IF (event_name NOT LIKE 'wait/io%',
|
||||
SUBSTRING_INDEX(event_name, '/', -2),
|
||||
IF (event_name NOT LIKE 'wait/io/file%' OR event_name NOT LIKE 'wait/io/socket%',
|
||||
SUBSTRING_INDEX(event_name, '/', -4),
|
||||
event_name)
|
||||
),
|
||||
-- Always dump the extra wait information gathered for transactions and statements
|
||||
IF (event_name LIKE 'transaction', IFNULL(CONCAT('\\n', wait_info), ''), ''),
|
||||
IF (event_name LIKE 'statement/%', IFNULL(CONCAT('\\n', wait_info), ''), ''),
|
||||
-- If debug is enabled, add the file:lineno information for waits
|
||||
IF (in_debug AND event_name LIKE 'wait%', wait_info, ''),
|
||||
'", ',
|
||||
-- Depending on the type of event, style appropriately
|
||||
CASE WHEN event_name LIKE 'wait/io/file%' THEN
|
||||
'shape=box, style=filled, color=red'
|
||||
WHEN event_name LIKE 'wait/io/table%' THEN
|
||||
'shape=box, style=filled, color=green'
|
||||
WHEN event_name LIKE 'wait/io/socket%' THEN
|
||||
'shape=box, style=filled, color=yellow'
|
||||
WHEN event_name LIKE 'wait/synch/mutex%' THEN
|
||||
'style=filled, color=lightskyblue'
|
||||
WHEN event_name LIKE 'wait/synch/cond%' THEN
|
||||
'style=filled, color=darkseagreen3'
|
||||
WHEN event_name LIKE 'wait/synch/rwlock%' THEN
|
||||
'style=filled, color=orchid'
|
||||
WHEN event_name LIKE 'wait/synch/sxlock%' THEN
|
||||
'style=filled, color=palevioletred'
|
||||
WHEN event_name LIKE 'wait/lock%' THEN
|
||||
'shape=box, style=filled, color=tan'
|
||||
WHEN event_name LIKE 'statement/%' THEN
|
||||
CONCAT('shape=box, style=bold',
|
||||
-- Style statements depending on COM vs SQL
|
||||
CASE WHEN event_name LIKE 'statement/com/%' THEN
|
||||
' style=filled, color=darkseagreen'
|
||||
ELSE
|
||||
-- Use long query time from the server to
|
||||
-- flag long running statements in red
|
||||
IF((timer_wait/1000000000000) > @@long_query_time,
|
||||
' style=filled, color=red',
|
||||
' style=filled, color=lightblue')
|
||||
END
|
||||
)
|
||||
WHEN event_name LIKE 'transaction' THEN
|
||||
'shape=box, style=filled, color=lightblue3'
|
||||
WHEN event_name LIKE 'stage/%' THEN
|
||||
'style=filled, color=slategray3'
|
||||
-- IDLE events are on their own, call attention to them
|
||||
WHEN event_name LIKE '%idle%' THEN
|
||||
'shape=box, style=filled, color=firebrick3'
|
||||
ELSE '' END,
|
||||
'];\n'
|
||||
) event, event_id
|
||||
FROM (
|
||||
-- Select all transactions
|
||||
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,
|
||||
CONCAT('trx_id: ', IFNULL(trx_id, ''), '\\n',
|
||||
'gtid: ', IFNULL(gtid, ''), '\\n',
|
||||
'state: ', state, '\\n',
|
||||
'mode: ', access_mode, '\\n',
|
||||
'isolation: ', isolation_level, '\\n',
|
||||
'autocommit: ', autocommit, '\\n',
|
||||
'savepoints: ', number_of_savepoints, '\\n'
|
||||
) AS wait_info
|
||||
FROM performance_schema.events_transactions_history_long
|
||||
WHERE thread_id = in_thread_id AND event_id > v_min_event_id)
|
||||
UNION
|
||||
-- Select all statements, with the extra tracing information available
|
||||
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,
|
||||
CONCAT('statement: ', sql_text, '\\n',
|
||||
'errors: ', errors, '\\n',
|
||||
'warnings: ', warnings, '\\n',
|
||||
'lock time: ', sys.format_time(lock_time),'\\n',
|
||||
'rows affected: ', rows_affected, '\\n',
|
||||
'rows sent: ', rows_sent, '\\n',
|
||||
'rows examined: ', rows_examined, '\\n',
|
||||
'tmp tables: ', created_tmp_tables, '\\n',
|
||||
'tmp disk tables: ', created_tmp_disk_tables, '\\n'
|
||||
'select scan: ', select_scan, '\\n',
|
||||
'select full join: ', select_full_join, '\\n',
|
||||
'select full range join: ', select_full_range_join, '\\n',
|
||||
'select range: ', select_range, '\\n',
|
||||
'select range check: ', select_range_check, '\\n',
|
||||
'sort merge passes: ', sort_merge_passes, '\\n',
|
||||
'sort rows: ', sort_rows, '\\n',
|
||||
'sort range: ', sort_range, '\\n',
|
||||
'sort scan: ', sort_scan, '\\n',
|
||||
'no index used: ', IF(no_index_used, 'TRUE', 'FALSE'), '\\n',
|
||||
'no good index used: ', IF(no_good_index_used, 'TRUE', 'FALSE'), '\\n'
|
||||
) AS wait_info
|
||||
FROM performance_schema.events_statements_history_long
|
||||
WHERE thread_id = in_thread_id AND event_id > v_min_event_id)
|
||||
UNION
|
||||
-- Select all stages
|
||||
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info
|
||||
FROM performance_schema.events_stages_history_long
|
||||
WHERE thread_id = in_thread_id AND event_id > v_min_event_id)
|
||||
UNION
|
||||
-- Select all events, adding information appropriate to the event
|
||||
(SELECT thread_id, event_id,
|
||||
CONCAT(event_name,
|
||||
IF(event_name NOT LIKE 'wait/synch/mutex%', IFNULL(CONCAT(' - ', operation), ''), ''),
|
||||
IF(number_of_bytes IS NOT NULL, CONCAT(' ', number_of_bytes, ' bytes'), ''),
|
||||
IF(event_name LIKE 'wait/io/file%', '\\n', ''),
|
||||
IF(object_schema IS NOT NULL, CONCAT('\\nObject: ', object_schema, '.'), ''),
|
||||
IF(object_name IS NOT NULL,
|
||||
IF (event_name LIKE 'wait/io/socket%',
|
||||
-- Print the socket if used, else the IP:port as reported
|
||||
CONCAT('\\n', IF (object_name LIKE ':0%', @@socket, object_name)),
|
||||
object_name),
|
||||
''
|
||||
),
|
||||
IF(index_name IS NOT NULL, CONCAT(' Index: ', index_name), ''), '\\n'
|
||||
) AS event_name,
|
||||
timer_wait, timer_start, nesting_event_id, source AS wait_info
|
||||
FROM performance_schema.events_waits_history_long
|
||||
WHERE thread_id = in_thread_id AND event_id > v_min_event_id)
|
||||
) events
|
||||
ORDER BY event_id;
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
|
||||
|
||||
SET @log_bin := @@sql_log_bin;
|
||||
SET sql_log_bin = 0;
|
||||
|
||||
-- Do not track the current thread, it will kill the stack
|
||||
SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();
|
||||
CALL sys.ps_setup_disable_thread(CONNECTION_ID());
|
||||
|
||||
IF (in_auto_setup) THEN
|
||||
CALL sys.ps_setup_save(0);
|
||||
|
||||
-- Ensure only the thread to create the stack trace for is instrumented and that we instrument everything.
|
||||
DELETE FROM performance_schema.setup_actors;
|
||||
|
||||
UPDATE performance_schema.threads
|
||||
SET INSTRUMENTED = IF(THREAD_ID = in_thread_id, 'YES', 'NO');
|
||||
|
||||
-- only the %_history_long tables and it ancestors are needed
|
||||
UPDATE performance_schema.setup_consumers
|
||||
SET ENABLED = 'YES'
|
||||
WHERE NAME NOT LIKE '%\_history';
|
||||
|
||||
UPDATE performance_schema.setup_instruments
|
||||
SET ENABLED = 'YES',
|
||||
TIMED = 'YES';
|
||||
END IF;
|
||||
|
||||
IF (in_start_fresh) THEN
|
||||
TRUNCATE performance_schema.events_transactions_history_long;
|
||||
TRUNCATE performance_schema.events_statements_history_long;
|
||||
TRUNCATE performance_schema.events_stages_history_long;
|
||||
TRUNCATE performance_schema.events_waits_history_long;
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_events;
|
||||
CREATE TEMPORARY TABLE tmp_events (
|
||||
event_id bigint unsigned NOT NULL,
|
||||
event longblob,
|
||||
PRIMARY KEY (event_id)
|
||||
);
|
||||
|
||||
-- Print headers for a .dot file
|
||||
INSERT INTO tmp_events VALUES (0, CONCAT('digraph events { rankdir=LR; nodesep=0.10;\n',
|
||||
'// Stack created .....: ', NOW(), '\n',
|
||||
'// MySQL version .....: ', VERSION(), '\n',
|
||||
'// MySQL hostname ....: ', @@hostname, '\n',
|
||||
'// MySQL port ........: ', @@port, '\n',
|
||||
'// MySQL socket ......: ', @@socket, '\n',
|
||||
'// MySQL user ........: ', CURRENT_USER(), '\n'));
|
||||
|
||||
SELECT CONCAT('Data collection starting for THREAD_ID = ', in_thread_id) AS 'Info';
|
||||
|
||||
SET v_min_event_id = 0,
|
||||
v_start = UNIX_TIMESTAMP(),
|
||||
in_interval = IFNULL(in_interval, 1.00),
|
||||
in_max_runtime = IFNULL(in_max_runtime, 60.00);
|
||||
|
||||
WHILE (v_runtime < in_max_runtime
|
||||
AND (SELECT INSTRUMENTED FROM performance_schema.threads WHERE THREAD_ID = in_thread_id) = 'YES') DO
|
||||
SET v_done = FALSE;
|
||||
OPEN c_stack;
|
||||
c_stack_loop: LOOP
|
||||
FETCH c_stack INTO v_event, v_min_event_id;
|
||||
IF v_done THEN
|
||||
LEAVE c_stack_loop;
|
||||
END IF;
|
||||
|
||||
IF (LENGTH(v_event) > 0) THEN
|
||||
INSERT INTO tmp_events VALUES (v_min_event_id, v_event);
|
||||
END IF;
|
||||
END LOOP;
|
||||
CLOSE c_stack;
|
||||
|
||||
SELECT SLEEP(in_interval) INTO @sleep;
|
||||
SET v_runtime = (UNIX_TIMESTAMP() - v_start);
|
||||
END WHILE;
|
||||
|
||||
INSERT INTO tmp_events VALUES (v_min_event_id+1, '}');
|
||||
|
||||
SET @query = CONCAT('SELECT event FROM tmp_events ORDER BY event_id INTO OUTFILE ''', in_outfile, ''' FIELDS ESCAPED BY '''' LINES TERMINATED BY ''''');
|
||||
PREPARE stmt_output FROM @query;
|
||||
EXECUTE stmt_output;
|
||||
DEALLOCATE PREPARE stmt_output;
|
||||
|
||||
SELECT CONCAT('Stack trace written to ', in_outfile) AS 'Info';
|
||||
SELECT CONCAT('dot -Tpdf -o /tmp/stack_', in_thread_id, '.pdf ', in_outfile) AS 'Convert to PDF';
|
||||
SELECT CONCAT('dot -Tpng -o /tmp/stack_', in_thread_id, '.png ', in_outfile) AS 'Convert to PNG';
|
||||
DROP TEMPORARY TABLE tmp_events;
|
||||
|
||||
-- Reset the settings for the performance schema
|
||||
IF (in_auto_setup) THEN
|
||||
CALL sys.ps_setup_reload_saved();
|
||||
END IF;
|
||||
-- Restore INSTRUMENTED for this thread
|
||||
IF (v_this_thread_enabed = 'YES') THEN
|
||||
CALL sys.ps_setup_enable_thread(CONNECTION_ID());
|
||||
END IF;
|
||||
|
||||
SET sql_log_bin = @log_bin;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
90
scripts/sys_schema/procedures/ps_truncate_all_tables.sql
Normal file
90
scripts/sys_schema/procedures/ps_truncate_all_tables.sql
Normal file
@ -0,0 +1,90 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS ps_truncate_all_tables;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE ps_truncate_all_tables (
|
||||
IN in_verbose BOOLEAN
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Truncates all summary tables within Performance Schema,
|
||||
resetting all aggregated instrumentation as a snapshot.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_verbose (BOOLEAN):
|
||||
Whether to print each TRUNCATE statement before running
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
mysql> CALL sys.ps_truncate_all_tables(false);
|
||||
+---------------------+
|
||||
| summary |
|
||||
+---------------------+
|
||||
| Truncated 44 tables |
|
||||
+---------------------+
|
||||
1 row in set (0.10 sec)
|
||||
|
||||
Query OK, 0 rows affected (0.10 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
DETERMINISTIC
|
||||
MODIFIES SQL DATA
|
||||
BEGIN
|
||||
DECLARE v_done INT DEFAULT FALSE;
|
||||
DECLARE v_total_tables INT DEFAULT 0;
|
||||
DECLARE v_ps_table VARCHAR(64);
|
||||
DECLARE ps_tables CURSOR FOR
|
||||
SELECT table_name
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE table_schema = 'performance_schema'
|
||||
AND (table_name LIKE '%summary%'
|
||||
OR table_name LIKE '%history%');
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
|
||||
|
||||
OPEN ps_tables;
|
||||
|
||||
ps_tables_loop: LOOP
|
||||
FETCH ps_tables INTO v_ps_table;
|
||||
IF v_done THEN
|
||||
LEAVE ps_tables_loop;
|
||||
END IF;
|
||||
|
||||
SET @truncate_stmt := CONCAT('TRUNCATE TABLE performance_schema.', v_ps_table);
|
||||
IF in_verbose THEN
|
||||
SELECT CONCAT('Running: ', @truncate_stmt) AS status;
|
||||
END IF;
|
||||
|
||||
PREPARE truncate_stmt FROM @truncate_stmt;
|
||||
EXECUTE truncate_stmt;
|
||||
DEALLOCATE PREPARE truncate_stmt;
|
||||
|
||||
SET v_total_tables = v_total_tables + 1;
|
||||
END LOOP;
|
||||
|
||||
CLOSE ps_tables;
|
||||
|
||||
SELECT CONCAT('Truncated ', v_total_tables, ' tables') AS summary;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
723
scripts/sys_schema/procedures/statement_performance_analyzer.sql
Normal file
723
scripts/sys_schema/procedures/statement_performance_analyzer.sql
Normal file
@ -0,0 +1,723 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS statement_performance_analyzer;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE statement_performance_analyzer (
|
||||
IN in_action ENUM('snapshot', 'overall', 'delta', 'create_table', 'create_tmp', 'save', 'cleanup'),
|
||||
IN in_table VARCHAR(129),
|
||||
IN in_views SET ('with_runtimes_in_95th_percentile', 'analysis', 'with_errors_or_warnings', 'with_full_table_scans', 'with_sorting', 'with_temp_tables', 'custom')
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Create a report of the statements running on the server.
|
||||
|
||||
The views are calculated based on the overall and/or delta activity.
|
||||
|
||||
Requires the SUPER privilege for "SET sql_log_bin = 0;".
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_action (ENUM(''snapshot'', ''overall'', ''delta'', ''create_tmp'', ''create_table'', ''save'', ''cleanup'')):
|
||||
The action to take. Supported actions are:
|
||||
* snapshot Store a snapshot. The default is to make a snapshot of the current content of
|
||||
performance_schema.events_statements_summary_by_digest, but by setting in_table
|
||||
this can be overwritten to copy the content of the specified table.
|
||||
The snapshot is stored in the sys.tmp_digests temporary table.
|
||||
* overall Generate analyzis based on the content specified by in_table. For the overall analyzis,
|
||||
in_table can be NOW() to use a fresh snapshot. This will overwrite an existing snapshot.
|
||||
Use NULL for in_table to use the existing snapshot. If in_table IS NULL and no snapshot
|
||||
exists, a new will be created.
|
||||
See also in_views and @sys.statement_performance_analyzer.limit.
|
||||
* delta Generate a delta analysis. The delta will be calculated between the reference table in
|
||||
in_table and the snapshot. An existing snapshot must exist.
|
||||
The action uses the sys.tmp_digests_delta temporary table.
|
||||
See also in_views and @sys.statement_performance_analyzer.limit.
|
||||
* create_table Create a regular table suitable for storing the snapshot for later use, e.g. for
|
||||
calculating deltas.
|
||||
* create_tmp Create a temporary table suitable for storing the snapshot for later use, e.g. for
|
||||
calculating deltas.
|
||||
* save Save the snapshot in the table specified by in_table. The table must exists and have
|
||||
the correct structure.
|
||||
If no snapshot exists, a new is created.
|
||||
* cleanup Remove the temporary tables used for the snapshot and delta.
|
||||
|
||||
in_table (VARCHAR(129)):
|
||||
The table argument used for some actions. Use the format ''db1.t1'' or ''t1'' without using any backticks (`)
|
||||
for quoting. Periods (.) are not supported in the database and table names.
|
||||
|
||||
The meaning of the table for each action supporting the argument is:
|
||||
|
||||
* snapshot The snapshot is created based on the specified table. Set to NULL or NOW() to use
|
||||
the current content of performance_schema.events_statements_summary_by_digest.
|
||||
* overall The table with the content to create the overall analyzis for. The following values
|
||||
can be used:
|
||||
- A table name - use the content of that table.
|
||||
- NOW() - create a fresh snapshot and overwrite the existing snapshot.
|
||||
- NULL - use the last stored snapshot.
|
||||
* delta The table name is mandatory and specified the reference view to compare the currently
|
||||
stored snapshot against. If no snapshot exists, a new will be created.
|
||||
* create_table The name of the regular table to create.
|
||||
* create_tmp The name of the temporary table to create.
|
||||
* save The name of the table to save the currently stored snapshot into.
|
||||
|
||||
in_views (SET (''with_runtimes_in_95th_percentile'', ''analysis'', ''with_errors_or_warnings'',
|
||||
''with_full_table_scans'', ''with_sorting'', ''with_temp_tables'', ''custom''))
|
||||
Which views to include:
|
||||
|
||||
* with_runtimes_in_95th_percentile Based on the sys.statements_with_runtimes_in_95th_percentile view
|
||||
* analysis Based on the sys.statement_analysis view
|
||||
* with_errors_or_warnings Based on the sys.statements_with_errors_or_warnings view
|
||||
* with_full_table_scans Based on the sys.statements_with_full_table_scans view
|
||||
* with_sorting Based on the sys.statements_with_sorting view
|
||||
* with_temp_tables Based on the sys.statements_with_temp_tables view
|
||||
* custom Use a custom view. This view must be specified in @sys.statement_performance_analyzer.view to an existing view or a query
|
||||
|
||||
Default is to include all except ''custom''.
|
||||
|
||||
|
||||
Configuration Options
|
||||
----------------------
|
||||
|
||||
sys.statement_performance_analyzer.limit
|
||||
The maximum number of rows to include for the views that does not have a built-in limit (e.g. the 95th percentile view).
|
||||
If not set the limit is 100.
|
||||
|
||||
sys.statement_performance_analyzer.view
|
||||
Used together with the ''custom'' view. If the value contains a space, it is considered a query, otherwise it must be
|
||||
an existing view querying the performance_schema.events_statements_summary_by_digest table. There cannot be any limit
|
||||
clause including in the query or view definition if @sys.statement_performance_analyzer.limit > 0.
|
||||
If specifying a view, use the same format as for in_table.
|
||||
|
||||
sys.debug
|
||||
Whether to provide debugging output.
|
||||
Default is ''OFF''. Set to ''ON'' to include.
|
||||
|
||||
|
||||
Example
|
||||
--------
|
||||
|
||||
To create a report with the queries in the 95th percentile since last truncate of performance_schema.events_statements_summary_by_digest
|
||||
and the delta for a 1 minute period:
|
||||
|
||||
1. Create a temporary table to store the initial snapshot.
|
||||
2. Create the initial snapshot.
|
||||
3. Save the initial snapshot in the temporary table.
|
||||
4. Wait one minute.
|
||||
5. Create a new snapshot.
|
||||
6. Perform analyzis based on the new snapshot.
|
||||
7. Perform analyzis based on the delta between the initial and new snapshots.
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''create_tmp'', ''mydb.tmp_digests_ini'', NULL);
|
||||
Query OK, 0 rows affected (0.08 sec)
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''snapshot'', NULL, NULL);
|
||||
Query OK, 0 rows affected (0.02 sec)
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''save'', ''mydb.tmp_digests_ini'', NULL);
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
mysql> DO SLEEP(60);
|
||||
Query OK, 0 rows affected (1 min 0.00 sec)
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''snapshot'', NULL, NULL);
|
||||
Query OK, 0 rows affected (0.02 sec)
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''overall'', NULL, ''with_runtimes_in_95th_percentile'');
|
||||
+-----------------------------------------+
|
||||
| Next Output |
|
||||
+-----------------------------------------+
|
||||
| Queries with Runtime in 95th Percentile |
|
||||
+-----------------------------------------+
|
||||
1 row in set (0.05 sec)
|
||||
|
||||
...
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''delta'', ''mydb.tmp_digests_ini'', ''with_runtimes_in_95th_percentile'');
|
||||
+-----------------------------------------+
|
||||
| Next Output |
|
||||
+-----------------------------------------+
|
||||
| Queries with Runtime in 95th Percentile |
|
||||
+-----------------------------------------+
|
||||
1 row in set (0.03 sec)
|
||||
|
||||
...
|
||||
|
||||
|
||||
To create an overall report of the 95th percentile queries and the top 10 queries with full table scans:
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''snapshot'', NULL, NULL);
|
||||
Query OK, 0 rows affected (0.01 sec)
|
||||
|
||||
mysql> SET @sys.statement_performance_analyzer.limit = 10;
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''overall'', NULL, ''with_runtimes_in_95th_percentile,with_full_table_scans'');
|
||||
+-----------------------------------------+
|
||||
| Next Output |
|
||||
+-----------------------------------------+
|
||||
| Queries with Runtime in 95th Percentile |
|
||||
+-----------------------------------------+
|
||||
1 row in set (0.01 sec)
|
||||
|
||||
...
|
||||
|
||||
+-------------------------------------+
|
||||
| Next Output |
|
||||
+-------------------------------------+
|
||||
| Top 10 Queries with Full Table Scan |
|
||||
+-------------------------------------+
|
||||
1 row in set (0.09 sec)
|
||||
|
||||
...
|
||||
|
||||
|
||||
Use a custom view showing the top 10 query sorted by total execution time refreshing the view every minute using
|
||||
the watch command in Linux.
|
||||
|
||||
mysql> CREATE OR REPLACE VIEW mydb.my_statements AS
|
||||
-> SELECT sys.format_statement(DIGEST_TEXT) AS query,
|
||||
-> SCHEMA_NAME AS db,
|
||||
-> COUNT_STAR AS exec_count,
|
||||
-> sys.format_time(SUM_TIMER_WAIT) AS total_latency,
|
||||
-> sys.format_time(AVG_TIMER_WAIT) AS avg_latency,
|
||||
-> ROUND(IFNULL(SUM_ROWS_SENT / NULLIF(COUNT_STAR, 0), 0)) AS rows_sent_avg,
|
||||
-> ROUND(IFNULL(SUM_ROWS_EXAMINED / NULLIF(COUNT_STAR, 0), 0)) AS rows_examined_avg,
|
||||
-> ROUND(IFNULL(SUM_ROWS_AFFECTED / NULLIF(COUNT_STAR, 0), 0)) AS rows_affected_avg,
|
||||
-> DIGEST AS digest
|
||||
-> FROM performance_schema.events_statements_summary_by_digest
|
||||
-> ORDER BY SUM_TIMER_WAIT DESC;
|
||||
Query OK, 0 rows affected (0.01 sec)
|
||||
|
||||
mysql> CALL sys.statement_performance_analyzer(''create_table'', ''mydb.digests_prev'', NULL);
|
||||
Query OK, 0 rows affected (0.10 sec)
|
||||
|
||||
shell$ watch -n 60 "mysql sys --table -e \"
|
||||
> SET @sys.statement_performance_analyzer.view = ''mydb.my_statements'';
|
||||
> SET @sys.statement_performance_analyzer.limit = 10;
|
||||
> CALL statement_performance_analyzer(''snapshot'', NULL, NULL);
|
||||
> CALL statement_performance_analyzer(''delta'', ''mydb.digests_prev'', ''custom'');
|
||||
> CALL statement_performance_analyzer(''save'', ''mydb.digests_prev'', NULL);
|
||||
> \""
|
||||
|
||||
Every 60.0s: mysql sys --table -e " ... Mon Dec 22 10:58:51 2014
|
||||
|
||||
+----------------------------------+
|
||||
| Next Output |
|
||||
+----------------------------------+
|
||||
| Top 10 Queries Using Custom View |
|
||||
+----------------------------------+
|
||||
+-------------------+-------+------------+---------------+-------------+---------------+-------------------+-------------------+----------------------------------+
|
||||
| query | db | exec_count | total_latency | avg_latency | rows_sent_avg | rows_examined_avg | rows_affected_avg | digest |
|
||||
+-------------------+-------+------------+---------------+-------------+---------------+-------------------+-------------------+----------------------------------+
|
||||
...
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
CONTAINS SQL
|
||||
BEGIN
|
||||
DECLARE v_table_exists, v_tmp_digests_table_exists, v_custom_view_exists ENUM('', 'BASE TABLE', 'VIEW', 'TEMPORARY') DEFAULT '';
|
||||
DECLARE v_this_thread_enabled ENUM('YES', 'NO');
|
||||
DECLARE v_force_new_snapshot BOOLEAN DEFAULT FALSE;
|
||||
DECLARE v_digests_table VARCHAR(133);
|
||||
DECLARE v_quoted_table, v_quoted_custom_view VARCHAR(133) DEFAULT '';
|
||||
DECLARE v_table_db, v_table_name, v_custom_db, v_custom_name VARCHAR(64);
|
||||
DECLARE v_digest_table_template, v_checksum_ref, v_checksum_table text;
|
||||
DECLARE v_sql longtext;
|
||||
-- Maximum supported length for MESSAGE_TEXT with the SIGNAL command is 128 chars.
|
||||
DECLARE v_error_msg VARCHAR(128);
|
||||
|
||||
|
||||
-- Don't instrument this thread
|
||||
SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();
|
||||
IF (v_this_thread_enabled = 'YES') THEN
|
||||
CALL sys.ps_setup_disable_thread(CONNECTION_ID());
|
||||
END IF;
|
||||
|
||||
-- Temporary table are used - disable sql_log_bin if necessary to prevent them replicating
|
||||
SET @log_bin := @@sql_log_bin;
|
||||
IF (@log_bin = 1) THEN
|
||||
SET sql_log_bin = 0;
|
||||
END IF;
|
||||
|
||||
|
||||
-- Set configuration options
|
||||
IF (@sys.statement_performance_analyzer.limit IS NULL) THEN
|
||||
SET @sys.statement_performance_analyzer.limit = sys.sys_get_config('statement_performance_analyzer.limit', '100');
|
||||
END IF;
|
||||
IF (@sys.debug IS NULL) THEN
|
||||
SET @sys.debug = sys.sys_get_config('debug' , 'OFF');
|
||||
END IF;
|
||||
|
||||
|
||||
-- If in_table is set, break in_table into a db and table component and check whether it exists
|
||||
-- in_table = NOW() is considered like it's not set.
|
||||
IF (in_table = 'NOW()') THEN
|
||||
SET v_force_new_snapshot = TRUE,
|
||||
in_table = NULL;
|
||||
ELSEIF (in_table IS NOT NULL) THEN
|
||||
IF (NOT INSTR(in_table, '.')) THEN
|
||||
-- No . in the table name - use current database
|
||||
-- DATABASE() will be the database of the procedure
|
||||
SET v_table_db = DATABASE(),
|
||||
v_table_name = in_table;
|
||||
ELSE
|
||||
SET v_table_db = SUBSTRING_INDEX(in_table, '.', 1);
|
||||
SET v_table_name = SUBSTRING(in_table, CHAR_LENGTH(v_table_db)+2);
|
||||
END IF;
|
||||
|
||||
SET v_quoted_table = CONCAT('`', v_table_db, '`.`', v_table_name, '`');
|
||||
|
||||
IF (@sys.debug = 'ON') THEN
|
||||
SELECT CONCAT('in_table is: db = ''', v_table_db, ''', table = ''', v_table_name, '''') AS 'Debug';
|
||||
END IF;
|
||||
|
||||
IF (v_table_db = DATABASE() AND (v_table_name = 'tmp_digests' OR v_table_name = 'tmp_digests_delta')) THEN
|
||||
SET v_error_msg = CONCAT('Invalid value for in_table: ', v_quoted_table, ' is reserved table name.');
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = v_error_msg;
|
||||
END IF;
|
||||
|
||||
CALL sys.table_exists(v_table_db, v_table_name, v_table_exists);
|
||||
IF (@sys.debug = 'ON') THEN
|
||||
SELECT CONCAT('v_table_exists = ', v_table_exists) AS 'Debug';
|
||||
END IF;
|
||||
|
||||
IF (v_table_exists = 'BASE TABLE') THEN
|
||||
-- Verify that the table has the correct table definition
|
||||
-- This can only be done for base tables as temporary aren't in information_schema.COLUMNS.
|
||||
-- This also minimises the risk of using a production table.
|
||||
SET v_checksum_ref = (
|
||||
SELECT GROUP_CONCAT(CONCAT(COLUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'performance_schema' AND TABLE_NAME = 'events_statements_summary_by_digest'
|
||||
),
|
||||
v_checksum_table = (
|
||||
SELECT GROUP_CONCAT(CONCAT(COLUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = v_table_db AND TABLE_NAME = v_table_name
|
||||
);
|
||||
|
||||
IF (v_checksum_ref <> v_checksum_table) THEN
|
||||
-- The table does not have the correct definition, so abandon
|
||||
SET v_error_msg = CONCAT('The table ',
|
||||
IF(CHAR_LENGTH(v_quoted_table) > 93, CONCAT('...', SUBSTRING(v_quoted_table, -90)), v_quoted_table),
|
||||
' has the wrong definition.');
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = v_error_msg;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
|
||||
IF (in_views IS NULL OR in_views = '') THEN
|
||||
-- Set to default
|
||||
SET in_views = 'with_runtimes_in_95th_percentile,analysis,with_errors_or_warnings,with_full_table_scans,with_sorting,with_temp_tables';
|
||||
END IF;
|
||||
|
||||
|
||||
-- Validate settings
|
||||
CALL sys.table_exists(DATABASE(), 'tmp_digests', v_tmp_digests_table_exists);
|
||||
IF (@sys.debug = 'ON') THEN
|
||||
SELECT CONCAT('v_tmp_digests_table_exists = ', v_tmp_digests_table_exists) AS 'Debug';
|
||||
END IF;
|
||||
|
||||
CASE
|
||||
WHEN in_action IN ('snapshot', 'overall') THEN
|
||||
-- in_table must be NULL, NOW(), or an existing table
|
||||
IF (in_table IS NOT NULL) THEN
|
||||
IF (NOT v_table_exists IN ('TEMPORARY', 'BASE TABLE')) THEN
|
||||
SET v_error_msg = CONCAT('The ', in_action, ' action requires in_table to be NULL, NOW() or specify an existing table.',
|
||||
' The table ',
|
||||
IF(CHAR_LENGTH(v_quoted_table) > 16, CONCAT('...', SUBSTRING(v_quoted_table, -13)), v_quoted_table),
|
||||
' does not exist.');
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = v_error_msg;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
WHEN in_action IN ('delta', 'save') THEN
|
||||
-- in_table must be an existing table
|
||||
IF (v_table_exists NOT IN ('TEMPORARY', 'BASE TABLE')) THEN
|
||||
SET v_error_msg = CONCAT('The ', in_action, ' action requires in_table to be an existing table.',
|
||||
IF(in_table IS NOT NULL, CONCAT(' The table ',
|
||||
IF(CHAR_LENGTH(v_quoted_table) > 39, CONCAT('...', SUBSTRING(v_quoted_table, -36)), v_quoted_table),
|
||||
' does not exist.'), ''));
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = v_error_msg;
|
||||
END IF;
|
||||
|
||||
IF (in_action = 'delta' AND v_tmp_digests_table_exists <> 'TEMPORARY') THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'An existing snapshot generated with the statement_performance_analyzer() must exist.';
|
||||
END IF;
|
||||
WHEN in_action = 'create_tmp' THEN
|
||||
-- in_table must not exists as a temporary table
|
||||
IF (v_table_exists = 'TEMPORARY') THEN
|
||||
SET v_error_msg = CONCAT('Cannot create the table ',
|
||||
IF(CHAR_LENGTH(v_quoted_table) > 72, CONCAT('...', SUBSTRING(v_quoted_table, -69)), v_quoted_table),
|
||||
' as it already exists.');
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = v_error_msg;
|
||||
END IF;
|
||||
|
||||
WHEN in_action = 'create_table' THEN
|
||||
-- in_table must not exists at all
|
||||
IF (v_table_exists <> '') THEN
|
||||
SET v_error_msg = CONCAT('Cannot create the table ',
|
||||
IF(CHAR_LENGTH(v_quoted_table) > 52, CONCAT('...', SUBSTRING(v_quoted_table, -49)), v_quoted_table),
|
||||
' as it already exists',
|
||||
IF(v_table_exists = 'TEMPORARY', ' as a temporary table.', '.'));
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = v_error_msg;
|
||||
END IF;
|
||||
|
||||
WHEN in_action = 'cleanup' THEN
|
||||
-- doesn't use any of the arguments
|
||||
DO (SELECT 1);
|
||||
ELSE
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'Unknown action. Supported actions are: cleanup, create_table, create_tmp, delta, overall, save, snapshot';
|
||||
END CASE;
|
||||
|
||||
SET v_digest_table_template = 'CREATE %{TEMPORARY}TABLE %{TABLE_NAME} (
|
||||
`SCHEMA_NAME` varchar(64) DEFAULT NULL,
|
||||
`DIGEST` varchar(32) DEFAULT NULL,
|
||||
`DIGEST_TEXT` longtext,
|
||||
`COUNT_STAR` bigint(20) unsigned NOT NULL,
|
||||
`SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL,
|
||||
`MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL,
|
||||
`AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL,
|
||||
`MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL,
|
||||
`SUM_LOCK_TIME` bigint(20) unsigned NOT NULL,
|
||||
`SUM_ERRORS` bigint(20) unsigned NOT NULL,
|
||||
`SUM_WARNINGS` bigint(20) unsigned NOT NULL,
|
||||
`SUM_ROWS_AFFECTED` bigint(20) unsigned NOT NULL,
|
||||
`SUM_ROWS_SENT` bigint(20) unsigned NOT NULL,
|
||||
`SUM_ROWS_EXAMINED` bigint(20) unsigned NOT NULL,
|
||||
`SUM_CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,
|
||||
`SUM_CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SELECT_RANGE` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SELECT_SCAN` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SORT_RANGE` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SORT_ROWS` bigint(20) unsigned NOT NULL,
|
||||
`SUM_SORT_SCAN` bigint(20) unsigned NOT NULL,
|
||||
`SUM_NO_INDEX_USED` bigint(20) unsigned NOT NULL,
|
||||
`SUM_NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,
|
||||
`FIRST_SEEN` timestamp NULL DEFAULT NULL,
|
||||
`LAST_SEEN` timestamp NULL DEFAULT NULL,
|
||||
INDEX (SCHEMA_NAME, DIGEST)
|
||||
) DEFAULT CHARSET=utf8';
|
||||
|
||||
-- Do the action
|
||||
-- The actions snapshot, ... requires a fresh snapshot - create it now
|
||||
IF (v_force_new_snapshot
|
||||
OR in_action = 'snapshot'
|
||||
OR (in_action = 'overall' AND in_table IS NULL)
|
||||
OR (in_action = 'save' AND v_tmp_digests_table_exists <> 'TEMPORARY')
|
||||
) THEN
|
||||
IF (v_tmp_digests_table_exists = 'TEMPORARY') THEN
|
||||
IF (@sys.debug = 'ON') THEN
|
||||
SELECT 'DROP TEMPORARY TABLE IF EXISTS tmp_digests' AS 'Debug';
|
||||
END IF;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_digests;
|
||||
END IF;
|
||||
CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, '%{TEMPORARY}', 'TEMPORARY '), '%{TABLE_NAME}', 'tmp_digests'));
|
||||
|
||||
SET v_sql = CONCAT('INSERT INTO tmp_digests SELECT * FROM ',
|
||||
IF(in_table IS NULL OR in_action = 'save', 'performance_schema.events_statements_summary_by_digest', v_quoted_table));
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
|
||||
-- Go through the remaining actions
|
||||
IF (in_action IN ('create_table', 'create_tmp')) THEN
|
||||
IF (in_action = 'create_table') THEN
|
||||
CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, '%{TEMPORARY}', ''), '%{TABLE_NAME}', v_quoted_table));
|
||||
ELSE
|
||||
CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, '%{TEMPORARY}', 'TEMPORARY '), '%{TABLE_NAME}', v_quoted_table));
|
||||
END IF;
|
||||
ELSEIF (in_action = 'save') THEN
|
||||
CALL sys.execute_prepared_stmt(CONCAT('DELETE FROM ', v_quoted_table));
|
||||
CALL sys.execute_prepared_stmt(CONCAT('INSERT INTO ', v_quoted_table, ' SELECT * FROM tmp_digests'));
|
||||
ELSEIF (in_action = 'cleanup') THEN
|
||||
DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests;
|
||||
DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests_delta;
|
||||
ELSEIF (in_action IN ('overall', 'delta')) THEN
|
||||
-- These are almost the same - for delta calculate the delta in tmp_digests_delta and use that instead of tmp_digests.
|
||||
-- And overall allows overriding the table to use.
|
||||
IF (in_action = 'overall') THEN
|
||||
IF (in_table IS NULL) THEN
|
||||
SET v_digests_table = 'tmp_digests';
|
||||
ELSE
|
||||
SET v_digests_table = v_quoted_table;
|
||||
END IF;
|
||||
ELSE
|
||||
SET v_digests_table = 'tmp_digests_delta';
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_digests_delta;
|
||||
CREATE TEMPORARY TABLE tmp_digests_delta LIKE tmp_digests;
|
||||
SET v_sql = CONCAT('INSERT INTO tmp_digests_delta
|
||||
SELECT `d_end`.`SCHEMA_NAME`,
|
||||
`d_end`.`DIGEST`,
|
||||
`d_end`.`DIGEST_TEXT`,
|
||||
`d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0) AS ''COUNT_STAR'',
|
||||
`d_end`.`SUM_TIMER_WAIT`-IFNULL(`d_start`.`SUM_TIMER_WAIT`, 0) AS ''SUM_TIMER_WAIT'',
|
||||
`d_end`.`MIN_TIMER_WAIT` AS ''MIN_TIMER_WAIT'',
|
||||
IFNULL((`d_end`.`SUM_TIMER_WAIT`-IFNULL(`d_start`.`SUM_TIMER_WAIT`, 0))/NULLIF(`d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0), 0), 0) AS ''AVG_TIMER_WAIT'',
|
||||
`d_end`.`MAX_TIMER_WAIT` AS ''MAX_TIMER_WAIT'',
|
||||
`d_end`.`SUM_LOCK_TIME`-IFNULL(`d_start`.`SUM_LOCK_TIME`, 0) AS ''SUM_LOCK_TIME'',
|
||||
`d_end`.`SUM_ERRORS`-IFNULL(`d_start`.`SUM_ERRORS`, 0) AS ''SUM_ERRORS'',
|
||||
`d_end`.`SUM_WARNINGS`-IFNULL(`d_start`.`SUM_WARNINGS`, 0) AS ''SUM_WARNINGS'',
|
||||
`d_end`.`SUM_ROWS_AFFECTED`-IFNULL(`d_start`.`SUM_ROWS_AFFECTED`, 0) AS ''SUM_ROWS_AFFECTED'',
|
||||
`d_end`.`SUM_ROWS_SENT`-IFNULL(`d_start`.`SUM_ROWS_SENT`, 0) AS ''SUM_ROWS_SENT'',
|
||||
`d_end`.`SUM_ROWS_EXAMINED`-IFNULL(`d_start`.`SUM_ROWS_EXAMINED`, 0) AS ''SUM_ROWS_EXAMINED'',
|
||||
`d_end`.`SUM_CREATED_TMP_DISK_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_DISK_TABLES`, 0) AS ''SUM_CREATED_TMP_DISK_TABLES'',
|
||||
`d_end`.`SUM_CREATED_TMP_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_TABLES`, 0) AS ''SUM_CREATED_TMP_TABLES'',
|
||||
`d_end`.`SUM_SELECT_FULL_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_JOIN`, 0) AS ''SUM_SELECT_FULL_JOIN'',
|
||||
`d_end`.`SUM_SELECT_FULL_RANGE_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_RANGE_JOIN`, 0) AS ''SUM_SELECT_FULL_RANGE_JOIN'',
|
||||
`d_end`.`SUM_SELECT_RANGE`-IFNULL(`d_start`.`SUM_SELECT_RANGE`, 0) AS ''SUM_SELECT_RANGE'',
|
||||
`d_end`.`SUM_SELECT_RANGE_CHECK`-IFNULL(`d_start`.`SUM_SELECT_RANGE_CHECK`, 0) AS ''SUM_SELECT_RANGE_CHECK'',
|
||||
`d_end`.`SUM_SELECT_SCAN`-IFNULL(`d_start`.`SUM_SELECT_SCAN`, 0) AS ''SUM_SELECT_SCAN'',
|
||||
`d_end`.`SUM_SORT_MERGE_PASSES`-IFNULL(`d_start`.`SUM_SORT_MERGE_PASSES`, 0) AS ''SUM_SORT_MERGE_PASSES'',
|
||||
`d_end`.`SUM_SORT_RANGE`-IFNULL(`d_start`.`SUM_SORT_RANGE`, 0) AS ''SUM_SORT_RANGE'',
|
||||
`d_end`.`SUM_SORT_ROWS`-IFNULL(`d_start`.`SUM_SORT_ROWS`, 0) AS ''SUM_SORT_ROWS'',
|
||||
`d_end`.`SUM_SORT_SCAN`-IFNULL(`d_start`.`SUM_SORT_SCAN`, 0) AS ''SUM_SORT_SCAN'',
|
||||
`d_end`.`SUM_NO_INDEX_USED`-IFNULL(`d_start`.`SUM_NO_INDEX_USED`, 0) AS ''SUM_NO_INDEX_USED'',
|
||||
`d_end`.`SUM_NO_GOOD_INDEX_USED`-IFNULL(`d_start`.`SUM_NO_GOOD_INDEX_USED`, 0) AS ''SUM_NO_GOOD_INDEX_USED'',
|
||||
`d_end`.`FIRST_SEEN`,
|
||||
`d_end`.`LAST_SEEN`
|
||||
FROM tmp_digests d_end
|
||||
LEFT OUTER JOIN ', v_quoted_table, ' d_start ON `d_start`.`DIGEST` = `d_end`.`DIGEST`
|
||||
AND (`d_start`.`SCHEMA_NAME` = `d_end`.`SCHEMA_NAME`
|
||||
OR (`d_start`.`SCHEMA_NAME` IS NULL AND `d_end`.`SCHEMA_NAME` IS NULL)
|
||||
)
|
||||
WHERE `d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0) > 0');
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
|
||||
IF (FIND_IN_SET('with_runtimes_in_95th_percentile', in_views)) THEN
|
||||
SELECT 'Queries with Runtime in 95th Percentile' AS 'Next Output';
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_digest_avg_latency_distribution1;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_digest_avg_latency_distribution2;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp_digest_95th_percentile_by_avg_us;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_digest_avg_latency_distribution1 (
|
||||
cnt bigint unsigned NOT NULL,
|
||||
avg_us decimal(21,0) NOT NULL,
|
||||
PRIMARY KEY (avg_us)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
SET v_sql = CONCAT('INSERT INTO tmp_digest_avg_latency_distribution1
|
||||
SELECT COUNT(*) cnt,
|
||||
ROUND(avg_timer_wait/1000000) AS avg_us
|
||||
FROM ', v_digests_table, '
|
||||
GROUP BY avg_us');
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_digest_avg_latency_distribution2 LIKE tmp_digest_avg_latency_distribution1;
|
||||
INSERT INTO tmp_digest_avg_latency_distribution2 SELECT * FROM tmp_digest_avg_latency_distribution1;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp_digest_95th_percentile_by_avg_us (
|
||||
avg_us decimal(21,0) NOT NULL,
|
||||
percentile decimal(46,4) NOT NULL,
|
||||
PRIMARY KEY (avg_us)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
SET v_sql = CONCAT('INSERT INTO tmp_digest_95th_percentile_by_avg_us
|
||||
SELECT s2.avg_us avg_us,
|
||||
IFNULL(SUM(s1.cnt)/NULLIF((SELECT COUNT(*) FROM ', v_digests_table, '), 0), 0) percentile
|
||||
FROM tmp_digest_avg_latency_distribution1 AS s1
|
||||
JOIN tmp_digest_avg_latency_distribution2 AS s2 ON s1.avg_us <= s2.avg_us
|
||||
GROUP BY s2.avg_us
|
||||
HAVING percentile > 0.95
|
||||
ORDER BY percentile
|
||||
LIMIT 1');
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
|
||||
SET v_sql =
|
||||
REPLACE(
|
||||
REPLACE(
|
||||
(SELECT VIEW_DEFINITION
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_runtimes_in_95th_percentile'
|
||||
),
|
||||
'`performance_schema`.`events_statements_summary_by_digest`',
|
||||
v_digests_table
|
||||
),
|
||||
'sys.x$ps_digest_95th_percentile_by_avg_us',
|
||||
'`sys`.`x$ps_digest_95th_percentile_by_avg_us`'
|
||||
);
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
|
||||
DROP TEMPORARY TABLE tmp_digest_avg_latency_distribution1;
|
||||
DROP TEMPORARY TABLE tmp_digest_avg_latency_distribution2;
|
||||
DROP TEMPORARY TABLE tmp_digest_95th_percentile_by_avg_us;
|
||||
END IF;
|
||||
|
||||
IF (FIND_IN_SET('analysis', in_views)) THEN
|
||||
SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries Ordered by Total Latency') AS 'Next Output';
|
||||
SET v_sql =
|
||||
REPLACE(
|
||||
(SELECT VIEW_DEFINITION
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statement_analysis'
|
||||
),
|
||||
'`performance_schema`.`events_statements_summary_by_digest`',
|
||||
v_digests_table
|
||||
);
|
||||
IF (@sys.statement_performance_analyzer.limit > 0) THEN
|
||||
SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit);
|
||||
END IF;
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
|
||||
IF (FIND_IN_SET('with_errors_or_warnings', in_views)) THEN
|
||||
SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries with Errors') AS 'Next Output';
|
||||
SET v_sql =
|
||||
REPLACE(
|
||||
(SELECT VIEW_DEFINITION
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_errors_or_warnings'
|
||||
),
|
||||
'`performance_schema`.`events_statements_summary_by_digest`',
|
||||
v_digests_table
|
||||
);
|
||||
IF (@sys.statement_performance_analyzer.limit > 0) THEN
|
||||
SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit);
|
||||
END IF;
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
|
||||
IF (FIND_IN_SET('with_full_table_scans', in_views)) THEN
|
||||
SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries with Full Table Scan') AS 'Next Output';
|
||||
SET v_sql =
|
||||
REPLACE(
|
||||
(SELECT VIEW_DEFINITION
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_full_table_scans'
|
||||
),
|
||||
'`performance_schema`.`events_statements_summary_by_digest`',
|
||||
v_digests_table
|
||||
);
|
||||
IF (@sys.statement_performance_analyzer.limit > 0) THEN
|
||||
SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit);
|
||||
END IF;
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
|
||||
IF (FIND_IN_SET('with_sorting', in_views)) THEN
|
||||
SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries with Sorting') AS 'Next Output';
|
||||
SET v_sql =
|
||||
REPLACE(
|
||||
(SELECT VIEW_DEFINITION
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_sorting'
|
||||
),
|
||||
'`performance_schema`.`events_statements_summary_by_digest`',
|
||||
v_digests_table
|
||||
);
|
||||
IF (@sys.statement_performance_analyzer.limit > 0) THEN
|
||||
SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit);
|
||||
END IF;
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
|
||||
IF (FIND_IN_SET('with_temp_tables', in_views)) THEN
|
||||
SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries with Internal Temporary Tables') AS 'Next Output';
|
||||
SET v_sql =
|
||||
REPLACE(
|
||||
(SELECT VIEW_DEFINITION
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_temp_tables'
|
||||
),
|
||||
'`performance_schema`.`events_statements_summary_by_digest`',
|
||||
v_digests_table
|
||||
);
|
||||
IF (@sys.statement_performance_analyzer.limit > 0) THEN
|
||||
SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit);
|
||||
END IF;
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
|
||||
IF (FIND_IN_SET('custom', in_views)) THEN
|
||||
SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries Using Custom View') AS 'Next Output';
|
||||
|
||||
IF (@sys.statement_performance_analyzer.view IS NULL) THEN
|
||||
SET @sys.statement_performance_analyzer.view = sys.sys_get_config('statement_performance_analyzer.view', NULL);
|
||||
END IF;
|
||||
IF (@sys.statement_performance_analyzer.view IS NULL) THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'The @sys.statement_performance_analyzer.view user variable must be set with the view or query to use.';
|
||||
END IF;
|
||||
|
||||
IF (NOT INSTR(@sys.statement_performance_analyzer.view, ' ')) THEN
|
||||
-- No spaces, so can't be a query
|
||||
IF (NOT INSTR(@sys.statement_performance_analyzer.view, '.')) THEN
|
||||
-- No . in the table name - use current database
|
||||
-- DATABASE() will be the database of the procedure
|
||||
SET v_custom_db = DATABASE(),
|
||||
v_custom_name = @sys.statement_performance_analyzer.view;
|
||||
ELSE
|
||||
SET v_custom_db = SUBSTRING_INDEX(@sys.statement_performance_analyzer.view, '.', 1);
|
||||
SET v_custom_name = SUBSTRING(@sys.statement_performance_analyzer.view, CHAR_LENGTH(v_custom_db)+2);
|
||||
END IF;
|
||||
|
||||
CALL sys.table_exists(v_custom_db, v_custom_name, v_custom_view_exists);
|
||||
IF (v_custom_view_exists <> 'VIEW') THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'The @sys.statement_performance_analyzer.view user variable is set but specified neither an existing view nor a query.';
|
||||
END IF;
|
||||
|
||||
SET v_sql =
|
||||
REPLACE(
|
||||
(SELECT VIEW_DEFINITION
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = v_custom_db AND TABLE_NAME = v_custom_name
|
||||
),
|
||||
'`performance_schema`.`events_statements_summary_by_digest`',
|
||||
v_digests_table
|
||||
);
|
||||
ELSE
|
||||
SET v_sql = REPLACE(@sys.statement_performance_analyzer.view, '`performance_schema`.`events_statements_summary_by_digest`', v_digests_table);
|
||||
END IF;
|
||||
|
||||
IF (@sys.statement_performance_analyzer.limit > 0) THEN
|
||||
SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit);
|
||||
END IF;
|
||||
|
||||
CALL sys.execute_prepared_stmt(v_sql);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- Restore INSTRUMENTED for this thread
|
||||
IF (v_this_thread_enabled = 'YES') THEN
|
||||
CALL sys.ps_setup_enable_thread(CONNECTION_ID());
|
||||
END IF;
|
||||
|
||||
IF (@log_bin = 1) THEN
|
||||
SET sql_log_bin = @log_bin;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
150
scripts/sys_schema/procedures/table_exists.sql
Normal file
150
scripts/sys_schema/procedures/table_exists.sql
Normal file
@ -0,0 +1,150 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS table_exists;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE table_exists (
|
||||
IN in_db VARCHAR(64), IN in_table VARCHAR(64),
|
||||
OUT out_exists ENUM('', 'BASE TABLE', 'VIEW', 'TEMPORARY')
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
Tests whether the table specified in in_db and in_table exists either as a regular
|
||||
table, or as a temporary table. The returned value corresponds to the table that
|
||||
will be used, so if there''s both a temporary and a permanent table with the given
|
||||
name, then ''TEMPORARY'' will be returned.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
in_db (VARCHAR(64)):
|
||||
The database name to check for the existance of the table in.
|
||||
|
||||
in_table (VARCHAR(64)):
|
||||
The name of the table to check the existance of.
|
||||
|
||||
out_exists ENUM('''', ''BASE TABLE'', ''VIEW'', ''TEMPORARY''):
|
||||
The return value: whether the table exists. The value is one of:
|
||||
* '''' - the table does not exist neither as a base table, view, nor temporary table.
|
||||
* ''BASE TABLE'' - the table name exists as a permanent base table table.
|
||||
* ''VIEW'' - the table name exists as a view.
|
||||
* ''TEMPORARY'' - the table name exists as a temporary table.
|
||||
|
||||
Example
|
||||
--------
|
||||
|
||||
mysql> CREATE DATABASE db1;
|
||||
Query OK, 1 row affected (0.07 sec)
|
||||
|
||||
mysql> use db1;
|
||||
Database changed
|
||||
mysql> CREATE TABLE t1 (id INT PRIMARY KEY);
|
||||
Query OK, 0 rows affected (0.08 sec)
|
||||
|
||||
mysql> CREATE TABLE t2 (id INT PRIMARY KEY);
|
||||
Query OK, 0 rows affected (0.08 sec)
|
||||
|
||||
mysql> CREATE view v_t1 AS SELECT * FROM t1;
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
mysql> CREATE TEMPORARY TABLE t1 (id INT PRIMARY KEY);
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
mysql> CALL sys.table_exists(''db1'', ''t1'', @exists); SELECT @exists;
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
+------------+
|
||||
| @exists |
|
||||
+------------+
|
||||
| TEMPORARY |
|
||||
+------------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> CALL sys.table_exists(''db1'', ''t2'', @exists); SELECT @exists;
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
+------------+
|
||||
| @exists |
|
||||
+------------+
|
||||
| BASE TABLE |
|
||||
+------------+
|
||||
1 row in set (0.01 sec)
|
||||
|
||||
mysql> CALL sys.table_exists(''db1'', ''v_t1'', @exists); SELECT @exists;
|
||||
Query OK, 0 rows affected (0.00 sec)
|
||||
|
||||
+---------+
|
||||
| @exists |
|
||||
+---------+
|
||||
| VIEW |
|
||||
+---------+
|
||||
1 row in set (0.00 sec)
|
||||
|
||||
mysql> CALL sys.table_exists(''db1'', ''t3'', @exists); SELECT @exists;
|
||||
Query OK, 0 rows affected (0.01 sec)
|
||||
|
||||
+---------+
|
||||
| @exists |
|
||||
+---------+
|
||||
| |
|
||||
+---------+
|
||||
1 row in set (0.00 sec)
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
NOT DETERMINISTIC
|
||||
CONTAINS SQL
|
||||
BEGIN
|
||||
DECLARE v_error BOOLEAN DEFAULT FALSE;
|
||||
DECLARE CONTINUE HANDLER FOR 1050 SET v_error = TRUE;
|
||||
DECLARE CONTINUE HANDLER FOR 1146 SET v_error = TRUE;
|
||||
|
||||
SET out_exists = '';
|
||||
|
||||
-- Verify whether the table name exists as a normal table
|
||||
IF (EXISTS(SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = in_db AND TABLE_NAME = in_table)) THEN
|
||||
-- Unfortunately the only way to determine whether there is also a temporary table is to try to create
|
||||
-- a temporary table with the same name. If it succeeds the table didn't exist as a temporary table.
|
||||
SET @sys.tmp.table_exists.SQL = CONCAT('CREATE TEMPORARY TABLE `', in_db, '`.`', in_table, '` (id INT PRIMARY KEY)');
|
||||
PREPARE stmt_create_table FROM @sys.tmp.table_exists.SQL;
|
||||
EXECUTE stmt_create_table;
|
||||
DEALLOCATE PREPARE stmt_create_table;
|
||||
IF (v_error) THEN
|
||||
SET out_exists = 'TEMPORARY';
|
||||
ELSE
|
||||
-- The temporary table was created, i.e. it didn't exist. Remove it again so we don't leave garbage around.
|
||||
SET @sys.tmp.table_exists.SQL = CONCAT('DROP TEMPORARY TABLE `', in_db, '`.`', in_table, '`');
|
||||
PREPARE stmt_drop_table FROM @sys.tmp.table_exists.SQL;
|
||||
EXECUTE stmt_drop_table;
|
||||
DEALLOCATE PREPARE stmt_drop_table;
|
||||
SET out_exists = (SELECT TABLE_TYPE FROM information_schema.TABLES WHERE TABLE_SCHEMA = in_db AND TABLE_NAME = in_table);
|
||||
END IF;
|
||||
ELSE
|
||||
-- Check whether a temporary table exists with the same name.
|
||||
-- If it does it's possible to SELECT from the table without causing an error.
|
||||
-- If it does not exist even a PREPARE using the table will fail.
|
||||
SET @sys.tmp.table_exists.SQL = CONCAT('SELECT COUNT(*) FROM `', in_db, '`.`', in_table, '`');
|
||||
PREPARE stmt_select FROM @sys.tmp.table_exists.SQL;
|
||||
IF (NOT v_error) THEN
|
||||
DEALLOCATE PREPARE stmt_select;
|
||||
SET out_exists = 'TEMPORARY';
|
||||
END IF;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
179
scripts/sys_schema/sys_56.sql
Normal file
179
scripts/sys_schema/sys_56.sql
Normal file
@ -0,0 +1,179 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
SOURCE ./before_setup.sql
|
||||
|
||||
SOURCE ./views/version.sql
|
||||
|
||||
SOURCE ./tables/sys_config.sql
|
||||
SOURCE ./tables/sys_config_data.sql
|
||||
|
||||
SOURCE ./triggers/sys_config_insert_set_user.sql
|
||||
SOURCE ./triggers/sys_config_update_set_user.sql
|
||||
|
||||
SOURCE ./functions/extract_schema_from_file_name.sql
|
||||
SOURCE ./functions/extract_table_from_file_name.sql
|
||||
SOURCE ./functions/format_bytes.sql
|
||||
SOURCE ./functions/format_path.sql
|
||||
SOURCE ./functions/format_statement.sql
|
||||
SOURCE ./functions/format_time.sql
|
||||
SOURCE ./functions/list_add.sql
|
||||
SOURCE ./functions/list_drop.sql
|
||||
SOURCE ./functions/ps_is_account_enabled.sql
|
||||
SOURCE ./functions/ps_is_consumer_enabled.sql
|
||||
SOURCE ./functions/ps_is_instrument_default_enabled.sql
|
||||
SOURCE ./functions/ps_is_instrument_default_timed.sql
|
||||
SOURCE ./functions/ps_is_thread_instrumented.sql
|
||||
SOURCE ./functions/ps_thread_id.sql
|
||||
SOURCE ./functions/ps_thread_account.sql
|
||||
SOURCE ./functions/ps_thread_stack.sql
|
||||
SOURCE ./functions/quote_identifier.sql
|
||||
SOURCE ./functions/sys_get_config.sql
|
||||
SOURCE ./functions/version_major.sql
|
||||
SOURCE ./functions/version_minor.sql
|
||||
SOURCE ./functions/version_patch.sql
|
||||
|
||||
SOURCE ./views/i_s/innodb_buffer_stats_by_schema.sql
|
||||
SOURCE ./views/i_s/x_innodb_buffer_stats_by_schema.sql
|
||||
SOURCE ./views/i_s/innodb_buffer_stats_by_table.sql
|
||||
SOURCE ./views/i_s/x_innodb_buffer_stats_by_table.sql
|
||||
SOURCE ./views/i_s/innodb_lock_waits.sql
|
||||
SOURCE ./views/i_s/x_innodb_lock_waits.sql
|
||||
SOURCE ./views/i_s/schema_object_overview.sql
|
||||
SOURCE ./views/i_s/schema_auto_increment_columns.sql
|
||||
SOURCE ./views/i_s/x_schema_flattened_keys.sql
|
||||
SOURCE ./views/i_s/schema_redundant_indexes.sql
|
||||
|
||||
SOURCE ./views/p_s/ps_check_lost_instrumentation.sql
|
||||
SOURCE ./views/p_s/processlist.sql
|
||||
SOURCE ./views/p_s/x_processlist.sql
|
||||
|
||||
SOURCE ./views/p_s/sessions.sql
|
||||
SOURCE ./views/p_s/x_sessions.sql
|
||||
|
||||
SOURCE ./views/p_s/latest_file_io.sql
|
||||
SOURCE ./views/p_s/x_latest_file_io.sql
|
||||
SOURCE ./views/p_s/io_by_thread_by_latency.sql
|
||||
SOURCE ./views/p_s/x_io_by_thread_by_latency.sql
|
||||
SOURCE ./views/p_s/io_global_by_file_by_bytes.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_file_by_bytes.sql
|
||||
SOURCE ./views/p_s/io_global_by_file_by_latency.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_file_by_latency.sql
|
||||
SOURCE ./views/p_s/io_global_by_wait_by_bytes.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_wait_by_bytes.sql
|
||||
SOURCE ./views/p_s/io_global_by_wait_by_latency.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_wait_by_latency.sql
|
||||
|
||||
SOURCE ./views/p_s/schema_index_statistics.sql
|
||||
SOURCE ./views/p_s/x_schema_index_statistics.sql
|
||||
SOURCE ./views/p_s/x_ps_schema_table_statistics_io.sql
|
||||
SOURCE ./views/p_s/schema_table_statistics.sql
|
||||
SOURCE ./views/p_s/x_schema_table_statistics.sql
|
||||
SOURCE ./views/p_s/schema_table_statistics_with_buffer.sql
|
||||
SOURCE ./views/p_s/x_schema_table_statistics_with_buffer.sql
|
||||
SOURCE ./views/p_s/schema_tables_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/x_schema_tables_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/schema_unused_indexes.sql
|
||||
|
||||
SOURCE ./views/p_s/statement_analysis.sql
|
||||
SOURCE ./views/p_s/x_statement_analysis.sql
|
||||
SOURCE ./views/p_s/statements_with_errors_or_warnings.sql
|
||||
SOURCE ./views/p_s/x_statements_with_errors_or_warnings.sql
|
||||
SOURCE ./views/p_s/statements_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/x_statements_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/x_ps_digest_avg_latency_distribution.sql
|
||||
SOURCE ./views/p_s/x_ps_digest_95th_percentile_by_avg_us.sql
|
||||
SOURCE ./views/p_s/statements_with_runtimes_in_95th_percentile.sql
|
||||
SOURCE ./views/p_s/x_statements_with_runtimes_in_95th_percentile.sql
|
||||
SOURCE ./views/p_s/statements_with_sorting.sql
|
||||
SOURCE ./views/p_s/x_statements_with_sorting.sql
|
||||
SOURCE ./views/p_s/statements_with_temp_tables.sql
|
||||
SOURCE ./views/p_s/x_statements_with_temp_tables.sql
|
||||
|
||||
SOURCE ./views/p_s/user_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/user_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/user_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/user_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/user_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/user_summary.sql
|
||||
SOURCE ./views/p_s/x_user_summary.sql
|
||||
|
||||
SOURCE ./views/p_s/host_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/host_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/host_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/host_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/host_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/host_summary.sql
|
||||
SOURCE ./views/p_s/x_host_summary.sql
|
||||
|
||||
SOURCE ./views/p_s/wait_classes_global_by_avg_latency.sql
|
||||
SOURCE ./views/p_s/x_wait_classes_global_by_avg_latency.sql
|
||||
SOURCE ./views/p_s/wait_classes_global_by_latency.sql
|
||||
SOURCE ./views/p_s/x_wait_classes_global_by_latency.sql
|
||||
SOURCE ./views/p_s/waits_by_user_by_latency.sql
|
||||
SOURCE ./views/p_s/x_waits_by_user_by_latency.sql
|
||||
SOURCE ./views/p_s/waits_by_host_by_latency.sql
|
||||
SOURCE ./views/p_s/x_waits_by_host_by_latency.sql
|
||||
SOURCE ./views/p_s/waits_global_by_latency.sql
|
||||
SOURCE ./views/p_s/x_waits_global_by_latency.sql
|
||||
|
||||
SOURCE ./views/p_s/metrics_56.sql
|
||||
|
||||
SOURCE ./procedures/create_synonym_db.sql
|
||||
SOURCE ./procedures/execute_prepared_stmt.sql
|
||||
|
||||
SOURCE ./procedures/diagnostics.sql
|
||||
|
||||
SOURCE ./procedures/ps_statement_avg_latency_histogram.sql
|
||||
SOURCE ./procedures/ps_trace_statement_digest.sql
|
||||
SOURCE ./procedures/ps_trace_thread.sql
|
||||
|
||||
SOURCE ./procedures/ps_setup_disable_background_threads.sql
|
||||
SOURCE ./procedures/ps_setup_disable_consumer.sql
|
||||
SOURCE ./procedures/ps_setup_disable_instrument.sql
|
||||
SOURCE ./procedures/ps_setup_disable_thread.sql
|
||||
|
||||
SOURCE ./procedures/ps_setup_enable_background_threads.sql
|
||||
SOURCE ./procedures/ps_setup_enable_consumer.sql
|
||||
SOURCE ./procedures/ps_setup_enable_instrument.sql
|
||||
SOURCE ./procedures/ps_setup_enable_thread.sql
|
||||
|
||||
SOURCE ./procedures/ps_setup_reload_saved.sql
|
||||
SOURCE ./procedures/ps_setup_reset_to_default_57_before.sql
|
||||
SOURCE ./procedures/ps_setup_reset_to_default.sql
|
||||
SOURCE ./procedures/ps_setup_reset_to_default_57_after.sql
|
||||
SOURCE ./procedures/ps_setup_save.sql
|
||||
SOURCE ./procedures/ps_setup_show_disabled.sql
|
||||
SOURCE ./procedures/ps_setup_show_disabled_consumers.sql
|
||||
SOURCE ./procedures/ps_setup_show_disabled_instruments.sql
|
||||
SOURCE ./procedures/ps_setup_show_enabled.sql
|
||||
SOURCE ./procedures/ps_setup_show_enabled_consumers.sql
|
||||
SOURCE ./procedures/ps_setup_show_enabled_instruments.sql
|
||||
SOURCE ./procedures/ps_truncate_all_tables.sql
|
||||
|
||||
SOURCE ./procedures/statement_performance_analyzer.sql
|
||||
SOURCE ./procedures/table_exists.sql
|
||||
|
||||
SOURCE ./after_setup.sql
|
195
scripts/sys_schema/sys_57.sql
Normal file
195
scripts/sys_schema/sys_57.sql
Normal file
@ -0,0 +1,195 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
SOURCE ./before_setup.sql
|
||||
|
||||
SOURCE ./views/version.sql
|
||||
|
||||
SOURCE ./tables/sys_config.sql
|
||||
SOURCE ./tables/sys_config_data_57.sql
|
||||
|
||||
SOURCE ./triggers/sys_config_insert_set_user.sql
|
||||
SOURCE ./triggers/sys_config_update_set_user.sql
|
||||
|
||||
SOURCE ./functions/extract_schema_from_file_name.sql
|
||||
SOURCE ./functions/extract_table_from_file_name.sql
|
||||
SOURCE ./functions/format_bytes.sql
|
||||
SOURCE ./functions/format_path_57.sql
|
||||
SOURCE ./functions/format_statement.sql
|
||||
SOURCE ./functions/format_time.sql
|
||||
SOURCE ./functions/list_add.sql
|
||||
SOURCE ./functions/list_drop.sql
|
||||
SOURCE ./functions/ps_is_account_enabled_57.sql
|
||||
SOURCE ./functions/ps_is_consumer_enabled.sql
|
||||
SOURCE ./functions/ps_is_instrument_default_enabled.sql
|
||||
SOURCE ./functions/ps_is_instrument_default_timed.sql
|
||||
SOURCE ./functions/ps_is_thread_instrumented.sql
|
||||
SOURCE ./functions/ps_thread_id.sql
|
||||
SOURCE ./functions/ps_thread_account.sql
|
||||
SOURCE ./functions/ps_thread_stack.sql
|
||||
SOURCE ./functions/ps_thread_trx_info.sql
|
||||
SOURCE ./functions/quote_identifier.sql
|
||||
SOURCE ./functions/sys_get_config.sql
|
||||
SOURCE ./functions/version_major.sql
|
||||
SOURCE ./functions/version_minor.sql
|
||||
SOURCE ./functions/version_patch.sql
|
||||
|
||||
SOURCE ./views/i_s/innodb_buffer_stats_by_schema.sql
|
||||
SOURCE ./views/i_s/x_innodb_buffer_stats_by_schema.sql
|
||||
SOURCE ./views/i_s/innodb_buffer_stats_by_table.sql
|
||||
SOURCE ./views/i_s/x_innodb_buffer_stats_by_table.sql
|
||||
SOURCE ./views/i_s/innodb_lock_waits.sql
|
||||
SOURCE ./views/i_s/x_innodb_lock_waits.sql
|
||||
SOURCE ./views/i_s/schema_object_overview.sql
|
||||
SOURCE ./views/i_s/schema_auto_increment_columns.sql
|
||||
SOURCE ./views/i_s/x_schema_flattened_keys.sql
|
||||
SOURCE ./views/i_s/schema_redundant_indexes.sql
|
||||
|
||||
SOURCE ./views/p_s/ps_check_lost_instrumentation_57.sql
|
||||
|
||||
SOURCE ./views/p_s/latest_file_io.sql
|
||||
SOURCE ./views/p_s/x_latest_file_io.sql
|
||||
SOURCE ./views/p_s/io_by_thread_by_latency.sql
|
||||
SOURCE ./views/p_s/x_io_by_thread_by_latency.sql
|
||||
SOURCE ./views/p_s/io_global_by_file_by_bytes.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_file_by_bytes.sql
|
||||
SOURCE ./views/p_s/io_global_by_file_by_latency.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_file_by_latency.sql
|
||||
SOURCE ./views/p_s/io_global_by_wait_by_bytes.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_wait_by_bytes.sql
|
||||
SOURCE ./views/p_s/io_global_by_wait_by_latency.sql
|
||||
SOURCE ./views/p_s/x_io_global_by_wait_by_latency.sql
|
||||
|
||||
SOURCE ./views/p_s/memory_by_user_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/x_memory_by_user_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/memory_by_host_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/x_memory_by_host_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/memory_by_thread_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/x_memory_by_thread_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/memory_global_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/x_memory_global_by_current_bytes.sql
|
||||
SOURCE ./views/p_s/memory_global_total.sql
|
||||
SOURCE ./views/p_s/x_memory_global_total.sql
|
||||
|
||||
SOURCE ./views/p_s/schema_index_statistics.sql
|
||||
SOURCE ./views/p_s/x_schema_index_statistics.sql
|
||||
SOURCE ./views/p_s/x_ps_schema_table_statistics_io.sql
|
||||
SOURCE ./views/p_s/schema_table_statistics.sql
|
||||
SOURCE ./views/p_s/x_schema_table_statistics.sql
|
||||
SOURCE ./views/p_s/schema_table_statistics_with_buffer.sql
|
||||
SOURCE ./views/p_s/x_schema_table_statistics_with_buffer.sql
|
||||
SOURCE ./views/p_s/schema_tables_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/x_schema_tables_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/schema_unused_indexes.sql
|
||||
SOURCE ./views/p_s/schema_table_lock_waits.sql
|
||||
SOURCE ./views/p_s/x_schema_table_lock_waits.sql
|
||||
|
||||
SOURCE ./views/p_s/statement_analysis.sql
|
||||
SOURCE ./views/p_s/x_statement_analysis.sql
|
||||
SOURCE ./views/p_s/statements_with_errors_or_warnings.sql
|
||||
SOURCE ./views/p_s/x_statements_with_errors_or_warnings.sql
|
||||
SOURCE ./views/p_s/statements_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/x_statements_with_full_table_scans.sql
|
||||
SOURCE ./views/p_s/x_ps_digest_avg_latency_distribution.sql
|
||||
SOURCE ./views/p_s/x_ps_digest_95th_percentile_by_avg_us.sql
|
||||
SOURCE ./views/p_s/statements_with_runtimes_in_95th_percentile.sql
|
||||
SOURCE ./views/p_s/x_statements_with_runtimes_in_95th_percentile.sql
|
||||
SOURCE ./views/p_s/statements_with_sorting.sql
|
||||
SOURCE ./views/p_s/x_statements_with_sorting.sql
|
||||
SOURCE ./views/p_s/statements_with_temp_tables.sql
|
||||
SOURCE ./views/p_s/x_statements_with_temp_tables.sql
|
||||
|
||||
SOURCE ./views/p_s/user_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/user_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/user_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/user_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/user_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/x_user_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/user_summary_57.sql
|
||||
SOURCE ./views/p_s/x_user_summary_57.sql
|
||||
|
||||
SOURCE ./views/p_s/host_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_file_io_type.sql
|
||||
SOURCE ./views/p_s/host_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_file_io.sql
|
||||
SOURCE ./views/p_s/host_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_statement_type.sql
|
||||
SOURCE ./views/p_s/host_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_statement_latency.sql
|
||||
SOURCE ./views/p_s/host_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/x_host_summary_by_stages.sql
|
||||
SOURCE ./views/p_s/host_summary_57.sql
|
||||
SOURCE ./views/p_s/x_host_summary_57.sql
|
||||
|
||||
SOURCE ./views/p_s/wait_classes_global_by_avg_latency.sql
|
||||
SOURCE ./views/p_s/x_wait_classes_global_by_avg_latency.sql
|
||||
SOURCE ./views/p_s/wait_classes_global_by_latency.sql
|
||||
SOURCE ./views/p_s/x_wait_classes_global_by_latency.sql
|
||||
SOURCE ./views/p_s/waits_by_user_by_latency.sql
|
||||
SOURCE ./views/p_s/x_waits_by_user_by_latency.sql
|
||||
SOURCE ./views/p_s/waits_by_host_by_latency.sql
|
||||
SOURCE ./views/p_s/x_waits_by_host_by_latency.sql
|
||||
SOURCE ./views/p_s/waits_global_by_latency.sql
|
||||
SOURCE ./views/p_s/x_waits_global_by_latency.sql
|
||||
|
||||
SOURCE ./views/p_s/metrics.sql
|
||||
|
||||
SOURCE ./views/p_s/processlist_57.sql
|
||||
SOURCE ./views/p_s/x_processlist_57.sql
|
||||
|
||||
SOURCE ./views/p_s/sessions.sql
|
||||
SOURCE ./views/p_s/x_sessions.sql
|
||||
SOURCE ./views/p_s/session_ssl_status.sql
|
||||
|
||||
SOURCE ./procedures/create_synonym_db.sql
|
||||
SOURCE ./procedures/execute_prepared_stmt.sql
|
||||
|
||||
SOURCE ./procedures/diagnostics.sql
|
||||
|
||||
SOURCE ./procedures/ps_statement_avg_latency_histogram.sql
|
||||
SOURCE ./procedures/ps_trace_statement_digest.sql
|
||||
SOURCE ./procedures/ps_trace_thread_57.sql
|
||||
|
||||
SOURCE ./procedures/ps_setup_disable_background_threads.sql
|
||||
SOURCE ./procedures/ps_setup_disable_consumer.sql
|
||||
SOURCE ./procedures/ps_setup_disable_instrument.sql
|
||||
SOURCE ./procedures/ps_setup_disable_thread.sql
|
||||
|
||||
SOURCE ./procedures/ps_setup_enable_background_threads.sql
|
||||
SOURCE ./procedures/ps_setup_enable_consumer.sql
|
||||
SOURCE ./procedures/ps_setup_enable_instrument.sql
|
||||
SOURCE ./procedures/ps_setup_enable_thread.sql
|
||||
|
||||
SOURCE ./procedures/ps_setup_reload_saved.sql
|
||||
SOURCE ./procedures/ps_setup_reset_to_default_57_before.sql
|
||||
SOURCE ./procedures/ps_setup_reset_to_default_57.sql
|
||||
SOURCE ./procedures/ps_setup_reset_to_default_57_after.sql
|
||||
SOURCE ./procedures/ps_setup_save.sql
|
||||
SOURCE ./procedures/ps_setup_show_disabled.sql
|
||||
SOURCE ./procedures/ps_setup_show_disabled_consumers.sql
|
||||
SOURCE ./procedures/ps_setup_show_disabled_instruments.sql
|
||||
SOURCE ./procedures/ps_setup_show_enabled.sql
|
||||
SOURCE ./procedures/ps_setup_show_enabled_consumers.sql
|
||||
SOURCE ./procedures/ps_setup_show_enabled_instruments.sql
|
||||
SOURCE ./procedures/ps_truncate_all_tables.sql
|
||||
|
||||
SOURCE ./procedures/statement_performance_analyzer.sql
|
||||
SOURCE ./procedures/table_exists.sql
|
||||
|
||||
SOURCE ./after_setup.sql
|
27
scripts/sys_schema/tables/sys_config.sql
Normal file
27
scripts/sys_schema/tables/sys_config.sql
Normal file
@ -0,0 +1,27 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- Table: sys_config
|
||||
--
|
||||
-- Stores configuration options for sys objects
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sys_config (
|
||||
variable VARCHAR(128) PRIMARY KEY,
|
||||
value VARCHAR(128),
|
||||
set_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
set_by VARCHAR(128)
|
||||
) ENGINE = InnoDB;
|
23
scripts/sys_schema/tables/sys_config_data.sql
Normal file
23
scripts/sys_schema/tables/sys_config_data.sql
Normal file
@ -0,0 +1,23 @@
|
||||
-- Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
-- NOTE: This needs to be replicated within the sys_config_clean.inc file
|
||||
|
||||
INSERT IGNORE INTO sys.sys_config (variable, value) VALUES
|
||||
('statement_truncate_len', 64),
|
||||
('statement_performance_analyzer.limit', 100),
|
||||
('statement_performance_analyzer.view', NULL),
|
||||
('diagnostics.allow_i_s_tables', 'OFF'),
|
||||
('diagnostics.include_raw', 'OFF');
|
24
scripts/sys_schema/tables/sys_config_data_57.sql
Normal file
24
scripts/sys_schema/tables/sys_config_data_57.sql
Normal file
@ -0,0 +1,24 @@
|
||||
-- Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
-- NOTE: This needs to be replicated within the sys_config_clean.inc file
|
||||
|
||||
INSERT IGNORE INTO sys.sys_config (variable, value) VALUES
|
||||
('statement_truncate_len', 64),
|
||||
('statement_performance_analyzer.limit', 100),
|
||||
('statement_performance_analyzer.view', NULL),
|
||||
('diagnostics.allow_i_s_tables', 'OFF'),
|
||||
('diagnostics.include_raw', 'OFF'),
|
||||
('ps_thread_trx_info.max_length', 65535);
|
56
scripts/sys_schema/templates/function.sql
Normal file
56
scripts/sys_schema/templates/function.sql
Normal file
@ -0,0 +1,56 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP FUNCTION IF EXISTS <function name>;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' FUNCTION <function name> (
|
||||
/* Variables */
|
||||
)
|
||||
RETURNS <data type>
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
...
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
...
|
||||
|
||||
Returns
|
||||
-----------
|
||||
|
||||
<data type>
|
||||
|
||||
Example
|
||||
-----------
|
||||
|
||||
...
|
||||
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
{ DETERMINISTIC | NOT DETERMINISTIC }
|
||||
{ CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
|
||||
BEGIN
|
||||
|
||||
/* BODY */
|
||||
RETURN <something>;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
56
scripts/sys_schema/templates/procedure.sql
Normal file
56
scripts/sys_schema/templates/procedure.sql
Normal file
@ -0,0 +1,56 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
DROP PROCEDURE IF EXISTS <procedure_name>;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' PROCEDURE <procedure_name> (
|
||||
/* Variables */
|
||||
)
|
||||
COMMENT '
|
||||
Description
|
||||
-----------
|
||||
|
||||
...
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
|
||||
...
|
||||
|
||||
|
||||
Configuration Options
|
||||
----------------------
|
||||
|
||||
...
|
||||
|
||||
|
||||
Example
|
||||
--------
|
||||
|
||||
...
|
||||
|
||||
'
|
||||
SQL SECURITY INVOKER
|
||||
{ DETERMINISTIC | NOT DETERMINISTIC }
|
||||
{ CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
|
||||
BEGIN
|
||||
|
||||
/* BODY */
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
35
scripts/sys_schema/triggers/sys_config_insert_set_user.sql
Normal file
35
scripts/sys_schema/triggers/sys_config_insert_set_user.sql
Normal file
@ -0,0 +1,35 @@
|
||||
-- Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- Trigger: sys_config_insert_set_user
|
||||
--
|
||||
-- Sets the user that inserts configuration
|
||||
--
|
||||
--
|
||||
|
||||
DROP TRIGGER IF EXISTS sys_config_insert_set_user;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' TRIGGER sys_config_insert_set_user BEFORE INSERT on sys_config
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
IF @sys.ignore_sys_config_triggers != true AND NEW.set_by IS NULL THEN
|
||||
SET NEW.set_by = USER();
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
36
scripts/sys_schema/triggers/sys_config_update_set_user.sql
Normal file
36
scripts/sys_schema/triggers/sys_config_update_set_user.sql
Normal file
@ -0,0 +1,36 @@
|
||||
-- Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- Trigger: sys_config_update_set_user
|
||||
--
|
||||
-- Sets the user that updates configuration
|
||||
--
|
||||
--
|
||||
|
||||
|
||||
DROP TRIGGER IF EXISTS sys_config_update_set_user;
|
||||
|
||||
DELIMITER $$
|
||||
|
||||
CREATE DEFINER='root'@'localhost' TRIGGER sys_config_update_set_user BEFORE UPDATE on sys_config
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
IF @sys.ignore_sys_config_triggers != true AND NEW.set_by IS NULL THEN
|
||||
SET NEW.set_by = USER();
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
@ -0,0 +1,56 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: innodb_buffer_stats_by_schema
|
||||
--
|
||||
-- Summarizes the output of the INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
|
||||
-- table, aggregating by schema
|
||||
--
|
||||
--
|
||||
-- mysql> select * from innodb_buffer_stats_by_schema;
|
||||
-- +--------------------------+------------+------------+-------+--------------+-----------+-------------+
|
||||
-- | object_schema | allocated | data | pages | pages_hashed | pages_old | rows_cached |
|
||||
-- +--------------------------+------------+------------+-------+--------------+-----------+-------------+
|
||||
-- | mem30_trunk__instruments | 1.69 MiB | 510.03 KiB | 108 | 108 | 108 | 3885 |
|
||||
-- | InnoDB System | 688.00 KiB | 351.62 KiB | 43 | 43 | 43 | 862 |
|
||||
-- | mem30_trunk__events | 80.00 KiB | 21.61 KiB | 5 | 5 | 5 | 229 |
|
||||
-- +--------------------------+------------+------------+-------+--------------+-----------+-------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW innodb_buffer_stats_by_schema (
|
||||
object_schema,
|
||||
allocated,
|
||||
data,
|
||||
pages,
|
||||
pages_hashed,
|
||||
pages_old,
|
||||
rows_cached
|
||||
) AS
|
||||
SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS object_schema,
|
||||
sys.format_bytes(SUM(IF(ibp.compressed_size = 0, 16384, compressed_size))) AS allocated,
|
||||
sys.format_bytes(SUM(ibp.data_size)) AS data,
|
||||
COUNT(ibp.page_number) AS pages,
|
||||
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
|
||||
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
|
||||
ROUND(SUM(ibp.number_records)/COUNT(DISTINCT ibp.index_name)) AS rows_cached
|
||||
FROM information_schema.innodb_buffer_page ibp
|
||||
WHERE table_name IS NOT NULL
|
||||
GROUP BY object_schema
|
||||
ORDER BY SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) DESC;
|
@ -0,0 +1,62 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: innodb_buffer_stats_by_table
|
||||
--
|
||||
-- Summarizes the output of the INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
|
||||
-- table, aggregating by schema and table name
|
||||
--
|
||||
-- mysql> select * from innodb_buffer_stats_by_table;
|
||||
-- +--------------------------+------------------------------------+------------+-----------+-------+--------------+-----------+-------------+
|
||||
-- | object_schema | object_name | allocated | data | pages | pages_hashed | pages_old | rows_cached |
|
||||
-- +--------------------------+------------------------------------+------------+-----------+-------+--------------+-----------+-------------+
|
||||
-- | InnoDB System | SYS_COLUMNS | 128.00 KiB | 98.97 KiB | 8 | 8 | 8 | 1532 |
|
||||
-- | InnoDB System | SYS_FOREIGN | 128.00 KiB | 55.48 KiB | 8 | 8 | 8 | 172 |
|
||||
-- | InnoDB System | SYS_TABLES | 128.00 KiB | 56.18 KiB | 8 | 8 | 8 | 365 |
|
||||
-- | InnoDB System | SYS_INDEXES | 112.00 KiB | 76.16 KiB | 7 | 7 | 7 | 1046 |
|
||||
-- | mem30_trunk__instruments | agentlatencytime | 96.00 KiB | 28.83 KiB | 6 | 6 | 6 | 252 |
|
||||
-- | mem30_trunk__instruments | binlogspaceusagedata | 96.00 KiB | 22.54 KiB | 6 | 6 | 6 | 196 |
|
||||
-- | mem30_trunk__instruments | connectionsdata | 96.00 KiB | 36.68 KiB | 6 | 6 | 6 | 276 |
|
||||
-- ...
|
||||
-- +--------------------------+------------------------------------+------------+-----------+-------+--------------+-----------+-------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW innodb_buffer_stats_by_table (
|
||||
object_schema,
|
||||
object_name,
|
||||
allocated,
|
||||
data,
|
||||
pages,
|
||||
pages_hashed,
|
||||
pages_old,
|
||||
rows_cached
|
||||
) AS
|
||||
SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS object_schema,
|
||||
REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', -1), '`', '') AS object_name,
|
||||
sys.format_bytes(SUM(IF(ibp.compressed_size = 0, 16384, compressed_size))) AS allocated,
|
||||
sys.format_bytes(SUM(ibp.data_size)) AS data,
|
||||
COUNT(ibp.page_number) AS pages,
|
||||
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
|
||||
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
|
||||
ROUND(SUM(ibp.number_records)/COUNT(DISTINCT ibp.index_name)) AS rows_cached
|
||||
FROM information_schema.innodb_buffer_page ibp
|
||||
WHERE table_name IS NOT NULL
|
||||
GROUP BY object_schema, object_name
|
||||
ORDER BY SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) DESC;
|
118
scripts/sys_schema/views/i_s/innodb_lock_waits.sql
Normal file
118
scripts/sys_schema/views/i_s/innodb_lock_waits.sql
Normal file
@ -0,0 +1,118 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: innodb_lock_waits
|
||||
--
|
||||
-- Give a snapshot of which InnoDB locks transactions are waiting for.
|
||||
-- The lock waits are ordered by the age of the lock descending.
|
||||
--
|
||||
-- Versions: 5.1+ (5.1 requires InnoDB Plugin with I_S tables)
|
||||
--
|
||||
-- mysql> SELECT * FROM x$innodb_lock_waits\G
|
||||
-- *************************** 1. row ***************************
|
||||
-- wait_started: 2014-11-11 13:39:20
|
||||
-- wait_age: 00:00:07
|
||||
-- wait_age_secs: 7
|
||||
-- locked_table: `db1`.`t1`
|
||||
-- locked_index: PRIMARY
|
||||
-- locked_type: RECORD
|
||||
-- waiting_trx_id: 867158
|
||||
-- waiting_trx_started: 2014-11-11 13:39:15
|
||||
-- waiting_trx_age: 00:00:12
|
||||
-- waiting_trx_rows_locked: 0
|
||||
-- waiting_trx_rows_modified: 0
|
||||
-- waiting_pid: 3
|
||||
-- waiting_query: UPDATE t1 SET val = val + 1 WHERE id = 2
|
||||
-- waiting_lock_id: 867158:2363:3:3
|
||||
-- waiting_lock_mode: X
|
||||
-- blocking_trx_id: 867157
|
||||
-- blocking_pid: 4
|
||||
-- blocking_query: UPDATE t1 SET val = val + 1 + SLEEP(10) WHERE id = 2
|
||||
-- blocking_lock_id: 867157:2363:3:3
|
||||
-- blocking_lock_mode: X
|
||||
-- blocking_trx_started: 2014-11-11 13:39:11
|
||||
-- blocking_trx_age: 00:00:16
|
||||
-- blocking_trx_rows_locked: 1
|
||||
-- blocking_trx_rows_modified: 1
|
||||
-- sql_kill_blocking_query: KILL QUERY 4
|
||||
-- sql_kill_blocking_connection: KILL 4
|
||||
-- 1 row in set (0.01 sec)
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW innodb_lock_waits (
|
||||
wait_started,
|
||||
wait_age,
|
||||
wait_age_secs,
|
||||
locked_table,
|
||||
locked_index,
|
||||
locked_type,
|
||||
waiting_trx_id,
|
||||
waiting_trx_started,
|
||||
waiting_trx_age,
|
||||
waiting_trx_rows_locked,
|
||||
waiting_trx_rows_modified,
|
||||
waiting_pid,
|
||||
waiting_query,
|
||||
waiting_lock_id,
|
||||
waiting_lock_mode,
|
||||
blocking_trx_id,
|
||||
blocking_pid,
|
||||
blocking_query,
|
||||
blocking_lock_id,
|
||||
blocking_lock_mode,
|
||||
blocking_trx_started,
|
||||
blocking_trx_age,
|
||||
blocking_trx_rows_locked,
|
||||
blocking_trx_rows_modified,
|
||||
sql_kill_blocking_query,
|
||||
sql_kill_blocking_connection
|
||||
) AS
|
||||
SELECT r.trx_wait_started AS wait_started,
|
||||
TIMEDIFF(NOW(), r.trx_wait_started) AS wait_age,
|
||||
TIMESTAMPDIFF(SECOND, r.trx_wait_started, NOW()) AS wait_age_secs,
|
||||
rl.lock_table AS locked_table,
|
||||
rl.lock_index AS locked_index,
|
||||
rl.lock_type AS locked_type,
|
||||
r.trx_id AS waiting_trx_id,
|
||||
r.trx_started as waiting_trx_started,
|
||||
TIMEDIFF(NOW(), r.trx_started) AS waiting_trx_age,
|
||||
r.trx_rows_locked AS waiting_trx_rows_locked,
|
||||
r.trx_rows_modified AS waiting_trx_rows_modified,
|
||||
r.trx_mysql_thread_id AS waiting_pid,
|
||||
sys.format_statement(r.trx_query) AS waiting_query,
|
||||
rl.lock_id AS waiting_lock_id,
|
||||
rl.lock_mode AS waiting_lock_mode,
|
||||
b.trx_id AS blocking_trx_id,
|
||||
b.trx_mysql_thread_id AS blocking_pid,
|
||||
sys.format_statement(b.trx_query) AS blocking_query,
|
||||
bl.lock_id AS blocking_lock_id,
|
||||
bl.lock_mode AS blocking_lock_mode,
|
||||
b.trx_started AS blocking_trx_started,
|
||||
TIMEDIFF(NOW(), b.trx_started) AS blocking_trx_age,
|
||||
b.trx_rows_locked AS blocking_trx_rows_locked,
|
||||
b.trx_rows_modified AS blocking_trx_rows_modified,
|
||||
CONCAT('KILL QUERY ', b.trx_mysql_thread_id) AS sql_kill_blocking_query,
|
||||
CONCAT('KILL ', b.trx_mysql_thread_id) AS sql_kill_blocking_connection
|
||||
FROM information_schema.innodb_lock_waits w
|
||||
INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
|
||||
INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id
|
||||
INNER JOIN information_schema.innodb_locks bl ON bl.lock_id = w.blocking_lock_id
|
||||
INNER JOIN information_schema.innodb_locks rl ON rl.lock_id = w.requested_lock_id
|
||||
ORDER BY r.trx_wait_started;
|
@ -0,0 +1,66 @@
|
||||
|
||||
--
|
||||
-- View: schema_auto_increment_columns
|
||||
--
|
||||
-- Present current auto_increment usage/capacity in all tables.
|
||||
--
|
||||
-- mysql> select * from schema_auto_increment_columns limit 5;
|
||||
-- +-------------------+-------------------+-------------+-----------+-------------+-----------+-------------+---------------------+----------------+----------------------+
|
||||
-- | table_schema | table_name | column_name | data_type | column_type | is_signed | is_unsigned | max_value | auto_increment | auto_increment_ratio |
|
||||
-- +-------------------+-------------------+-------------+-----------+-------------+-----------+-------------+---------------------+----------------+----------------------+
|
||||
-- | test | t1 | i | tinyint | tinyint(4) | 1 | 0 | 127 | 34 | 0.2677 |
|
||||
-- | mem__advisor_text | template_meta | hib_id | int | int(11) | 1 | 0 | 2147483647 | 516 | 0.0000 |
|
||||
-- | mem__advisors | advisor_schedules | schedule_id | int | int(11) | 1 | 0 | 2147483647 | 249 | 0.0000 |
|
||||
-- | mem__advisors | app_identity_path | hib_id | int | int(11) | 1 | 0 | 2147483647 | 251 | 0.0000 |
|
||||
-- | mem__bean_config | plists | id | bigint | bigint(20) | 1 | 0 | 9223372036854775807 | 1 | 0.0000 |
|
||||
-- +-------------------+-------------------+-------------+-----------+-------------+-----------+-------------+---------------------+----------------+----------------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW schema_auto_increment_columns (
|
||||
table_schema,
|
||||
table_name,
|
||||
column_name,
|
||||
data_type,
|
||||
column_type,
|
||||
is_signed,
|
||||
is_unsigned,
|
||||
max_value,
|
||||
auto_increment,
|
||||
auto_increment_ratio
|
||||
) AS
|
||||
SELECT TABLE_SCHEMA,
|
||||
TABLE_NAME,
|
||||
COLUMN_NAME,
|
||||
DATA_TYPE,
|
||||
COLUMN_TYPE,
|
||||
(LOCATE('unsigned', COLUMN_TYPE) = 0) AS is_signed,
|
||||
(LOCATE('unsigned', COLUMN_TYPE) > 0) AS is_unsigned,
|
||||
(
|
||||
CASE DATA_TYPE
|
||||
WHEN 'tinyint' THEN 255
|
||||
WHEN 'smallint' THEN 65535
|
||||
WHEN 'mediumint' THEN 16777215
|
||||
WHEN 'int' THEN 4294967295
|
||||
WHEN 'bigint' THEN 18446744073709551615
|
||||
END >> IF(LOCATE('unsigned', COLUMN_TYPE) > 0, 0, 1)
|
||||
) AS max_value,
|
||||
AUTO_INCREMENT,
|
||||
AUTO_INCREMENT / (
|
||||
CASE DATA_TYPE
|
||||
WHEN 'tinyint' THEN 255
|
||||
WHEN 'smallint' THEN 65535
|
||||
WHEN 'mediumint' THEN 16777215
|
||||
WHEN 'int' THEN 4294967295
|
||||
WHEN 'bigint' THEN 18446744073709551615
|
||||
END >> IF(LOCATE('unsigned', COLUMN_TYPE) > 0, 0, 1)
|
||||
) AS auto_increment_ratio
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
INNER JOIN INFORMATION_SCHEMA.TABLES USING (TABLE_SCHEMA, TABLE_NAME)
|
||||
WHERE TABLE_SCHEMA NOT IN ('mysql', 'sys', 'INFORMATION_SCHEMA', 'performance_schema')
|
||||
AND TABLE_TYPE='BASE TABLE'
|
||||
AND EXTRA='auto_increment'
|
||||
ORDER BY auto_increment_ratio DESC, max_value;
|
58
scripts/sys_schema/views/i_s/schema_object_overview.sql
Normal file
58
scripts/sys_schema/views/i_s/schema_object_overview.sql
Normal file
@ -0,0 +1,58 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: schema_object_overview
|
||||
--
|
||||
-- Shows an overview of the types of objects within each schema
|
||||
--
|
||||
-- Note: On instances with a large number of objects, this could take
|
||||
-- some time to execute, and is not recommended.
|
||||
--
|
||||
-- mysql> select * from schema_object_overview;
|
||||
-- +---------------------------------+---------------+-------+
|
||||
-- | db | object_type | count |
|
||||
-- +---------------------------------+---------------+-------+
|
||||
-- | information_schema | SYSTEM VIEW | 59 |
|
||||
-- | mem30_test__instruments | BASE TABLE | 1 |
|
||||
-- | mem30_test__instruments | INDEX (BTREE) | 2 |
|
||||
-- | mem30_test__test | BASE TABLE | 9 |
|
||||
-- | mem30_test__test | INDEX (BTREE) | 19 |
|
||||
-- ...
|
||||
-- | sys | FUNCTION | 8 |
|
||||
-- | sys | PROCEDURE | 16 |
|
||||
-- | sys | VIEW | 59 |
|
||||
-- +---------------------------------+---------------+-------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW schema_object_overview (
|
||||
db,
|
||||
object_type,
|
||||
count
|
||||
) AS
|
||||
SELECT ROUTINE_SCHEMA AS db, ROUTINE_TYPE AS object_type, COUNT(*) AS count FROM information_schema.routines GROUP BY ROUTINE_SCHEMA, ROUTINE_TYPE
|
||||
UNION
|
||||
SELECT TABLE_SCHEMA, TABLE_TYPE, COUNT(*) FROM information_schema.tables GROUP BY TABLE_SCHEMA, TABLE_TYPE
|
||||
UNION
|
||||
SELECT TABLE_SCHEMA, CONCAT('INDEX (', INDEX_TYPE, ')'), COUNT(*) FROM information_schema.statistics GROUP BY TABLE_SCHEMA, INDEX_TYPE
|
||||
UNION
|
||||
SELECT TRIGGER_SCHEMA, 'TRIGGER', COUNT(*) FROM information_schema.triggers GROUP BY TRIGGER_SCHEMA
|
||||
UNION
|
||||
SELECT EVENT_SCHEMA, 'EVENT', COUNT(*) FROM information_schema.events GROUP BY EVENT_SCHEMA
|
||||
ORDER BY DB, OBJECT_TYPE;
|
92
scripts/sys_schema/views/i_s/schema_redundant_indexes.sql
Normal file
92
scripts/sys_schema/views/i_s/schema_redundant_indexes.sql
Normal file
@ -0,0 +1,92 @@
|
||||
--
|
||||
-- View: schema_redundant_keys
|
||||
--
|
||||
-- Shows indexes which are made redundant (or duplicate) by other (dominant) keys.
|
||||
--
|
||||
-- mysql> select * from sys.schema_redundant_indexes\G
|
||||
-- *************************** 1. row ***************************
|
||||
-- table_schema: test
|
||||
-- table_name: rkey
|
||||
-- redundant_index_name: j
|
||||
-- redundant_index_columns: j
|
||||
-- redundant_index_non_unique: 1
|
||||
-- dominant_index_name: j_2
|
||||
-- dominant_index_columns: j,k
|
||||
-- dominant_index_non_unique: 1
|
||||
-- subpart_exists: 0
|
||||
-- sql_drop_index: ALTER TABLE `test`.`rkey` DROP INDEX `j`
|
||||
-- 1 row in set (0.20 sec)
|
||||
--
|
||||
-- mysql> SHOW CREATE TABLE test.rkey\G
|
||||
-- *************************** 1. row ***************************
|
||||
-- Table: rkey
|
||||
-- Create Table: CREATE TABLE `rkey` (
|
||||
-- `i` int(11) NOT NULL,
|
||||
-- `j` int(11) DEFAULT NULL,
|
||||
-- `k` int(11) DEFAULT NULL,
|
||||
-- PRIMARY KEY (`i`),
|
||||
-- KEY `j` (`j`),
|
||||
-- KEY `j_2` (`j`,`k`)
|
||||
-- ) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
||||
-- 1 row in set (0.06 sec)
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW schema_redundant_indexes (
|
||||
table_schema,
|
||||
table_name,
|
||||
redundant_index_name,
|
||||
redundant_index_columns,
|
||||
redundant_index_non_unique,
|
||||
dominant_index_name,
|
||||
dominant_index_columns,
|
||||
dominant_index_non_unique,
|
||||
subpart_exists,
|
||||
sql_drop_index
|
||||
) AS
|
||||
SELECT
|
||||
redundant_keys.table_schema,
|
||||
redundant_keys.table_name,
|
||||
redundant_keys.index_name AS redundant_index_name,
|
||||
redundant_keys.index_columns AS redundant_index_columns,
|
||||
redundant_keys.non_unique AS redundant_index_non_unique,
|
||||
dominant_keys.index_name AS dominant_index_name,
|
||||
dominant_keys.index_columns AS dominant_index_columns,
|
||||
dominant_keys.non_unique AS dominant_index_non_unique,
|
||||
IF(redundant_keys.subpart_exists OR dominant_keys.subpart_exists, 1 ,0) AS subpart_exists,
|
||||
CONCAT(
|
||||
'ALTER TABLE `', redundant_keys.table_schema, '`.`', redundant_keys.table_name, '` DROP INDEX `', redundant_keys.index_name, '`'
|
||||
) AS sql_drop_index
|
||||
FROM
|
||||
x$schema_flattened_keys AS redundant_keys
|
||||
INNER JOIN x$schema_flattened_keys AS dominant_keys
|
||||
USING (TABLE_SCHEMA, TABLE_NAME)
|
||||
WHERE
|
||||
redundant_keys.index_name != dominant_keys.index_name
|
||||
AND (
|
||||
(
|
||||
/* Identical columns */
|
||||
(redundant_keys.index_columns = dominant_keys.index_columns)
|
||||
AND (
|
||||
(redundant_keys.non_unique > dominant_keys.non_unique)
|
||||
OR (redundant_keys.non_unique = dominant_keys.non_unique
|
||||
AND IF(redundant_keys.index_name='PRIMARY', '', redundant_keys.index_name) > IF(dominant_keys.index_name='PRIMARY', '', dominant_keys.index_name)
|
||||
)
|
||||
)
|
||||
)
|
||||
OR
|
||||
(
|
||||
/* Non-unique prefix columns */
|
||||
LOCATE(CONCAT(redundant_keys.index_columns, ','), dominant_keys.index_columns) = 1
|
||||
AND redundant_keys.non_unique = 1
|
||||
)
|
||||
OR
|
||||
(
|
||||
/* Unique prefix columns */
|
||||
LOCATE(CONCAT(dominant_keys.index_columns, ','), redundant_keys.index_columns) = 1
|
||||
AND dominant_keys.non_unique = 0
|
||||
)
|
||||
);
|
@ -0,0 +1,55 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: x$innodb_buffer_stats_by_schema
|
||||
--
|
||||
-- Summarizes the output of the INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
|
||||
-- table, aggregating by schema
|
||||
--
|
||||
-- mysql> select * from x$innodb_buffer_stats_by_schema;
|
||||
-- +--------------------------+-----------+--------+-------+--------------+-----------+-------------+
|
||||
-- | object_schema | allocated | data | pages | pages_hashed | pages_old | rows_cached |
|
||||
-- +--------------------------+-----------+--------+-------+--------------+-----------+-------------+
|
||||
-- | mem30_trunk__instruments | 1769472 | 522272 | 108 | 108 | 108 | 3885 |
|
||||
-- | InnoDB System | 704512 | 360054 | 43 | 43 | 43 | 862 |
|
||||
-- | mem30_trunk__events | 81920 | 22125 | 5 | 5 | 5 | 229 |
|
||||
-- +--------------------------+-----------+--------+-------+--------------+-----------+-------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW x$innodb_buffer_stats_by_schema (
|
||||
object_schema,
|
||||
allocated,
|
||||
data,
|
||||
pages,
|
||||
pages_hashed,
|
||||
pages_old,
|
||||
rows_cached
|
||||
) AS
|
||||
SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS object_schema,
|
||||
SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) AS allocated,
|
||||
SUM(ibp.data_size) AS data,
|
||||
COUNT(ibp.page_number) AS pages,
|
||||
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
|
||||
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
|
||||
ROUND(IFNULL(SUM(ibp.number_records)/NULLIF(COUNT(DISTINCT ibp.index_name), 0), 0)) AS rows_cached
|
||||
FROM information_schema.innodb_buffer_page ibp
|
||||
WHERE table_name IS NOT NULL
|
||||
GROUP BY object_schema
|
||||
ORDER BY SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) DESC;
|
@ -0,0 +1,62 @@
|
||||
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: x$innodb_buffer_stats_by_table
|
||||
--
|
||||
-- Summarizes the output of the INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
|
||||
-- table, aggregating by schema and table name
|
||||
--
|
||||
-- mysql> select * from x$innodb_buffer_stats_by_table;
|
||||
-- +--------------------------+------------------------------------+-----------+--------+-------+--------------+-----------+-------------+
|
||||
-- | object_schema | object_name | allocated | data | pages | pages_hashed | pages_old | rows_cached |
|
||||
-- +--------------------------+------------------------------------+-----------+--------+-------+--------------+-----------+-------------+
|
||||
-- | InnoDB System | SYS_COLUMNS | 131072 | 101350 | 8 | 8 | 8 | 1532 |
|
||||
-- | InnoDB System | SYS_FOREIGN | 131072 | 56808 | 8 | 8 | 8 | 172 |
|
||||
-- | InnoDB System | SYS_TABLES | 131072 | 57529 | 8 | 8 | 8 | 365 |
|
||||
-- | InnoDB System | SYS_INDEXES | 114688 | 77984 | 7 | 7 | 7 | 1046 |
|
||||
-- | mem30_trunk__instruments | agentlatencytime | 98304 | 29517 | 6 | 6 | 6 | 252 |
|
||||
-- | mem30_trunk__instruments | binlogspaceusagedata | 98304 | 23076 | 6 | 6 | 6 | 196 |
|
||||
-- | mem30_trunk__instruments | connectionsdata | 98304 | 37563 | 6 | 6 | 6 | 276 |
|
||||
-- ...
|
||||
-- +--------------------------+------------------------------------+-----------+--------+-------+--------------+-----------+-------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW x$innodb_buffer_stats_by_table (
|
||||
object_schema,
|
||||
object_name,
|
||||
allocated,
|
||||
data,
|
||||
pages,
|
||||
pages_hashed,
|
||||
pages_old,
|
||||
rows_cached
|
||||
) AS
|
||||
SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS object_schema,
|
||||
REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', -1), '`', '') AS object_name,
|
||||
SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) AS allocated,
|
||||
SUM(ibp.data_size) AS data,
|
||||
COUNT(ibp.page_number) AS pages,
|
||||
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
|
||||
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
|
||||
ROUND(IFNULL(SUM(ibp.number_records)/NULLIF(COUNT(DISTINCT ibp.index_name), 0), 0)) AS rows_cached
|
||||
FROM information_schema.innodb_buffer_page ibp
|
||||
WHERE table_name IS NOT NULL
|
||||
GROUP BY object_schema, object_name
|
||||
ORDER BY SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) DESC;
|
118
scripts/sys_schema/views/i_s/x_innodb_lock_waits.sql
Normal file
118
scripts/sys_schema/views/i_s/x_innodb_lock_waits.sql
Normal file
@ -0,0 +1,118 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: x$innodb_lock_waits
|
||||
--
|
||||
-- Give a snapshot of which InnoDB locks transactions are waiting for.
|
||||
-- The lock waits are ordered by the age of the lock descending.
|
||||
--
|
||||
-- Versions: 5.1+ (5.1 requires InnoDB Plugin with I_S tables)
|
||||
--
|
||||
-- mysql> SELECT * FROM x$innodb_lock_waits\G
|
||||
-- *************************** 1. row ***************************
|
||||
-- wait_started: 2014-11-11 13:39:20
|
||||
-- wait_age: 00:00:07
|
||||
-- wait_age_secs: 7
|
||||
-- locked_table: `db1`.`t1`
|
||||
-- locked_index: PRIMARY
|
||||
-- locked_type: RECORD
|
||||
-- waiting_trx_id: 867158
|
||||
-- waiting_trx_started: 2014-11-11 13:39:15
|
||||
-- waiting_trx_age: 00:00:12
|
||||
-- waiting_trx_rows_locked: 0
|
||||
-- waiting_trx_rows_modified: 0
|
||||
-- waiting_pid: 3
|
||||
-- waiting_query: UPDATE t1 SET val = val + 1 WHERE id = 2
|
||||
-- waiting_lock_id: 867158:2363:3:3
|
||||
-- waiting_lock_mode: X
|
||||
-- blocking_trx_id: 867157
|
||||
-- blocking_pid: 4
|
||||
-- blocking_query: UPDATE t1 SET val = val + 1 + SLEEP(10) WHERE id = 2
|
||||
-- blocking_lock_id: 867157:2363:3:3
|
||||
-- blocking_lock_mode: X
|
||||
-- blocking_trx_started: 2014-11-11 13:39:11
|
||||
-- blocking_trx_age: 00:00:16
|
||||
-- blocking_trx_rows_locked: 1
|
||||
-- blocking_trx_rows_modified: 1
|
||||
-- sql_kill_blocking_query: KILL QUERY 4
|
||||
-- sql_kill_blocking_connection: KILL 4
|
||||
-- 1 row in set (0.01 sec)
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW x$innodb_lock_waits (
|
||||
wait_started,
|
||||
wait_age,
|
||||
wait_age_secs,
|
||||
locked_table,
|
||||
locked_index,
|
||||
locked_type,
|
||||
waiting_trx_id,
|
||||
waiting_trx_started,
|
||||
waiting_trx_age,
|
||||
waiting_trx_rows_locked,
|
||||
waiting_trx_rows_modified,
|
||||
waiting_pid,
|
||||
waiting_query,
|
||||
waiting_lock_id,
|
||||
waiting_lock_mode,
|
||||
blocking_trx_id,
|
||||
blocking_pid,
|
||||
blocking_query,
|
||||
blocking_lock_id,
|
||||
blocking_lock_mode,
|
||||
blocking_trx_started,
|
||||
blocking_trx_age,
|
||||
blocking_trx_rows_locked,
|
||||
blocking_trx_rows_modified,
|
||||
sql_kill_blocking_query,
|
||||
sql_kill_blocking_connection
|
||||
) AS
|
||||
SELECT r.trx_wait_started AS wait_started,
|
||||
TIMEDIFF(NOW(), r.trx_wait_started) AS wait_age,
|
||||
TIMESTAMPDIFF(SECOND, r.trx_wait_started, NOW()) AS wait_age_secs,
|
||||
rl.lock_table AS locked_table,
|
||||
rl.lock_index AS locked_index,
|
||||
rl.lock_type AS locked_type,
|
||||
r.trx_id AS waiting_trx_id,
|
||||
r.trx_started as waiting_trx_started,
|
||||
TIMEDIFF(NOW(), r.trx_started) AS waiting_trx_age,
|
||||
r.trx_rows_locked AS waiting_trx_rows_locked,
|
||||
r.trx_rows_modified AS waiting_trx_rows_modified,
|
||||
r.trx_mysql_thread_id AS waiting_pid,
|
||||
r.trx_query AS waiting_query,
|
||||
rl.lock_id AS waiting_lock_id,
|
||||
rl.lock_mode AS waiting_lock_mode,
|
||||
b.trx_id AS blocking_trx_id,
|
||||
b.trx_mysql_thread_id AS blocking_pid,
|
||||
b.trx_query AS blocking_query,
|
||||
bl.lock_id AS blocking_lock_id,
|
||||
bl.lock_mode AS blocking_lock_mode,
|
||||
b.trx_started AS blocking_trx_started,
|
||||
TIMEDIFF(NOW(), b.trx_started) AS blocking_trx_age,
|
||||
b.trx_rows_locked AS blocking_trx_rows_locked,
|
||||
b.trx_rows_modified AS blocking_trx_rows_modified,
|
||||
CONCAT('KILL QUERY ', b.trx_mysql_thread_id) AS sql_kill_blocking_query,
|
||||
CONCAT('KILL ', b.trx_mysql_thread_id) AS sql_kill_blocking_connection
|
||||
FROM information_schema.innodb_lock_waits w
|
||||
INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
|
||||
INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id
|
||||
INNER JOIN information_schema.innodb_locks bl ON bl.lock_id = w.blocking_lock_id
|
||||
INNER JOIN information_schema.innodb_locks rl ON rl.lock_id = w.requested_lock_id
|
||||
ORDER BY r.trx_wait_started;
|
42
scripts/sys_schema/views/i_s/x_schema_flattened_keys.sql
Normal file
42
scripts/sys_schema/views/i_s/x_schema_flattened_keys.sql
Normal file
@ -0,0 +1,42 @@
|
||||
--
|
||||
-- View: x$schema_flattened_keys
|
||||
--
|
||||
-- Helper view for the schema_redundant_keys view.
|
||||
--
|
||||
-- mysql> select * from sys.x$schema_flattened_keys;
|
||||
-- +---------------+---------------------+------------------------------+------------+----------------+-----------------+
|
||||
-- | table_schema | table_name | index_name | non_unique | subpart_exists | index_columns |
|
||||
-- +---------------+---------------------+------------------------------+------------+----------------+-----------------+
|
||||
-- | mem__advisors | advisor_initialized | PRIMARY | 0 | 0 | advisorClassId |
|
||||
-- | mem__advisors | advisor_schedules | advisorClassIdIdx | 1 | 0 | advisorClassId |
|
||||
-- | mem__advisors | advisor_schedules | PRIMARY | 0 | 0 | schedule_id |
|
||||
-- | mem__advisors | app_identity_path | FK_7xbq2i81hgo0xlvnb6rr77s21 | 1 | 0 | for_schedule_id |
|
||||
-- | mem__advisors | app_identity_path | PRIMARY | 0 | 0 | hib_id |
|
||||
-- ...
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW x$schema_flattened_keys (
|
||||
table_schema,
|
||||
table_name,
|
||||
index_name,
|
||||
non_unique,
|
||||
subpart_exists,
|
||||
index_columns
|
||||
) AS
|
||||
SELECT
|
||||
TABLE_SCHEMA,
|
||||
TABLE_NAME,
|
||||
INDEX_NAME,
|
||||
MAX(NON_UNIQUE) AS non_unique,
|
||||
MAX(IF(SUB_PART IS NULL, 0, 1)) AS subpart_exists,
|
||||
GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX) AS index_columns
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE
|
||||
INDEX_TYPE='BTREE'
|
||||
AND TABLE_SCHEMA NOT IN ('mysql', 'sys', 'INFORMATION_SCHEMA', 'PERFORMANCE_SCHEMA')
|
||||
GROUP BY
|
||||
TABLE_SCHEMA, TABLE_NAME, INDEX_NAME;
|
60
scripts/sys_schema/views/p_s/host_summary.sql
Normal file
60
scripts/sys_schema/views/p_s/host_summary.sql
Normal file
@ -0,0 +1,60 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: host_summary
|
||||
--
|
||||
-- Summarizes statement activity, file IO and connections by host.
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select * from host_summary;
|
||||
-- +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+
|
||||
-- | host | statements | statement_latency | statement_avg_latency | table_scans | file_ios | file_io_latency | current_connections | total_connections | unique_users |
|
||||
-- +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+
|
||||
-- | hal1 | 2924 | 00:03:59.53 | 81.92 ms | 82 | 54702 | 55.61 s | 1 | 1 | 1 |
|
||||
-- +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW host_summary (
|
||||
host,
|
||||
statements,
|
||||
statement_latency,
|
||||
statement_avg_latency,
|
||||
table_scans,
|
||||
file_ios,
|
||||
file_io_latency,
|
||||
current_connections,
|
||||
total_connections,
|
||||
unique_users
|
||||
) AS
|
||||
SELECT IF(accounts.host IS NULL, 'background', accounts.host) AS host,
|
||||
SUM(stmt.total) AS statements,
|
||||
sys.format_time(SUM(stmt.total_latency)) AS statement_latency,
|
||||
sys.format_time(IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0)) AS statement_avg_latency,
|
||||
SUM(stmt.full_scans) AS table_scans,
|
||||
SUM(io.ios) AS file_ios,
|
||||
sys.format_time(SUM(io.io_latency)) AS file_io_latency,
|
||||
SUM(accounts.current_connections) AS current_connections,
|
||||
SUM(accounts.total_connections) AS total_connections,
|
||||
COUNT(DISTINCT accounts.user) AS unique_users
|
||||
FROM performance_schema.accounts
|
||||
LEFT JOIN sys.x$host_summary_by_statement_latency AS stmt ON accounts.host = stmt.host
|
||||
LEFT JOIN sys.x$host_summary_by_file_io AS io ON accounts.host = io.host
|
||||
GROUP BY IF(accounts.host IS NULL, 'background', accounts.host);
|
66
scripts/sys_schema/views/p_s/host_summary_57.sql
Normal file
66
scripts/sys_schema/views/p_s/host_summary_57.sql
Normal file
@ -0,0 +1,66 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: host_summary
|
||||
--
|
||||
-- Summarizes statement activity and connections by host
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select * from host_summary;
|
||||
-- +------+------------+---------------+-------------+---------------------+-------------------+--------------+----------------+------------------------+
|
||||
-- | host | statements | total_latency | avg_latency | current_connections | total_connections | unique_users | current_memory | total_memory_allocated |
|
||||
-- +------+------------+---------------+-------------+---------------------+-------------------+--------------+----------------+------------------------+
|
||||
-- | hal1 | 5663 | 00:01:47.14 | 18.92 ms | 1 | 1 | 1 | 1.41 MiB | 543.55 MiB |
|
||||
-- | hal2 | 225 | 14.49 s | 64.40 ms | 1 | 1 | 1 | 707.60 KiB | 81.02 MiB |
|
||||
-- +------+------------+---------------+-------------+---------------------+-------------------+--------------+----------------+------------------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW host_summary (
|
||||
host,
|
||||
statements,
|
||||
statement_latency,
|
||||
statement_avg_latency,
|
||||
table_scans,
|
||||
file_ios,
|
||||
file_io_latency,
|
||||
current_connections,
|
||||
total_connections,
|
||||
unique_users,
|
||||
current_memory,
|
||||
total_memory_allocated
|
||||
) AS
|
||||
SELECT IF(accounts.host IS NULL, 'background', accounts.host) AS host,
|
||||
SUM(stmt.total) AS statements,
|
||||
sys.format_time(SUM(stmt.total_latency)) AS statement_latency,
|
||||
sys.format_time(IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0)) AS statement_avg_latency,
|
||||
SUM(stmt.full_scans) AS table_scans,
|
||||
SUM(io.ios) AS file_ios,
|
||||
sys.format_time(SUM(io.io_latency)) AS file_io_latency,
|
||||
SUM(accounts.current_connections) AS current_connections,
|
||||
SUM(accounts.total_connections) AS total_connections,
|
||||
COUNT(DISTINCT user) AS unique_users,
|
||||
sys.format_bytes(SUM(mem.current_allocated)) AS current_memory,
|
||||
sys.format_bytes(SUM(mem.total_allocated)) AS total_memory_allocated
|
||||
FROM performance_schema.accounts
|
||||
JOIN sys.x$host_summary_by_statement_latency AS stmt ON accounts.host = stmt.host
|
||||
JOIN sys.x$host_summary_by_file_io AS io ON accounts.host = io.host
|
||||
JOIN sys.x$memory_by_host_by_current_bytes mem ON accounts.host = mem.host
|
||||
GROUP BY IF(accounts.host IS NULL, 'background', accounts.host);
|
47
scripts/sys_schema/views/p_s/host_summary_by_file_io.sql
Normal file
47
scripts/sys_schema/views/p_s/host_summary_by_file_io.sql
Normal file
@ -0,0 +1,47 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: host_summary_by_file_io
|
||||
--
|
||||
-- Summarizes file IO totals per host.
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select * from host_summary_by_file_io;
|
||||
-- +------------+-------+------------+
|
||||
-- | host | ios | io_latency |
|
||||
-- +------------+-------+------------+
|
||||
-- | hal1 | 26457 | 21.58 s |
|
||||
-- | hal2 | 1189 | 394.21 ms |
|
||||
-- +------------+-------+------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW host_summary_by_file_io (
|
||||
host,
|
||||
ios,
|
||||
io_latency
|
||||
) AS
|
||||
SELECT IF(host IS NULL, 'background', host) AS host,
|
||||
SUM(count_star) AS ios,
|
||||
sys.format_time(SUM(sum_timer_wait)) AS io_latency
|
||||
FROM performance_schema.events_waits_summary_by_host_by_event_name
|
||||
WHERE event_name LIKE 'wait/io/file/%'
|
||||
GROUP BY IF(host IS NULL, 'background', host)
|
||||
ORDER BY SUM(sum_timer_wait) DESC;
|
@ -0,0 +1,66 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: host_summary_by_file_io_type
|
||||
--
|
||||
-- Summarizes file IO by event type per host.
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select * from host_summary_by_file_io_type;
|
||||
-- +------------+--------------------------------------+-------+---------------+-------------+
|
||||
-- | host | event_name | total | total_latency | max_latency |
|
||||
-- +------------+--------------------------------------+-------+---------------+-------------+
|
||||
-- | hal1 | wait/io/file/sql/FRM | 871 | 168.15 ms | 18.48 ms |
|
||||
-- | hal1 | wait/io/file/innodb/innodb_data_file | 173 | 129.56 ms | 34.09 ms |
|
||||
-- | hal1 | wait/io/file/innodb/innodb_log_file | 20 | 77.53 ms | 60.66 ms |
|
||||
-- | hal1 | wait/io/file/myisam/dfile | 40 | 6.54 ms | 4.58 ms |
|
||||
-- | hal1 | wait/io/file/mysys/charset | 3 | 4.79 ms | 4.71 ms |
|
||||
-- | hal1 | wait/io/file/myisam/kfile | 67 | 4.38 ms | 300.04 us |
|
||||
-- | hal1 | wait/io/file/sql/ERRMSG | 5 | 2.72 ms | 1.69 ms |
|
||||
-- | hal1 | wait/io/file/sql/pid | 3 | 266.30 us | 185.47 us |
|
||||
-- | hal1 | wait/io/file/sql/casetest | 5 | 246.81 us | 150.19 us |
|
||||
-- | hal1 | wait/io/file/sql/global_ddl_log | 2 | 21.24 us | 18.59 us |
|
||||
-- | hal2 | wait/io/file/sql/file_parser | 1422 | 4.80 s | 135.14 ms |
|
||||
-- | hal2 | wait/io/file/sql/FRM | 865 | 85.82 ms | 9.81 ms |
|
||||
-- | hal2 | wait/io/file/myisam/kfile | 1073 | 37.14 ms | 15.79 ms |
|
||||
-- | hal2 | wait/io/file/myisam/dfile | 2991 | 25.53 ms | 5.25 ms |
|
||||
-- | hal2 | wait/io/file/sql/dbopt | 20 | 1.07 ms | 153.07 us |
|
||||
-- | hal2 | wait/io/file/sql/misc | 4 | 59.71 us | 33.75 us |
|
||||
-- | hal2 | wait/io/file/archive/data | 1 | 13.91 us | 13.91 us |
|
||||
-- +------------+--------------------------------------+-------+---------------+-------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW host_summary_by_file_io_type (
|
||||
host,
|
||||
event_name,
|
||||
total,
|
||||
total_latency,
|
||||
max_latency
|
||||
) AS
|
||||
SELECT IF(host IS NULL, 'background', host) AS host,
|
||||
event_name,
|
||||
count_star AS total,
|
||||
sys.format_time(sum_timer_wait) AS total_latency,
|
||||
sys.format_time(max_timer_wait) AS max_latency
|
||||
FROM performance_schema.events_waits_summary_by_host_by_event_name
|
||||
WHERE event_name LIKE 'wait/io/file%'
|
||||
AND count_star > 0
|
||||
ORDER BY IF(host IS NULL, 'background', host), sum_timer_wait DESC;
|
64
scripts/sys_schema/views/p_s/host_summary_by_stages.sql
Normal file
64
scripts/sys_schema/views/p_s/host_summary_by_stages.sql
Normal file
@ -0,0 +1,64 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: host_summary_by_stages
|
||||
--
|
||||
-- Summarizes stages by host, ordered by host and total latency per stage.
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select * from host_summary_by_stages;
|
||||
-- +------+--------------------------------+-------+---------------+-------------+
|
||||
-- | host | event_name | total | total_latency | avg_latency |
|
||||
-- +------+--------------------------------+-------+---------------+-------------+
|
||||
-- | hal | stage/sql/Opening tables | 889 | 1.97 ms | 2.22 us |
|
||||
-- | hal | stage/sql/Creating sort index | 4 | 1.79 ms | 446.30 us |
|
||||
-- | hal | stage/sql/init | 10 | 312.27 us | 31.23 us |
|
||||
-- | hal | stage/sql/checking permissions | 10 | 300.62 us | 30.06 us |
|
||||
-- | hal | stage/sql/freeing items | 5 | 85.89 us | 17.18 us |
|
||||
-- | hal | stage/sql/statistics | 5 | 79.15 us | 15.83 us |
|
||||
-- | hal | stage/sql/preparing | 5 | 69.12 us | 13.82 us |
|
||||
-- | hal | stage/sql/optimizing | 5 | 53.11 us | 10.62 us |
|
||||
-- | hal | stage/sql/Sending data | 5 | 44.66 us | 8.93 us |
|
||||
-- | hal | stage/sql/closing tables | 5 | 37.54 us | 7.51 us |
|
||||
-- | hal | stage/sql/System lock | 5 | 34.28 us | 6.86 us |
|
||||
-- | hal | stage/sql/query end | 5 | 24.37 us | 4.87 us |
|
||||
-- | hal | stage/sql/end | 5 | 8.60 us | 1.72 us |
|
||||
-- | hal | stage/sql/Sorting result | 5 | 8.33 us | 1.67 us |
|
||||
-- | hal | stage/sql/executing | 5 | 5.37 us | 1.07 us |
|
||||
-- | hal | stage/sql/cleaning up | 5 | 4.60 us | 919.00 ns |
|
||||
-- +------+--------------------------------+-------+---------------+-------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW host_summary_by_stages (
|
||||
host,
|
||||
event_name,
|
||||
total,
|
||||
total_latency,
|
||||
avg_latency
|
||||
) AS
|
||||
SELECT IF(host IS NULL, 'background', host) AS host,
|
||||
event_name,
|
||||
count_star AS total,
|
||||
sys.format_time(sum_timer_wait) AS total_latency,
|
||||
sys.format_time(avg_timer_wait) AS avg_latency
|
||||
FROM performance_schema.events_stages_summary_by_host_by_event_name
|
||||
WHERE sum_timer_wait != 0
|
||||
ORDER BY IF(host IS NULL, 'background', host), sum_timer_wait DESC;
|
@ -0,0 +1,57 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: host_summary_by_statement_latency
|
||||
--
|
||||
-- Summarizes overall statement statistics by host.
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select-- from host_summary_by_statement_latency;
|
||||
-- +------+-------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
|
||||
-- | host | total | total_latency | max_latency | lock_latency | rows_sent | rows_examined | rows_affected | full_scans |
|
||||
-- +------+-------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
|
||||
-- | hal | 3381 | 00:02:09.13 | 1.48 s | 1.07 s | 1151 | 93947 | 150 | 91 |
|
||||
-- +------+-------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW host_summary_by_statement_latency (
|
||||
host,
|
||||
total,
|
||||
total_latency,
|
||||
max_latency,
|
||||
lock_latency,
|
||||
rows_sent,
|
||||
rows_examined,
|
||||
rows_affected,
|
||||
full_scans
|
||||
) AS
|
||||
SELECT IF(host IS NULL, 'background', host) AS host,
|
||||
SUM(count_star) AS total,
|
||||
sys.format_time(SUM(sum_timer_wait)) AS total_latency,
|
||||
sys.format_time(MAX(max_timer_wait)) AS max_latency,
|
||||
sys.format_time(SUM(sum_lock_time)) AS lock_latency,
|
||||
SUM(sum_rows_sent) AS rows_sent,
|
||||
SUM(sum_rows_examined) AS rows_examined,
|
||||
SUM(sum_rows_affected) AS rows_affected,
|
||||
SUM(sum_no_index_used) + SUM(sum_no_good_index_used) AS full_scans
|
||||
FROM performance_schema.events_statements_summary_by_host_by_event_name
|
||||
GROUP BY IF(host IS NULL, 'background', host)
|
||||
ORDER BY SUM(sum_timer_wait) DESC;
|
@ -0,0 +1,64 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: host_summary_by_statement_type
|
||||
--
|
||||
-- Summarizes the types of statements executed by each host.
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select * from host_summary_by_statement_type;
|
||||
-- +------+----------------------+--------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
|
||||
-- | host | statement | total | total_latency | max_latency | lock_latency | rows_sent | rows_examined | rows_affected | full_scans |
|
||||
-- +------+----------------------+--------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
|
||||
-- | hal | create_view | 2063 | 00:05:04.20 | 463.58 ms | 1.42 s | 0 | 0 | 0 | 0 |
|
||||
-- | hal | select | 174 | 40.87 s | 28.83 s | 858.13 ms | 5212 | 157022 | 0 | 82 |
|
||||
-- | hal | stmt | 6645 | 15.31 s | 491.78 ms | 0 ps | 0 | 0 | 7951 | 0 |
|
||||
-- | hal | call_procedure | 17 | 4.78 s | 1.02 s | 37.94 ms | 0 | 0 | 19 | 0 |
|
||||
-- | hal | create_table | 19 | 3.04 s | 431.71 ms | 0 ps | 0 | 0 | 0 | 0 |
|
||||
-- ...
|
||||
-- +------+----------------------+--------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW host_summary_by_statement_type (
|
||||
host,
|
||||
statement,
|
||||
total,
|
||||
total_latency,
|
||||
max_latency,
|
||||
lock_latency,
|
||||
rows_sent,
|
||||
rows_examined,
|
||||
rows_affected,
|
||||
full_scans
|
||||
) AS
|
||||
SELECT IF(host IS NULL, 'background', host) AS host,
|
||||
SUBSTRING_INDEX(event_name, '/', -1) AS statement,
|
||||
count_star AS total,
|
||||
sys.format_time(sum_timer_wait) AS total_latency,
|
||||
sys.format_time(max_timer_wait) AS max_latency,
|
||||
sys.format_time(sum_lock_time) AS lock_latency,
|
||||
sum_rows_sent AS rows_sent,
|
||||
sum_rows_examined AS rows_examined,
|
||||
sum_rows_affected AS rows_affected,
|
||||
sum_no_index_used + sum_no_good_index_used AS full_scans
|
||||
FROM performance_schema.events_statements_summary_by_host_by_event_name
|
||||
WHERE sum_timer_wait != 0
|
||||
ORDER BY IF(host IS NULL, 'background', host), sum_timer_wait DESC;
|
70
scripts/sys_schema/views/p_s/io_by_thread_by_latency.sql
Normal file
70
scripts/sys_schema/views/p_s/io_by_thread_by_latency.sql
Normal file
@ -0,0 +1,70 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: io_by_thread_by_latency
|
||||
--
|
||||
-- Show the top IO consumers by thread, ordered by total latency
|
||||
--
|
||||
-- mysql> select * from io_by_thread_by_latency;
|
||||
-- +---------------------+-------+---------------+-------------+-------------+-------------+-----------+----------------+
|
||||
-- | user | total | total_latency | min_latency | avg_latency | max_latency | thread_id | processlist_id |
|
||||
-- +---------------------+-------+---------------+-------------+-------------+-------------+-----------+----------------+
|
||||
-- | root@localhost | 11580 | 18.01 s | 429.78 ns | 1.12 ms | 181.07 ms | 25 | 6 |
|
||||
-- | main | 1358 | 1.31 s | 475.02 ns | 2.27 ms | 350.70 ms | 1 | NULL |
|
||||
-- | page_cleaner_thread | 654 | 147.44 ms | 588.12 ns | 225.44 us | 46.41 ms | 18 | NULL |
|
||||
-- | io_write_thread | 131 | 107.75 ms | 8.60 us | 822.55 us | 27.69 ms | 8 | NULL |
|
||||
-- | io_write_thread | 46 | 47.07 ms | 10.64 us | 1.02 ms | 16.90 ms | 9 | NULL |
|
||||
-- | io_write_thread | 71 | 46.99 ms | 9.11 us | 661.81 us | 17.04 ms | 11 | NULL |
|
||||
-- | io_log_thread | 20 | 21.01 ms | 14.25 us | 1.05 ms | 7.08 ms | 3 | NULL |
|
||||
-- | srv_master_thread | 13 | 17.60 ms | 8.49 us | 1.35 ms | 9.99 ms | 16 | NULL |
|
||||
-- | srv_purge_thread | 4 | 1.81 ms | 34.31 us | 452.45 us | 1.02 ms | 17 | NULL |
|
||||
-- | io_write_thread | 19 | 951.39 us | 9.75 us | 50.07 us | 297.47 us | 10 | NULL |
|
||||
-- | signal_handler | 3 | 218.03 us | 21.64 us | 72.68 us | 154.84 us | 19 | NULL |
|
||||
-- +---------------------+-------+---------------+-------------+-------------+-------------+-----------+----------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW io_by_thread_by_latency (
|
||||
user,
|
||||
total,
|
||||
total_latency,
|
||||
min_latency,
|
||||
avg_latency,
|
||||
max_latency,
|
||||
thread_id,
|
||||
processlist_id
|
||||
)
|
||||
AS
|
||||
SELECT IF(processlist_id IS NULL,
|
||||
SUBSTRING_INDEX(name, '/', -1),
|
||||
CONCAT(processlist_user, '@', processlist_host)
|
||||
) user,
|
||||
SUM(count_star) total,
|
||||
sys.format_time(SUM(sum_timer_wait)) total_latency,
|
||||
sys.format_time(MIN(min_timer_wait)) min_latency,
|
||||
sys.format_time(AVG(avg_timer_wait)) avg_latency,
|
||||
sys.format_time(MAX(max_timer_wait)) max_latency,
|
||||
thread_id,
|
||||
processlist_id
|
||||
FROM performance_schema.events_waits_summary_by_thread_by_event_name
|
||||
LEFT JOIN performance_schema.threads USING (thread_id)
|
||||
WHERE event_name LIKE 'wait/io/file/%'
|
||||
AND sum_timer_wait > 0
|
||||
GROUP BY thread_id, processlist_id, user
|
||||
ORDER BY SUM(sum_timer_wait) DESC;
|
58
scripts/sys_schema/views/p_s/io_global_by_file_by_bytes.sql
Normal file
58
scripts/sys_schema/views/p_s/io_global_by_file_by_bytes.sql
Normal file
@ -0,0 +1,58 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: io_global_by_file_by_bytes
|
||||
--
|
||||
-- Shows the top global IO consumers by bytes usage by file.
|
||||
--
|
||||
-- mysql> SELECT * FROM io_global_by_file_by_bytes LIMIT 5;
|
||||
-- +--------------------------------------------+------------+------------+-----------+-------------+---------------+-----------+------------+-----------+
|
||||
-- | file | count_read | total_read | avg_read | count_write | total_written | avg_write | total | write_pct |
|
||||
-- +--------------------------------------------+------------+------------+-----------+-------------+---------------+-----------+------------+-----------+
|
||||
-- | @@datadir/ibdata1 | 147 | 4.27 MiB | 29.71 KiB | 3 | 48.00 KiB | 16.00 KiB | 4.31 MiB | 1.09 |
|
||||
-- | @@datadir/mysql/proc.MYD | 347 | 85.35 KiB | 252 bytes | 111 | 19.08 KiB | 176 bytes | 104.43 KiB | 18.27 |
|
||||
-- | @@datadir/ib_logfile0 | 6 | 68.00 KiB | 11.33 KiB | 8 | 4.00 KiB | 512 bytes | 72.00 KiB | 5.56 |
|
||||
-- | /opt/mysql/5.5.33/share/english/errmsg.sys | 3 | 43.68 KiB | 14.56 KiB | 0 | 0 bytes | 0 bytes | 43.68 KiB | 0.00 |
|
||||
-- | /opt/mysql/5.5.33/share/charsets/Index.xml | 1 | 17.89 KiB | 17.89 KiB | 0 | 0 bytes | 0 bytes | 17.89 KiB | 0.00 |
|
||||
-- +--------------------------------------------+------------+------------+-----------+-------------+---------------+-----------+------------+-----------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW io_global_by_file_by_bytes (
|
||||
file,
|
||||
count_read,
|
||||
total_read,
|
||||
avg_read,
|
||||
count_write,
|
||||
total_written,
|
||||
avg_write,
|
||||
total,
|
||||
write_pct
|
||||
) AS
|
||||
SELECT sys.format_path(file_name) AS file,
|
||||
count_read,
|
||||
sys.format_bytes(sum_number_of_bytes_read) AS total_read,
|
||||
sys.format_bytes(IFNULL(sum_number_of_bytes_read / NULLIF(count_read, 0), 0)) AS avg_read,
|
||||
count_write,
|
||||
sys.format_bytes(sum_number_of_bytes_write) AS total_written,
|
||||
sys.format_bytes(IFNULL(sum_number_of_bytes_write / NULLIF(count_write, 0), 0.00)) AS avg_write,
|
||||
sys.format_bytes(sum_number_of_bytes_read + sum_number_of_bytes_write) AS total,
|
||||
IFNULL(ROUND(100-((sum_number_of_bytes_read/ NULLIF((sum_number_of_bytes_read+sum_number_of_bytes_write), 0))*100), 2), 0.00) AS write_pct
|
||||
FROM performance_schema.file_summary_by_instance
|
||||
ORDER BY sum_number_of_bytes_read + sum_number_of_bytes_write DESC;
|
@ -0,0 +1,58 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: io_global_by_file_by_latency
|
||||
--
|
||||
-- Shows the top global IO consumers by latency by file.
|
||||
--
|
||||
-- mysql> select * from io_global_by_file_by_latency limit 5;
|
||||
-- +-----------------------------------------------------------+-------+---------------+------------+--------------+-------------+---------------+------------+--------------+
|
||||
-- | file | total | total_latency | count_read | read_latency | count_write | write_latency | count_misc | misc_latency |
|
||||
-- +-----------------------------------------------------------+-------+---------------+------------+--------------+-------------+---------------+------------+--------------+
|
||||
-- | @@datadir/sys/wait_classes_global_by_avg_latency_raw.frm~ | 24 | 451.99 ms | 0 | 0 ps | 4 | 108.07 us | 20 | 451.88 ms |
|
||||
-- | @@datadir/sys/innodb_buffer_stats_by_schema_raw.frm~ | 24 | 379.84 ms | 0 | 0 ps | 4 | 108.88 us | 20 | 379.73 ms |
|
||||
-- | @@datadir/sys/io_by_thread_by_latency_raw.frm~ | 24 | 379.46 ms | 0 | 0 ps | 4 | 101.37 us | 20 | 379.36 ms |
|
||||
-- | @@datadir/ibtmp1 | 53 | 373.45 ms | 0 | 0 ps | 48 | 246.08 ms | 5 | 127.37 ms |
|
||||
-- | @@datadir/sys/statement_analysis_raw.frm~ | 24 | 353.14 ms | 0 | 0 ps | 4 | 94.96 us | 20 | 353.04 ms |
|
||||
-- +-----------------------------------------------------------+-------+---------------+------------+--------------+-------------+---------------+------------+--------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW io_global_by_file_by_latency (
|
||||
file,
|
||||
total,
|
||||
total_latency,
|
||||
count_read,
|
||||
read_latency,
|
||||
count_write,
|
||||
write_latency,
|
||||
count_misc,
|
||||
misc_latency
|
||||
) AS
|
||||
SELECT sys.format_path(file_name) AS file,
|
||||
count_star AS total,
|
||||
sys.format_time(sum_timer_wait) AS total_latency,
|
||||
count_read,
|
||||
sys.format_time(sum_timer_read) AS read_latency,
|
||||
count_write,
|
||||
sys.format_time(sum_timer_write) AS write_latency,
|
||||
count_misc,
|
||||
sys.format_time(sum_timer_misc) AS misc_latency
|
||||
FROM performance_schema.file_summary_by_instance
|
||||
ORDER BY sum_timer_wait DESC;
|
79
scripts/sys_schema/views/p_s/io_global_by_wait_by_bytes.sql
Normal file
79
scripts/sys_schema/views/p_s/io_global_by_wait_by_bytes.sql
Normal file
@ -0,0 +1,79 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: io_global_by_wait_by_bytes
|
||||
--
|
||||
-- Shows the top global IO consumer classes by bytes usage.
|
||||
--
|
||||
-- mysql> select * from io_global_by_wait_by_bytes;
|
||||
-- +--------------------+--------+---------------+-------------+-------------+-------------+------------+------------+-----------+-------------+---------------+-------------+-----------------+
|
||||
-- | event_name | total | total_latency | min_latency | avg_latency | max_latency | count_read | total_read | avg_read | count_write | total_written | avg_written | total_requested |
|
||||
-- +--------------------+--------+---------------+-------------+-------------+-------------+------------+------------+-----------+-------------+---------------+-------------+-----------------+
|
||||
-- | myisam/dfile | 163681 | 983.13 ms | 379.08 ns | 6.01 us | 22.06 ms | 68737 | 127.31 MiB | 1.90 KiB | 1012221 | 121.52 MiB | 126 bytes | 248.83 MiB |
|
||||
-- | myisam/kfile | 1775 | 375.13 ms | 1.02 us | 211.34 us | 35.15 ms | 54066 | 9.97 MiB | 193 bytes | 428257 | 12.40 MiB | 30 bytes | 22.37 MiB |
|
||||
-- | sql/FRM | 57889 | 8.40 s | 19.44 ns | 145.05 us | 336.71 ms | 8009 | 2.60 MiB | 341 bytes | 14675 | 2.91 MiB | 208 bytes | 5.51 MiB |
|
||||
-- | sql/global_ddl_log | 164 | 75.96 ms | 5.72 us | 463.19 us | 7.43 ms | 20 | 80.00 KiB | 4.00 KiB | 76 | 304.00 KiB | 4.00 KiB | 384.00 KiB |
|
||||
-- | sql/file_parser | 419 | 601.37 ms | 1.96 us | 1.44 ms | 37.14 ms | 66 | 42.01 KiB | 652 bytes | 64 | 226.98 KiB | 3.55 KiB | 268.99 KiB |
|
||||
-- | sql/binlog | 190 | 6.79 s | 1.56 us | 35.76 ms | 4.21 s | 52 | 60.54 KiB | 1.16 KiB | 0 | 0 bytes | 0 bytes | 60.54 KiB |
|
||||
-- | sql/ERRMSG | 5 | 2.03 s | 8.61 us | 405.40 ms | 2.03 s | 3 | 51.82 KiB | 17.27 KiB | 0 | 0 bytes | 0 bytes | 51.82 KiB |
|
||||
-- | mysys/charset | 3 | 196.52 us | 17.61 us | 65.51 us | 137.33 us | 1 | 17.83 KiB | 17.83 KiB | 0 | 0 bytes | 0 bytes | 17.83 KiB |
|
||||
-- | sql/partition | 81 | 18.87 ms | 888.08 ns | 232.92 us | 4.67 ms | 66 | 2.75 KiB | 43 bytes | 8 | 288 bytes | 36 bytes | 3.04 KiB |
|
||||
-- | sql/dbopt | 329166 | 26.95 s | 2.06 us | 81.89 us | 178.71 ms | 0 | 0 bytes | 0 bytes | 9 | 585 bytes | 65 bytes | 585 bytes |
|
||||
-- | sql/relaylog | 7 | 1.18 ms | 838.84 ns | 168.30 us | 892.70 us | 0 | 0 bytes | 0 bytes | 1 | 120 bytes | 120 bytes | 120 bytes |
|
||||
-- | mysys/cnf | 5 | 171.61 us | 303.26 ns | 34.32 us | 115.21 us | 3 | 56 bytes | 19 bytes | 0 | 0 bytes | 0 bytes | 56 bytes |
|
||||
-- | sql/pid | 3 | 220.55 us | 29.29 us | 73.52 us | 143.11 us | 0 | 0 bytes | 0 bytes | 1 | 5 bytes | 5 bytes | 5 bytes |
|
||||
-- | sql/casetest | 1 | 121.19 us | 121.19 us | 121.19 us | 121.19 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes | 0 bytes |
|
||||
-- | sql/binlog_index | 5 | 593.47 us | 1.07 us | 118.69 us | 535.90 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes | 0 bytes |
|
||||
-- | sql/misc | 23 | 2.73 ms | 65.14 us | 118.50 us | 255.31 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes | 0 bytes |
|
||||
-- +--------------------+--------+---------------+-------------+-------------+-------------+------------+------------+-----------+-------------+---------------+-------------+-----------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW io_global_by_wait_by_bytes (
|
||||
event_name,
|
||||
total,
|
||||
total_latency,
|
||||
min_latency,
|
||||
avg_latency,
|
||||
max_latency,
|
||||
count_read,
|
||||
total_read,
|
||||
avg_read,
|
||||
count_write,
|
||||
total_written,
|
||||
avg_written,
|
||||
total_requested
|
||||
) AS
|
||||
SELECT SUBSTRING_INDEX(event_name, '/', -2) event_name,
|
||||
count_star AS total,
|
||||
sys.format_time(sum_timer_wait) AS total_latency,
|
||||
sys.format_time(min_timer_wait) AS min_latency,
|
||||
sys.format_time(avg_timer_wait) AS avg_latency,
|
||||
sys.format_time(max_timer_wait) AS max_latency,
|
||||
count_read,
|
||||
sys.format_bytes(sum_number_of_bytes_read) AS total_read,
|
||||
sys.format_bytes(IFNULL(sum_number_of_bytes_read / NULLIF(count_read, 0), 0)) AS avg_read,
|
||||
count_write,
|
||||
sys.format_bytes(sum_number_of_bytes_write) AS total_written,
|
||||
sys.format_bytes(IFNULL(sum_number_of_bytes_write / NULLIF(count_write, 0), 0)) AS avg_written,
|
||||
sys.format_bytes(sum_number_of_bytes_write + sum_number_of_bytes_read) AS total_requested
|
||||
FROM performance_schema.file_summary_by_event_name
|
||||
WHERE event_name LIKE 'wait/io/file/%'
|
||||
AND count_star > 0
|
||||
ORDER BY sum_number_of_bytes_write + sum_number_of_bytes_read DESC;
|
@ -0,0 +1,81 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: io_global_by_wait_by_latency
|
||||
--
|
||||
-- Shows the top global IO consumers by latency.
|
||||
--
|
||||
-- mysql> SELECT * FROM io_global_by_wait_by_latency;
|
||||
-- +-------------------------+-------+---------------+-------------+-------------+--------------+---------------+--------------+------------+------------+-----------+-------------+---------------+-------------+
|
||||
-- | event_name | total | total_latency | avg_latency | max_latency | read_latency | write_latency | misc_latency | count_read | total_read | avg_read | count_write | total_written | avg_written |
|
||||
-- +-------------------------+-------+---------------+-------------+-------------+--------------+---------------+--------------+------------+------------+-----------+-------------+---------------+-------------+
|
||||
-- | sql/file_parser | 5433 | 30.20 s | 5.56 ms | 203.65 ms | 22.08 ms | 24.89 ms | 30.16 s | 24 | 6.18 KiB | 264 bytes | 737 | 2.15 MiB | 2.99 KiB |
|
||||
-- | innodb/innodb_data_file | 1344 | 1.52 s | 1.13 ms | 350.70 ms | 203.82 ms | 450.96 ms | 868.21 ms | 147 | 2.30 MiB | 16.00 KiB | 1001 | 53.61 MiB | 54.84 KiB |
|
||||
-- | innodb/innodb_log_file | 828 | 893.48 ms | 1.08 ms | 30.11 ms | 16.32 ms | 705.89 ms | 171.27 ms | 6 | 68.00 KiB | 11.33 KiB | 413 | 2.19 MiB | 5.42 KiB |
|
||||
-- | myisam/kfile | 7642 | 242.34 ms | 31.71 us | 19.27 ms | 73.60 ms | 23.48 ms | 145.26 ms | 758 | 135.63 KiB | 183 bytes | 4386 | 232.52 KiB | 54 bytes |
|
||||
-- | myisam/dfile | 12540 | 223.47 ms | 17.82 us | 32.50 ms | 87.76 ms | 16.97 ms | 118.74 ms | 5390 | 4.49 MiB | 873 bytes | 1448 | 2.65 MiB | 1.88 KiB |
|
||||
-- | csv/metadata | 8 | 28.98 ms | 3.62 ms | 20.15 ms | 399.27 us | 0 ps | 28.58 ms | 2 | 70 bytes | 35 bytes | 0 | 0 bytes | 0 bytes |
|
||||
-- | mysys/charset | 3 | 24.24 ms | 8.08 ms | 24.15 ms | 24.15 ms | 0 ps | 93.18 us | 1 | 17.31 KiB | 17.31 KiB | 0 | 0 bytes | 0 bytes |
|
||||
-- | sql/ERRMSG | 5 | 20.43 ms | 4.09 ms | 19.31 ms | 20.32 ms | 0 ps | 103.20 us | 3 | 58.97 KiB | 19.66 KiB | 0 | 0 bytes | 0 bytes |
|
||||
-- | mysys/cnf | 5 | 11.37 ms | 2.27 ms | 11.28 ms | 11.29 ms | 0 ps | 78.22 us | 3 | 56 bytes | 19 bytes | 0 | 0 bytes | 0 bytes |
|
||||
-- | sql/dbopt | 57 | 4.04 ms | 70.92 us | 843.70 us | 0 ps | 186.43 us | 3.86 ms | 0 | 0 bytes | 0 bytes | 7 | 431 bytes | 62 bytes |
|
||||
-- | csv/data | 4 | 411.55 us | 102.89 us | 234.89 us | 0 ps | 0 ps | 411.55 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes |
|
||||
-- | sql/misc | 22 | 340.38 us | 15.47 us | 33.77 us | 0 ps | 0 ps | 340.38 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes |
|
||||
-- | archive/data | 39 | 277.86 us | 7.12 us | 16.18 us | 0 ps | 0 ps | 277.86 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes |
|
||||
-- | sql/pid | 3 | 218.03 us | 72.68 us | 154.84 us | 0 ps | 21.64 us | 196.39 us | 0 | 0 bytes | 0 bytes | 1 | 6 bytes | 6 bytes |
|
||||
-- | sql/casetest | 5 | 197.15 us | 39.43 us | 126.31 us | 0 ps | 0 ps | 197.15 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes |
|
||||
-- | sql/global_ddl_log | 2 | 14.60 us | 7.30 us | 12.12 us | 0 ps | 0 ps | 14.60 us | 0 | 0 bytes | 0 bytes | 0 | 0 bytes | 0 bytes |
|
||||
-- +-------------------------+-------+---------------+-------------+-------------+--------------+---------------+--------------+------------+------------+-----------+-------------+---------------+-------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW io_global_by_wait_by_latency (
|
||||
event_name,
|
||||
total,
|
||||
total_latency,
|
||||
avg_latency,
|
||||
max_latency,
|
||||
read_latency,
|
||||
write_latency,
|
||||
misc_latency,
|
||||
count_read,
|
||||
total_read,
|
||||
avg_read,
|
||||
count_write,
|
||||
total_written,
|
||||
avg_written
|
||||
) AS
|
||||
SELECT SUBSTRING_INDEX(event_name, '/', -2) AS event_name,
|
||||
count_star AS total,
|
||||
sys.format_time(sum_timer_wait) AS total_latency,
|
||||
sys.format_time(avg_timer_wait) AS avg_latency,
|
||||
sys.format_time(max_timer_wait) AS max_latency,
|
||||
sys.format_time(sum_timer_read) AS read_latency,
|
||||
sys.format_time(sum_timer_write) AS write_latency,
|
||||
sys.format_time(sum_timer_misc) AS misc_latency,
|
||||
count_read,
|
||||
sys.format_bytes(sum_number_of_bytes_read) AS total_read,
|
||||
sys.format_bytes(IFNULL(sum_number_of_bytes_read / NULLIF(count_read, 0), 0)) AS avg_read,
|
||||
count_write,
|
||||
sys.format_bytes(sum_number_of_bytes_write) AS total_written,
|
||||
sys.format_bytes(IFNULL(sum_number_of_bytes_write / NULLIF(count_write, 0), 0)) AS avg_written
|
||||
FROM performance_schema.file_summary_by_event_name
|
||||
WHERE event_name LIKE 'wait/io/file/%'
|
||||
AND count_star > 0
|
||||
ORDER BY sum_timer_wait DESC;
|
57
scripts/sys_schema/views/p_s/latest_file_io.sql
Normal file
57
scripts/sys_schema/views/p_s/latest_file_io.sql
Normal file
@ -0,0 +1,57 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: latest_file_io
|
||||
--
|
||||
-- Shows the latest file IO, by file / thread.
|
||||
--
|
||||
-- mysql> select * from latest_file_io limit 5;
|
||||
-- +----------------------+----------------------------------------+------------+-----------+-----------+
|
||||
-- | thread | file | latency | operation | requested |
|
||||
-- +----------------------+----------------------------------------+------------+-----------+-----------+
|
||||
-- | msandbox@localhost:1 | @@tmpdir/#sqlcf28_1_4e.MYI | 9.26 us | write | 124 bytes |
|
||||
-- | msandbox@localhost:1 | @@tmpdir/#sqlcf28_1_4e.MYI | 4.00 us | write | 2 bytes |
|
||||
-- | msandbox@localhost:1 | @@tmpdir/#sqlcf28_1_4e.MYI | 56.34 us | close | NULL |
|
||||
-- | msandbox@localhost:1 | @@tmpdir/#sqlcf28_1_4e.MYD | 53.93 us | close | NULL |
|
||||
-- | msandbox@localhost:1 | @@tmpdir/#sqlcf28_1_4e.MYI | 104.05 ms | delete | NULL |
|
||||
-- +----------------------+----------------------------------------+------------+-----------+-----------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW latest_file_io (
|
||||
thread,
|
||||
file,
|
||||
latency,
|
||||
operation,
|
||||
requested
|
||||
) AS
|
||||
SELECT IF(id IS NULL,
|
||||
CONCAT(SUBSTRING_INDEX(name, '/', -1), ':', thread_id),
|
||||
CONCAT(user, '@', host, ':', id)
|
||||
) thread,
|
||||
sys.format_path(object_name) file,
|
||||
sys.format_time(timer_wait) AS latency,
|
||||
operation,
|
||||
sys.format_bytes(number_of_bytes) AS requested
|
||||
FROM performance_schema.events_waits_history_long
|
||||
JOIN performance_schema.threads USING (thread_id)
|
||||
LEFT JOIN information_schema.processlist ON processlist_id = id
|
||||
WHERE object_name IS NOT NULL
|
||||
AND event_name LIKE 'wait/io/file/%'
|
||||
ORDER BY timer_start;
|
@ -0,0 +1,52 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: memory_by_host_by_current_bytes
|
||||
--
|
||||
-- Summarizes memory use by host using the 5.7 Performance Schema instrumentation.
|
||||
--
|
||||
-- When the host found is NULL, it is assumed to be a local "background" thread.
|
||||
--
|
||||
-- mysql> select * from memory_by_host_by_current_bytes;
|
||||
-- +------------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
-- | host | current_count_used | current_allocated | current_avg_alloc | current_max_alloc | total_allocated |
|
||||
-- +------------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
-- | background | 2773 | 10.84 MiB | 4.00 KiB | 8.00 MiB | 30.69 MiB |
|
||||
-- | localhost | 1509 | 809.30 KiB | 549 bytes | 176.38 KiB | 83.59 MiB |
|
||||
-- +------------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW memory_by_host_by_current_bytes (
|
||||
host,
|
||||
current_count_used,
|
||||
current_allocated,
|
||||
current_avg_alloc,
|
||||
current_max_alloc,
|
||||
total_allocated
|
||||
) AS
|
||||
SELECT IF(host IS NULL, 'background', host) AS host,
|
||||
SUM(current_count_used) AS current_count_used,
|
||||
sys.format_bytes(SUM(current_number_of_bytes_used)) AS current_allocated,
|
||||
sys.format_bytes(IFNULL(SUM(current_number_of_bytes_used) / NULLIF(SUM(current_count_used), 0), 0)) AS current_avg_alloc,
|
||||
sys.format_bytes(MAX(current_number_of_bytes_used)) AS current_max_alloc,
|
||||
sys.format_bytes(SUM(sum_number_of_bytes_alloc)) AS total_allocated
|
||||
FROM performance_schema.memory_summary_by_host_by_event_name
|
||||
GROUP BY IF(host IS NULL, 'background', host)
|
||||
ORDER BY SUM(current_number_of_bytes_used) DESC;
|
@ -0,0 +1,62 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: memory_by_thread_by_current_bytes
|
||||
--
|
||||
-- Summarizes memory use by user using the 5.7 Performance Schema instrumentation.
|
||||
--
|
||||
-- User shows either the background or foreground user name appropriately.
|
||||
--
|
||||
-- mysql> select * from sys.memory_by_thread_by_current_bytes limit 5;
|
||||
-- +-----------+----------------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
-- | thread_id | user | current_count_used | current_allocated | current_avg_alloc | current_max_alloc | total_allocated |
|
||||
-- +-----------+----------------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
-- | 1 | sql/main | 29333 | 166.02 MiB | 5.80 KiB | 131.13 MiB | 196.00 MiB |
|
||||
-- | 55 | root@localhost | 175 | 1.04 MiB | 6.09 KiB | 350.86 KiB | 67.37 MiB |
|
||||
-- | 58 | root@localhost | 236 | 368.13 KiB | 1.56 KiB | 312.05 KiB | 130.34 MiB |
|
||||
-- | 904 | root@localhost | 32 | 18.00 KiB | 576 bytes | 16.00 KiB | 6.68 MiB |
|
||||
-- | 970 | root@localhost | 12 | 16.80 KiB | 1.40 KiB | 16.00 KiB | 1.20 MiB |
|
||||
-- +-----------+----------------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW memory_by_thread_by_current_bytes (
|
||||
thread_id,
|
||||
user,
|
||||
current_count_used,
|
||||
current_allocated,
|
||||
current_avg_alloc,
|
||||
current_max_alloc,
|
||||
total_allocated
|
||||
) AS
|
||||
SELECT thread_id,
|
||||
IF(t.name = 'thread/sql/one_connection',
|
||||
CONCAT(t.processlist_user, '@', t.processlist_host),
|
||||
REPLACE(t.name, 'thread/', '')) user,
|
||||
SUM(mt.current_count_used) AS current_count_used,
|
||||
sys.format_bytes(SUM(mt.current_number_of_bytes_used)) AS current_allocated,
|
||||
sys.format_bytes(IFNULL(SUM(mt.current_number_of_bytes_used) / NULLIF(SUM(current_count_used), 0), 0)) AS current_avg_alloc,
|
||||
sys.format_bytes(MAX(mt.current_number_of_bytes_used)) AS current_max_alloc,
|
||||
sys.format_bytes(SUM(mt.sum_number_of_bytes_alloc)) AS total_allocated
|
||||
FROM performance_schema.memory_summary_by_thread_by_event_name AS mt
|
||||
JOIN performance_schema.threads AS t USING (thread_id)
|
||||
GROUP BY thread_id, IF(t.name = 'thread/sql/one_connection',
|
||||
CONCAT(t.processlist_user, '@', t.processlist_host),
|
||||
REPLACE(t.name, 'thread/', ''))
|
||||
ORDER BY SUM(current_number_of_bytes_used) DESC;
|
@ -0,0 +1,52 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: memory_by_user_by_current_bytes
|
||||
--
|
||||
-- Summarizes memory use by user using the 5.7 Performance Schema instrumentation.
|
||||
--
|
||||
-- When the user found is NULL, it is assumed to be a "background" thread.
|
||||
--
|
||||
-- mysql> select * from memory_by_user_by_current_bytes;
|
||||
-- +------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
-- | user | current_count_used | current_allocated | current_avg_alloc | current_max_alloc | total_allocated |
|
||||
-- +------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
-- | root | 1401 | 1.09 MiB | 815 bytes | 334.97 KiB | 42.73 MiB |
|
||||
-- | mark | 201 | 496.08 KiB | 2.47 KiB | 334.97 KiB | 5.50 MiB |
|
||||
-- +------+--------------------+-------------------+-------------------+-------------------+-----------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW memory_by_user_by_current_bytes (
|
||||
user,
|
||||
current_count_used,
|
||||
current_allocated,
|
||||
current_avg_alloc,
|
||||
current_max_alloc,
|
||||
total_allocated
|
||||
) AS
|
||||
SELECT IF(user IS NULL, 'background', user) AS user,
|
||||
SUM(current_count_used) AS current_count_used,
|
||||
sys.format_bytes(SUM(current_number_of_bytes_used)) AS current_allocated,
|
||||
sys.format_bytes(IFNULL(SUM(current_number_of_bytes_used) / NULLIF(SUM(current_count_used), 0), 0)) AS current_avg_alloc,
|
||||
sys.format_bytes(MAX(current_number_of_bytes_used)) AS current_max_alloc,
|
||||
sys.format_bytes(SUM(sum_number_of_bytes_alloc)) AS total_allocated
|
||||
FROM performance_schema.memory_summary_by_user_by_event_name
|
||||
GROUP BY IF(user IS NULL, 'background', user)
|
||||
ORDER BY SUM(current_number_of_bytes_used) DESC;
|
@ -0,0 +1,56 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: memory_global_by_current_bytes
|
||||
--
|
||||
-- Shows the current memory usage within the server globally broken down by allocation type.
|
||||
--
|
||||
-- mysql> select * from memory_global_by_current_bytes;
|
||||
-- +-------------------------------------------------+---------------+---------------+-------------------+------------+-------------+----------------+
|
||||
-- | event_name | current_count | current_alloc | current_avg_alloc | high_count | high_alloc | high_avg_alloc |
|
||||
-- +-------------------------------------------------+---------------+---------------+-------------------+------------+-------------+----------------+
|
||||
-- | memory/performance_schema/internal_buffers | 62 | 293.80 MiB | 4.74 MiB | 62 | 293.80 MiB | 4.74 MiB |
|
||||
-- | memory/innodb/buf_buf_pool | 1 | 131.06 MiB | 131.06 MiB | 1 | 131.06 MiB | 131.06 MiB |
|
||||
-- | memory/innodb/log0log | 9 | 8.01 MiB | 911.15 KiB | 9 | 8.01 MiB | 911.15 KiB |
|
||||
-- | memory/mysys/KEY_CACHE | 3 | 8.00 MiB | 2.67 MiB | 3 | 8.00 MiB | 2.67 MiB |
|
||||
-- | memory/innodb/hash0hash | 27 | 4.73 MiB | 179.51 KiB | 27 | 6.84 MiB | 259.47 KiB |
|
||||
-- | memory/innodb/os0event | 24998 | 4.01 MiB | 168 bytes | 24998 | 4.01 MiB | 168 bytes |
|
||||
-- ...
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = MERGE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW memory_global_by_current_bytes (
|
||||
event_name,
|
||||
current_count,
|
||||
current_alloc,
|
||||
current_avg_alloc,
|
||||
high_count,
|
||||
high_alloc,
|
||||
high_avg_alloc
|
||||
) AS
|
||||
SELECT event_name,
|
||||
current_count_used AS current_count,
|
||||
sys.format_bytes(current_number_of_bytes_used) AS current_alloc,
|
||||
sys.format_bytes(IFNULL(current_number_of_bytes_used / NULLIF(current_count_used, 0), 0)) AS current_avg_alloc,
|
||||
high_count_used AS high_count,
|
||||
sys.format_bytes(high_number_of_bytes_used) AS high_alloc,
|
||||
sys.format_bytes(IFNULL(high_number_of_bytes_used / NULLIF(high_count_used, 0), 0)) AS high_avg_alloc
|
||||
FROM performance_schema.memory_summary_global_by_event_name
|
||||
WHERE current_number_of_bytes_used > 0
|
||||
ORDER BY current_number_of_bytes_used DESC;
|
37
scripts/sys_schema/views/p_s/memory_global_total.sql
Normal file
37
scripts/sys_schema/views/p_s/memory_global_total.sql
Normal file
@ -0,0 +1,37 @@
|
||||
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
--
|
||||
-- View: memory_global_total
|
||||
--
|
||||
-- Shows the total memory usage within the server globally.
|
||||
--
|
||||
-- mysql> select * from memory_global_total;
|
||||
-- +-----------------+
|
||||
-- | total_allocated |
|
||||
-- +-----------------+
|
||||
-- | 123.35 MiB |
|
||||
-- +-----------------+
|
||||
--
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW memory_global_total (
|
||||
total_allocated
|
||||
) AS
|
||||
SELECT sys.format_bytes(SUM(CURRENT_NUMBER_OF_BYTES_USED)) total_allocated
|
||||
FROM performance_schema.memory_summary_global_by_event_name;
|
121
scripts/sys_schema/views/p_s/metrics.sql
Normal file
121
scripts/sys_schema/views/p_s/metrics.sql
Normal file
@ -0,0 +1,121 @@
|
||||
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; version 2 of the License.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program; if not, write to the Free Software
|
||||
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
-- IMPORTANT
|
||||
-- If you update this view, also update the "5.7+ and the Performance Schema disabled"
|
||||
-- query in procedures/diagnostics.sql
|
||||
|
||||
-- View: metrics
|
||||
--
|
||||
-- Creates a union of the following information:
|
||||
--
|
||||
-- * performance_schema.global_status
|
||||
-- * information_schema.INNODB_METRICS
|
||||
-- * Performance Schema global memory usage information
|
||||
-- * Current time
|
||||
--
|
||||
-- This is the same as the metrics_56 view with the exception that the global status is taken from performance_schema.global_status instead of
|
||||
-- from the Information Schema. Use this view if the MySQL version is 5.7.6 or later and show_compatibility_56 = OFF.
|
||||
-- See also https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_show_compatibility_56
|
||||
--
|
||||
-- For view has the following columns:
|
||||
--
|
||||
-- * Variable_name: The name of the variable
|
||||
-- * Variable_value: The value of the variable
|
||||
-- * Type: The type of the variable. This will depend on the source, e.g. Global Status, InnoDB Metrics - ..., etc.
|
||||
-- * Enabled: Whether the variable is enabled or not. Possible values are 'YES', 'NO', 'PARTIAL'.
|
||||
-- PARTIAL is currently only supported for the memory usage variables and means some but not all of the memory/% instruments
|
||||
-- are enabled.
|
||||
--
|
||||
-- mysql> SELECT * FROM metrics;
|
||||
-- +-----------------------------------------------+-------------------------...+--------------------------------------+---------+
|
||||
-- | Variable_name | Variable_value ...| Type | Enabled |
|
||||
-- +-----------------------------------------------+-------------------------...+--------------------------------------+---------+
|
||||
-- | aborted_clients | 0 ...| Global Status | YES |
|
||||
-- | aborted_connects | 0 ...| Global Status | YES |
|
||||
-- | binlog_cache_disk_use | 0 ...| Global Status | YES |
|
||||
-- | binlog_cache_use | 0 ...| Global Status | YES |
|
||||
-- | binlog_stmt_cache_disk_use | 0 ...| Global Status | YES |
|
||||
-- | binlog_stmt_cache_use | 0 ...| Global Status | YES |
|
||||
-- | bytes_received | 217081 ...| Global Status | YES |
|
||||
-- | bytes_sent | 27257 ...| Global Status | YES |
|
||||
-- ...
|
||||
-- | innodb_rwlock_x_os_waits | 0 ...| InnoDB Metrics - server | YES |
|
||||
-- | innodb_rwlock_x_spin_rounds | 2723 ...| InnoDB Metrics - server | YES |
|
||||
-- | innodb_rwlock_x_spin_waits | 1 ...| InnoDB Metrics - server | YES |
|
||||
-- | trx_active_transactions | 0 ...| InnoDB Metrics - transaction | NO |
|
||||
-- ...
|
||||
-- | trx_rseg_current_size | 0 ...| InnoDB Metrics - transaction | NO |
|
||||
-- | trx_rseg_history_len | 4 ...| InnoDB Metrics - transaction | YES |
|
||||
-- | trx_rw_commits | 0 ...| InnoDB Metrics - transaction | NO |
|
||||
-- | trx_undo_slots_cached | 0 ...| InnoDB Metrics - transaction | NO |
|
||||
-- | trx_undo_slots_used | 0 ...| InnoDB Metrics - transaction | NO |
|
||||
-- | memory_current_allocated | 138244216 ...| Performance Schema | PARTIAL |
|
||||
-- | memory_total_allocated | 138244216 ...| Performance Schema | PARTIAL |
|
||||
-- | NOW() | 2015-05-31 13:27:50.382 ...| System Time | YES |
|
||||
-- | UNIX_TIMESTAMP() | 1433042870.382 ...| System Time | YES |
|
||||
-- +-----------------------------------------------+-------------------------...+--------------------------------------+---------+
|
||||
-- 412 rows in set (0.02 sec)
|
||||
|
||||
CREATE OR REPLACE
|
||||
ALGORITHM = TEMPTABLE
|
||||
DEFINER = 'root'@'localhost'
|
||||
SQL SECURITY INVOKER
|
||||
VIEW metrics (
|
||||
Variable_name,
|
||||
Variable_value,
|
||||
Type,
|
||||
Enabled
|
||||
) AS
|
||||
(
|
||||
SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_value, 'Global Status' AS Type, 'YES' AS Enabled
|
||||
FROM performance_schema.global_status
|
||||
) UNION ALL (
|
||||
SELECT NAME AS Variable_name, COUNT AS Variable_value,
|
||||
CONCAT('InnoDB Metrics - ', SUBSYSTEM) AS Type,
|
||||
IF(STATUS = 'enabled', 'YES', 'NO') AS Enabled
|
||||
FROM information_schema.INNODB_METRICS
|
||||
-- Deduplication - some variables exists both in GLOBAL_STATUS and INNODB_METRICS
|
||||
-- Keep the one from GLOBAL_STATUS as it is always enabled and it's more likely to be used for existing tools.
|
||||
WHERE NAME NOT IN (
|
||||
'lock_row_lock_time', 'lock_row_lock_time_avg', 'lock_row_lock_time_max', 'lock_row_lock_waits',
|
||||
'buffer_pool_reads', 'buffer_pool_read_requests', 'buffer_pool_write_requests', 'buffer_pool_wait_free',
|
||||
'buffer_pool_read_ahead', 'buffer_pool_read_ahead_evicted', 'buffer_pool_pages_total', 'buffer_pool_pages_misc',
|
||||
'buffer_pool_pages_data', 'buffer_pool_bytes_data', 'buffer_pool_pages_dirty', 'buffer_pool_bytes_dirty',
|
||||
'buffer_pool_pages_free', 'buffer_pages_created', 'buffer_pages_written', 'buffer_pages_read',
|
||||
'buffer_data_reads', 'buffer_data_written', 'file_num_open_files',
|
||||
'os_log_bytes_written', 'os_log_fsyncs', 'os_log_pending_fsyncs', 'os_log_pending_writes',
|
||||
'log_waits', 'log_write_requests', 'log_writes', 'innodb_dblwr_writes', 'innodb_dblwr_pages_written', 'innodb_page_size')
|
||||
) /*!50702
|
||||
-- memory instrumentation available in 5.7.2 and later
|
||||
UNION ALL (
|
||||
SELECT 'memory_current_allocated' AS Variable_name, SUM(CURRENT_NUMBER_OF_BYTES_USED) AS Variable_value, 'Performance Schema' AS Type,
|
||||
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = 0, 'NO',
|
||||
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = (SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%'), 'YES',
|
||||
'PARTIAL')) AS Enabled
|
||||
FROM performance_schema.memory_summary_global_by_event_name
|
||||
) UNION ALL (
|
||||
SELECT 'memory_total_allocated' AS Variable_name, SUM(SUM_NUMBER_OF_BYTES_ALLOC) AS Variable_value, 'Performance Schema' AS Type,
|
||||
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = 0, 'NO',
|
||||
IF((SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = (SELECT COUNT(*) FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%'), 'YES',
|
||||
'PARTIAL')) AS Enabled
|
||||
FROM performance_schema.memory_summary_global_by_event_name
|
||||
) */
|
||||
UNION ALL (
|
||||
SELECT 'NOW()' AS Variable_name, NOW(3) AS Variable_value, 'System Time' AS Type, 'YES' AS Enabled
|
||||
) UNION ALL (
|
||||
SELECT 'UNIX_TIMESTAMP()' AS Variable_name, ROUND(UNIX_TIMESTAMP(NOW(3)), 3) AS Variable_value, 'System Time' AS Type, 'YES' AS Enabled
|
||||
)
|
||||
ORDER BY Type, Variable_name;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user