pfs_engine_table.cc 21.5 KB
Newer Older
1
/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
Marc Alff's avatar
Marc Alff committed
2 3 4 5 6 7 8 9 10 11 12

  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
13 14
  along with this program; if not, write to the Free Software Foundation,
  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
Marc Alff's avatar
Marc Alff committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

/**
  @file storage/perfschema/pfs_engine_table.cc
  Performance schema tables (implementation).
*/

#include "pfs_engine_table.h"

#include "table_events_waits.h"
#include "table_setup_consumers.h"
#include "table_setup_instruments.h"
#include "table_setup_objects.h"
#include "table_setup_timers.h"
#include "table_performance_timers.h"
#include "table_processlist.h"
#include "table_events_waits_summary.h"
#include "table_sync_instances.h"
#include "table_file_instances.h"
#include "table_file_summary.h"

/* For show status */
#include "pfs_column_values.h"
#include "pfs_instr.h"
38
#include "pfs_global.h"
Marc Alff's avatar
Marc Alff committed
39

40 41 42
#include "sql_base.h"                           // close_thread_tables
#include "lock.h"                               // MYSQL_LOCK_IGNORE_TIMEOUT

Marc Alff's avatar
Marc Alff committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
/**
  @addtogroup Performance_schema_engine
  @{
*/

static PFS_engine_table_share *all_shares[]=
{
  &table_events_waits_current::m_share,
  &table_events_waits_history::m_share,
  &table_events_waits_history_long::m_share,
  &table_setup_consumers::m_share,
  &table_setup_instruments::m_share,
  &table_setup_objects::m_share,
  &table_setup_timers::m_share,
  &table_performance_timers::m_share,
  &table_processlist::m_share,
  &table_events_waits_summary_by_thread_by_event_name::m_share,
  &table_events_waits_summary_by_event_name::m_share,
  &table_events_waits_summary_by_instance::m_share,
  &table_file_summary_by_event_name::m_share,
  &table_file_summary_by_instance::m_share,
  &table_mutex_instances::m_share,
  &table_rwlock_instances::m_share,
  &table_cond_instances::m_share,
  &table_file_instances::m_share,
  NULL
};

/**
  Check all the tables structure.
  @param thd              current thread
*/
void PFS_engine_table_share::check_all_tables(THD *thd)
{
  PFS_engine_table_share **current;

  DBUG_EXECUTE_IF("tampered_perfschema_table1",
                  {
                    /* Hack SETUP_INSTRUMENT, incompatible change. */
                    all_shares[4]->m_field_def->count++;
                  });

  for (current= &all_shares[0]; (*current) != NULL; current++)
    (*current)->check_one_table(thd);
}

class PFS_check_intact : public Table_check_intact
{
protected:
  virtual void report_error(uint code, const char *fmt, ...);

public:
  PFS_check_intact()
  {}

  ~PFS_check_intact()
  {}
};

void PFS_check_intact::report_error(uint code, const char *fmt, ...)
{
  va_list args;
  char buff[MYSQL_ERRMSG_SIZE];

  va_start(args, fmt);
  my_vsnprintf(buff, sizeof(buff), fmt, args);
  va_end(args);

111 112 113 114 115 116
  /*
    This is an install/upgrade issue:
    - do not report it in the user connection, there is none in main(),
    - report it in the server error log.
  */
  sql_print_error("%s", buff);
Marc Alff's avatar
Marc Alff committed
117 118 119 120 121 122 123 124 125 126 127 128
}

/**
  Check integrity of the actual table schema.
  The actual table schema (.frm) is compared to the expected schema.
  @param thd              current thread
*/
void PFS_engine_table_share::check_one_table(THD *thd)
{
  TABLE_LIST tables;

  tables.init_one_table(PERFORMANCE_SCHEMA_str.str,
129 130
                        PERFORMANCE_SCHEMA_str.length,
                        m_name.str, m_name.length,
Marc Alff's avatar
Marc Alff committed
131 132 133 134 135 136 137 138
                        m_name.str, TL_READ);

  /* Work around until Bug#32115 is backported. */
  LEX dummy_lex;
  LEX *old_lex= thd->lex;
  thd->lex= &dummy_lex;
  lex_start(thd);

139
  if (! open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT))
Marc Alff's avatar
Marc Alff committed
140 141 142 143 144 145 146
  {
    PFS_check_intact checker;

    if (!checker.check(tables.table, m_field_def))
      m_checked= true;
    close_thread_tables(thd);
  }
147 148 149
  else
    sql_print_error(ER(ER_WRONG_NATIVE_TABLE_STRUCTURE),
                    PERFORMANCE_SCHEMA_str.str, m_name.str);
Marc Alff's avatar
Marc Alff committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234

  lex_end(&dummy_lex);
  thd->lex= old_lex;
}

/** Initialize all the table share locks. */
void PFS_engine_table_share::init_all_locks(void)
{
  PFS_engine_table_share **current;

  for (current= &all_shares[0]; (*current) != NULL; current++)
    thr_lock_init((*current)->m_thr_lock_ptr);
}

/** Delete all the table share locks. */
void PFS_engine_table_share::delete_all_locks(void)
{
  PFS_engine_table_share **current;

  for (current= &all_shares[0]; (*current) != NULL; current++)
    thr_lock_delete((*current)->m_thr_lock_ptr);
}

static int compare_table_names(const char *name1, const char *name2)
{
  /*
    The performance schema is implemented as a storage engine, in memory.
    The current storage engine interface exposed by the server,
    and in particular handlerton::discover, uses 'FRM' files to describe a
    table structure, which are later stored on disk, by the server,
    in ha_create_table_from_engine().
    Because the table metadata is stored on disk, the table naming rules
    used by the performance schema then have to comply with the constraints
    imposed by the disk storage, and in particular with lower_case_table_names.
    Once the server is changed to be able to discover a table in a storage engine
    and then open the table without storing a FRM file on disk, this constraint
    on the performance schema will be lifted, and the naming logic can be relaxed
    to be simply my_strcasecmp(system_charset_info, name1, name2).
  */
  if (lower_case_table_names)
    return strcasecmp(name1, name2);
  return strcmp(name1, name2);
}

/**
  Find a table share by name.
  @param name             The table name
  @return table share
*/
const PFS_engine_table_share*
PFS_engine_table::find_engine_table_share(const char *name)
{
  DBUG_ENTER("PFS_engine_table::find_table_share");

  PFS_engine_table_share **current;

  for (current= &all_shares[0]; (*current) != NULL; current++)
  {
    if (compare_table_names(name, (*current)->m_name.str) == 0)
      DBUG_RETURN(*current);
  }

  DBUG_RETURN(NULL);
}

/**
  Read a table row.
  @param table            Table handle
  @param buf              Row buffer
  @param fields           Table fields
  @return 0 on success
*/
int PFS_engine_table::read_row(TABLE *table,
                               unsigned char *buf,
                               Field **fields)
{
  my_bitmap_map *org_bitmap;

  /*
    Make sure the table structure is as expected before mapping
    hard wired columns in read_row_values.
  */
  if (! m_share_ptr->m_checked)
  {
    my_error(ER_WRONG_NATIVE_TABLE_STRUCTURE, MYF(0),
235
             PERFORMANCE_SCHEMA_str.str, m_share_ptr->m_name.str);
Marc Alff's avatar
Marc Alff committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
    return HA_ERR_TABLE_NEEDS_UPGRADE;
  }

  /* We must read all columns in case a table is opened for update */
  bool read_all= !bitmap_is_clear_all(table->write_set);

  /* We internally write to Fields to support the read interface */
  org_bitmap= dbug_tmp_use_all_columns(table, table->write_set);
  int result= read_row_values(table, buf, fields, read_all);
  dbug_tmp_restore_column_map(table->write_set, org_bitmap);

  return result;
}

/**
  Update a table row.
  @param table            Table handle
  @param old_buf          old row buffer
  @param new_buf          new row buffer
  @param fields           Table fields
  @return 0 on success
*/
int PFS_engine_table::update_row(TABLE *table,
                                 const unsigned char *old_buf,
                                 unsigned char *new_buf,
                                 Field **fields)
{
  my_bitmap_map *org_bitmap;

  /*
    Make sure the table structure is as expected before mapping
    hard wired columns in update_row_values.
  */
  if (! m_share_ptr->m_checked)
  {
    my_error(ER_WRONG_NATIVE_TABLE_STRUCTURE, MYF(0),
272
             PERFORMANCE_SCHEMA_str.str, m_share_ptr->m_name.str);
Marc Alff's avatar
Marc Alff committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
    return HA_ERR_TABLE_NEEDS_UPGRADE;
  }

  /* We internally read from Fields to support the write interface */
  org_bitmap= dbug_tmp_use_all_columns(table, table->read_set);
  int result= update_row_values(table, old_buf, new_buf, fields);
  dbug_tmp_restore_column_map(table->read_set, org_bitmap);

  return result;
}

/**
  Get the position of the current row.
  @param [out] ref        position
*/
void PFS_engine_table::get_position(void *ref)
{
  memcpy(ref, m_pos_ptr, m_share_ptr->m_ref_length);
}

/**
  Set the table cursor at a given position.
  @param [in] ref         position
*/
void PFS_engine_table::set_position(const void *ref)
{
  memcpy(m_pos_ptr, ref, m_share_ptr->m_ref_length);
}

void PFS_engine_table::set_field_ulong(Field *f, ulong value)
{
  DBUG_ASSERT(f->real_type() == MYSQL_TYPE_LONG);
  Field_long *f2= (Field_long*) f;
  f2->store(value, true);
}

void PFS_engine_table::set_field_ulonglong(Field *f, ulonglong value)
{
  DBUG_ASSERT(f->real_type() == MYSQL_TYPE_LONGLONG);
  Field_longlong *f2= (Field_longlong*) f;
  f2->store(value, true);
}

void PFS_engine_table::set_field_varchar_utf8(Field *f, const char* str,
                                              uint len)
{
  DBUG_ASSERT(f->real_type() == MYSQL_TYPE_VARCHAR);
  Field_varstring *f2= (Field_varstring*) f;
  f2->store(str, len, &my_charset_utf8_bin);
}

void PFS_engine_table::set_field_enum(Field *f, ulonglong value)
{
  DBUG_ASSERT(f->real_type() == MYSQL_TYPE_ENUM);
  Field_enum *f2= (Field_enum*) f;
  f2->store_type(value);
}

ulonglong PFS_engine_table::get_field_enum(Field *f)
{
  DBUG_ASSERT(f->real_type() == MYSQL_TYPE_ENUM);
  Field_enum *f2= (Field_enum*) f;
  return f2->val_int();
}

338 339 340 341
int PFS_engine_table::update_row_values(TABLE *,
                                        const unsigned char *,
                                        unsigned char *,
                                        Field **)
Marc Alff's avatar
Marc Alff committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
{
  my_error(ER_WRONG_PERFSCHEMA_USAGE, MYF(0));
  return HA_ERR_WRONG_COMMAND;
}

class PFS_internal_schema_access : public ACL_internal_schema_access
{
public:
  PFS_internal_schema_access()
  {}

  ~PFS_internal_schema_access()
  {}

  ACL_internal_access_result check(ulong want_access,
                                   ulong *save_priv) const;

  const ACL_internal_table_access *lookup(const char *name) const;
};

ACL_internal_access_result
PFS_internal_schema_access::check(ulong want_access,
                                  ulong *save_priv)  const
{
  const ulong always_forbidden= /* CREATE_ACL | */ REFERENCES_ACL
    | INDEX_ACL | ALTER_ACL | CREATE_TMP_ACL | EXECUTE_ACL
    | CREATE_VIEW_ACL | SHOW_VIEW_ACL | CREATE_PROC_ACL | ALTER_PROC_ACL
    | EVENT_ACL | TRIGGER_ACL ;

  if (unlikely(want_access & always_forbidden))
    return ACL_INTERNAL_ACCESS_DENIED;

  /*
    Proceed with regular grant tables,
    to give administrative control to the DBA.
  */
  return ACL_INTERNAL_ACCESS_CHECK_GRANT;
}

const ACL_internal_table_access *
PFS_internal_schema_access::lookup(const char *name) const
{
  const PFS_engine_table_share* share;
  share= PFS_engine_table::find_engine_table_share(name);
  if (share)
    return share->m_acl;
  /*
    Do not return NULL, it would mean we are not interested
    in privilege checks for unknown tables.
    Instead, return an object that denies every actions,
    to prevent users for creating their own tables in the
    performance_schema database schema.
  */
  return &pfs_unknown_acl;
}

PFS_internal_schema_access pfs_internal_access;

void initialize_performance_schema_acl(bool bootstrap)
{
  /*
    ACL is always enforced, even if the performance schema
    is not enabled (the tables are still visible).
  */
  if (! bootstrap)
  {
    ACL_internal_schema_registry::register_schema(&PERFORMANCE_SCHEMA_str,
                                                  &pfs_internal_access);
  }
}

PFS_readonly_acl pfs_readonly_acl;

ACL_internal_access_result
PFS_readonly_acl::check(ulong want_access, ulong *save_priv) const
{
  const ulong always_forbidden= INSERT_ACL | UPDATE_ACL | DELETE_ACL
    | /* CREATE_ACL | */ REFERENCES_ACL | INDEX_ACL | ALTER_ACL
    | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL | LOCK_TABLES_ACL;

  if (unlikely(want_access & always_forbidden))
    return ACL_INTERNAL_ACCESS_DENIED;

  return ACL_INTERNAL_ACCESS_CHECK_GRANT;
}

PFS_truncatable_acl pfs_truncatable_acl;

ACL_internal_access_result
PFS_truncatable_acl::check(ulong want_access, ulong *save_priv) const
{
  const ulong always_forbidden= INSERT_ACL | UPDATE_ACL | DELETE_ACL
    | /* CREATE_ACL | */ REFERENCES_ACL | INDEX_ACL | ALTER_ACL
    | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL | LOCK_TABLES_ACL;

  if (unlikely(want_access & always_forbidden))
    return ACL_INTERNAL_ACCESS_DENIED;

  return ACL_INTERNAL_ACCESS_CHECK_GRANT;
}

PFS_updatable_acl pfs_updatable_acl;

ACL_internal_access_result
PFS_updatable_acl::check(ulong want_access, ulong *save_priv) const
{
  const ulong always_forbidden= INSERT_ACL | DELETE_ACL
    | /* CREATE_ACL | */ REFERENCES_ACL | INDEX_ACL | ALTER_ACL
    | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL;

  if (unlikely(want_access & always_forbidden))
    return ACL_INTERNAL_ACCESS_DENIED;

  return ACL_INTERNAL_ACCESS_CHECK_GRANT;
}

PFS_editable_acl pfs_editable_acl;

ACL_internal_access_result
PFS_editable_acl::check(ulong want_access, ulong *save_priv) const
{
  const ulong always_forbidden= /* CREATE_ACL | */ REFERENCES_ACL
    | INDEX_ACL | ALTER_ACL | CREATE_VIEW_ACL | SHOW_VIEW_ACL | TRIGGER_ACL;

  if (unlikely(want_access & always_forbidden))
    return ACL_INTERNAL_ACCESS_DENIED;

  return ACL_INTERNAL_ACCESS_CHECK_GRANT;
}

PFS_unknown_acl pfs_unknown_acl;

ACL_internal_access_result
PFS_unknown_acl::check(ulong want_access, ulong *save_priv) const
{
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
  const ulong always_forbidden= INSERT_ACL | UPDATE_ACL | DELETE_ACL
    | CREATE_ACL | REFERENCES_ACL | INDEX_ACL | ALTER_ACL
    | CREATE_VIEW_ACL | TRIGGER_ACL | LOCK_TABLES_ACL;

  if (unlikely(want_access & always_forbidden))
    return ACL_INTERNAL_ACCESS_DENIED;

  /*
    There is no point in hidding (by enforcing ACCESS_DENIED for SELECT_ACL
    on performance_schema.*) tables that do not exist anyway.
    When SELECT_ACL is granted on performance_schema.* or *.*,
    SELECT * from performance_schema.wrong_table
    will fail with a more understandable ER_NO_SUCH_TABLE error,
    instead of ER_TABLEACCESS_DENIED_ERROR.
  */
  return ACL_INTERNAL_ACCESS_CHECK_GRANT;
Marc Alff's avatar
Marc Alff committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
}

/**
  SHOW ENGINE PERFORMANCE_SCHEMA STATUS.
  @param hton               Storage engine handler
  @param thd                Current thread
  @param print              Print function
  @param stat               status to show
*/
bool pfs_show_status(handlerton *hton, THD *thd,
                     stat_print_fn *print, enum ha_stat_type stat)
{
  char buf[1024];
  uint buflen;
  const char *name;
  int i;
  uint size;

  DBUG_ENTER("pfs_show_status");

  /*
    Note about naming conventions:
    - Internal buffers exposed as a table in the performance schema are named
    after the table, as in 'EVENTS_WAITS_CURRENT'
    - Internal buffers not exposed by a table are named with parenthesis,
    as in '(PFS_MUTEX_CLASS)'.
  */
  if (stat != HA_ENGINE_STATUS)
    DBUG_RETURN(false);

  uint total_memory= 0;

  for (i=0; /* empty */; i++)
  {
    switch (i){
    case 0:
      name= "EVENTS_WAITS_CURRENT.ROW_SIZE";
      size= sizeof(PFS_wait_locker);
      break;
    case 1:
      name= "EVENTS_WAITS_CURRENT.ROW_COUNT";
      size= LOCKER_STACK_SIZE * thread_max;
      break;
    case 2:
      name= "EVENTS_WAITS_HISTORY.ROW_SIZE";
      size= sizeof(PFS_events_waits);
      break;
    case 3:
      name= "EVENTS_WAITS_HISTORY.ROW_COUNT";
      size= events_waits_history_per_thread * thread_max;
      break;
    case 4:
      name= "EVENTS_WAITS_HISTORY.MEMORY";
      size= events_waits_history_per_thread * thread_max
        * sizeof(PFS_events_waits);
      total_memory+= size;
      break;
    case 5:
      name= "EVENTS_WAITS_HISTORY_LONG.ROW_SIZE";
      size= sizeof(PFS_events_waits);
      break;
    case 6:
      name= "EVENTS_WAITS_HISTORY_LONG.ROW_COUNT";
      size= events_waits_history_long_size;
      break;
    case 7:
      name= "EVENTS_WAITS_HISTORY_LONG.MEMORY";
      size= events_waits_history_long_size * sizeof(PFS_events_waits);
      total_memory+= size;
      break;
    case 8:
      name= "(PFS_MUTEX_CLASS).ROW_SIZE";
      size= sizeof(PFS_mutex_class);
      break;
    case 9:
      name= "(PFS_MUTEX_CLASS).ROW_COUNT";
      size= mutex_class_max;
      break;
    case 10:
      name= "(PFS_MUTEX_CLASS).MEMORY";
      size= mutex_class_max * sizeof(PFS_mutex_class);
      total_memory+= size;
      break;
    case 11:
      name= "(PFS_RWLOCK_CLASS).ROW_SIZE";
      size= sizeof(PFS_rwlock_class);
      break;
    case 12:
      name= "(PFS_RWLOCK_CLASS).ROW_COUNT";
      size= rwlock_class_max;
      break;
    case 13:
      name= "(PFS_RWLOCK_CLASS).MEMORY";
      size= rwlock_class_max * sizeof(PFS_rwlock_class);
      total_memory+= size;
      break;
    case 14:
      name= "(PFS_COND_CLASS).ROW_SIZE";
      size= sizeof(PFS_cond_class);
      break;
    case 15:
      name= "(PFS_COND_CLASS).ROW_COUNT";
      size= cond_class_max;
      break;
    case 16:
      name= "(PFS_COND_CLASS).MEMORY";
      size= cond_class_max * sizeof(PFS_cond_class);
      total_memory+= size;
      break;
    case 17:
      name= "(PFS_THREAD_CLASS).ROW_SIZE";
      size= sizeof(PFS_thread_class);
      break;
    case 18:
      name= "(PFS_THREAD_CLASS).ROW_COUNT";
      size= thread_class_max;
      break;
    case 19:
      name= "(PFS_THREAD_CLASS).MEMORY";
      size= thread_class_max * sizeof(PFS_thread_class);
      total_memory+= size;
      break;
    case 20:
      name= "(PFS_FILE_CLASS).ROW_SIZE";
      size= sizeof(PFS_file_class);
      break;
    case 21:
      name= "(PFS_FILE_CLASS).ROW_COUNT";
      size= file_class_max;
      break;
    case 22:
      name= "(PFS_FILE_CLASS).MEMORY";
      size= file_class_max * sizeof(PFS_file_class);
      total_memory+= size;
      break;
    case 23:
      name= "MUTEX_INSTANCES.ROW_SIZE";
      size= sizeof(PFS_mutex);
      break;
    case 24:
      name= "MUTEX_INSTANCES.ROW_COUNT";
      size= mutex_max;
      break;
    case 25:
      name= "MUTEX_INSTANCES.MEMORY";
      size= mutex_max * sizeof(PFS_mutex);
      total_memory+= size;
      break;
    case 26:
      name= "RWLOCK_INSTANCES.ROW_SIZE";
      size= sizeof(PFS_rwlock);
      break;
    case 27:
      name= "RWLOCK_INSTANCES.ROW_COUNT";
      size= rwlock_max;
      break;
    case 28:
      name= "RWLOCK_INSTANCES.MEMORY";
      size= rwlock_max * sizeof(PFS_rwlock);
      total_memory+= size;
      break;
    case 29:
      name= "COND_INSTANCES.ROW_SIZE";
      size= sizeof(PFS_cond);
      break;
    case 30:
      name= "COND_INSTANCES.ROW_COUNT";
      size= cond_max;
      break;
    case 31:
      name= "COND_INSTANCES.MEMORY";
      size= cond_max * sizeof(PFS_cond);
      total_memory+= size;
      break;
    case 32:
      name= "PROCESSLIST.ROW_SIZE";
      size= sizeof(PFS_thread);
      break;
    case 33:
      name= "PROCESSLIST.ROW_COUNT";
      size= thread_max;
      break;
    case 34:
      name= "PROCESSLIST.MEMORY";
      size= thread_max * sizeof(PFS_thread);
      total_memory+= size;
      break;
    case 35:
      name= "FILE_INSTANCES.ROW_SIZE";
      size= sizeof(PFS_file);
      break;
    case 36:
      name= "FILE_INSTANCES.ROW_COUNT";
      size= file_max;
      break;
    case 37:
      name= "FILE_INSTANCES.MEMORY";
      size= file_max * sizeof(PFS_file);
      total_memory+= size;
      break;
    case 38:
      name= "(PFS_FILE_HANDLE).ROW_SIZE";
      size= sizeof(PFS_file*);
      break;
    case 39:
      name= "(PFS_FILE_HANDLE).ROW_COUNT";
      size= file_handle_max;
      break;
    case 40:
      name= "(PFS_FILE_HANDLE).MEMORY";
      size= file_handle_max * sizeof(PFS_file*);
704
      total_memory+= size;
Marc Alff's avatar
Marc Alff committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718
      break;
    case 41:
      name= "EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME.ROW_SIZE";
      size= sizeof(PFS_single_stat_chain);
      break;
    case 42:
      name= "EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME.ROW_COUNT";
      size= thread_max * instr_class_per_thread;
      break;
    case 43:
      name= "EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME.MEMORY";
      size= thread_max * instr_class_per_thread * sizeof(PFS_single_stat_chain);
      total_memory+= size;
      break;
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
    case 44:
      name= "(PFS_TABLE_SHARE).ROW_SIZE";
      size= sizeof(PFS_table_share);
      break;
    case 45:
      name= "(PFS_TABLE_SHARE).ROW_COUNT";
      size= table_share_max;
      break;
    case 46:
      name= "(PFS_TABLE_SHARE).MEMORY";
      size= table_share_max * sizeof(PFS_table_share);
      total_memory+= size;
      break;
    case 47:
      name= "(PFS_TABLE).ROW_SIZE";
      size= sizeof(PFS_table);
      break;
    case 48:
      name= "(PFS_TABLE).ROW_COUNT";
      size= table_max;
      break;
    case 49:
      name= "(PFS_TABLE).MEMORY";
      size= table_max * sizeof(PFS_table);
      total_memory+= size;
      break;
Marc Alff's avatar
Marc Alff committed
745 746 747 748
    /*
      This case must be last,
      for aggregation in total_memory.
    */
749
    case 50:
Marc Alff's avatar
Marc Alff committed
750 751
      name= "PERFORMANCE_SCHEMA.MEMORY";
      size= total_memory;
752 753
      /* This will fail if something is not advertised here */
      DBUG_ASSERT(size == pfs_allocated_memory);
Marc Alff's avatar
Marc Alff committed
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
      break;
    default:
      goto end;
      break;
    }

    buflen= int10_to_str(size, buf, 10) - buf;
    if (print(thd,
              PERFORMANCE_SCHEMA_str.str, PERFORMANCE_SCHEMA_str.length,
              name, strlen(name),
              buf, buflen))
      DBUG_RETURN(true);
  }

end:
  DBUG_RETURN(false);
}

/** @} */