1 /* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24 #ifndef PFS_TABLE_HELPER_H 25 #define PFS_TABLE_HELPER_H 26 27 /** 28 @file storage/perfschema/table_helper.h 29 Helpers to implement a performance schema table. 30 */ 31 32 #include <stddef.h> 33 #include <sys/types.h> 34 35 #include "lex_string.h" 36 #include "my_dbug.h" 37 #include "my_inttypes.h" 38 #include "storage/perfschema/digest.h" 39 #include "storage/perfschema/pfs_column_types.h" 40 #include "storage/perfschema/pfs_digest.h" 41 #include "storage/perfschema/pfs_engine_table.h" 42 #include "storage/perfschema/pfs_events.h" 43 #include "storage/perfschema/pfs_instr_class.h" 44 #include "storage/perfschema/pfs_setup_actor.h" 45 #include "storage/perfschema/pfs_stat.h" 46 #include "storage/perfschema/pfs_timer.h" 47 48 struct PFS_host; 49 struct PFS_user; 50 struct PFS_account; 51 struct PFS_object_name; 52 struct PFS_program; 53 class System_variable; 54 class Status_variable; 55 struct User_variable; 56 struct PFS_events_waits; 57 struct PFS_table; 58 struct PFS_prepared_stmt; 59 struct PFS_metadata_lock; 60 struct PFS_setup_actor; 61 struct PFS_setup_object; 62 class Json_wrapper; 63 64 /** 65 @file storage/perfschema/table_helper.h 66 Performance schema table helpers (declarations). 67 */ 68 69 /** 70 @addtogroup performance_schema_tables 71 @{ 72 */ 73 74 /** 75 Helper, assign a value to a @c tinyint field. 76 @param f the field to set 77 @param value the value to assign 78 */ 79 void set_field_tiny(Field *f, long value); 80 81 /** 82 Helper, assign a value to a @c unsigned tinyint field. 83 @param f the field to set 84 @param value the value to assign 85 */ 86 void set_field_utiny(Field *f, ulong value); 87 88 /** 89 Helper, read a value from an @c tinyint field. 90 @param f the field to read 91 @return the field value 92 */ 93 long get_field_tiny(Field *f); 94 95 ulong get_field_utiny(Field *f); 96 97 /** 98 Helper, assign a value to a @c short field. 99 @param f the field to set 100 @param value the value to assign 101 */ 102 void set_field_short(Field *f, long value); 103 104 /** 105 Helper, assign a value to a @c unsigned short field. 106 @param f the field to set 107 @param value the value to assign 108 */ 109 void set_field_ushort(Field *f, ulong value); 110 111 /** 112 Helper, read a value from an @c smallint field. 113 @param f the field to read 114 @return the field value 115 */ 116 long get_field_short(Field *f); 117 118 ulong get_field_ushort(Field *f); 119 120 /** 121 Helper, assign a value to a @c medium field. 122 @param f the field to set 123 @param value the value to assign 124 */ 125 void set_field_medium(Field *f, long value); 126 127 /** 128 Helper, assign a value to a @c unsigned medium field. 129 @param f the field to set 130 @param value the value to assign 131 */ 132 void set_field_umedium(Field *f, ulong value); 133 134 /** 135 Helper, read a value from an @c mediumint field. 136 @param f the field to read 137 @return the field value 138 */ 139 long get_field_medium(Field *f); 140 141 ulong get_field_umedium(Field *f); 142 143 /** 144 Helper, assign a value to a @c long field. 145 @param f the field to set 146 @param value the value to assign 147 */ 148 void set_field_long(Field *f, long value); 149 150 /** 151 Helper, assign a value to a @c ulong field. 152 @param f the field to set 153 @param value the value to assign 154 */ 155 void set_field_ulong(Field *f, ulong value); 156 157 /** 158 Helper, read a value from a @c long field. 159 @param f the field to read 160 @return the field value 161 */ 162 long get_field_long(Field *f); 163 164 ulong get_field_ulong(Field *f); 165 166 /** 167 Helper, assign a value to a @c longlong field. 168 @param f the field to set 169 @param value the value to assign 170 */ 171 void set_field_longlong(Field *f, longlong value); 172 173 /** 174 Helper, assign a value to a @c ulonglong field. 175 @param f the field to set 176 @param value the value to assign 177 */ 178 void set_field_ulonglong(Field *f, ulonglong value); 179 180 longlong get_field_longlong(Field *f); 181 182 /** 183 Helper, read a value from an @c ulonglong field. 184 @param f the field to read 185 @return the field value 186 */ 187 ulonglong get_field_ulonglong(Field *f); 188 189 /** 190 Helper, assign a value to a @c decimal field. 191 @param f the field to set 192 @param value the value to assign 193 */ 194 void set_field_decimal(Field *f, double value); 195 196 /** 197 Helper, read a value from a @c decimal field. 198 @param f the field to read 199 @return the field value 200 */ 201 double get_field_decimal(Field *f); 202 203 /** 204 Helper, assign a value to a @c float field. 205 @param f the field to set 206 @param value the value to assign 207 */ 208 void set_field_float(Field *f, double value); 209 210 /** 211 Helper, read a value from a @c float field. 212 @param f the field to read 213 @return the field value 214 */ 215 double get_field_float(Field *f); 216 217 /** 218 Helper, assign a value to a @c double field. 219 @param f the field to set 220 @param value the value to assign 221 */ 222 void set_field_double(Field *f, double value); 223 224 /** 225 Helper, read a value from a @c double field. 226 @param f the field to read 227 @return the field value 228 */ 229 double get_field_double(Field *f); 230 231 /** 232 Helper, assign a value to a @code char utf8 @endcode field. 233 @param f the field to set 234 @param str the string to assign 235 @param len the length of the string to assign 236 */ 237 void set_field_char_utf8(Field *f, const char *str, uint len); 238 239 /** 240 Helper, read a value from a @code char utf8 @endcode field. 241 @param f the field to read 242 @param[out] val the field value 243 @param[out] len field value length 244 @return the field value 245 */ 246 char *get_field_char_utf8(Field *f, char *val, uint *len); 247 248 /** 249 Helper, read a value from a @code char utf8 @endcode field. 250 @param f the field to read 251 @param[out] val the field value 252 @return the field value 253 */ 254 String *get_field_char_utf8(Field *f, String *val); 255 256 /** 257 Helper, assign a value to a @code varchar utf8 @endcode field. 258 @param f the field to set 259 @param cs the string character set 260 @param str the string to assign 261 @param len the length of the string to assign 262 */ 263 void set_field_varchar(Field *f, const CHARSET_INFO *cs, const char *str, 264 uint len); 265 266 /** 267 Helper, assign a value to a @code varchar utf8 @endcode field. 268 @param f the field to set 269 @param str the string to assign 270 */ 271 void set_field_varchar_utf8(Field *f, const char *str); 272 273 /** 274 Helper, assign a value to a @code varchar utf8 @endcode field. 275 @param f the field to set 276 @param str the string to assign 277 @param len the length of the string to assign 278 */ 279 void set_field_varchar_utf8(Field *f, const char *str, size_t len); 280 281 /** 282 Helper, read a value from a @code varchar utf8 @endcode field. 283 @param f the field to read 284 @param[out] val the field value 285 @return the field value 286 */ 287 String *get_field_varchar_utf8(Field *f, String *val); 288 289 /** 290 Helper, read a value from a @code varchar utf8 @endcode field. 291 @param f the field to read 292 @param[out] val the field value 293 @param[out] len field value length 294 @return the field value 295 */ 296 char *get_field_varchar_utf8(Field *f, char *val, uint *len); 297 298 /** 299 Helper, assign a value to a @code varchar utf8mb4 @endcode field. 300 @param f the field to set 301 @param str the string to assign 302 */ 303 void set_field_varchar_utf8mb4(Field *f, const char *str); 304 305 /** 306 Helper, assign a value to a @code varchar utf8mb4 @endcode field. 307 @param f the field to set 308 @param str the string to assign 309 @param len the length of the string to assign 310 */ 311 void set_field_varchar_utf8mb4(Field *f, const char *str, uint len); 312 313 /** 314 Helper, assign a value to a text/blob field. 315 @param f the field to set 316 @param val the value to assign 317 @param len the length of the string to assign 318 */ 319 void set_field_blob(Field *f, const char *val, size_t len); 320 321 /** 322 Helper, assign a value to a text field. 323 @param f the field to set 324 @param val the value to assign 325 @param len the length of the string to assign 326 @param cs the charset of the string 327 */ 328 void set_field_text(Field *f, const char *val, size_t len, 329 const CHARSET_INFO *cs); 330 /** 331 Helper, read a value from a @c blob field. 332 @param f the field to read 333 @param[out] val the field value 334 @param[out] len field value length 335 @return the field value 336 */ 337 char *get_field_blob(Field *f, char *val, uint *len); 338 339 /** 340 Helper, assign a value to an @c enum field. 341 @param f the field to set 342 @param value the value to assign 343 */ 344 void set_field_enum(Field *f, ulonglong value); 345 346 /** 347 Helper, read a value from an @c enum field. 348 @param f the field to read 349 @return the field value 350 */ 351 ulonglong get_field_enum(Field *f); 352 353 /** 354 Helper, assign a value to a @c set field. 355 @param f the field to set 356 @param value the value to assign 357 */ 358 void set_field_set(Field *f, ulonglong value); 359 360 /** 361 Helper, read a value from a @c set field. 362 @param f the field to read 363 @return the field value 364 */ 365 ulonglong get_field_set(Field *f); 366 367 /** 368 Helper, assign a value to a @c date field. 369 @param f the field to set 370 @param value the value to assign 371 @param len length of the value 372 */ 373 void set_field_date(Field *f, const char *value, uint len); 374 375 /** 376 Helper, read a value from an @c date field. 377 @param f the field to read 378 @param[out] val the field value 379 @param[out] len field value length 380 @return the field value 381 */ 382 char *get_field_date(Field *f, char *val, uint *len); 383 384 /** 385 Helper, assign a value to a @c time field. 386 @param f the field to set 387 @param value the value to assign 388 @param len length of the value 389 */ 390 void set_field_time(Field *f, const char *value, uint len); 391 392 /** 393 Helper, read a value from an @c time field. 394 @param f the field to read 395 @param[out] val the field value 396 @param[out] len field value length 397 @return the field value 398 */ 399 char *get_field_time(Field *f, char *val, uint *len); 400 401 /** 402 Helper, assign a value to a @c datetime field. 403 @param f the field to set 404 @param value the value to assign 405 @param len length of the value 406 */ 407 void set_field_datetime(Field *f, const char *value, uint len); 408 409 /** 410 Helper, read a value from an @c datetime field. 411 @param f the field to read 412 @param[out] val the field value 413 @param[out] len field value length 414 @return the field value 415 */ 416 char *get_field_datetime(Field *f, char *val, uint *len); 417 418 /** 419 Helper, assign a value to a @c timestamp field. 420 @param f the field to set 421 @param value the value to assign 422 */ 423 void set_field_timestamp(Field *f, ulonglong value); 424 425 /** 426 Helper, assign a value to a @c timestamp field. 427 @param f the field to set 428 @param value the value to assign 429 @param len length of the value 430 */ 431 void set_field_timestamp(Field *f, const char *value, uint len); 432 433 /** 434 Helper, read a value from an @c timestamp field. 435 @param f the field to read 436 @param[out] val the field value 437 @param[out] len field value length 438 @return the field value 439 */ 440 char *get_field_timestamp(Field *f, char *val, uint *len); 441 442 /** 443 Helper, assign a value to a @c year field. 444 @param f the field to set 445 @param value the value to assign 446 */ 447 void set_field_year(Field *f, ulong value); 448 449 /** 450 Helper, read a value from an @c year field. 451 @param f the field to read 452 @return the field value 453 */ 454 ulong get_field_year(Field *f); 455 456 /** 457 Helper, assign a value to a JSON field. 458 @param f the field to set 459 @param json the value to assign 460 */ 461 void set_field_json(Field *f, const Json_wrapper *json); 462 463 /** 464 Helper, format sql text for output. 465 466 @param source_sqltext raw sqltext, possibly truncated 467 @param source_length length of source_sqltext 468 @param source_cs character set of source_sqltext 469 @param truncated true if source_sqltext was truncated 470 @param sqltext sqltext formatted for output 471 */ 472 void format_sqltext(const char *source_sqltext, size_t source_length, 473 const CHARSET_INFO *source_cs, bool truncated, 474 String &sqltext); 475 476 /** 477 Create a SOURCE column from source file and line. 478 479 @param source_file source file name pointer from __FILE__ 480 @param source_line line number 481 @param row_buffer target string buffer 482 @param row_buffer_size size of target buffer 483 @param row_length string length of combined source file and line 484 */ 485 void make_source_column(const char *source_file, size_t source_line, 486 char row_buffer[], size_t row_buffer_size, 487 uint &row_length); 488 489 /** Name space, internal views used within table setup_instruments. */ 490 struct PFS_instrument_view_constants { 491 static const uint FIRST_INSTRUMENT = 1; 492 493 static const uint FIRST_VIEW = 1; 494 static const uint VIEW_MUTEX = 1; 495 static const uint VIEW_RWLOCK = 2; 496 static const uint VIEW_COND = 3; 497 static const uint VIEW_FILE = 4; 498 static const uint VIEW_TABLE = 5; 499 static const uint VIEW_SOCKET = 6; 500 static const uint VIEW_IDLE = 7; 501 static const uint VIEW_METADATA = 8; 502 static const uint LAST_VIEW = 8; 503 504 /* 505 THREAD are displayed in table setup_threads 506 instead of setup_instruments. 507 */ 508 509 static const uint VIEW_STAGE = 9; 510 static const uint VIEW_STATEMENT = 10; 511 static const uint VIEW_TRANSACTION = 11; 512 static const uint VIEW_BUILTIN_MEMORY = 12; 513 static const uint VIEW_MEMORY = 13; 514 static const uint VIEW_ERROR = 14; 515 516 static const uint LAST_INSTRUMENT = 14; 517 }; 518 519 /** Name space, internal views used within object summaries. */ 520 struct PFS_object_view_constants { 521 static const uint FIRST_VIEW = 1; 522 static const uint VIEW_TABLE = 1; 523 static const uint VIEW_PROGRAM = 2; 524 static const uint LAST_VIEW = 2; 525 }; 526 527 /** Row fragment for column HOST. */ 528 struct PFS_host_row { 529 /** Column HOST. */ 530 char m_hostname[HOSTNAME_LENGTH]; 531 /** Length in bytes of @c m_hostname. */ 532 uint m_hostname_length; 533 534 /** Build a row from a memory buffer. */ 535 int make_row(PFS_host *pfs); 536 /** Set a table field from the row. */ 537 void set_field(Field *f); 538 }; 539 540 /** Row fragment for column USER. */ 541 struct PFS_user_row { 542 /** Column USER. */ 543 char m_username[USERNAME_LENGTH]; 544 /** Length in bytes of @c m_username. */ 545 uint m_username_length; 546 547 /** Build a row from a memory buffer. */ 548 int make_row(PFS_user *pfs); 549 /** Set a table field from the row. */ 550 void set_field(Field *f); 551 }; 552 553 /** Row fragment for columns USER, HOST. */ 554 struct PFS_account_row { 555 /** Column USER. */ 556 char m_username[USERNAME_LENGTH]; 557 /** Length in bytes of @c m_username. */ 558 uint m_username_length; 559 /** Column HOST. */ 560 char m_hostname[HOSTNAME_LENGTH]; 561 /** Length in bytes of @c m_hostname. */ 562 uint m_hostname_length; 563 564 /** Build a row from a memory buffer. */ 565 int make_row(PFS_account *pfs); 566 /** Set a table field from the row. */ 567 void set_field(uint index, Field *f); 568 }; 569 570 /** Row fragment for columns DIGEST, DIGEST_TEXT. */ 571 struct PFS_digest_row { 572 /** Column SCHEMA_NAME. */ 573 char m_schema_name[NAME_LEN]; 574 /** Length in bytes of @c m_schema_name. */ 575 uint m_schema_name_length; 576 /** Column DIGEST. */ 577 char m_digest[DIGEST_HASH_TO_STRING_LENGTH + 1]; 578 /** Length in bytes of @c m_digest. */ 579 uint m_digest_length; 580 /** Column DIGEST_TEXT. */ 581 String m_digest_text; 582 583 /** Build a row from a memory buffer. */ 584 int make_row(PFS_statements_digest_stat *); 585 /** Set a table field from the row. */ 586 void set_field(uint index, Field *f); 587 }; 588 589 /** Row fragment for column EVENT_NAME. */ 590 struct PFS_event_name_row { 591 /** Column EVENT_NAME. */ 592 const char *m_name; 593 /** Length in bytes of @c m_name. */ 594 uint m_name_length; 595 596 /** Build a row from a memory buffer. */ make_rowPFS_event_name_row597 inline int make_row(PFS_instr_class *pfs) { 598 m_name = pfs->m_name; 599 m_name_length = pfs->m_name_length; 600 return 0; 601 } 602 603 /** Set a table field from the row. */ set_fieldPFS_event_name_row604 inline void set_field(Field *f) { 605 set_field_varchar_utf8(f, m_name, m_name_length); 606 } 607 }; 608 609 /** Row fragment for columns OBJECT_TYPE, SCHEMA_NAME, OBJECT_NAME. */ 610 struct PFS_object_row { 611 /** Column OBJECT_TYPE. */ 612 enum_object_type m_object_type; 613 /** Column SCHEMA_NAME. */ 614 char m_schema_name[NAME_LEN]; 615 /** Length in bytes of @c m_schema_name. */ 616 size_t m_schema_name_length; 617 /** Column OBJECT_NAME. */ 618 char m_object_name[NAME_LEN]; 619 /** Length in bytes of @c m_object_name. */ 620 size_t m_object_name_length; 621 622 /** Build a row from a memory buffer. */ 623 int make_row(PFS_table_share *pfs); 624 int make_row(PFS_program *pfs); 625 /** Set a table field from the row. */ 626 void set_field(uint index, Field *f); 627 void set_nullable_field(uint index, Field *f); 628 }; 629 630 /** Row fragment for columns OBJECT_TYPE, SCHEMA_NAME, OBJECT_NAME, COLUMN_NAME. 631 */ 632 struct PFS_column_row { 633 /** Column OBJECT_TYPE. */ 634 enum_object_type m_object_type; 635 /** Column SCHEMA_NAME. */ 636 char m_schema_name[NAME_LEN]; 637 /** Length in bytes of @c m_schema_name. */ 638 size_t m_schema_name_length; 639 /** Column OBJECT_NAME. */ 640 char m_object_name[NAME_LEN]; 641 /** Length in bytes of @c m_object_name. */ 642 size_t m_object_name_length; 643 /** Column OBJECT_NAME. */ 644 char m_column_name[NAME_LEN]; 645 /** Length in bytes of @c m_column_name. */ 646 size_t m_column_name_length; 647 648 /** Build a row from a memory buffer. */ 649 int make_row(const MDL_key *pfs); 650 /** Set a table field from the row. */ 651 void set_nullable_field(uint index, Field *f); 652 }; 653 654 /** Row fragment for columns OBJECT_TYPE, SCHEMA_NAME, OBJECT_NAME, INDEX_NAME. 655 */ 656 struct PFS_index_row { 657 PFS_object_row m_object_row; 658 /** Column INDEX_NAME. */ 659 char m_index_name[NAME_LEN]; 660 /** Length in bytes of @c m_index_name. */ 661 size_t m_index_name_length; 662 663 /** Build a row from a memory buffer. */ 664 int make_index_name(PFS_table_share_index *pfs_index, uint table_index); 665 int make_row(PFS_table_share *pfs, PFS_table_share_index *pfs_index, 666 uint table_index); 667 /** Set a table field from the row. */ 668 void set_field(uint index, Field *f); 669 }; 670 671 /** Row fragment for single statistics columns (COUNT, SUM, MIN, AVG, MAX) */ 672 struct PFS_stat_row { 673 /** Column COUNT_STAR. */ 674 ulonglong m_count; 675 /** Column SUM_TIMER_WAIT. */ 676 ulonglong m_sum; 677 /** Column MIN_TIMER_WAIT. */ 678 ulonglong m_min; 679 /** Column AVG_TIMER_WAIT. */ 680 ulonglong m_avg; 681 /** Column MAX_TIMER_WAIT. */ 682 ulonglong m_max; 683 resetPFS_stat_row684 inline void reset() { 685 m_count = 0; 686 m_sum = 0; 687 m_min = 0; 688 m_avg = 0; 689 m_max = 0; 690 } 691 692 /** Build a row with timer fields from a memory buffer. */ setPFS_stat_row693 inline void set(time_normalizer *normalizer, const PFS_single_stat *stat) { 694 m_count = stat->m_count; 695 696 if ((m_count != 0) && stat->has_timed_stats()) { 697 m_sum = normalizer->wait_to_pico(stat->m_sum); 698 m_min = normalizer->wait_to_pico(stat->m_min); 699 m_max = normalizer->wait_to_pico(stat->m_max); 700 m_avg = normalizer->wait_to_pico(stat->m_sum / m_count); 701 } else { 702 m_sum = 0; 703 m_min = 0; 704 m_avg = 0; 705 m_max = 0; 706 } 707 } 708 709 /** Set a table field from the row. */ set_fieldPFS_stat_row710 void set_field(uint index, Field *f) { 711 switch (index) { 712 case 0: /* COUNT */ 713 set_field_ulonglong(f, m_count); 714 break; 715 case 1: /* SUM */ 716 set_field_ulonglong(f, m_sum); 717 break; 718 case 2: /* MIN */ 719 set_field_ulonglong(f, m_min); 720 break; 721 case 3: /* AVG */ 722 set_field_ulonglong(f, m_avg); 723 break; 724 case 4: /* MAX */ 725 set_field_ulonglong(f, m_max); 726 break; 727 default: 728 DBUG_ASSERT(false); 729 } 730 } 731 }; 732 733 /** Row fragment for timer and byte count stats. Corresponds to PFS_byte_stat */ 734 struct PFS_byte_stat_row { 735 PFS_stat_row m_waits; 736 ulonglong m_bytes; 737 738 /** Build a row with timer and byte count fields from a memory buffer. */ setPFS_byte_stat_row739 inline void set(time_normalizer *normalizer, const PFS_byte_stat *stat) { 740 m_waits.set(normalizer, stat); 741 m_bytes = stat->m_bytes; 742 } 743 }; 744 745 /** Row fragment for table I/O statistics columns. */ 746 struct PFS_table_io_stat_row { 747 PFS_stat_row m_all; 748 PFS_stat_row m_all_read; 749 PFS_stat_row m_all_write; 750 PFS_stat_row m_fetch; 751 PFS_stat_row m_insert; 752 PFS_stat_row m_update; 753 PFS_stat_row m_delete; 754 755 /** Build a row from a memory buffer. */ setPFS_table_io_stat_row756 inline void set(time_normalizer *normalizer, const PFS_table_io_stat *stat) { 757 PFS_single_stat all_read; 758 PFS_single_stat all_write; 759 PFS_single_stat all; 760 761 m_fetch.set(normalizer, &stat->m_fetch); 762 763 all_read.aggregate(&stat->m_fetch); 764 765 m_insert.set(normalizer, &stat->m_insert); 766 m_update.set(normalizer, &stat->m_update); 767 m_delete.set(normalizer, &stat->m_delete); 768 769 all_write.aggregate(&stat->m_insert); 770 all_write.aggregate(&stat->m_update); 771 all_write.aggregate(&stat->m_delete); 772 773 all.aggregate(&all_read); 774 all.aggregate(&all_write); 775 776 m_all_read.set(normalizer, &all_read); 777 m_all_write.set(normalizer, &all_write); 778 m_all.set(normalizer, &all); 779 } 780 }; 781 782 /** Row fragment for table lock statistics columns. */ 783 struct PFS_table_lock_stat_row { 784 PFS_stat_row m_all; 785 PFS_stat_row m_all_read; 786 PFS_stat_row m_all_write; 787 PFS_stat_row m_read_normal; 788 PFS_stat_row m_read_with_shared_locks; 789 PFS_stat_row m_read_high_priority; 790 PFS_stat_row m_read_no_insert; 791 PFS_stat_row m_read_external; 792 PFS_stat_row m_write_allow_write; 793 PFS_stat_row m_write_concurrent_insert; 794 PFS_stat_row m_write_low_priority; 795 PFS_stat_row m_write_normal; 796 PFS_stat_row m_write_external; 797 798 /** Build a row from a memory buffer. */ setPFS_table_lock_stat_row799 inline void set(time_normalizer *normalizer, 800 const PFS_table_lock_stat *stat) { 801 PFS_single_stat all_read; 802 PFS_single_stat all_write; 803 PFS_single_stat all; 804 805 m_read_normal.set(normalizer, &stat->m_stat[PFS_TL_READ]); 806 m_read_with_shared_locks.set(normalizer, 807 &stat->m_stat[PFS_TL_READ_WITH_SHARED_LOCKS]); 808 m_read_high_priority.set(normalizer, 809 &stat->m_stat[PFS_TL_READ_HIGH_PRIORITY]); 810 m_read_no_insert.set(normalizer, &stat->m_stat[PFS_TL_READ_NO_INSERT]); 811 m_read_external.set(normalizer, &stat->m_stat[PFS_TL_READ_EXTERNAL]); 812 813 all_read.aggregate(&stat->m_stat[PFS_TL_READ]); 814 all_read.aggregate(&stat->m_stat[PFS_TL_READ_WITH_SHARED_LOCKS]); 815 all_read.aggregate(&stat->m_stat[PFS_TL_READ_HIGH_PRIORITY]); 816 all_read.aggregate(&stat->m_stat[PFS_TL_READ_NO_INSERT]); 817 all_read.aggregate(&stat->m_stat[PFS_TL_READ_EXTERNAL]); 818 819 m_write_allow_write.set(normalizer, 820 &stat->m_stat[PFS_TL_WRITE_ALLOW_WRITE]); 821 m_write_concurrent_insert.set( 822 normalizer, &stat->m_stat[PFS_TL_WRITE_CONCURRENT_INSERT]); 823 m_write_low_priority.set(normalizer, 824 &stat->m_stat[PFS_TL_WRITE_LOW_PRIORITY]); 825 m_write_normal.set(normalizer, &stat->m_stat[PFS_TL_WRITE]); 826 m_write_external.set(normalizer, &stat->m_stat[PFS_TL_WRITE_EXTERNAL]); 827 828 all_write.aggregate(&stat->m_stat[PFS_TL_WRITE_ALLOW_WRITE]); 829 all_write.aggregate(&stat->m_stat[PFS_TL_WRITE_CONCURRENT_INSERT]); 830 all_write.aggregate(&stat->m_stat[PFS_TL_WRITE_LOW_PRIORITY]); 831 all_write.aggregate(&stat->m_stat[PFS_TL_WRITE]); 832 all_write.aggregate(&stat->m_stat[PFS_TL_WRITE_EXTERNAL]); 833 834 all.aggregate(&all_read); 835 all.aggregate(&all_write); 836 837 m_all_read.set(normalizer, &all_read); 838 m_all_write.set(normalizer, &all_write); 839 m_all.set(normalizer, &all); 840 } 841 }; 842 843 /** Row fragment for stage statistics columns. */ 844 struct PFS_stage_stat_row { 845 PFS_stat_row m_timer1_row; 846 847 /** Build a row from a memory buffer. */ setPFS_stage_stat_row848 inline void set(time_normalizer *normalizer, const PFS_stage_stat *stat) { 849 m_timer1_row.set(normalizer, &stat->m_timer1_stat); 850 } 851 852 /** Set a table field from the row. */ set_fieldPFS_stage_stat_row853 void set_field(uint index, Field *f) { m_timer1_row.set_field(index, f); } 854 }; 855 856 /** Row fragment for statement statistics columns. */ 857 struct PFS_statement_stat_row { 858 PFS_stat_row m_timer1_row; 859 ulonglong m_error_count; 860 ulonglong m_warning_count; 861 ulonglong m_rows_affected; 862 ulonglong m_lock_time; 863 ulonglong m_rows_sent; 864 ulonglong m_rows_examined; 865 ulonglong m_created_tmp_disk_tables; 866 ulonglong m_created_tmp_tables; 867 ulonglong m_select_full_join; 868 ulonglong m_select_full_range_join; 869 ulonglong m_select_range; 870 ulonglong m_select_range_check; 871 ulonglong m_select_scan; 872 ulonglong m_sort_merge_passes; 873 ulonglong m_sort_range; 874 ulonglong m_sort_rows; 875 ulonglong m_sort_scan; 876 ulonglong m_no_index_used; 877 ulonglong m_no_good_index_used; 878 879 /** Build a row from a memory buffer. */ setPFS_statement_stat_row880 inline void set(time_normalizer *normalizer, const PFS_statement_stat *stat) { 881 if (stat->m_timer1_stat.m_count != 0) { 882 m_timer1_row.set(normalizer, &stat->m_timer1_stat); 883 884 m_error_count = stat->m_error_count; 885 m_warning_count = stat->m_warning_count; 886 m_lock_time = stat->m_lock_time * MICROSEC_TO_PICOSEC; 887 m_rows_affected = stat->m_rows_affected; 888 m_rows_sent = stat->m_rows_sent; 889 m_rows_examined = stat->m_rows_examined; 890 m_created_tmp_disk_tables = stat->m_created_tmp_disk_tables; 891 m_created_tmp_tables = stat->m_created_tmp_tables; 892 m_select_full_join = stat->m_select_full_join; 893 m_select_full_range_join = stat->m_select_full_range_join; 894 m_select_range = stat->m_select_range; 895 m_select_range_check = stat->m_select_range_check; 896 m_select_scan = stat->m_select_scan; 897 m_sort_merge_passes = stat->m_sort_merge_passes; 898 m_sort_range = stat->m_sort_range; 899 m_sort_rows = stat->m_sort_rows; 900 m_sort_scan = stat->m_sort_scan; 901 m_no_index_used = stat->m_no_index_used; 902 m_no_good_index_used = stat->m_no_good_index_used; 903 } else { 904 m_timer1_row.reset(); 905 906 m_error_count = 0; 907 m_warning_count = 0; 908 m_lock_time = 0; 909 m_rows_affected = 0; 910 m_rows_sent = 0; 911 m_rows_examined = 0; 912 m_created_tmp_disk_tables = 0; 913 m_created_tmp_tables = 0; 914 m_select_full_join = 0; 915 m_select_full_range_join = 0; 916 m_select_range = 0; 917 m_select_range_check = 0; 918 m_select_scan = 0; 919 m_sort_merge_passes = 0; 920 m_sort_range = 0; 921 m_sort_rows = 0; 922 m_sort_scan = 0; 923 m_no_index_used = 0; 924 m_no_good_index_used = 0; 925 } 926 } 927 928 /** Set a table field from the row. */ 929 void set_field(uint index, Field *f); 930 }; 931 932 /** Row fragment for stored program statistics. */ 933 struct PFS_sp_stat_row { 934 PFS_stat_row m_timer1_row; 935 936 /** Build a row from a memory buffer. */ setPFS_sp_stat_row937 inline void set(time_normalizer *normalizer, const PFS_sp_stat *stat) { 938 m_timer1_row.set(normalizer, &stat->m_timer1_stat); 939 } 940 941 /** Set a table field from the row. */ set_fieldPFS_sp_stat_row942 inline void set_field(uint index, Field *f) { 943 m_timer1_row.set_field(index, f); 944 } 945 }; 946 947 /** Row fragment for transaction statistics columns. */ 948 struct PFS_transaction_stat_row { 949 PFS_stat_row m_timer1_row; 950 PFS_stat_row m_read_write_row; 951 PFS_stat_row m_read_only_row; 952 ulonglong m_savepoint_count; 953 ulonglong m_rollback_to_savepoint_count; 954 ulonglong m_release_savepoint_count; 955 956 /** Build a row from a memory buffer. */ setPFS_transaction_stat_row957 inline void set(time_normalizer *normalizer, 958 const PFS_transaction_stat *stat) { 959 /* Combine read write/read only stats */ 960 PFS_single_stat all; 961 all.aggregate(&stat->m_read_only_stat); 962 all.aggregate(&stat->m_read_write_stat); 963 964 m_timer1_row.set(normalizer, &all); 965 m_read_write_row.set(normalizer, &stat->m_read_write_stat); 966 m_read_only_row.set(normalizer, &stat->m_read_only_stat); 967 } 968 969 /** Set a table field from the row. */ 970 void set_field(uint index, Field *f); 971 }; 972 973 /** Row fragment for error statistics columns. */ 974 struct PFS_error_stat_row { 975 ulonglong m_count; 976 ulonglong m_handled_count; 977 uint m_error_index; 978 ulonglong m_first_seen; 979 ulonglong m_last_seen; 980 981 /** Build a row from a memory buffer. */ setPFS_error_stat_row982 inline void set(const PFS_error_single_stat *stat, uint error_index) { 983 m_count = stat->m_count; 984 m_handled_count = stat->m_handled_count; 985 m_error_index = error_index; 986 m_first_seen = stat->m_first_seen; 987 m_last_seen = stat->m_last_seen; 988 } 989 990 /** Set a table field from the row. */ 991 void set_field(uint index, Field *f, server_error *temp_error); 992 }; 993 994 /** Row fragment for connection statistics. */ 995 struct PFS_connection_stat_row { 996 ulonglong m_current_connections; 997 ulonglong m_total_connections; 998 setPFS_connection_stat_row999 inline void set(const PFS_connection_stat *stat) { 1000 m_current_connections = stat->m_current_connections; 1001 m_total_connections = stat->m_total_connections; 1002 } 1003 1004 /** Set a table field from the row. */ 1005 void set_field(uint index, Field *f); 1006 }; 1007 1008 void set_field_object_type(Field *f, enum_object_type object_type); 1009 void set_field_lock_type(Field *f, PFS_TL_LOCK_TYPE lock_type); 1010 void set_field_mdl_type(Field *f, opaque_mdl_type mdl_type); 1011 void set_field_mdl_duration(Field *f, opaque_mdl_duration mdl_duration); 1012 void set_field_mdl_status(Field *f, opaque_mdl_status mdl_status); 1013 void set_field_isolation_level(Field *f, enum_isolation_level iso_level); 1014 void set_field_xa_state(Field *f, enum_xa_transaction_state xa_state); 1015 1016 /** Row fragment for socket I/O statistics columns. */ 1017 struct PFS_socket_io_stat_row { 1018 PFS_byte_stat_row m_read; 1019 PFS_byte_stat_row m_write; 1020 PFS_byte_stat_row m_misc; 1021 PFS_byte_stat_row m_all; 1022 setPFS_socket_io_stat_row1023 inline void set(time_normalizer *normalizer, const PFS_socket_io_stat *stat) { 1024 PFS_byte_stat all; 1025 1026 m_read.set(normalizer, &stat->m_read); 1027 m_write.set(normalizer, &stat->m_write); 1028 m_misc.set(normalizer, &stat->m_misc); 1029 1030 /* Combine stats for all operations */ 1031 all.aggregate(&stat->m_read); 1032 all.aggregate(&stat->m_write); 1033 all.aggregate(&stat->m_misc); 1034 1035 m_all.set(normalizer, &all); 1036 } 1037 }; 1038 1039 /** Row fragment for file I/O statistics columns. */ 1040 struct PFS_file_io_stat_row { 1041 PFS_byte_stat_row m_read; 1042 PFS_byte_stat_row m_write; 1043 PFS_byte_stat_row m_misc; 1044 PFS_byte_stat_row m_all; 1045 setPFS_file_io_stat_row1046 inline void set(time_normalizer *normalizer, const PFS_file_io_stat *stat) { 1047 PFS_byte_stat all; 1048 1049 m_read.set(normalizer, &stat->m_read); 1050 m_write.set(normalizer, &stat->m_write); 1051 m_misc.set(normalizer, &stat->m_misc); 1052 1053 /* Combine stats for all operations */ 1054 all.aggregate(&stat->m_read); 1055 all.aggregate(&stat->m_write); 1056 all.aggregate(&stat->m_misc); 1057 1058 m_all.set(normalizer, &all); 1059 } 1060 }; 1061 1062 /** Row fragment for memory statistics columns. */ 1063 struct PFS_memory_stat_row { 1064 PFS_memory_safe_stat m_stat; 1065 1066 /** Build a row from a memory buffer. */ setPFS_memory_stat_row1067 inline void set(const PFS_memory_safe_stat *stat) { m_stat = *stat; } 1068 1069 /** Build a row from a memory buffer. */ setPFS_memory_stat_row1070 inline void set(const PFS_memory_shared_stat *stat) { 1071 m_stat.m_used = stat->m_used; 1072 m_stat.m_alloc_count = stat->m_alloc_count; 1073 m_stat.m_free_count = stat->m_free_count; 1074 m_stat.m_alloc_size = stat->m_alloc_size; 1075 m_stat.m_free_size = stat->m_free_size; 1076 m_stat.m_alloc_count_capacity = stat->m_alloc_count_capacity; 1077 m_stat.m_free_count_capacity = stat->m_free_count_capacity; 1078 m_stat.m_alloc_size_capacity = stat->m_alloc_size_capacity; 1079 m_stat.m_free_size_capacity = stat->m_free_size_capacity; 1080 } 1081 1082 /** Set a table field from the row. */ 1083 void set_field(uint index, Field *f); 1084 }; 1085 1086 struct PFS_variable_name_row { 1087 public: PFS_variable_name_rowPFS_variable_name_row1088 PFS_variable_name_row() { 1089 m_str[0] = '\0'; 1090 m_length = 0; 1091 } 1092 1093 int make_row(const char *str, size_t length); 1094 1095 char m_str[NAME_CHAR_LEN + 1]; 1096 uint m_length; 1097 }; 1098 1099 struct PFS_variable_value_row { 1100 public: 1101 /** Set the row from a status variable. */ 1102 int make_row(const Status_variable *var); 1103 1104 /** Set the row from a system variable. */ 1105 int make_row(const System_variable *var); 1106 1107 /** Set a table field from the row. */ 1108 void set_field(Field *f); 1109 get_strPFS_variable_value_row1110 const char *get_str() const { return m_str; } get_lengthPFS_variable_value_row1111 uint get_length() const { return m_length; } 1112 1113 private: 1114 int make_row(const CHARSET_INFO *cs, const char *str, size_t length); 1115 1116 char m_str[1024]; 1117 uint m_length; 1118 const CHARSET_INFO *m_charset; 1119 }; 1120 1121 struct PFS_user_variable_value_row { 1122 public: PFS_user_variable_value_rowPFS_user_variable_value_row1123 PFS_user_variable_value_row() : m_value(nullptr), m_value_length(0) {} 1124 PFS_user_variable_value_rowPFS_user_variable_value_row1125 PFS_user_variable_value_row(const PFS_user_variable_value_row &rhs) { 1126 make_row(rhs.m_value, rhs.m_value_length); 1127 } 1128 ~PFS_user_variable_value_rowPFS_user_variable_value_row1129 ~PFS_user_variable_value_row() { clear(); } 1130 1131 int make_row(const char *val, size_t length); 1132 get_valuePFS_user_variable_value_row1133 const char *get_value() const { return m_value; } 1134 get_value_lengthPFS_user_variable_value_row1135 size_t get_value_length() const { return m_value_length; } 1136 1137 void clear(); 1138 1139 private: 1140 char *m_value; 1141 size_t m_value_length; 1142 }; 1143 1144 class PFS_key_long : public PFS_engine_key { 1145 public: PFS_key_long(const char * name)1146 PFS_key_long(const char *name) : PFS_engine_key(name), m_key_value(0) {} 1147 ~PFS_key_long()1148 virtual ~PFS_key_long() {} 1149 stateless_read(PFS_key_reader & reader,enum ha_rkey_function find_flag,bool & is_null,long * key_value)1150 static enum ha_rkey_function stateless_read(PFS_key_reader &reader, 1151 enum ha_rkey_function find_flag, 1152 bool &is_null, long *key_value) { 1153 return reader.read_long(find_flag, is_null, key_value); 1154 } 1155 read(PFS_key_reader & reader,enum ha_rkey_function find_flag)1156 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag) { 1157 m_find_flag = stateless_read(reader, find_flag, m_is_null, &m_key_value); 1158 } 1159 1160 static bool stateless_match(bool record_null, long record_value, 1161 bool m_is_null, long m_key_value, 1162 enum ha_rkey_function find_flag); 1163 1164 protected: do_match(bool record_null,long record_value)1165 bool do_match(bool record_null, long record_value) { 1166 return stateless_match(record_null, record_value, m_is_null, m_key_value, 1167 m_find_flag); 1168 } 1169 1170 private: 1171 long m_key_value; 1172 }; 1173 1174 class PFS_key_ulong : public PFS_engine_key { 1175 public: PFS_key_ulong(const char * name)1176 PFS_key_ulong(const char *name) : PFS_engine_key(name), m_key_value(0) {} 1177 ~PFS_key_ulong()1178 virtual ~PFS_key_ulong() {} 1179 stateless_read(PFS_key_reader & reader,enum ha_rkey_function find_flag,bool & is_null,ulong * key_value)1180 static enum ha_rkey_function stateless_read(PFS_key_reader &reader, 1181 enum ha_rkey_function find_flag, 1182 bool &is_null, ulong *key_value) { 1183 return reader.read_ulong(find_flag, is_null, key_value); 1184 } 1185 read(PFS_key_reader & reader,enum ha_rkey_function find_flag)1186 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag) { 1187 m_find_flag = reader.read_ulong(find_flag, m_is_null, &m_key_value); 1188 } 1189 1190 static bool stateless_match(bool record_null, ulong record_value, 1191 bool m_is_null, ulong m_key_value, 1192 enum ha_rkey_function find_flag); 1193 1194 protected: 1195 bool do_match(bool record_null, ulong record_value); 1196 1197 private: 1198 ulong m_key_value; 1199 }; 1200 1201 class PFS_key_longlong : public PFS_engine_key { 1202 public: PFS_key_longlong(const char * name)1203 PFS_key_longlong(const char *name) : PFS_engine_key(name), m_key_value(0) {} 1204 ~PFS_key_longlong()1205 virtual ~PFS_key_longlong() {} 1206 read(PFS_key_reader & reader,enum ha_rkey_function find_flag)1207 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag) { 1208 m_find_flag = reader.read_longlong(find_flag, m_is_null, &m_key_value); 1209 } 1210 1211 static bool stateless_match(bool record_null, longlong record_value, 1212 bool m_is_null, longlong m_key_value, 1213 enum ha_rkey_function find_flag); 1214 1215 protected: do_match(bool record_null,longlong record_value)1216 bool do_match(bool record_null, longlong record_value) { 1217 return stateless_match(record_null, record_value, m_is_null, m_key_value, 1218 m_find_flag); 1219 } 1220 1221 private: 1222 longlong m_key_value; 1223 }; 1224 1225 class PFS_key_ulonglong : public PFS_engine_key { 1226 public: PFS_key_ulonglong(const char * name)1227 PFS_key_ulonglong(const char *name) : PFS_engine_key(name), m_key_value(0) {} 1228 ~PFS_key_ulonglong()1229 virtual ~PFS_key_ulonglong() {} 1230 read(PFS_key_reader & reader,enum ha_rkey_function find_flag)1231 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag) { 1232 m_find_flag = reader.read_ulonglong(find_flag, m_is_null, &m_key_value); 1233 } 1234 1235 static bool stateless_match(bool record_null, ulonglong record_value, 1236 bool m_is_null, ulonglong m_key_value, 1237 enum ha_rkey_function find_flag); 1238 1239 protected: 1240 bool do_match(bool record_null, ulonglong record_value); 1241 1242 private: 1243 ulonglong m_key_value; 1244 }; 1245 1246 class PFS_key_thread_id : public PFS_key_ulonglong { 1247 public: PFS_key_thread_id(const char * name)1248 PFS_key_thread_id(const char *name) : PFS_key_ulonglong(name) {} 1249 ~PFS_key_thread_id()1250 ~PFS_key_thread_id() {} 1251 1252 bool match(ulonglong thread_id); 1253 bool match(const PFS_thread *pfs); 1254 bool match_owner(const PFS_table *pfs); 1255 bool match_owner(const PFS_socket *pfs); 1256 bool match_owner(const PFS_mutex *pfs); 1257 bool match_owner(const PFS_prepared_stmt *pfs); 1258 bool match_owner(const PFS_metadata_lock *pfs); 1259 bool match_writer(const PFS_rwlock *pfs); 1260 }; 1261 1262 class PFS_key_event_id : public PFS_key_ulonglong { 1263 public: PFS_key_event_id(const char * name)1264 PFS_key_event_id(const char *name) : PFS_key_ulonglong(name) {} 1265 ~PFS_key_event_id()1266 ~PFS_key_event_id() {} 1267 1268 bool match(ulonglong event_id); 1269 bool match(const PFS_events *pfs); 1270 bool match(const PFS_events_waits *pfs); 1271 bool match_owner(const PFS_table *pfs); 1272 bool match_owner(const PFS_prepared_stmt *pfs); 1273 bool match_owner(const PFS_metadata_lock *pfs); 1274 }; 1275 1276 class PFS_key_processlist_id : public PFS_key_ulonglong { 1277 public: PFS_key_processlist_id(const char * name)1278 PFS_key_processlist_id(const char *name) : PFS_key_ulonglong(name) {} 1279 ~PFS_key_processlist_id()1280 ~PFS_key_processlist_id() {} 1281 1282 bool match(const PFS_thread *pfs); 1283 }; 1284 1285 class PFS_key_engine_transaction_id : public PFS_key_ulonglong { 1286 public: PFS_key_engine_transaction_id(const char * name)1287 PFS_key_engine_transaction_id(const char *name) : PFS_key_ulonglong(name) {} 1288 ~PFS_key_engine_transaction_id()1289 ~PFS_key_engine_transaction_id() {} 1290 1291 bool match(ulonglong engine_transaction_id); 1292 }; 1293 1294 class PFS_key_thread_os_id : public PFS_key_ulonglong { 1295 public: PFS_key_thread_os_id(const char * name)1296 PFS_key_thread_os_id(const char *name) : PFS_key_ulonglong(name) {} 1297 ~PFS_key_thread_os_id()1298 ~PFS_key_thread_os_id() {} 1299 1300 bool match(const PFS_thread *pfs); 1301 }; 1302 1303 class PFS_key_statement_id : public PFS_key_ulonglong { 1304 public: PFS_key_statement_id(const char * name)1305 PFS_key_statement_id(const char *name) : PFS_key_ulonglong(name) {} 1306 ~PFS_key_statement_id()1307 ~PFS_key_statement_id() {} 1308 1309 bool match(const PFS_prepared_stmt *pfs); 1310 }; 1311 1312 class PFS_key_worker_id : public PFS_key_ulonglong { 1313 public: PFS_key_worker_id(const char * name)1314 PFS_key_worker_id(const char *name) : PFS_key_ulonglong(name) {} 1315 ~PFS_key_worker_id()1316 ~PFS_key_worker_id() {} 1317 1318 bool match_not_null(ulonglong worker_id); 1319 }; 1320 1321 class PFS_key_socket_id : public PFS_key_long { 1322 public: PFS_key_socket_id(const char * name)1323 PFS_key_socket_id(const char *name) : PFS_key_long(name) {} 1324 ~PFS_key_socket_id()1325 ~PFS_key_socket_id() {} 1326 1327 bool match(const PFS_socket *pfs); 1328 }; 1329 1330 class PFS_key_port : public PFS_key_long { 1331 public: PFS_key_port(const char * name)1332 PFS_key_port(const char *name) : PFS_key_long(name) {} 1333 ~PFS_key_port()1334 ~PFS_key_port() {} 1335 1336 bool match(const PFS_socket *pfs); 1337 }; 1338 1339 class PFS_key_error_number : public PFS_key_long { 1340 public: PFS_key_error_number(const char * name)1341 PFS_key_error_number(const char *name) : PFS_key_long(name) {} 1342 ~PFS_key_error_number()1343 ~PFS_key_error_number() {} 1344 1345 bool match_error_index(uint error_index); 1346 }; 1347 1348 class PFS_key_pstring : public PFS_engine_key { 1349 public: PFS_key_pstring(const char * name)1350 PFS_key_pstring(const char *name) : PFS_engine_key(name) {} 1351 ~PFS_key_pstring()1352 virtual ~PFS_key_pstring() {} 1353 stateless_read(PFS_key_reader & reader,enum ha_rkey_function find_flag,bool & is_null,char * key_value,uint * key_value_length,uint key_value_max_length)1354 static enum ha_rkey_function stateless_read(PFS_key_reader &reader, 1355 enum ha_rkey_function find_flag, 1356 bool &is_null, char *key_value, 1357 uint *key_value_length, 1358 uint key_value_max_length) { 1359 if (reader.get_key_type() == HA_KEYTYPE_TEXT) { 1360 return (reader.read_text_utf8(find_flag, is_null, key_value, 1361 key_value_length, key_value_max_length)); 1362 } else { 1363 return (reader.read_varchar_utf8(find_flag, is_null, key_value, 1364 key_value_length, key_value_max_length)); 1365 } 1366 } 1367 1368 static bool stateless_match(bool record_null, const char *record_string, 1369 size_t record_string_length, 1370 const char *m_key_value, 1371 size_t m_key_value_length, bool m_is_null, 1372 enum ha_rkey_function m_find_flag); 1373 1374 protected: 1375 bool do_match(bool record_null, const char *record_value, 1376 size_t record_value_length); 1377 bool do_match_prefix(bool record_null, const char *record_value, 1378 size_t record_value_length); 1379 }; 1380 1381 template <int SIZE> 1382 class PFS_key_string : public PFS_key_pstring { 1383 public: PFS_key_string(const char * name)1384 PFS_key_string(const char *name) 1385 : PFS_key_pstring(name), m_key_value_length(0) {} 1386 ~PFS_key_string()1387 virtual ~PFS_key_string() {} 1388 read(PFS_key_reader & reader,enum ha_rkey_function find_flag)1389 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag) { 1390 m_find_flag = stateless_read(reader, find_flag, m_is_null, m_key_value, 1391 &m_key_value_length, sizeof(m_key_value)); 1392 } 1393 1394 protected: do_match(bool record_null,const char * record_value,size_t record_value_length)1395 bool do_match(bool record_null, const char *record_value, 1396 size_t record_value_length) { 1397 return stateless_match(record_null, record_value, record_value_length, 1398 m_key_value, m_key_value_length, m_is_null, 1399 m_find_flag); 1400 } 1401 bool do_match_prefix(bool record_null, const char *record_value, 1402 size_t record_value_length); 1403 1404 private: 1405 char m_key_value[SIZE * 1406 SYSTEM_CHARSET_MBMAXLEN]; // FIXME FILENAME_CHARSET_MBMAXLEN 1407 // for file names 1408 uint m_key_value_length; 1409 }; 1410 1411 class PFS_key_thread_name : public PFS_key_string<PFS_MAX_INFO_NAME_LENGTH> { 1412 public: PFS_key_thread_name(const char * name)1413 PFS_key_thread_name(const char *name) : PFS_key_string(name) {} 1414 ~PFS_key_thread_name()1415 ~PFS_key_thread_name() {} 1416 1417 bool match(const PFS_thread *pfs); 1418 bool match(const PFS_thread_class *klass); 1419 }; 1420 1421 class PFS_key_event_name : public PFS_key_string<PFS_MAX_INFO_NAME_LENGTH> { 1422 public: PFS_key_event_name(const char * name)1423 PFS_key_event_name(const char *name) : PFS_key_string(name) {} 1424 ~PFS_key_event_name()1425 ~PFS_key_event_name() {} 1426 1427 bool match(const PFS_instr_class *klass); 1428 bool match(const PFS_mutex *pfs); 1429 bool match(const PFS_rwlock *pfs); 1430 bool match(const PFS_cond *pfs); 1431 bool match(const PFS_file *pfs); 1432 bool match(const PFS_socket *pfs); 1433 bool match_view(uint view); 1434 }; 1435 1436 class PFS_key_user : public PFS_key_string<USERNAME_LENGTH> { 1437 public: PFS_key_user(const char * name)1438 PFS_key_user(const char *name) : PFS_key_string(name) {} 1439 ~PFS_key_user()1440 ~PFS_key_user() {} 1441 1442 bool match(const PFS_thread *pfs); 1443 bool match(const PFS_user *pfs); 1444 bool match(const PFS_account *pfs); 1445 bool match(const PFS_setup_actor *pfs); 1446 }; 1447 1448 class PFS_key_host : public PFS_key_string<HOSTNAME_LENGTH> { 1449 public: PFS_key_host(const char * name)1450 PFS_key_host(const char *name) : PFS_key_string(name) {} 1451 ~PFS_key_host()1452 ~PFS_key_host() {} 1453 1454 bool match(const PFS_thread *pfs); 1455 bool match(const PFS_host *pfs); 1456 bool match(const PFS_account *pfs); 1457 bool match(const PFS_setup_actor *pfs); 1458 bool match(const char *host, size_t host_length); 1459 }; 1460 1461 class PFS_key_role : public PFS_key_string<ROLENAME_LENGTH> { 1462 public: PFS_key_role(const char * name)1463 PFS_key_role(const char *name) : PFS_key_string(name) {} 1464 ~PFS_key_role()1465 ~PFS_key_role() {} 1466 1467 bool match(const PFS_setup_actor *pfs); 1468 }; 1469 1470 class PFS_key_schema : public PFS_key_string<NAME_CHAR_LEN> { 1471 public: PFS_key_schema(const char * schema)1472 PFS_key_schema(const char *schema) : PFS_key_string(schema) {} 1473 ~PFS_key_schema()1474 ~PFS_key_schema() {} 1475 1476 bool match(const PFS_statements_digest_stat *pfs); 1477 }; 1478 1479 class PFS_key_digest : public PFS_key_string<MAX_KEY_LENGTH> { 1480 public: PFS_key_digest(const char * digest)1481 PFS_key_digest(const char *digest) : PFS_key_string(digest) {} 1482 ~PFS_key_digest()1483 ~PFS_key_digest() {} 1484 1485 bool match(PFS_statements_digest_stat *pfs); 1486 }; 1487 1488 class PFS_key_bucket_number : public PFS_key_ulong { 1489 public: PFS_key_bucket_number(const char * name)1490 PFS_key_bucket_number(const char *name) : PFS_key_ulong(name) {} 1491 ~PFS_key_bucket_number()1492 ~PFS_key_bucket_number() {} 1493 1494 bool match(ulong value); 1495 }; 1496 1497 /* Generic NAME key */ 1498 class PFS_key_name : public PFS_key_string<NAME_CHAR_LEN> { 1499 public: PFS_key_name(const char * name)1500 PFS_key_name(const char *name) : PFS_key_string(name) {} 1501 ~PFS_key_name()1502 ~PFS_key_name() {} 1503 1504 bool match(const LEX_CSTRING *name); 1505 bool match(const char *name, size_t name_length); 1506 bool match_not_null(const LEX_STRING *name); 1507 bool match_not_null(const char *name, size_t name_length); 1508 }; 1509 1510 class PFS_key_group_name : public PFS_key_string<NAME_CHAR_LEN> { 1511 public: PFS_key_group_name(const char * name)1512 PFS_key_group_name(const char *name) : PFS_key_string(name) {} 1513 ~PFS_key_group_name()1514 ~PFS_key_group_name() {} 1515 1516 bool match(const LEX_STRING *name); 1517 bool match(const char *name, size_t name_length); 1518 bool match(PFS_thread *pfs); 1519 }; 1520 1521 class PFS_key_variable_name : public PFS_key_string<NAME_CHAR_LEN> { 1522 public: PFS_key_variable_name(const char * name)1523 PFS_key_variable_name(const char *name) : PFS_key_string(name) {} 1524 ~PFS_key_variable_name()1525 ~PFS_key_variable_name() {} 1526 1527 bool match(const System_variable *pfs); 1528 bool match(const Status_variable *pfs); 1529 bool match(const PFS_variable_name_row *pfs); 1530 }; 1531 1532 // FIXME: 32 1533 class PFS_key_engine_name : public PFS_key_string<32> { 1534 public: PFS_key_engine_name(const char * name)1535 PFS_key_engine_name(const char *name) : PFS_key_string(name) {} 1536 ~PFS_key_engine_name()1537 ~PFS_key_engine_name() {} 1538 1539 bool match(const char *engine_name, size_t length); 1540 }; 1541 1542 // FIXME: 128 1543 class PFS_key_engine_lock_id : public PFS_key_string<128> { 1544 public: PFS_key_engine_lock_id(const char * name)1545 PFS_key_engine_lock_id(const char *name) : PFS_key_string(name) {} 1546 ~PFS_key_engine_lock_id()1547 ~PFS_key_engine_lock_id() {} 1548 1549 bool match(const char *engine_lock_id, size_t length); 1550 }; 1551 1552 class PFS_key_ip : public PFS_key_string<PFS_MAX_INFO_NAME_LENGTH> // FIXME 1553 // <INET6_ADDRSTRLEN+1> 1554 // fails on freebsd 1555 { 1556 public: PFS_key_ip(const char * name)1557 PFS_key_ip(const char *name) : PFS_key_string(name) {} 1558 ~PFS_key_ip()1559 ~PFS_key_ip() {} 1560 1561 bool match(const PFS_socket *pfs); 1562 bool match(const char *ip, size_t ip_length); 1563 }; 1564 1565 class PFS_key_statement_name : public PFS_key_string<PFS_MAX_INFO_NAME_LENGTH> { 1566 public: PFS_key_statement_name(const char * name)1567 PFS_key_statement_name(const char *name) : PFS_key_string(name) {} 1568 ~PFS_key_statement_name()1569 ~PFS_key_statement_name() {} 1570 1571 bool match(const PFS_prepared_stmt *pfs); 1572 }; 1573 1574 class PFS_key_file_name 1575 : public PFS_key_string<1350> // FIXME FN_REFLEN or FN_REFLEN_SE 1576 { 1577 public: PFS_key_file_name(const char * name)1578 PFS_key_file_name(const char *name) : PFS_key_string(name) {} 1579 ~PFS_key_file_name()1580 ~PFS_key_file_name() {} 1581 1582 bool match(const PFS_file *pfs); 1583 }; 1584 1585 class PFS_key_object_schema : public PFS_key_string<NAME_CHAR_LEN> { 1586 public: PFS_key_object_schema(const char * name)1587 PFS_key_object_schema(const char *name) : PFS_key_string(name) {} 1588 ~PFS_key_object_schema()1589 ~PFS_key_object_schema() {} 1590 1591 bool match(const PFS_table_share *pfs); 1592 bool match(const PFS_program *pfs); 1593 bool match(const PFS_prepared_stmt *pfs); 1594 bool match(const PFS_object_row *pfs); 1595 bool match(const PFS_column_row *pfs); 1596 bool match(const PFS_setup_object *pfs); 1597 bool match(const char *schema_name, size_t schema_name_length); 1598 }; 1599 1600 class PFS_key_object_name : public PFS_key_string<NAME_CHAR_LEN> { 1601 public: PFS_key_object_name(const char * name)1602 PFS_key_object_name(const char *name) : PFS_key_string(name) {} 1603 ~PFS_key_object_name()1604 ~PFS_key_object_name() {} 1605 1606 bool match(const PFS_table_share *pfs); 1607 bool match(const PFS_program *pfs); 1608 bool match(const PFS_prepared_stmt *pfs); 1609 bool match(const PFS_object_row *pfs); 1610 bool match(const PFS_column_row *pfs); 1611 bool match(const PFS_index_row *pfs); 1612 bool match(const PFS_setup_object *pfs); 1613 bool match(const char *schema_name, size_t schema_name_length); 1614 }; 1615 1616 class PFS_key_column_name : public PFS_key_string<NAME_CHAR_LEN> { 1617 public: PFS_key_column_name(const char * name)1618 PFS_key_column_name(const char *name) : PFS_key_string(name) {} 1619 ~PFS_key_column_name()1620 ~PFS_key_column_name() {} 1621 1622 bool match(const PFS_column_row *pfs); 1623 }; 1624 1625 class PFS_key_object_type : public PFS_engine_key { 1626 public: PFS_key_object_type(const char * name)1627 PFS_key_object_type(const char *name) 1628 : PFS_engine_key(name), m_object_type(NO_OBJECT_TYPE) {} 1629 ~PFS_key_object_type()1630 virtual ~PFS_key_object_type() {} 1631 1632 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag); 1633 1634 bool match(enum_object_type object_type); 1635 bool match(const PFS_object_row *pfs); 1636 bool match(const PFS_column_row *pfs); 1637 bool match(const PFS_program *pfs); 1638 1639 private: 1640 bool do_match(bool record_null, enum_object_type object_type); 1641 enum_object_type m_object_type; 1642 }; 1643 1644 class PFS_key_object_type_enum : public PFS_engine_key { 1645 public: PFS_key_object_type_enum(const char * name)1646 PFS_key_object_type_enum(const char *name) 1647 : PFS_engine_key(name), m_object_type(NO_OBJECT_TYPE) {} 1648 ~PFS_key_object_type_enum()1649 virtual ~PFS_key_object_type_enum() {} 1650 1651 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag); 1652 1653 bool match(enum_object_type object_type); 1654 bool match(const PFS_prepared_stmt *pfs); 1655 bool match(const PFS_object_row *pfs); 1656 bool match(const PFS_program *pfs); 1657 1658 private: 1659 bool do_match(bool record_null, enum_object_type object_type); 1660 enum_object_type m_object_type; 1661 }; 1662 1663 class PFS_key_object_instance : public PFS_engine_key { 1664 public: PFS_key_object_instance(const char * name)1665 PFS_key_object_instance(const char *name) 1666 : PFS_engine_key(name), m_identity(nullptr) {} 1667 ~PFS_key_object_instance()1668 virtual ~PFS_key_object_instance() {} 1669 read(PFS_key_reader & reader,enum ha_rkey_function find_flag)1670 virtual void read(PFS_key_reader &reader, enum ha_rkey_function find_flag) { 1671 ulonglong object_instance_begin; 1672 m_find_flag = 1673 reader.read_ulonglong(find_flag, m_is_null, &object_instance_begin); 1674 m_identity = (void *)object_instance_begin; 1675 } 1676 1677 bool match(const PFS_table *pfs); 1678 bool match(const PFS_mutex *pfs); 1679 bool match(const PFS_rwlock *pfs); 1680 bool match(const PFS_cond *pfs); 1681 bool match(const PFS_file *pfs); 1682 bool match(const PFS_socket *pfs); 1683 bool match(const PFS_prepared_stmt *pfs); 1684 bool match(const PFS_metadata_lock *pfs); 1685 1686 const void *m_identity; 1687 }; 1688 1689 /** @} */ 1690 1691 #endif 1692