List:Commits« Previous MessageNext Message »
From:Marc Alff Date:February 15 2011 5:15pm
Subject:bzr push into mysql-trunk branch (marc.alff:3208 to 3209) WL#2515 WL#4813
View as plain text  
 3209 Marc Alff	2011-02-15
      WL#4813 PERFORMANCE_SCHEMA Instrumenting Stages
      WL#2515 PERFORMANCE_SCHEMA statements
      
      Implementation (continued)

    modified:
      mysql-test/r/mysqld--help-notwin.result
      mysql-test/r/mysqld--help-win.result
      mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result
      mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result
      mysql-test/suite/perfschema/r/query_cache.result
      mysql-test/suite/perfschema/r/schema_lc0.result
      mysql-test/suite/perfschema/r/schema_lc1.result
      sql/filesort.cc
      sql/item_func.cc
      sql/lock.cc
      sql/log.cc
      sql/log_event.cc
      sql/mysqld.cc
      sql/mysqld.h
      sql/rpl_master.cc
      sql/rpl_slave.cc
      sql/sql_base.cc
      sql/sql_cache.cc
      sql/sql_class.cc
      sql/sql_class.h
      sql/sql_cursor.cc
      sql/sql_delete.cc
      sql/sql_insert.cc
      sql/sql_parse.cc
      sql/sql_partition_admin.cc
      sql/sql_prepare.cc
      sql/sql_select.cc
      sql/sql_table.cc
      sql/sql_union.cc
      sql/sql_update.cc
      sql/sql_view.cc
 3208 Marc Alff	2011-02-15
      WL#4813 PERFORMANCE_SCHEMA Instrumenting Stages
      WL#2515 PERFORMANCE_SCHEMA statements
      
      Implementation (continued)

    added:
      mysql-test/suite/perfschema/r/ddl_esgs_by_thread_by_event_name.result
      mysql-test/suite/perfschema/r/ddl_esgs_global_by_event_name.result
      mysql-test/suite/perfschema/r/ddl_esms_by_thread_by_event_name.result
      mysql-test/suite/perfschema/r/ddl_esms_global_by_event_name.result
      mysql-test/suite/perfschema/r/ddl_events_stages_current.result
      mysql-test/suite/perfschema/r/ddl_events_stages_history.result
      mysql-test/suite/perfschema/r/ddl_events_stages_history_long.result
      mysql-test/suite/perfschema/r/ddl_events_statements_current.result
      mysql-test/suite/perfschema/r/ddl_events_statements_history.result
      mysql-test/suite/perfschema/r/ddl_events_statements_history_long.result
      mysql-test/suite/perfschema/r/dml_esgs_by_thread_by_event_name.result
      mysql-test/suite/perfschema/r/dml_esgs_global_by_event_name.result
      mysql-test/suite/perfschema/r/dml_esms_by_thread_by_event_name.result
      mysql-test/suite/perfschema/r/dml_esms_global_by_event_name.result
      mysql-test/suite/perfschema/r/dml_events_stages_current.result
      mysql-test/suite/perfschema/r/dml_events_stages_history.result
      mysql-test/suite/perfschema/r/dml_events_stages_history_long.result
      mysql-test/suite/perfschema/r/dml_events_statements_current.result
      mysql-test/suite/perfschema/r/dml_events_statements_history.result
      mysql-test/suite/perfschema/r/dml_events_statements_history_long.result
      mysql-test/suite/perfschema/t/ddl_esgs_by_thread_by_event_name.test
      mysql-test/suite/perfschema/t/ddl_esgs_global_by_event_name.test
      mysql-test/suite/perfschema/t/ddl_esms_by_thread_by_event_name.test
      mysql-test/suite/perfschema/t/ddl_esms_global_by_event_name.test
      mysql-test/suite/perfschema/t/ddl_events_stages_current.test
      mysql-test/suite/perfschema/t/ddl_events_stages_history.test
      mysql-test/suite/perfschema/t/ddl_events_stages_history_long.test
      mysql-test/suite/perfschema/t/ddl_events_statements_current.test
      mysql-test/suite/perfschema/t/ddl_events_statements_history.test
      mysql-test/suite/perfschema/t/ddl_events_statements_history_long.test
      mysql-test/suite/perfschema/t/dml_esgs_by_thread_by_event_name.test
      mysql-test/suite/perfschema/t/dml_esgs_global_by_event_name.test
      mysql-test/suite/perfschema/t/dml_esms_by_thread_by_event_name.test
      mysql-test/suite/perfschema/t/dml_esms_global_by_event_name.test
      mysql-test/suite/perfschema/t/dml_events_stages_current.test
      mysql-test/suite/perfschema/t/dml_events_stages_history.test
      mysql-test/suite/perfschema/t/dml_events_stages_history_long.test
      mysql-test/suite/perfschema/t/dml_events_statements_current.test
      mysql-test/suite/perfschema/t/dml_events_statements_history.test
      mysql-test/suite/perfschema/t/dml_events_statements_history_long.test
      mysql-test/suite/sys_vars/r/pfs_events_stages_history_long_size_basic.result
      mysql-test/suite/sys_vars/r/pfs_events_stages_history_size_basic.result
      mysql-test/suite/sys_vars/r/pfs_events_statements_history_long_size_basic.result
      mysql-test/suite/sys_vars/r/pfs_events_statements_history_size_basic.result
      mysql-test/suite/sys_vars/r/pfs_max_stage_classes_basic.result
      mysql-test/suite/sys_vars/r/pfs_max_statement_classes_basic.result
      mysql-test/suite/sys_vars/t/pfs_events_stages_history_long_size_basic-master.opt
      mysql-test/suite/sys_vars/t/pfs_events_stages_history_long_size_basic.test
      mysql-test/suite/sys_vars/t/pfs_events_stages_history_size_basic-master.opt
      mysql-test/suite/sys_vars/t/pfs_events_stages_history_size_basic.test
      mysql-test/suite/sys_vars/t/pfs_events_statements_history_long_size_basic-master.opt
      mysql-test/suite/sys_vars/t/pfs_events_statements_history_long_size_basic.test
      mysql-test/suite/sys_vars/t/pfs_events_statements_history_size_basic-master.opt
      mysql-test/suite/sys_vars/t/pfs_events_statements_history_size_basic.test
      mysql-test/suite/sys_vars/t/pfs_max_stage_classes_basic-master.opt
      mysql-test/suite/sys_vars/t/pfs_max_stage_classes_basic.test
      mysql-test/suite/sys_vars/t/pfs_max_statement_classes_basic-master.opt
      mysql-test/suite/sys_vars/t/pfs_max_statement_classes_basic.test
    modified:
      mysql-test/suite/perfschema/r/checksum.result
      mysql-test/suite/perfschema/r/start_server_nothing.result
      mysql-test/suite/perfschema/t/checksum.test
      mysql-test/suite/perfschema/t/start_server_nothing.test
      storage/perfschema/pfs_engine_table.cc
      storage/perfschema/pfs_instr.cc
=== modified file 'mysql-test/r/mysqld--help-notwin.result'
--- a/mysql-test/r/mysqld--help-notwin.result	2011-02-09 15:17:14 +0000
+++ b/mysql-test/r/mysqld--help-notwin.result	2011-02-15 17:14:15 +0000
@@ -426,6 +426,14 @@ The following options may be given as th
  mrr_cost_based} and val is one of {on, off, default}
  --performance-schema 
  Enable the performance schema.
+ --performance-schema-events-stages-history-long-size=# 
+ Number of rows in EVENTS_STAGES_HISTORY_LONG.
+ --performance-schema-events-stages-history-size=# 
+ Number of rows per thread in EVENTS_STAGES_HISTORY.
+ --performance-schema-events-statements-history-long-size=# 
+ Number of rows in EVENTS_STATEMENTS_HISTORY_LONG.
+ --performance-schema-events-statements-history-size=# 
+ Number of rows per thread in EVENTS_STATEMENTS_HISTORY.
  --performance-schema-events-waits-history-long-size=# 
  Number of rows in EVENTS_WAITS_HISTORY_LONG.
  --performance-schema-events-waits-history-size=# 
@@ -448,6 +456,10 @@ The following options may be given as th
  Maximum number of rwlock instruments.
  --performance-schema-max-rwlock-instances=# 
  Maximum number of instrumented RWLOCK objects.
+ --performance-schema-max-stage-classes=# 
+ Maximum number of stage instruments.
+ --performance-schema-max-statement-classes=# 
+ Maximum number of statement instruments.
  --performance-schema-max-table-handles=# 
  Maximum number of opened instrumented tables.
  --performance-schema-max-table-instances=# 
@@ -884,6 +896,10 @@ optimizer-prune-level 1
 optimizer-search-depth 62
 optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on
 performance-schema FALSE
+performance-schema-events-stages-history-long-size 10000
+performance-schema-events-stages-history-size 10
+performance-schema-events-statements-history-long-size 10000
+performance-schema-events-statements-history-size 10
 performance-schema-events-waits-history-long-size 10000
 performance-schema-events-waits-history-size 10
 performance-schema-max-cond-classes 80
@@ -895,6 +911,8 @@ performance-schema-max-mutex-classes 200
 performance-schema-max-mutex-instances 1000000
 performance-schema-max-rwlock-classes 30
 performance-schema-max-rwlock-instances 1000000
+performance-schema-max-stage-classes 100
+performance-schema-max-statement-classes 166
 performance-schema-max-table-handles 10000
 performance-schema-max-table-instances 1000
 performance-schema-max-thread-classes 50

=== modified file 'mysql-test/r/mysqld--help-win.result'
--- a/mysql-test/r/mysqld--help-win.result	2011-02-09 15:17:14 +0000
+++ b/mysql-test/r/mysqld--help-win.result	2011-02-15 17:14:15 +0000
@@ -426,6 +426,14 @@ The following options may be given as th
  mrr_cost_based} and val is one of {on, off, default}
  --performance-schema 
  Enable the performance schema.
+ --performance-schema-events-stages-history-long-size=# 
+ Number of rows in EVENTS_STAGES_HISTORY_LONG.
+ --performance-schema-events-stages-history-size=# 
+ Number of rows per thread in EVENTS_STAGES_HISTORY.
+ --performance-schema-events-statements-history-long-size=# 
+ Number of rows in EVENTS_STATEMENTS_HISTORY_LONG.
+ --performance-schema-events-statements-history-size=# 
+ Number of rows per thread in EVENTS_STATEMENTS_HISTORY.
  --performance-schema-events-waits-history-long-size=# 
  Number of rows in EVENTS_WAITS_HISTORY_LONG.
  --performance-schema-events-waits-history-size=# 
@@ -448,6 +456,10 @@ The following options may be given as th
  Maximum number of rwlock instruments.
  --performance-schema-max-rwlock-instances=# 
  Maximum number of instrumented RWLOCK objects.
+ --performance-schema-max-stage-classes=# 
+ Maximum number of stage instruments.
+ --performance-schema-max-statement-classes=# 
+ Maximum number of statement instruments.
  --performance-schema-max-table-handles=# 
  Maximum number of opened instrumented tables.
  --performance-schema-max-table-instances=# 
@@ -888,6 +900,10 @@ optimizer-prune-level 1
 optimizer-search-depth 62
 optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on
 performance-schema FALSE
+performance-schema-events-stages-history-long-size 10000
+performance-schema-events-stages-history-size 10
+performance-schema-events-statements-history-long-size 10000
+performance-schema-events-statements-history-size 10
 performance-schema-events-waits-history-long-size 10000
 performance-schema-events-waits-history-size 10
 performance-schema-max-cond-classes 80
@@ -899,6 +915,8 @@ performance-schema-max-mutex-classes 200
 performance-schema-max-mutex-instances 1000000
 performance-schema-max-rwlock-classes 30
 performance-schema-max-rwlock-instances 1000000
+performance-schema-max-stage-classes 100
+performance-schema-max-statement-classes 166
 performance-schema-max-table-handles 10000
 performance-schema-max-table-instances 1000
 performance-schema-max-thread-classes 50

=== modified file 'mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result'
--- a/mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result	2010-12-09 16:17:13 +0000
+++ b/mysql-test/suite/perfschema/r/pfs_upgrade_lc0.result	2011-02-15 17:14:15 +0000
@@ -9,29 +9,39 @@ show tables like "user_table";
 Tables_in_performance_schema (user_table)
 user_table
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_table";
 Tables_in_performance_schema (user_table)
@@ -45,29 +55,39 @@ show tables like "user_view";
 Tables_in_performance_schema (user_view)
 user_view
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_view";
 Tables_in_performance_schema (user_view)
@@ -79,29 +99,39 @@ create procedure test.user_proc()
 select "Not supposed to be here";
 update mysql.proc set db='performance_schema' where name='user_proc';
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -113,29 +143,39 @@ create function test.user_func() returns
 return 0;
 update mysql.proc set db='performance_schema' where name='user_func';
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -147,29 +187,39 @@ create event test.user_event on schedule
 select "not supposed to be here";
 update mysql.event set db='performance_schema' where name='user_event';
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.event where db='performance_schema';
 name

=== modified file 'mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result'
--- a/mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result	2010-12-09 16:17:13 +0000
+++ b/mysql-test/suite/perfschema/r/pfs_upgrade_lc1.result	2011-02-15 17:14:15 +0000
@@ -9,29 +9,39 @@ show tables like "user_table";
 Tables_in_performance_schema (user_table)
 user_table
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_table";
 Tables_in_performance_schema (user_table)
@@ -45,29 +55,39 @@ show tables like "user_view";
 Tables_in_performance_schema (user_view)
 user_view
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 show tables like "user_view";
 Tables_in_performance_schema (user_view)
@@ -79,29 +99,39 @@ create procedure test.user_proc()
 select "Not supposed to be here";
 update mysql.proc set db='performance_schema' where name='user_proc';
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -113,29 +143,39 @@ create function test.user_func() returns
 return 0;
 update mysql.proc set db='performance_schema' where name='user_func';
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.proc where db='performance_schema';
 name
@@ -147,29 +187,39 @@ create event test.user_event on schedule
 select "not supposed to be here";
 update mysql.event set db='performance_schema' where name='user_event';
 ERROR 1050 (42S01) at line 70: Table 'cond_instances' already exists
-ERROR 1050 (42S01) at line 93: Table 'events_waits_current' already exists
-ERROR 1050 (42S01) at line 116: Table 'events_waits_history' already exists
-ERROR 1050 (42S01) at line 139: Table 'events_waits_history_long' already exists
-ERROR 1050 (42S01) at line 152: Table 'events_waits_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 165: Table 'events_waits_summary_by_thread_by_event_name' already exists
-ERROR 1050 (42S01) at line 177: Table 'events_waits_summary_global_by_event_name' already exists
-ERROR 1050 (42S01) at line 186: Table 'file_instances' already exists
-ERROR 1050 (42S01) at line 197: Table 'file_summary_by_event_name' already exists
-ERROR 1050 (42S01) at line 209: Table 'file_summary_by_instance' already exists
-ERROR 1050 (42S01) at line 218: Table 'mutex_instances' already exists
-ERROR 1050 (42S01) at line 232: Table 'objects_summary_global_by_type' already exists
-ERROR 1050 (42S01) at line 242: Table 'performance_timers' already exists
-ERROR 1050 (42S01) at line 252: Table 'rwlock_instances' already exists
-ERROR 1050 (42S01) at line 261: Table 'setup_actors' already exists
-ERROR 1050 (42S01) at line 269: Table 'setup_consumers' already exists
-ERROR 1050 (42S01) at line 278: Table 'setup_instruments' already exists
-ERROR 1050 (42S01) at line 288: Table 'setup_objects' already exists
-ERROR 1050 (42S01) at line 296: Table 'setup_timers' already exists
-ERROR 1050 (42S01) at line 341: Table 'table_io_waits_summary_by_index_usage' already exists
-ERROR 1050 (42S01) at line 385: Table 'table_io_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 464: Table 'table_lock_waits_summary_by_table' already exists
-ERROR 1050 (42S01) at line 484: Table 'threads' already exists
-ERROR 1644 (HY000) at line 902: Unexpected content found in the performance_schema database.
+ERROR 1050 (42S01) at line 94: Table 'events_waits_current' already exists
+ERROR 1050 (42S01) at line 118: Table 'events_waits_history' already exists
+ERROR 1050 (42S01) at line 142: Table 'events_waits_history_long' already exists
+ERROR 1050 (42S01) at line 155: Table 'events_waits_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 168: Table 'events_waits_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 180: Table 'events_waits_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 189: Table 'file_instances' already exists
+ERROR 1050 (42S01) at line 200: Table 'file_summary_by_event_name' already exists
+ERROR 1050 (42S01) at line 212: Table 'file_summary_by_instance' already exists
+ERROR 1050 (42S01) at line 221: Table 'mutex_instances' already exists
+ERROR 1050 (42S01) at line 235: Table 'objects_summary_global_by_type' already exists
+ERROR 1050 (42S01) at line 245: Table 'performance_timers' already exists
+ERROR 1050 (42S01) at line 255: Table 'rwlock_instances' already exists
+ERROR 1050 (42S01) at line 264: Table 'setup_actors' already exists
+ERROR 1050 (42S01) at line 272: Table 'setup_consumers' already exists
+ERROR 1050 (42S01) at line 281: Table 'setup_instruments' already exists
+ERROR 1050 (42S01) at line 291: Table 'setup_objects' already exists
+ERROR 1050 (42S01) at line 299: Table 'setup_timers' already exists
+ERROR 1050 (42S01) at line 344: Table 'table_io_waits_summary_by_index_usage' already exists
+ERROR 1050 (42S01) at line 388: Table 'table_io_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 467: Table 'table_lock_waits_summary_by_table' already exists
+ERROR 1050 (42S01) at line 487: Table 'threads' already exists
+ERROR 1050 (42S01) at line 502: Table 'events_stages_current' already exists
+ERROR 1050 (42S01) at line 517: Table 'events_stages_history' already exists
+ERROR 1050 (42S01) at line 532: Table 'events_stages_history_long' already exists
+ERROR 1050 (42S01) at line 545: Table 'events_stages_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 557: Table 'events_stages_summary_global_by_event_name' already exists
+ERROR 1050 (42S01) at line 600: Table 'events_statements_current' already exists
+ERROR 1050 (42S01) at line 643: Table 'events_statements_history' already exists
+ERROR 1050 (42S01) at line 686: Table 'events_statements_history_long' already exists
+ERROR 1050 (42S01) at line 718: Table 'events_statements_summary_by_thread_by_event_name' already exists
+ERROR 1050 (42S01) at line 749: Table 'events_statements_summary_global_by_event_name' already exists
+ERROR 1644 (HY000) at line 1167: Unexpected content found in the performance_schema database.
 FATAL ERROR: Upgrade failed
 select name from mysql.event where db='performance_schema';
 name

=== modified file 'mysql-test/suite/perfschema/r/query_cache.result'
--- a/mysql-test/suite/perfschema/r/query_cache.result	2010-11-08 19:35:17 +0000
+++ b/mysql-test/suite/perfschema/r/query_cache.result	2011-02-15 17:14:15 +0000
@@ -38,7 +38,7 @@ spins
 NULL
 select name from performance_schema.setup_instruments order by name limit 1;
 name
-wait/io/file/csv/data
+stage/sql/After create
 show status like "Qcache_queries_in_cache";
 Variable_name	Value
 Qcache_queries_in_cache	1
@@ -53,7 +53,7 @@ spins
 NULL
 select name from performance_schema.setup_instruments order by name limit 1;
 name
-wait/io/file/csv/data
+stage/sql/After create
 show status like "Qcache_queries_in_cache";
 Variable_name	Value
 Qcache_queries_in_cache	1

=== modified file 'mysql-test/suite/perfschema/r/schema_lc0.result'
--- a/mysql-test/suite/perfschema/r/schema_lc0.result	2010-12-09 16:17:13 +0000
+++ b/mysql-test/suite/perfschema/r/schema_lc0.result	2011-02-15 17:14:15 +0000
@@ -8,6 +8,16 @@ use performance_schema;
 show tables;
 Tables_in_performance_schema
 cond_instances
+events_stages_current
+events_stages_history
+events_stages_history_long
+events_stages_summary_by_thread_by_event_name
+events_stages_summary_global_by_event_name
+events_statements_current
+events_statements_history
+events_statements_history_long
+events_statements_summary_by_thread_by_event_name
+events_statements_summary_global_by_event_name
 events_waits_current
 events_waits_history
 events_waits_history_long
@@ -36,6 +46,248 @@ cond_instances	CREATE TABLE `cond_instan
   `NAME` varchar(128) NOT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL
 ) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_current;
+Table	Create Table
+events_stages_current	CREATE TABLE `events_stages_current` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_history;
+Table	Create Table
+events_stages_history	CREATE TABLE `events_stages_history` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_history_long;
+Table	Create Table
+events_stages_history_long	CREATE TABLE `events_stages_history_long` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_summary_by_thread_by_event_name;
+Table	Create Table
+events_stages_summary_by_thread_by_event_name	CREATE TABLE `events_stages_summary_by_thread_by_event_name` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_summary_global_by_event_name;
+Table	Create Table
+events_stages_summary_global_by_event_name	CREATE TABLE `events_stages_summary_global_by_event_name` (
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_current;
+Table	Create Table
+events_statements_current	CREATE TABLE `events_statements_current` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `LOCK_TIME` bigint(20) unsigned NOT NULL,
+  `SQL_TEXT` longtext,
+  `CURRENT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_TYPE` varchar(64) DEFAULT NULL,
+  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_NAME` varchar(64) DEFAULT NULL,
+  `OBJECT_INSTANCE_BEGIN` bigint(20) DEFAULT NULL,
+  `MYSQL_ERRNO` int(11) DEFAULT NULL,
+  `RETURNED_SQLSTATE` varchar(5) DEFAULT NULL,
+  `MESSAGE_TEXT` varchar(128) DEFAULT NULL,
+  `ERRORS` bigint(20) unsigned NOT NULL,
+  `WARNINGS` bigint(20) unsigned NOT NULL,
+  `ROWS_AFFECTED` bigint(20) unsigned NOT NULL,
+  `ROWS_SENT` bigint(20) unsigned NOT NULL,
+  `ROWS_EXAMINED` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,
+  `SELECT_SCAN` bigint(20) unsigned NOT NULL,
+  `SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,
+  `SORT_RANGE` bigint(20) unsigned NOT NULL,
+  `SORT_ROWS` bigint(20) unsigned NOT NULL,
+  `SORT_SCAN` bigint(20) unsigned NOT NULL,
+  `NO_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_history;
+Table	Create Table
+events_statements_history	CREATE TABLE `events_statements_history` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `LOCK_TIME` bigint(20) unsigned NOT NULL,
+  `SQL_TEXT` longtext,
+  `CURRENT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_TYPE` varchar(64) DEFAULT NULL,
+  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_NAME` varchar(64) DEFAULT NULL,
+  `OBJECT_INSTANCE_BEGIN` bigint(20) DEFAULT NULL,
+  `MYSQL_ERRNO` int(11) DEFAULT NULL,
+  `RETURNED_SQLSTATE` varchar(5) DEFAULT NULL,
+  `MESSAGE_TEXT` varchar(128) DEFAULT NULL,
+  `ERRORS` bigint(20) unsigned NOT NULL,
+  `WARNINGS` bigint(20) unsigned NOT NULL,
+  `ROWS_AFFECTED` bigint(20) unsigned NOT NULL,
+  `ROWS_SENT` bigint(20) unsigned NOT NULL,
+  `ROWS_EXAMINED` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,
+  `SELECT_SCAN` bigint(20) unsigned NOT NULL,
+  `SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,
+  `SORT_RANGE` bigint(20) unsigned NOT NULL,
+  `SORT_ROWS` bigint(20) unsigned NOT NULL,
+  `SORT_SCAN` bigint(20) unsigned NOT NULL,
+  `NO_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_history_long;
+Table	Create Table
+events_statements_history_long	CREATE TABLE `events_statements_history_long` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `LOCK_TIME` bigint(20) unsigned NOT NULL,
+  `SQL_TEXT` longtext,
+  `CURRENT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_TYPE` varchar(64) DEFAULT NULL,
+  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_NAME` varchar(64) DEFAULT NULL,
+  `OBJECT_INSTANCE_BEGIN` bigint(20) DEFAULT NULL,
+  `MYSQL_ERRNO` int(11) DEFAULT NULL,
+  `RETURNED_SQLSTATE` varchar(5) DEFAULT NULL,
+  `MESSAGE_TEXT` varchar(128) DEFAULT NULL,
+  `ERRORS` bigint(20) unsigned NOT NULL,
+  `WARNINGS` bigint(20) unsigned NOT NULL,
+  `ROWS_AFFECTED` bigint(20) unsigned NOT NULL,
+  `ROWS_SENT` bigint(20) unsigned NOT NULL,
+  `ROWS_EXAMINED` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,
+  `SELECT_SCAN` bigint(20) unsigned NOT NULL,
+  `SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,
+  `SORT_RANGE` bigint(20) unsigned NOT NULL,
+  `SORT_ROWS` bigint(20) unsigned NOT NULL,
+  `SORT_SCAN` bigint(20) unsigned NOT NULL,
+  `NO_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_summary_by_thread_by_event_name;
+Table	Create Table
+events_statements_summary_by_thread_by_event_name	CREATE TABLE `events_statements_summary_by_thread_by_event_name` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_summary_global_by_event_name;
+Table	Create Table
+events_statements_summary_global_by_event_name	CREATE TABLE `events_statements_summary_global_by_event_name` (
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
 show create table events_waits_current;
 Table	Create Table
 events_waits_current	CREATE TABLE `events_waits_current` (
@@ -53,6 +305,7 @@ events_waits_current	CREATE TABLE `event
   `OBJECT_TYPE` varchar(64) DEFAULT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL,
   `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL,
   `OPERATION` varchar(32) NOT NULL,
   `NUMBER_OF_BYTES` bigint(20) unsigned DEFAULT NULL,
   `FLAGS` int(10) unsigned DEFAULT NULL
@@ -74,6 +327,7 @@ events_waits_history	CREATE TABLE `event
   `OBJECT_TYPE` varchar(64) DEFAULT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL,
   `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL,
   `OPERATION` varchar(32) NOT NULL,
   `NUMBER_OF_BYTES` bigint(20) unsigned DEFAULT NULL,
   `FLAGS` int(10) unsigned DEFAULT NULL
@@ -95,6 +349,7 @@ events_waits_history_long	CREATE TABLE `
   `OBJECT_TYPE` varchar(64) DEFAULT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL,
   `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL,
   `OPERATION` varchar(32) NOT NULL,
   `NUMBER_OF_BYTES` bigint(20) unsigned DEFAULT NULL,
   `FLAGS` int(10) unsigned DEFAULT NULL

=== modified file 'mysql-test/suite/perfschema/r/schema_lc1.result'
--- a/mysql-test/suite/perfschema/r/schema_lc1.result	2010-12-09 16:17:13 +0000
+++ b/mysql-test/suite/perfschema/r/schema_lc1.result	2011-02-15 17:14:15 +0000
@@ -8,6 +8,16 @@ use performance_schema;
 show tables;
 Tables_in_performance_schema
 cond_instances
+events_stages_current
+events_stages_history
+events_stages_history_long
+events_stages_summary_by_thread_by_event_name
+events_stages_summary_global_by_event_name
+events_statements_current
+events_statements_history
+events_statements_history_long
+events_statements_summary_by_thread_by_event_name
+events_statements_summary_global_by_event_name
 events_waits_current
 events_waits_history
 events_waits_history_long
@@ -36,6 +46,248 @@ cond_instances	CREATE TABLE `cond_instan
   `NAME` varchar(128) NOT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL
 ) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_current;
+Table	Create Table
+events_stages_current	CREATE TABLE `events_stages_current` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_history;
+Table	Create Table
+events_stages_history	CREATE TABLE `events_stages_history` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_history_long;
+Table	Create Table
+events_stages_history_long	CREATE TABLE `events_stages_history_long` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_summary_by_thread_by_event_name;
+Table	Create Table
+events_stages_summary_by_thread_by_event_name	CREATE TABLE `events_stages_summary_by_thread_by_event_name` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_stages_summary_global_by_event_name;
+Table	Create Table
+events_stages_summary_global_by_event_name	CREATE TABLE `events_stages_summary_global_by_event_name` (
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_current;
+Table	Create Table
+events_statements_current	CREATE TABLE `events_statements_current` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `LOCK_TIME` bigint(20) unsigned NOT NULL,
+  `SQL_TEXT` longtext,
+  `CURRENT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_TYPE` varchar(64) DEFAULT NULL,
+  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_NAME` varchar(64) DEFAULT NULL,
+  `OBJECT_INSTANCE_BEGIN` bigint(20) DEFAULT NULL,
+  `MYSQL_ERRNO` int(11) DEFAULT NULL,
+  `RETURNED_SQLSTATE` varchar(5) DEFAULT NULL,
+  `MESSAGE_TEXT` varchar(128) DEFAULT NULL,
+  `ERRORS` bigint(20) unsigned NOT NULL,
+  `WARNINGS` bigint(20) unsigned NOT NULL,
+  `ROWS_AFFECTED` bigint(20) unsigned NOT NULL,
+  `ROWS_SENT` bigint(20) unsigned NOT NULL,
+  `ROWS_EXAMINED` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,
+  `SELECT_SCAN` bigint(20) unsigned NOT NULL,
+  `SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,
+  `SORT_RANGE` bigint(20) unsigned NOT NULL,
+  `SORT_ROWS` bigint(20) unsigned NOT NULL,
+  `SORT_SCAN` bigint(20) unsigned NOT NULL,
+  `NO_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_history;
+Table	Create Table
+events_statements_history	CREATE TABLE `events_statements_history` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `LOCK_TIME` bigint(20) unsigned NOT NULL,
+  `SQL_TEXT` longtext,
+  `CURRENT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_TYPE` varchar(64) DEFAULT NULL,
+  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_NAME` varchar(64) DEFAULT NULL,
+  `OBJECT_INSTANCE_BEGIN` bigint(20) DEFAULT NULL,
+  `MYSQL_ERRNO` int(11) DEFAULT NULL,
+  `RETURNED_SQLSTATE` varchar(5) DEFAULT NULL,
+  `MESSAGE_TEXT` varchar(128) DEFAULT NULL,
+  `ERRORS` bigint(20) unsigned NOT NULL,
+  `WARNINGS` bigint(20) unsigned NOT NULL,
+  `ROWS_AFFECTED` bigint(20) unsigned NOT NULL,
+  `ROWS_SENT` bigint(20) unsigned NOT NULL,
+  `ROWS_EXAMINED` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,
+  `SELECT_SCAN` bigint(20) unsigned NOT NULL,
+  `SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,
+  `SORT_RANGE` bigint(20) unsigned NOT NULL,
+  `SORT_ROWS` bigint(20) unsigned NOT NULL,
+  `SORT_SCAN` bigint(20) unsigned NOT NULL,
+  `NO_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_history_long;
+Table	Create Table
+events_statements_history_long	CREATE TABLE `events_statements_history_long` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_ID` bigint(20) unsigned NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `SOURCE` varchar(64) DEFAULT NULL,
+  `TIMER_START` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_END` bigint(20) unsigned DEFAULT NULL,
+  `TIMER_WAIT` bigint(20) unsigned DEFAULT NULL,
+  `LOCK_TIME` bigint(20) unsigned NOT NULL,
+  `SQL_TEXT` longtext,
+  `CURRENT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_TYPE` varchar(64) DEFAULT NULL,
+  `OBJECT_SCHEMA` varchar(64) DEFAULT NULL,
+  `OBJECT_NAME` varchar(64) DEFAULT NULL,
+  `OBJECT_INSTANCE_BEGIN` bigint(20) DEFAULT NULL,
+  `MYSQL_ERRNO` int(11) DEFAULT NULL,
+  `RETURNED_SQLSTATE` varchar(5) DEFAULT NULL,
+  `MESSAGE_TEXT` varchar(128) DEFAULT NULL,
+  `ERRORS` bigint(20) unsigned NOT NULL,
+  `WARNINGS` bigint(20) unsigned NOT NULL,
+  `ROWS_AFFECTED` bigint(20) unsigned NOT NULL,
+  `ROWS_SENT` bigint(20) unsigned NOT NULL,
+  `ROWS_EXAMINED` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,
+  `CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE` bigint(20) unsigned NOT NULL,
+  `SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,
+  `SELECT_SCAN` bigint(20) unsigned NOT NULL,
+  `SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,
+  `SORT_RANGE` bigint(20) unsigned NOT NULL,
+  `SORT_ROWS` bigint(20) unsigned NOT NULL,
+  `SORT_SCAN` bigint(20) unsigned NOT NULL,
+  `NO_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,
+  `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_summary_by_thread_by_event_name;
+Table	Create Table
+events_statements_summary_by_thread_by_event_name	CREATE TABLE `events_statements_summary_by_thread_by_event_name` (
+  `THREAD_ID` int(11) NOT NULL,
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
+show create table events_statements_summary_global_by_event_name;
+Table	Create Table
+events_statements_summary_global_by_event_name	CREATE TABLE `events_statements_summary_global_by_event_name` (
+  `EVENT_NAME` varchar(128) NOT NULL,
+  `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
+) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8
 show create table events_waits_current;
 Table	Create Table
 events_waits_current	CREATE TABLE `events_waits_current` (
@@ -53,6 +305,7 @@ events_waits_current	CREATE TABLE `event
   `OBJECT_TYPE` varchar(64) DEFAULT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL,
   `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL,
   `OPERATION` varchar(32) NOT NULL,
   `NUMBER_OF_BYTES` bigint(20) unsigned DEFAULT NULL,
   `FLAGS` int(10) unsigned DEFAULT NULL
@@ -74,6 +327,7 @@ events_waits_history	CREATE TABLE `event
   `OBJECT_TYPE` varchar(64) DEFAULT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL,
   `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL,
   `OPERATION` varchar(32) NOT NULL,
   `NUMBER_OF_BYTES` bigint(20) unsigned DEFAULT NULL,
   `FLAGS` int(10) unsigned DEFAULT NULL
@@ -95,6 +349,7 @@ events_waits_history_long	CREATE TABLE `
   `OBJECT_TYPE` varchar(64) DEFAULT NULL,
   `OBJECT_INSTANCE_BEGIN` bigint(20) NOT NULL,
   `NESTING_EVENT_ID` bigint(20) unsigned DEFAULT NULL,
+  `NESTING_EVENT_TYPE` enum('STATEMENT','STAGE','WAIT') DEFAULT NULL,
   `OPERATION` varchar(32) NOT NULL,
   `NUMBER_OF_BYTES` bigint(20) unsigned DEFAULT NULL,
   `FLAGS` int(10) unsigned DEFAULT NULL

=== modified file 'sql/filesort.cc'
--- a/sql/filesort.cc	2011-02-02 13:41:10 +0000
+++ b/sql/filesort.cc	2011-02-15 17:14:15 +0000
@@ -203,9 +203,9 @@ ha_rows filesort(THD *thd, TABLE *table,
       goto err;
 
   if (select && select->quick)
-    status_var_increment(thd->status_var.filesort_range_count);
+    thd->inc_status_sort_range();
   else
-    status_var_increment(thd->status_var.filesort_scan_count);
+    thd->inc_status_sort_scan();
 
   // If number of rows is not known, use as much of sort buffer as possible. 
   num_rows= table->file->estimate_rows_upper_bound();
@@ -375,8 +375,7 @@ ha_rows filesort(THD *thd, TABLE *table,
     }
   }
   else
-    statistic_add(thd->status_var.filesort_rows,
-                  (ulong) num_rows, &LOCK_status);
+    thd->inc_status_sort_rows(num_rows);
   *examined_rows= param.examined_rows;
 #ifdef SKIP_DBUG_IN_FILESORT
   DBUG_POP();			/* Ok to DBUG */
@@ -1422,7 +1421,7 @@ int merge_buffers(Sort_param *param, IO_
   THD::killed_state not_killable;
   DBUG_ENTER("merge_buffers");
 
-  status_var_increment(current_thd->status_var.filesort_merge_passes);
+  current_thd->inc_status_sort_merge_passes();
   if (param->not_killable)
   {
     killed= &not_killable;

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2011-02-08 15:54:12 +0000
+++ b/sql/item_func.cc	2011-02-15 17:14:15 +0000
@@ -3886,7 +3886,7 @@ longlong Item_func_get_lock::val_int()
     Structure is now initialized.  Try to get the lock.
     Set up control struct to allow others to abort locks.
   */
-  thd_proc_info(thd, "User lock");
+  THD_STAGE_INFO(thd, stage_user_lock);
   thd->mysys_var->current_mutex= &LOCK_user_locks;
   thd->mysys_var->current_cond=  &ull->cond;
 
@@ -3930,7 +3930,6 @@ longlong Item_func_get_lock::val_int()
   mysql_mutex_unlock(&LOCK_user_locks);
 
   mysql_mutex_lock(&thd->mysys_var->mutex);
-  thd_proc_info(thd, 0);
   thd->mysys_var->current_mutex= 0;
   thd->mysys_var->current_cond=  0;
   mysql_mutex_unlock(&thd->mysys_var->mutex);
@@ -4116,7 +4115,7 @@ longlong Item_func_sleep::val_int()
   mysql_cond_init(key_item_func_sleep_cond, &cond, NULL);
   mysql_mutex_lock(&LOCK_user_locks);
 
-  thd_proc_info(thd, "User sleep");
+  THD_STAGE_INFO(thd, stage_user_sleep);
   thd->mysys_var->current_mutex= &LOCK_user_locks;
   thd->mysys_var->current_cond=  &cond;
 
@@ -4128,7 +4127,6 @@ longlong Item_func_sleep::val_int()
       break;
     error= 0;
   }
-  thd_proc_info(thd, 0);
   mysql_mutex_unlock(&LOCK_user_locks);
   mysql_mutex_lock(&thd->mysys_var->mutex);
   thd->mysys_var->current_mutex= 0;

=== modified file 'sql/lock.cc'
--- a/sql/lock.cc	2010-11-23 22:37:59 +0000
+++ b/sql/lock.cc	2011-02-15 17:14:15 +0000
@@ -321,7 +321,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, 
   if (! (sql_lock= get_lock_data(thd, tables, count, GET_LOCK_STORE_LOCKS)))
     DBUG_RETURN(NULL);
 
-  thd_proc_info(thd, "System lock");
+  THD_STAGE_INFO(thd, stage_system_lock);
   DBUG_PRINT("info", ("thd->proc_info %s", thd->proc_info));
   if (sql_lock->table_count && lock_external(thd, sql_lock->table,
                                              sql_lock->table_count))
@@ -348,8 +348,6 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, 
       my_error(rc, MYF(0));
   }
 end:
-  thd_proc_info(thd, 0);
-
   if (thd->killed)
   {
     thd->send_kill_message();

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2011-02-09 07:31:17 +0000
+++ b/sql/log.cc	2011-02-15 17:14:15 +0000
@@ -482,10 +482,10 @@ bool Log_to_csv_event_handler::
     if (table->field[3]->store_time(&t, MYSQL_TIMESTAMP_TIME))
       goto err;
     /* rows_sent */
-    if (table->field[4]->store((longlong) thd->sent_row_count, TRUE))
+    if (table->field[4]->store((longlong) thd->get_sent_row_count(), TRUE))
       goto err;
     /* rows_examined */
-    if (table->field[5]->store((longlong) thd->examined_row_count, TRUE))
+    if (table->field[5]->store((longlong) thd->get_examined_row_count(), TRUE))
       goto err;
   }
   else
@@ -1784,8 +1784,8 @@ bool MYSQL_QUERY_LOG::write(THD *thd, ti
                     "# Query_time: %s  Lock_time: %s"
                     " Rows_sent: %lu  Rows_examined: %lu\n",
                     query_time_buff, lock_time_buff,
-                    (ulong) thd->sent_row_count,
-                    (ulong) thd->examined_row_count) == (uint) -1)
+                    (ulong) thd->get_sent_row_count(),
+                    (ulong) thd->get_examined_row_count()) == (uint) -1)
       tmp_errno= errno;
     if (thd->db && strcmp(thd->db, db))
     {						// Database changed

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2011-01-11 05:13:23 +0000
+++ b/sql/log_event.cc	2011-02-15 17:14:15 +0000
@@ -6826,7 +6826,6 @@ err:
     end_io_cache(&file);
   if (fd >= 0)
     mysql_file_close(fd, MYF(0));
-  thd_proc_info(thd, 0);
   return error != 0;
 }
 #endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
@@ -6997,7 +6996,6 @@ int Append_block_log_event::do_apply_eve
 err:
   if (fd >= 0)
     mysql_file_close(fd, MYF(0));
-  thd_proc_info(thd, 0);
   DBUG_RETURN(error);
 }
 #endif

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-02-04 05:11:09 +0000
+++ b/sql/mysqld.cc	2011-02-15 17:14:15 +0000
@@ -3079,6 +3079,67 @@ SHOW_VAR com_status_vars[]= {
   {NullS, NullS, SHOW_LONG}
 };
 
+#ifdef HAVE_PSI_INTERFACE
+PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1];
+PSI_statement_info com_statement_info[(uint) COM_END + 1];
+
+/**
+  Initialize the command names array.
+  Since we do not want to maintain a separate array,
+  this is populated from data mined in com_status_vars,
+  which already has one name for each command.
+*/
+void init_sql_statement_info()
+{
+  char *first_com= (char*) offsetof(STATUS_VAR, com_stat[0]);
+  char *last_com= (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_END]);
+  int record_size= (char*) offsetof(STATUS_VAR, com_stat[1])
+                   - (char*) offsetof(STATUS_VAR, com_stat[0]);
+  char *ptr;
+  uint i;
+  uint com_index;
+
+  static const char* dummy= "";
+  for (i= 0; i < ((uint) SQLCOM_END + 1); i++)
+  {
+    sql_statement_info[i].m_name= dummy;
+    sql_statement_info[i].m_flags= 0;
+  }
+
+  SHOW_VAR *var= &com_status_vars[0];
+  while (var->name != NULL)
+  {
+    ptr= var->value;
+    if ((first_com <= ptr) && (ptr <= last_com))
+    {
+      com_index= ((int)(ptr - first_com))/record_size;
+      DBUG_ASSERT(com_index < (uint) SQLCOM_END);
+      sql_statement_info[com_index].m_name= var->name;
+    }
+    var++;
+  }
+
+  DBUG_ASSERT(strcmp(sql_statement_info[(uint) SQLCOM_SELECT].m_name, "select") == 0);
+  DBUG_ASSERT(strcmp(sql_statement_info[(uint) SQLCOM_SIGNAL].m_name, "signal") == 0);
+
+  sql_statement_info[(uint) SQLCOM_END].m_name= "error";
+}
+
+void init_com_statement_info()
+{
+  uint index;
+
+  for (index= 0; index < (uint) COM_END + 1; index++)
+  {
+    com_statement_info[index].m_name= command_name[index].str;
+    com_statement_info[index].m_flags= 0;
+  }
+
+  /* "statement/com/query" can mutate into "statement/sql/..." */
+  com_statement_info[(uint) COM_QUERY].m_flags= PSI_FLAG_MUTABLE;
+}
+#endif
+
 /**
   Create the name of the default general log file
   
@@ -8116,6 +8177,181 @@ static PSI_file_info all_server_files[]=
   { &key_file_trn, "trigger", 0},
   { &key_file_init, "init", 0}
 };
+#endif /* HAVE_PSI_INTERFACE */
+
+PSI_stage_info stage_after_create= { 0, "After create", 0};
+PSI_stage_info stage_allocating_local_table= { 0, "allocating local table", 0};
+PSI_stage_info stage_changing_master= { 0, "Changing master", 0};
+PSI_stage_info stage_checking_master_version= { 0, "Checking master version", 0};
+PSI_stage_info stage_checking_permissions= { 0, "checking permissions", 0};
+PSI_stage_info stage_checking_privileges_on_cached_query= { 0, "checking privileges on cached query", 0};
+PSI_stage_info stage_checking_query_cache_for_query= { 0, "checking query cache for query", 0};
+PSI_stage_info stage_cleaning_up= { 0, "cleaning up", 0};
+PSI_stage_info stage_closing_tables= { 0, "closing tables", 0};
+PSI_stage_info stage_connecting_to_master= { 0, "Connecting to master", 0};
+PSI_stage_info stage_converting_heap_to_myisam= { 0, "converting HEAP to MyISAM", 0};
+PSI_stage_info stage_copying_to_group_table= { 0, "Copying to group table", 0};
+PSI_stage_info stage_copying_to_tmp_table= { 0, "Copying to tmp table", 0};
+PSI_stage_info stage_copy_to_tmp_table= { 0, "copy to tmp table", 0};
+PSI_stage_info stage_creating_delayed_handler= { 0, "Creating delayed handler", 0};
+PSI_stage_info stage_creating_sort_index= { 0, "Creating sort index", 0};
+PSI_stage_info stage_creating_table= { 0, "creating table", 0};
+PSI_stage_info stage_creating_tmp_table= { 0, "Creating tmp table", 0};
+PSI_stage_info stage_deleting_from_main_table= { 0, "deleting from main table", 0};
+PSI_stage_info stage_deleting_from_reference_tables= { 0, "deleting from reference tables", 0};
+PSI_stage_info stage_discard_or_import_tablespace= { 0, "discard_or_import_tablespace", 0};
+PSI_stage_info stage_end= { 0, "end", 0};
+PSI_stage_info stage_executing= { 0, "executing", 0};
+PSI_stage_info stage_execution_of_init_command= { 0, "Execution of init_command", 0};
+PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog= { 0, "Finished reading one binlog; switching to next binlog", 0};
+PSI_stage_info stage_flushing_relay_log_and_master_info_files= { 0, "Flushing relay log and master info files.", 0};
+PSI_stage_info stage_flushing_relay_log_info_file= { 0, "Flushing relay-log info file.", 0};
+PSI_stage_info stage_freeing_items= { 0, "freeing items", 0};
+PSI_stage_info stage_fulltext_initialization= { 0, "FULLTEXT initialization", 0};
+PSI_stage_info stage_got_handler_lock= { 0, "got handler lock", 0};
+PSI_stage_info stage_got_old_table= { 0, "got old table", 0};
+PSI_stage_info stage_init= { 0, "init", 0};
+PSI_stage_info stage_insert= { 0, "insert", 0};
+PSI_stage_info stage_invalidating_query_cache_entries_table= { 0, "invalidating query cache entries (table)", 0};
+PSI_stage_info stage_invalidating_query_cache_entries_table_list= { 0, "invalidating query cache entries (table list)", 0};
+PSI_stage_info stage_killing_slave= { 0, "Killing slave", 0};
+PSI_stage_info stage_logging_slow_query= { 0, "logging slow query", 0};
+PSI_stage_info stage_manage_keys= { 0, "manage keys", 0};
+PSI_stage_info stage_opening_tables= { 0, "Opening tables", 0};
+PSI_stage_info stage_optimizing= { 0, "optimizing", 0};
+PSI_stage_info stage_preparing= { 0, "preparing", 0};
+PSI_stage_info stage_purging_old_relay_logs= { 0, "Purging old relay logs", 0};
+PSI_stage_info stage_query_end= { 0, "query end", 0};
+PSI_stage_info stage_queueing_master_event_to_the_relay_log= { 0, "Queueing master event to the relay log", 0};
+PSI_stage_info stage_reading_event_from_the_relay_log= { 0, "Reading event from the relay log", 0};
+PSI_stage_info stage_registering_slave_on_master= { 0, "Registering slave on master", 0};
+PSI_stage_info stage_removing_duplicates= { 0, "Removing duplicates", 0};
+PSI_stage_info stage_removing_tmp_table= { 0, "removing tmp table", 0};
+PSI_stage_info stage_rename= { 0, "rename", 0};
+PSI_stage_info stage_rename_result_table= { 0, "rename result table", 0};
+PSI_stage_info stage_requesting_binlog_dump= { 0, "Requesting binlog dump", 0};
+PSI_stage_info stage_reschedule= { 0, "reschedule", 0};
+PSI_stage_info stage_searching_rows_for_update= { 0, "Searching rows for update", 0};
+PSI_stage_info stage_sending_binlog_event_to_slave= { 0, "Sending binlog event to slave", 0};
+PSI_stage_info stage_sending_cached_result_to_client= { 0, "sending cached result to client", 0};
+PSI_stage_info stage_sending_data= { 0, "Sending data", 0};
+PSI_stage_info stage_setup= { 0, "setup", 0};
+PSI_stage_info stage_sorting_for_group= { 0, "Sorting for group", 0};
+PSI_stage_info stage_sorting_for_order= { 0, "Sorting for order", 0};
+PSI_stage_info stage_sorting_result= { 0, "Sorting result", 0};
+PSI_stage_info stage_statistics= { 0, "statistics", 0};
+PSI_stage_info stage_storing_result_in_query_cache= { 0, "storing result in query cache", 0};
+PSI_stage_info stage_storing_row_into_queue= { 0, "storing row into queue", 0};
+PSI_stage_info stage_system_lock= { 0, "System lock", 0};
+PSI_stage_info stage_update= { 0, "update", 0};
+PSI_stage_info stage_updating= { 0, "updating", 0};
+PSI_stage_info stage_updating_main_table= { 0, "updating main table", 0};
+PSI_stage_info stage_updating_reference_tables= { 0, "updating reference tables", 0};
+PSI_stage_info stage_upgrading_lock= { 0, "upgrading lock", 0};
+PSI_stage_info stage_user_lock= { 0, "User lock", 0};
+PSI_stage_info stage_user_sleep= { 0, "User sleep", 0};
+PSI_stage_info stage_verifying_table= { 0, "verifying table", 0};
+PSI_stage_info stage_waiting_for_delay_list= { 0, "waiting for delay_list", 0};
+PSI_stage_info stage_waiting_for_handler_insert= { 0, "waiting for handler insert", 0};
+PSI_stage_info stage_waiting_for_handler_lock= { 0, "waiting for handler lock", 0};
+PSI_stage_info stage_waiting_for_handler_open= { 0, "waiting for handler open", 0};
+PSI_stage_info stage_waiting_for_insert= { 0, "Waiting for INSERT", 0};
+PSI_stage_info stage_waiting_for_master_to_send_event= { 0, "Waiting for master to send event", 0};
+PSI_stage_info stage_waiting_for_master_update= { 0, "Waiting for master update", 0};
+PSI_stage_info stage_waiting_for_slave_mutex_on_exit= { 0, "Waiting for slave mutex on exit", 0};
+PSI_stage_info stage_waiting_for_the_next_event_in_relay_log= { 0, "Waiting for the next event in relay log", 0};
+PSI_stage_info stage_waiting_to_finalize_termination= { 0, "Waiting to finalize termination", 0};
+PSI_stage_info stage_waiting_to_get_readlock= { 0, "Waiting to get readlock", 0};
+
+
+#ifdef HAVE_PSI_INTERFACE
+
+PSI_stage_info *all_server_stages[]=
+{
+  & stage_after_create,
+  & stage_allocating_local_table,
+  & stage_changing_master,
+  & stage_checking_master_version,
+  & stage_checking_permissions,
+  & stage_checking_privileges_on_cached_query,
+  & stage_checking_query_cache_for_query,
+  & stage_cleaning_up,
+  & stage_closing_tables,
+  & stage_connecting_to_master,
+  & stage_converting_heap_to_myisam,
+  & stage_copying_to_group_table,
+  & stage_copying_to_tmp_table,
+  & stage_copy_to_tmp_table,
+  & stage_creating_delayed_handler,
+  & stage_creating_sort_index,
+  & stage_creating_table,
+  & stage_creating_tmp_table,
+  & stage_deleting_from_main_table,
+  & stage_deleting_from_reference_tables,
+  & stage_discard_or_import_tablespace,
+  & stage_end,
+  & stage_executing,
+  & stage_execution_of_init_command,
+  & stage_finished_reading_one_binlog_switching_to_next_binlog,
+  & stage_flushing_relay_log_and_master_info_files,
+  & stage_flushing_relay_log_info_file,
+  & stage_freeing_items,
+  & stage_fulltext_initialization,
+  & stage_got_handler_lock,
+  & stage_got_old_table,
+  & stage_init,
+  & stage_insert,
+  & stage_invalidating_query_cache_entries_table,
+  & stage_invalidating_query_cache_entries_table_list,
+  & stage_killing_slave,
+  & stage_logging_slow_query,
+  & stage_manage_keys,
+  & stage_opening_tables,
+  & stage_optimizing,
+  & stage_preparing,
+  & stage_purging_old_relay_logs,
+  & stage_query_end,
+  & stage_queueing_master_event_to_the_relay_log,
+  & stage_reading_event_from_the_relay_log,
+  & stage_registering_slave_on_master,
+  & stage_removing_duplicates,
+  & stage_removing_tmp_table,
+  & stage_rename,
+  & stage_rename_result_table,
+  & stage_requesting_binlog_dump,
+  & stage_reschedule,
+  & stage_searching_rows_for_update,
+  & stage_sending_binlog_event_to_slave,
+  & stage_sending_cached_result_to_client,
+  & stage_sending_data,
+  & stage_setup,
+  & stage_sorting_for_group,
+  & stage_sorting_for_order,
+  & stage_sorting_result,
+  & stage_statistics,
+  & stage_storing_result_in_query_cache,
+  & stage_storing_row_into_queue,
+  & stage_system_lock,
+  & stage_update,
+  & stage_updating,
+  & stage_updating_main_table,
+  & stage_updating_reference_tables,
+  & stage_upgrading_lock,
+  & stage_user_lock,
+  & stage_user_sleep,
+  & stage_verifying_table,
+  & stage_waiting_for_delay_list,
+  & stage_waiting_for_handler_insert,
+  & stage_waiting_for_handler_lock,
+  & stage_waiting_for_handler_open,
+  & stage_waiting_for_insert,
+  & stage_waiting_for_master_to_send_event,
+  & stage_waiting_for_master_update,
+  & stage_waiting_for_slave_mutex_on_exit,
+  & stage_waiting_for_the_next_event_in_relay_log,
+  & stage_waiting_to_finalize_termination,
+  & stage_waiting_to_get_readlock
+};
 
 /**
   Initialise all the performance schema instrumentation points
@@ -8143,6 +8379,18 @@ void init_server_psi_keys(void)
 
   count= array_elements(all_server_files);
   PSI_server->register_file(category, all_server_files, count);
+
+  count= array_elements(all_server_stages);
+  PSI_server->register_stage(category, all_server_stages, count);
+
+  init_sql_statement_info();
+  count= array_elements(sql_statement_info);
+  PSI_server->register_statement(category, sql_statement_info, count);
+
+  category= "com";
+  init_com_statement_info();
+  count= array_elements(com_statement_info);
+  PSI_server->register_statement(category, com_statement_info, count);
 }
 
 #endif /* HAVE_PSI_INTERFACE */

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2011-02-01 07:52:46 +0000
+++ b/sql/mysqld.h	2011-02-15 17:14:15 +0000
@@ -23,6 +23,7 @@
 #include "my_atomic.h"                     /* my_atomic_rwlock_t */
 #include "mysql/psi/mysql_file.h"          /* MYSQL_FILE */
 #include "sql_list.h"                      /* I_List */
+#include "sql_cmd.h"                       /* SQLCOM_END */
 
 class THD;
 struct handlerton;
@@ -291,6 +292,109 @@ extern PSI_file_key key_file_query_log, 
 void init_server_psi_keys();
 #endif /* HAVE_PSI_INTERFACE */
 
+/*
+  MAINTAINER: Please keep this list in order, to limit merge collisions.
+  Hint: grep PSI_stage_info | sort -u
+*/
+extern PSI_stage_info stage_after_create;
+extern PSI_stage_info stage_allocating_local_table;
+extern PSI_stage_info stage_changing_master;
+extern PSI_stage_info stage_checking_master_version;
+extern PSI_stage_info stage_checking_permissions;
+extern PSI_stage_info stage_checking_privileges_on_cached_query;
+extern PSI_stage_info stage_checking_query_cache_for_query;
+extern PSI_stage_info stage_cleaning_up;
+extern PSI_stage_info stage_closing_tables;
+extern PSI_stage_info stage_connecting_to_master;
+extern PSI_stage_info stage_converting_heap_to_myisam;
+extern PSI_stage_info stage_copying_to_group_table;
+extern PSI_stage_info stage_copying_to_tmp_table;
+extern PSI_stage_info stage_copy_to_tmp_table;
+extern PSI_stage_info stage_creating_delayed_handler;
+extern PSI_stage_info stage_creating_sort_index;
+extern PSI_stage_info stage_creating_table;
+extern PSI_stage_info stage_creating_tmp_table;
+extern PSI_stage_info stage_deleting_from_main_table;
+extern PSI_stage_info stage_deleting_from_reference_tables;
+extern PSI_stage_info stage_discard_or_import_tablespace;
+extern PSI_stage_info stage_end;
+extern PSI_stage_info stage_executing;
+extern PSI_stage_info stage_execution_of_init_command;
+extern PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog;
+extern PSI_stage_info stage_flushing_relay_log_and_master_info_files;
+extern PSI_stage_info stage_flushing_relay_log_info_file;
+extern PSI_stage_info stage_freeing_items;
+extern PSI_stage_info stage_fulltext_initialization;
+extern PSI_stage_info stage_got_handler_lock;
+extern PSI_stage_info stage_got_old_table;
+extern PSI_stage_info stage_init;
+extern PSI_stage_info stage_insert;
+extern PSI_stage_info stage_invalidating_query_cache_entries_table;
+extern PSI_stage_info stage_invalidating_query_cache_entries_table_list;
+extern PSI_stage_info stage_killing_slave;
+extern PSI_stage_info stage_logging_slow_query;
+extern PSI_stage_info stage_manage_keys;
+extern PSI_stage_info stage_opening_tables;
+extern PSI_stage_info stage_optimizing;
+extern PSI_stage_info stage_preparing;
+extern PSI_stage_info stage_purging_old_relay_logs;
+extern PSI_stage_info stage_query_end;
+extern PSI_stage_info stage_queueing_master_event_to_the_relay_log;
+extern PSI_stage_info stage_reading_event_from_the_relay_log;
+extern PSI_stage_info stage_registering_slave_on_master;
+extern PSI_stage_info stage_removing_duplicates;
+extern PSI_stage_info stage_removing_tmp_table;
+extern PSI_stage_info stage_rename;
+extern PSI_stage_info stage_rename_result_table;
+extern PSI_stage_info stage_requesting_binlog_dump;
+extern PSI_stage_info stage_reschedule;
+extern PSI_stage_info stage_searching_rows_for_update;
+extern PSI_stage_info stage_sending_binlog_event_to_slave;
+extern PSI_stage_info stage_sending_cached_result_to_client;
+extern PSI_stage_info stage_sending_data;
+extern PSI_stage_info stage_setup;
+extern PSI_stage_info stage_sorting_for_group;
+extern PSI_stage_info stage_sorting_for_order;
+extern PSI_stage_info stage_sorting_result;
+extern PSI_stage_info stage_statistics;
+extern PSI_stage_info stage_storing_result_in_query_cache;
+extern PSI_stage_info stage_storing_row_into_queue;
+extern PSI_stage_info stage_system_lock;
+extern PSI_stage_info stage_update;
+extern PSI_stage_info stage_updating;
+extern PSI_stage_info stage_updating_main_table;
+extern PSI_stage_info stage_updating_reference_tables;
+extern PSI_stage_info stage_upgrading_lock;
+extern PSI_stage_info stage_user_lock;
+extern PSI_stage_info stage_user_sleep;
+extern PSI_stage_info stage_verifying_table;
+extern PSI_stage_info stage_waiting_for_delay_list;
+extern PSI_stage_info stage_waiting_for_handler_insert;
+extern PSI_stage_info stage_waiting_for_handler_lock;
+extern PSI_stage_info stage_waiting_for_handler_open;
+extern PSI_stage_info stage_waiting_for_insert;
+extern PSI_stage_info stage_waiting_for_master_to_send_event;
+extern PSI_stage_info stage_waiting_for_master_update;
+extern PSI_stage_info stage_waiting_for_slave_mutex_on_exit;
+extern PSI_stage_info stage_waiting_for_the_next_event_in_relay_log;
+extern PSI_stage_info stage_waiting_to_finalize_termination;
+extern PSI_stage_info stage_waiting_to_get_readlock;
+
+/**
+  Statement instrumentation keys (sql).
+  The last entry, at [SQLCOM_END], is for parsing errors.
+*/
+extern PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1];
+
+/**
+  Statement instrumentation keys (com).
+  The last entry, at [COM_END], is for packet errors.
+*/
+extern PSI_statement_info com_statement_info[(uint) COM_END + 1];
+
+void init_sql_statement_info();
+void init_com_statement_info();
+
 #ifndef __WIN__
 extern pthread_t signal_thread;
 #endif

=== modified file 'sql/rpl_master.cc'
--- a/sql/rpl_master.cc	2011-01-31 13:44:38 +0000
+++ b/sql/rpl_master.cc	2011-02-15 17:14:15 +0000
@@ -1160,7 +1160,7 @@ impossible position";
 
 	if (read_packet)
         {
-          thd_proc_info(thd, "Sending binlog event to slave");
+          THD_STAGE_INFO(thd, stage_sending_binlog_event_to_slave);
           pos = my_b_tell(&log);
           if (RUN_HOOK(binlog_transmit, before_send_event,
                        (thd, flags, packet, log_file_name, pos)))
@@ -1203,7 +1203,7 @@ impossible position";
       bool loop_breaker = 0;
       /* need this to break out of the for loop from switch */
 
-      thd_proc_info(thd, "Finished reading one binlog; switching to next binlog");
+      THD_STAGE_INFO(thd, stage_finished_reading_one_binlog_switching_to_next_binlog);
       switch (mysql_bin_log.find_next_log(&linfo, 1)) {
       case 0:
 	break;
@@ -1258,7 +1258,7 @@ end:
 
   RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags));
   my_eof(thd);
-  thd_proc_info(thd, "Waiting to finalize termination");
+  THD_STAGE_INFO(thd, stage_waiting_to_finalize_termination);
   mysql_mutex_lock(&LOCK_thread_count);
   thd->current_linfo = 0;
   mysql_mutex_unlock(&LOCK_thread_count);
@@ -1266,7 +1266,7 @@ end:
   DBUG_VOID_RETURN;
 
 err:
-  thd_proc_info(thd, "Waiting to finalize termination");
+  THD_STAGE_INFO(thd, stage_waiting_to_finalize_termination);
   end_io_cache(&log);
   RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags));
   /*

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	2011-02-03 10:13:06 +0000
+++ b/sql/rpl_slave.cc	2011-02-15 17:14:15 +0000
@@ -2359,9 +2359,13 @@ static int init_slave_thread(THD* thd, S
   }
 
   if (thd_type == SLAVE_THD_SQL)
-    thd_proc_info(thd, "Waiting for the next event in relay log");
+  {
+    THD_STAGE_INFO(thd, stage_waiting_for_the_next_event_in_relay_log);
+  }
   else
-    thd_proc_info(thd, "Waiting for master update");
+  {
+    THD_STAGE_INFO(thd, stage_waiting_for_master_update);
+  }
   thd->set_time();
   /* Do not use user-supplied timeout value for system threads. */
   thd->variables.lock_wait_timeout= LONG_TIMEOUT;
@@ -3223,7 +3227,7 @@ pthread_handler_t handle_slave_io(void *
     goto err;
   }
 
-  thd_proc_info(thd, "Connecting to master");
+  THD_STAGE_INFO(thd, stage_connecting_to_master);
   // we can get killed during safe_connect
   if (!safe_connect(thd, mysql, mi))
   {
@@ -3266,7 +3270,7 @@ connected:
   mysql_mutex_unlock(&mi->run_lock);
 
   thd->slave_net = &mysql->net;
-  thd_proc_info(thd, "Checking master version");
+  THD_STAGE_INFO(thd, stage_checking_master_version);
   ret= get_master_version_and_clock(mysql, mi);
   if (!ret)
     ret= get_master_uuid(mysql, mi);
@@ -3295,7 +3299,7 @@ connected:
     /*
       Register ourselves with the master.
     */
-    thd_proc_info(thd, "Registering slave on master");
+    THD_STAGE_INFO(thd, stage_registering_slave_on_master);
     if (register_slave_on_master(mysql, mi, &suppress_warnings))
     {
       if (!check_io_slave_killed(thd, mi, "Slave I/O thread killed "
@@ -3325,7 +3329,7 @@ connected:
   DBUG_PRINT("info",("Starting reading binary log from master"));
   while (!io_slave_killed(thd,mi))
   {
-    thd_proc_info(thd, "Requesting binlog dump");
+    THD_STAGE_INFO(thd, stage_requesting_binlog_dump);
     if (request_dump(thd, mysql, mi, &suppress_warnings))
     {
       sql_print_error("Failed on request_dump()");
@@ -3358,7 +3362,7 @@ requesting master dump") ||
          important thing is to not confuse users by saying "reading" whereas
          we're in fact receiving nothing.
       */
-      thd_proc_info(thd, "Waiting for master to send event");
+      THD_STAGE_INFO(thd, stage_waiting_for_master_to_send_event);
       event_len= read_event(mysql, mi, &suppress_warnings);
       if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
 reading event"))
@@ -3406,7 +3410,7 @@ Stopping slave I/O thread due to out-of-
       } // if (event_len == packet_error)
 
       retry_count=0;                    // ok event, reset retry counter
-      thd_proc_info(thd, "Queueing master event to the relay log");
+      THD_STAGE_INFO(thd, stage_queueing_master_event_to_the_relay_log);
       event_buf= (const char*)mysql->net.read_pos + 1;
       if (RUN_HOOK(binlog_relay_io, after_read_event,
                    (thd, mi,(const char*)mysql->net.read_pos + 1,
@@ -3503,7 +3507,7 @@ err:
     mi->mysql=0;
   }
   write_ignored_events_info_to_relay_log(thd, mi);
-  thd_proc_info(thd, "Waiting for slave mutex on exit");
+  THD_STAGE_INFO(thd, stage_waiting_for_slave_mutex_on_exit);
   mysql_mutex_lock(&mi->run_lock);
 
   /* Forget the relay log's format */
@@ -3877,7 +3881,7 @@ llstr(rli->get_group_master_log_pos(), l
   thd->catalog= 0;
   thd->reset_query();
   thd->reset_db(NULL, 0);
-  thd_proc_info(thd, "Waiting for slave mutex on exit");
+  THD_STAGE_INFO(thd, stage_waiting_for_slave_mutex_on_exit);
   mysql_mutex_lock(&rli->run_lock);
   /* We need data_lock, at least to wake up any waiting master_pos_wait() */
   mysql_mutex_lock(&rli->data_lock);
@@ -5720,7 +5724,7 @@ int stop_slave(THD* thd, Master_info* mi
 
   if (check_access(thd, SUPER_ACL, any_db, NULL, NULL, 0, 0))
     DBUG_RETURN(1);
-  thd_proc_info(thd, "Killing slave");
+  THD_STAGE_INFO(thd, stage_killing_slave);
   int thread_mask;
   lock_slave_threads(mi);
   // Get a mask of _running_ threads
@@ -5747,7 +5751,6 @@ int stop_slave(THD* thd, Master_info* mi
                  ER(ER_SLAVE_WAS_NOT_RUNNING));
   }
   unlock_slave_threads(mi);
-  thd_proc_info(thd, 0);
 
   if (slave_errno)
   {
@@ -5854,7 +5857,7 @@ bool change_master(THD* thd, Master_info
   }
   thread_mask= SLAVE_IO | SLAVE_SQL;
 
-  thd_proc_info(thd, "Changing master");
+  THD_STAGE_INFO(thd, stage_changing_master);
   /* 
     We need to check if there is an empty master_host. Otherwise
     change master succeeds, a master.info file is created containing 
@@ -6123,7 +6126,6 @@ bool change_master(THD* thd, Master_info
 
 err:
   unlock_slave_threads(mi);
-  thd_proc_info(thd, 0);
   if (ret == FALSE)
     my_ok(thd);
   DBUG_RETURN(ret);

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2011-02-08 15:54:12 +0000
+++ b/sql/sql_base.cc	2011-02-15 17:14:15 +0000
@@ -4741,7 +4741,7 @@ restart:
   table_to_open= start;
   sroutine_to_open= (Sroutine_hash_entry**) &thd->lex->sroutines_list.first;
   *counter= 0;
-  thd_proc_info(thd, "Opening tables");
+  THD_STAGE_INFO(thd, stage_opening_tables);
 
   /*
     If we are executing LOCK TABLES statement or a DDL statement
@@ -4932,7 +4932,6 @@ restart:
   }
 
 err:
-  thd_proc_info(thd, 0);
   free_root(&new_frm_mem, MYF(0));              // Free pre-alloced block
 
   if (error && *table_to_open)
@@ -5305,7 +5304,7 @@ TABLE *open_ltable(THD *thd, TABLE_LIST 
   /* should not be used in a prelocked_mode context, see NOTE above */
   DBUG_ASSERT(thd->locked_tables_mode < LTM_PRELOCKED);
 
-  thd_proc_info(thd, "Opening table");
+  THD_STAGE_INFO(thd, stage_opening_tables);
   thd->current_tablenr= 0;
   /* open_ltable can be used only for BASIC TABLEs */
   table_list->required_type= FRMTYPE_TABLE;
@@ -5374,7 +5373,6 @@ end:
       trans_rollback_stmt(thd);
     close_thread_tables(thd);
   }
-  thd_proc_info(thd, 0);
   DBUG_RETURN(table);
 }
 
@@ -8805,7 +8803,7 @@ int init_ftfuncs(THD *thd, SELECT_LEX *s
     List_iterator<Item_func_match> li(*(select_lex->ftfunc_list));
     Item_func_match *ifm;
     DBUG_PRINT("info",("Performing FULLTEXT search"));
-    thd_proc_info(thd, "FULLTEXT initialization");
+    THD_STAGE_INFO(thd, stage_fulltext_initialization);
 
     while ((ifm=li++))
       ifm->init_search(no_order);

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2010-11-29 16:27:58 +0000
+++ b/sql/sql_cache.cc	2011-02-15 17:14:15 +0000
@@ -966,7 +966,7 @@ Query_cache::abort(Query_cache_tls *quer
   Query_cache_block *query_block= query_cache_tls->first_query_block;
   if (query_block)
   {
-    thd_proc_info(thd, "storing result in query cache");
+    THD_STAGE_INFO(thd, stage_storing_result_in_query_cache);
     DUMP(this);
     BLOCK_LOCK_WR(query_block);
     // The following call will remove the lock on query_block
@@ -1017,7 +1017,7 @@ void Query_cache::end_of_result(THD *thd
       suitable size if needed and setting block type. Since this is the last
       block, the writer should be dropped.
     */
-    thd_proc_info(thd, "storing result in query cache");
+    THD_STAGE_INFO(thd, stage_storing_result_in_query_cache);
     DUMP(this);
     BLOCK_LOCK_WR(query_block);
     Query_cache_query *header= query_block->query();
@@ -1534,7 +1534,7 @@ Query_cache::send_result_to_client(THD *
     DBUG_PRINT("qcache", ("No active database"));
   }
 
-  thd_proc_info(thd, "checking query cache for query");
+  THD_STAGE_INFO(thd, stage_checking_query_cache_for_query);
 
   // fill all gaps between fields with 0 to get repeatable key
   bzero(&flags, QUERY_CACHE_FLAGS_SIZE);
@@ -1625,7 +1625,7 @@ def_week_frmt: %lu, in_trans: %d, autoco
   }
       
   // Check access;
-  thd_proc_info(thd, "checking privileges on cached query");
+  THD_STAGE_INFO(thd, stage_checking_privileges_on_cached_query);
   block_table= query_block->table(0);
   block_table_end= block_table+query_block->n_tables;
   for (; block_table != block_table_end; block_table++)
@@ -1722,7 +1722,7 @@ def_week_frmt: %lu, in_trans: %d, autoco
     Send cached result to client
   */
 #ifndef EMBEDDED_LIBRARY
-  thd_proc_info(thd, "sending cached result to client");
+  THD_STAGE_INFO(thd, stage_sending_cached_result_to_client);
   do
   {
     DBUG_PRINT("qcache", ("Results  (len: %lu  used: %lu  headers: %lu)",
@@ -1815,7 +1815,7 @@ void Query_cache::invalidate(CHANGED_TAB
   THD *thd= current_thd;
   for (; tables_used; tables_used= tables_used->next)
   {
-    thd_proc_info(thd, "invalidating query cache entries (table list)");
+    THD_STAGE_INFO(thd, stage_invalidating_query_cache_entries_table_list);
     invalidate_table(thd, (uchar*) tables_used->key, tables_used->key_length);
     DBUG_PRINT("qcache", ("db: %s  table: %s", tables_used->key,
                           tables_used->key+
@@ -1844,7 +1844,7 @@ void Query_cache::invalidate_locked_for_
   THD *thd= current_thd;
   for (; tables_used; tables_used= tables_used->next_local)
   {
-    thd_proc_info(thd, "invalidating query cache entries (table)");
+    THD_STAGE_INFO(thd, stage_invalidating_query_cache_entries_table);
     if (tables_used->lock_type >= TL_WRITE_ALLOW_WRITE &&
         tables_used->table)
     {

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2011-02-03 10:13:06 +0000
+++ b/sql/sql_class.cc	2011-02-15 17:14:15 +0000
@@ -60,6 +60,8 @@
 #include "sql_callback.h"
 #include "lock.h"
 
+#include <mysql/psi/mysql_statement.h>
+
 /*
   The following is used to initialise Table_ident with a internal
   table name
@@ -511,9 +513,10 @@ THD::THD(bool enable_plugins)
    first_successful_insert_id_in_prev_stmt_for_binlog(0),
    first_successful_insert_id_in_cur_stmt(0),
    stmt_depends_on_first_successful_insert_id_in_prev_stmt(FALSE),
-   examined_row_count(0),
+   m_examined_row_count(0),
    warning_info(&main_warning_info),
    stmt_da(&main_da),
+   m_statement_psi(NULL),
    is_fatal_error(0),
    transaction_rollback_request(0),
    is_fatal_sub_stmt_error(0),
@@ -555,7 +558,7 @@ THD::THD(bool enable_plugins)
   tmp_table=0;
   used_tables=0;
   cuted_fields= 0L;
-  sent_row_count= 0L;
+  m_sent_row_count= 0L;
   limit_found_rows= 0;
   m_row_count_func= -1;
   statement_id_counter= 0UL;
@@ -1918,7 +1921,7 @@ bool select_send::send_data(List<Item> &
     DBUG_RETURN(TRUE);
   }
 
-  thd->sent_row_count++;
+  thd->inc_sent_row_count(1);
 
   if (thd->vio_ok())
     DBUG_RETURN(protocol->write());
@@ -2010,7 +2013,7 @@ select_to_file::~select_to_file()
 
 select_export::~select_export()
 {
-  thd->sent_row_count=row_count;
+  thd->set_sent_row_count(row_count);
 }
 
 
@@ -3434,8 +3437,8 @@ void THD::reset_sub_statement_state(Sub_
   backup->in_sub_stmt=     in_sub_stmt;
   backup->enable_slow_log= enable_slow_log;
   backup->limit_found_rows= limit_found_rows;
-  backup->examined_row_count= examined_row_count;
-  backup->sent_row_count=   sent_row_count;
+  backup->examined_row_count= m_examined_row_count;
+  backup->sent_row_count= m_sent_row_count;
   backup->cuted_fields=     cuted_fields;
   backup->client_capabilities= client_capabilities;
   backup->savepoints= transaction.savepoints;
@@ -3458,8 +3461,8 @@ void THD::reset_sub_statement_state(Sub_
   /* Disable result sets */
   client_capabilities &= ~CLIENT_MULTI_RESULTS;
   in_sub_stmt|= new_state;
-  examined_row_count= 0;
-  sent_row_count= 0;
+  m_examined_row_count= 0;
+  m_sent_row_count= 0;
   cuted_fields= 0;
   transaction.savepoints= 0;
   first_successful_insert_id_in_cur_stmt= 0;
@@ -3505,7 +3508,7 @@ void THD::restore_sub_statement_state(Su
   first_successful_insert_id_in_cur_stmt= 
     backup->first_successful_insert_id_in_cur_stmt;
   limit_found_rows= backup->limit_found_rows;
-  sent_row_count=   backup->sent_row_count;
+  set_sent_row_count(backup->sent_row_count);
   client_capabilities= backup->client_capabilities;
   /*
     If we've left sub-statement mode, reset the fatal error flag.
@@ -3523,7 +3526,7 @@ void THD::restore_sub_statement_state(Su
     The following is added to the old values as we are interested in the
     total complexity of the query
   */
-  examined_row_count+= backup->examined_row_count;
+  inc_examined_row_count(backup->examined_row_count);
   cuted_fields+=       backup->cuted_fields;
   DBUG_VOID_RETURN;
 }
@@ -3536,6 +3539,146 @@ void THD::set_statement(Statement *stmt)
   mysql_mutex_unlock(&LOCK_thd_data);
 }
 
+void THD::set_sent_row_count(ha_rows count)
+{
+  m_sent_row_count= count;
+  MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, m_sent_row_count);
+}
+
+void THD::set_examined_row_count(ha_rows count)
+{
+  m_examined_row_count= count;
+  MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, m_examined_row_count);
+}
+
+void THD::inc_sent_row_count(ha_rows count)
+{
+  m_sent_row_count+= count;
+  MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, m_sent_row_count);
+}
+
+void THD::inc_examined_row_count(ha_rows count)
+{
+  m_examined_row_count+= count;
+  MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, m_examined_row_count);
+}
+
+void THD::inc_status_created_tmp_disk_tables()
+{
+  status_var_increment(status_var.created_tmp_disk_tables);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_created_tmp_disk_tables(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_created_tmp_tables()
+{
+  status_var_increment(status_var.created_tmp_tables);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_created_tmp_tables(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_full_join()
+{
+  status_var_increment(status_var.select_full_join_count);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_select_full_join(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_full_range_join()
+{
+  status_var_increment(status_var.select_full_range_join_count);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_select_full_range_join(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_range()
+{
+  status_var_increment(status_var.select_range_count);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_select_range(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_range_check()
+{
+  status_var_increment(status_var.select_range_check_count);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_select_range_check(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_scan()
+{
+  status_var_increment(status_var.select_scan_count);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_select_scan(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_sort_merge_passes()
+{
+  status_var_increment(status_var.filesort_merge_passes);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_sort_merge_passes(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_sort_range()
+{
+  status_var_increment(status_var.filesort_range_count);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_sort_range(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_sort_rows(ha_rows count)
+{
+  statistic_add(status_var.filesort_rows, count, &LOCK_status);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_sort_rows(m_statement_psi, count);
+#endif
+}
+
+void THD::inc_status_sort_scan()
+{
+  status_var_increment(status_var.filesort_scan_count);
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->inc_statement_sort_scan(m_statement_psi, 1);
+#endif
+}
+
+void THD::set_status_no_index_used()
+{
+  server_status|= SERVER_QUERY_NO_INDEX_USED;
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->set_statement_no_index_used(m_statement_psi);
+#endif
+}
+
+void THD::set_status_no_good_index_used()
+{
+  server_status|= SERVER_QUERY_NO_GOOD_INDEX_USED;
+#ifdef HAVE_PSI_INTERFACE
+  if (PSI_server && m_statement_psi)
+    PSI_server->set_statement_no_good_index_used(m_statement_psi);
+#endif
+}
 
 void THD::set_command(enum enum_server_command command)
 {

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2011-02-02 18:31:39 +0000
+++ b/sql/sql_class.h	2011-02-15 17:14:15 +0000
@@ -40,6 +40,8 @@
 #include "thr_lock.h"             /* thr_lock_type, THR_LOCK_DATA,
                                      THR_LOCK_INFO */
 
+#include <mysql/psi/mysql_stage.h>
+#include <mysql/psi/mysql_statement.h>
 
 class Reprepare_observer;
 class Relay_log_info;
@@ -1993,11 +1995,12 @@ public:
 
   ha_rows    cuted_fields;
 
-  /*
-    number of rows we actually sent to the client, including "synthetic"
+private:
+  /**
+    Number of rows we actually sent to the client, including "synthetic"
     rows in ROLLUP etc.
   */
-  ha_rows    sent_row_count;
+  ha_rows m_sent_row_count;
 
   /**
     Number of rows read and/or evaluated for a statement. Used for
@@ -2009,7 +2012,35 @@ public:
     statement including ORDER BY could possibly evaluate the row in
     filesort() before reading it for e.g. update.
   */
-  ha_rows    examined_row_count;
+  ha_rows m_examined_row_count;
+
+public:
+  ha_rows get_sent_row_count() const
+  { return m_sent_row_count; }
+
+  ha_rows get_examined_row_count() const
+  { return m_examined_row_count; }
+
+  void set_sent_row_count(ha_rows count);
+  void set_examined_row_count(ha_rows count);
+
+  void inc_sent_row_count(ha_rows count);
+  void inc_examined_row_count(ha_rows count);
+
+  void inc_status_created_tmp_disk_tables();
+  void inc_status_created_tmp_files();
+  void inc_status_created_tmp_tables();
+  void inc_status_select_full_join();
+  void inc_status_select_full_range_join();
+  void inc_status_select_range();
+  void inc_status_select_range_check();
+  void inc_status_select_scan();
+  void inc_status_sort_merge_passes();
+  void inc_status_sort_range();
+  void inc_status_sort_rows(ha_rows count);
+  void inc_status_sort_scan();
+  void set_status_no_index_used();
+  void set_status_no_good_index_used();
 
   /*
     The set of those tables whose fields are referenced in all subqueries
@@ -2026,6 +2057,9 @@ public:
   PROFILING  profiling;
 #endif
 
+  /** Current statement instrumentation. */
+  PSI_statement_locker *m_statement_psi;
+
   /*
     Id of current query. Statement can be reused to execute several queries
     query_id is global in context of the whole MySQL server.
@@ -2396,7 +2430,11 @@ public:
   { 
     return (IS_TIME_T_VALID_FOR_TIMESTAMP(start_time));
   }
-  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
+  void set_time_after_lock()
+  {
+    utime_after_lock= my_micro_time();
+    MYSQL_SET_STATEMENT_LOCK_TIME(m_statement_psi, (utime_after_lock - start_utime));
+  }
   ulonglong current_utime()  { return my_micro_time(); }
   /**
    Update server status after execution of a top level statement.
@@ -3840,4 +3878,10 @@ const char *set_thd_proc_info(void *thd_
 #define thd_proc_info(thd, msg) \
   set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__)
 
+#define THD_STAGE_INFO(thd, stage) \
+  { \
+    set_thd_proc_info(thd, stage.m_name, __func__, __FILE__, __LINE__); \
+    MYSQL_SET_STAGE(stage.m_key, __FILE__, __LINE__); \
+  }
+
 #endif /* SQL_CLASS_INCLUDED */

=== modified file 'sql/sql_cursor.cc'
--- a/sql/sql_cursor.cc	2010-12-14 15:12:13 +0000
+++ b/sql/sql_cursor.cc	2011-02-15 17:14:15 +0000
@@ -97,6 +97,7 @@ public:
 int mysql_open_cursor(THD *thd, select_result *result,
                       Server_side_cursor **pcursor)
 {
+  PSI_statement_locker *parent_locker;
   select_result *save_result;
   Select_materialize *result_materialize;
   LEX *lex= thd->lex;
@@ -115,7 +116,10 @@ int mysql_open_cursor(THD *thd, select_r
                          &thd->security_ctx->priv_user[0],
                          (char *) thd->security_ctx->host_or_ip,
                          2);
+  parent_locker= thd->m_statement_psi;
+  thd->m_statement_psi= NULL;
   rc= mysql_execute_command(thd);
+  thd->m_statement_psi= parent_locker;
   MYSQL_QUERY_EXEC_DONE(rc);
 
   lex->result= save_result;

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2011-02-02 10:32:21 +0000
+++ b/sql/sql_delete.cc	2011-02-15 17:14:15 +0000
@@ -76,7 +76,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
 	     table_list->view_db.str, table_list->view_name.str);
     DBUG_RETURN(TRUE);
   }
-  thd_proc_info(thd, "init");
+  THD_STAGE_INFO(thd, stage_init);
   table->map=1;
 
   if (mysql_prepare_delete(thd, table_list, &conds))
@@ -252,7 +252,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
         free_underlaid_joins(thd, &thd->lex->select_lex);
         DBUG_RETURN(TRUE);
       }
-      thd->examined_row_count+= examined_rows;
+      thd->inc_examined_row_count(examined_rows);
       /*
         Filesort has already found and selected the rows we want to delete,
         so we don't need the where clause
@@ -276,7 +276,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     init_read_record_idx(&info, thd, table, 1, usable_index, reverse);
 
   init_ftfuncs(thd, select_lex, 1);
-  thd_proc_info(thd, "updating");
+  THD_STAGE_INFO(thd, stage_updating);
 
   if (table->triggers &&
       table->triggers->has_triggers(TRG_EVENT_DELETE,
@@ -299,7 +299,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
   while (!(error=info.read_record(&info)) && !thd->killed &&
 	 ! thd->is_error())
   {
-    thd->examined_row_count++;
+    thd->inc_examined_row_count(1);
     // thd->is_error() is tested to disallow delete row on error
     if (!select || (!select->skip_record(thd, &skip_record) && !skip_record))
     {
@@ -355,7 +355,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
       table->file->print_error(loc_error,MYF(0));
     error=1;
   }
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
   end_read_record(&info);
   if (options & OPTION_QUICK)
     (void) table->file->extra(HA_EXTRA_NORMAL);
@@ -580,7 +580,7 @@ multi_delete::prepare(List<Item> &values
   DBUG_ENTER("multi_delete::prepare");
   unit= u;
   do_delete= 1;
-  thd_proc_info(thd, "deleting from main table");
+  THD_STAGE_INFO(thd, stage_deleting_from_main_table);
   DBUG_RETURN(0);
 }
 
@@ -960,7 +960,7 @@ int multi_delete::do_table_deletes(TABLE
 bool multi_delete::send_eof()
 {
   THD::killed_state killed_status= THD::NOT_KILLED;
-  thd_proc_info(thd, "deleting from reference tables");
+  THD_STAGE_INFO(thd, stage_deleting_from_reference_tables);
 
   /* Does deletes for the last n - 1 tables, returns 0 if ok */
   int local_error= do_deletes();		// returns 0 if success
@@ -969,7 +969,7 @@ bool multi_delete::send_eof()
   local_error= local_error || error;
   killed_status= (local_error == 0)? THD::NOT_KILLED : thd->killed;
   /* reset used flags */
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
 
   if (thd->transaction.stmt.modified_non_trans_table)
     thd->transaction.all.modified_non_trans_table= TRUE;

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2011-01-31 13:44:38 +0000
+++ b/sql/sql_insert.cc	2011-02-15 17:14:15 +0000
@@ -716,7 +716,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
   }
   lock_type= table_list->lock_type;
 
-  thd_proc_info(thd, "init");
+  THD_STAGE_INFO(thd, stage_init);
   thd->used_tables=0;
   values= its++;
   value_count= values->elements;
@@ -801,7 +801,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
 #endif
 
   error=0;
-  thd_proc_info(thd, "update");
+  THD_STAGE_INFO(thd, stage_update);
   if (duplic == DUP_REPLACE &&
       (!table->triggers || !table->triggers->has_delete_triggers()))
     table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
@@ -1046,7 +1046,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
     DBUG_ASSERT(transactional_table || !changed || 
                 thd->transaction.stmt.modified_non_trans_table);
   }
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
   /*
     We'll report to the client this id:
     - if the table contains an autoincrement column and we successfully
@@ -1995,7 +1995,7 @@ I_List<Delayed_insert> delayed_threads;
 static
 Delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list)
 {
-  thd_proc_info(thd, "waiting for delay_list");
+  THD_STAGE_INFO(thd, stage_waiting_for_delay_list);
   mysql_mutex_lock(&LOCK_delayed_insert);       // Protect master list
   I_List_iterator<Delayed_insert> it(delayed_threads);
   Delayed_insert *di;
@@ -2077,7 +2077,7 @@ bool delayed_get_table(THD *thd, MDL_req
     */
     if (delayed_insert_threads >= thd->variables.max_insert_delayed_threads)
       DBUG_RETURN(0);
-    thd_proc_info(thd, "Creating delayed handler");
+    THD_STAGE_INFO(thd, stage_creating_delayed_handler);
     mysql_mutex_lock(&LOCK_delayed_create);
     /*
       The first search above was done without LOCK_delayed_create.
@@ -2133,14 +2133,14 @@ bool delayed_get_table(THD *thd, MDL_req
         handler thread has been properly initialized before exiting. Otherwise
         we risk doing clone_ticket() on a ticket that is no longer valid.
       */
-      thd_proc_info(thd, "waiting for handler open");
+      THD_STAGE_INFO(thd, stage_waiting_for_handler_open);
       while (!di->handler_thread_initialized ||
              (!di->thd.killed && !di->table && !thd->killed))
       {
         mysql_cond_wait(&di->cond_client, &di->mutex);
       }
       mysql_mutex_unlock(&di->mutex);
-      thd_proc_info(thd, "got old table");
+      THD_STAGE_INFO(thd, stage_got_old_table);
       if (thd->killed)
       {
         di->unlock();
@@ -2221,13 +2221,13 @@ TABLE *Delayed_insert::get_local_table(T
   tables_in_use++;
   if (!thd.lock)				// Table is not locked
   {
-    thd_proc_info(client_thd, "waiting for handler lock");
+    THD_STAGE_INFO(client_thd, stage_waiting_for_handler_lock);
     mysql_cond_signal(&cond);			// Tell handler to lock table
     while (!thd.killed && !thd.lock && ! client_thd->killed)
     {
       mysql_cond_wait(&cond_client, &mutex);
     }
-    thd_proc_info(client_thd, "got handler lock");
+    THD_STAGE_INFO(client_thd, stage_got_handler_lock);
     if (client_thd->killed)
       goto error;
     if (thd.killed)
@@ -2261,7 +2261,7 @@ TABLE *Delayed_insert::get_local_table(T
     bytes. Since the table copy is used for creating one record only,
     the other record buffers and alignment are unnecessary.
   */
-  thd_proc_info(client_thd, "allocating local table");
+  THD_STAGE_INFO(client_thd, stage_allocating_local_table);
   copy= (TABLE*) client_thd->alloc(sizeof(*copy)+
 				   (share->fields+1)*sizeof(Field**)+
 				   share->reclength +
@@ -2347,11 +2347,11 @@ int write_delayed(THD *thd, TABLE *table
   DBUG_PRINT("enter", ("query = '%s' length %lu", query.str,
                        (ulong) query.length));
 
-  thd_proc_info(thd, "waiting for handler insert");
+  THD_STAGE_INFO(thd, stage_waiting_for_handler_insert);
   mysql_mutex_lock(&di->mutex);
   while (di->stacked_inserts >= delayed_queue_size && !thd->killed)
     mysql_cond_wait(&di->cond_client, &di->mutex);
-  thd_proc_info(thd, "storing row into queue");
+  THD_STAGE_INFO(thd, stage_storing_row_into_queue);
 
   if (thd->killed)
     goto err;
@@ -2715,7 +2715,7 @@ pthread_handler_t handle_delayed_insert(
         /* Information for pthread_kill */
         di->thd.mysys_var->current_mutex= &di->mutex;
         di->thd.mysys_var->current_cond= &di->cond;
-        thd_proc_info(&(di->thd), "Waiting for INSERT");
+        THD_STAGE_INFO(&(di->thd), stage_waiting_for_insert);
 
         DBUG_PRINT("info",("Waiting for someone to insert rows"));
         while (!thd->killed && !di->status)
@@ -2746,7 +2746,6 @@ pthread_handler_t handle_delayed_insert(
         mysql_mutex_unlock(&di->thd.mysys_var->mutex);
         mysql_mutex_lock(&di->mutex);
       }
-      thd_proc_info(&(di->thd), 0);
 
       if (di->tables_in_use && ! thd->lock && !thd->killed)
       {
@@ -2871,7 +2870,7 @@ bool Delayed_insert::handle_inserts(void
 
   table->next_number_field=table->found_next_number_field;
 
-  thd_proc_info(&thd, "upgrading lock");
+  THD_STAGE_INFO(&thd, stage_upgrading_lock);
   if (thr_upgrade_write_delay_lock(*thd.lock->locks, delayed_lock,
                                    thd.variables.lock_wait_timeout))
   {
@@ -2885,7 +2884,7 @@ bool Delayed_insert::handle_inserts(void
     goto err;
   }
 
-  thd_proc_info(&thd, "insert");
+  THD_STAGE_INFO(&thd, stage_insert);
   max_rows= delayed_insert_limit;
   if (thd.killed || table->s->has_old_version())
   {
@@ -3047,7 +3046,7 @@ bool Delayed_insert::handle_inserts(void
       {
 	if (tables_in_use)
           mysql_cond_broadcast(&cond_client);   // If waiting clients
-	thd_proc_info(&thd, "reschedule");
+	THD_STAGE_INFO(&thd, stage_reschedule);
         mysql_mutex_unlock(&mutex);
 	if ((error=table->file->extra(HA_EXTRA_NO_CACHE)))
 	{
@@ -3069,13 +3068,12 @@ bool Delayed_insert::handle_inserts(void
 	if (!using_bin_log)
 	  table->file->extra(HA_EXTRA_WRITE_CACHE);
         mysql_mutex_lock(&mutex);
-	thd_proc_info(&thd, "insert");
+	THD_STAGE_INFO(&thd, stage_insert);
       }
       if (tables_in_use)
         mysql_cond_broadcast(&cond_client);     // If waiting clients
     }
   }
-  thd_proc_info(&thd, 0);
   mysql_mutex_unlock(&mutex);
 
   /*

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2011-02-07 11:49:18 +0000
+++ b/sql/sql_parse.cc	2011-02-15 17:14:15 +0000
@@ -94,6 +94,7 @@
 #include "debug_sync.h"
 #include "probes_mysql.h"
 #include "set_var.h"
+#include "mysql/psi/mysql_statement.h"
 #include "sql_bootstrap.h"
 
 #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
@@ -509,7 +510,7 @@ void execute_init_command(THD *thd, LEX_
   thd->profiling.set_query_source(buf, len);
 #endif
 
-  thd_proc_info(thd, "Execution of init_command");
+  THD_STAGE_INFO(thd, stage_execution_of_init_command);
   save_client_capabilities= thd->client_capabilities;
   thd->client_capabilities|= CLIENT_MULTI_QUERIES;
   /*
@@ -548,7 +549,6 @@ static void handle_bootstrap_impl(THD *t
   thd->thread_stack= (char*) &thd;
 #endif /* EMBEDDED_LIBRARY */
 
-  thd_proc_info(thd, 0);
   thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME));
   thd->security_ctx->priv_user[0]= thd->security_ctx->priv_host[0]=0;
   /*
@@ -812,6 +812,7 @@ bool do_command(THD *thd)
   my_net_set_read_timeout(net, thd->variables.net_read_timeout);
 
   DBUG_ASSERT(packet_length);
+
   return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1));
 
 out:
@@ -911,17 +912,29 @@ static my_bool deny_updates_if_read_only
 bool dispatch_command(enum enum_server_command command, THD *thd,
 		      char* packet, uint packet_length)
 {
+#ifdef HAVE_PSI_INTERFACE
+  PSI_statement_locker_state state;
+#endif
+
   NET *net= &thd->net;
   bool error= 0;
   DBUG_ENTER("dispatch_command");
   DBUG_PRINT("info",("packet: '%*.s'; command: %d", packet_length, packet, command));
 
+  /* SHOW PROFILE instrumentation, begin */
 #if defined(ENABLED_PROFILING)
   thd->profiling.start_new_query();
 #endif
+
+  /* DTRACE instrumentation, begin */
   MYSQL_COMMAND_START(thd->thread_id, command,
                       &thd->security_ctx->priv_user[0],
                       (char *) thd->security_ctx->host_or_ip);
+
+  /* Performance Schema Interface instrumentation, begin */
+  thd->m_statement_psi= MYSQL_START_STATEMENT(& state, com_statement_info[command].m_key,
+                                              thd->db, thd->db_length);
+  THD_STAGE_INFO(thd, stage_init);
   
   thd->set_command(command);
   /*
@@ -1064,13 +1077,16 @@ bool dispatch_command(enum enum_server_c
                       &thd->security_ctx->priv_user[0],
                       (char *) thd->security_ctx->host_or_ip);
     char *packet_end= thd->query() + thd->query_length();
-    /* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */
 
     general_log_write(thd, command, thd->query(), thd->query_length());
     DBUG_PRINT("query",("%-.4096s",thd->query()));
+
 #if defined(ENABLED_PROFILING)
     thd->profiling.set_query_source(thd->query(), thd->query_length());
 #endif
+
+    MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(), thd->query_length());
+
     Parser_state parser_state;
     if (parser_state.init(thd, thd->query(), thd->query_length()))
       break;
@@ -1100,22 +1116,39 @@ bool dispatch_command(enum enum_server_c
         length--;
       }
 
+/* PSI end */
+      MYSQL_END_STATEMENT(thd->m_statement_psi, thd->stmt_da);
+
+/* DTRACE end */
       if (MYSQL_QUERY_DONE_ENABLED())
       {
         MYSQL_QUERY_DONE(thd->is_error());
       }
 
+/* SHOW PROFILE end */
 #if defined(ENABLED_PROFILING)
       thd->profiling.finish_current_query();
+#endif
+
+/* SHOW PROFILE begin */
+#if defined(ENABLED_PROFILING)
       thd->profiling.start_new_query("continuing");
       thd->profiling.set_query_source(beginning_of_next_stmt, length);
 #endif
 
+/* DTRACE begin */
       MYSQL_QUERY_START(beginning_of_next_stmt, thd->thread_id,
                         (char *) (thd->db ? thd->db : ""),
                         &thd->security_ctx->priv_user[0],
                         (char *) thd->security_ctx->host_or_ip);
 
+/* PSI begin */
+      thd->m_statement_psi= MYSQL_START_STATEMENT(& state,
+                                                  com_statement_info[command].m_key,
+                                                  thd->db, thd->db_length);
+      THD_STAGE_INFO(thd, stage_init);
+      MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, beginning_of_next_stmt, length);
+
       thd->set_query_and_id(beginning_of_next_stmt, length,
                             thd->charset(), next_query_id());
       /*
@@ -1447,17 +1480,18 @@ bool dispatch_command(enum enum_server_c
 
   log_slow_statement(thd);
 
-  thd_proc_info(thd, "cleaning up");
+  THD_STAGE_INFO(thd, stage_cleaning_up);
   thd->reset_query();
   thd->set_command(COM_SLEEP);
   dec_thread_running();
-  thd_proc_info(thd, 0);
   thd->packet.shrink(thd->variables.net_buffer_length);	// Reclaim some memory
   free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
 
-#if defined(ENABLED_PROFILING)
-  thd->profiling.finish_current_query();
-#endif
+  /* Performance Schema Interface instrumentation, end */
+  MYSQL_END_STATEMENT(thd->m_statement_psi, thd->stmt_da);
+  thd->m_statement_psi= NULL;
+
+  /* DTRACE instrumentation, end */
   if (MYSQL_QUERY_DONE_ENABLED() || MYSQL_COMMAND_DONE_ENABLED())
   {
     int res __attribute__((unused));
@@ -1468,6 +1502,12 @@ bool dispatch_command(enum enum_server_c
     }
     MYSQL_COMMAND_DONE(res);
   }
+
+  /* SHOW PROFILE instrumentation, end */
+#if defined(ENABLED_PROFILING)
+  thd->profiling.finish_current_query();
+#endif
+
   DBUG_RETURN(error);
 }
 
@@ -1497,9 +1537,9 @@ void log_slow_statement(THD *thd)
            (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
           opt_log_queries_not_using_indexes &&
            !(sql_command_flags[thd->lex->sql_command] & CF_STATUS_COMMAND))) &&
-        thd->examined_row_count >= thd->variables.min_examined_row_limit)
+        thd->get_examined_row_count() >= thd->variables.min_examined_row_limit)
     {
-      thd_proc_info(thd, "logging slow query");
+      THD_STAGE_INFO(thd, stage_logging_slow_query);
       thd->status_var.long_query_count++;
       slow_log_print(thd, thd->query(), thd->query_length(), 
                      end_utime_of_query);
@@ -1828,6 +1868,7 @@ mysql_execute_command(THD *thd)
   bool have_table_map_for_update= FALSE;
 #endif
   DBUG_ENTER("mysql_execute_command");
+
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   thd->work_part_info= 0;
 #endif
@@ -2962,7 +3003,7 @@ end_with_restore_list:
     if (add_item_to_list(thd, new Item_null()))
       goto error;
 
-    thd_proc_info(thd, "init");
+    THD_STAGE_INFO(thd, stage_init);
     if ((res= open_and_lock_tables(thd, all_tables, TRUE, 0)))
       break;
 
@@ -4362,7 +4403,7 @@ create_sp_error:
     my_ok(thd);
     break;
   }
-  thd_proc_info(thd, "query end");
+  THD_STAGE_INFO(thd, stage_query_end);
 
   /*
     Binlog-related cleanup:
@@ -4414,9 +4455,8 @@ finish:
 
   lex->unit.cleanup();
   /* Free tables */
-  thd_proc_info(thd, "closing tables");
+  THD_STAGE_INFO(thd, stage_closing_tables);
   close_thread_tables(thd);
-  thd_proc_info(thd, 0);
 
 #ifndef DBUG_OFF
   if (lex->sql_command != SQLCOM_SET_OPTION && ! thd->in_sub_stmt)
@@ -4456,7 +4496,6 @@ finish:
   DBUG_RETURN(res || thd->is_error());
 }
 
-
 static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
 {
   LEX	*lex= thd->lex;
@@ -4670,7 +4709,7 @@ check_access(THD *thd, ulong want_access
     dummy= 0;
   }
 
-  thd_proc_info(thd, "checking permissions");
+  THD_STAGE_INFO(thd, stage_checking_permissions);
   if ((!db || !db[0]) && !thd->db && !dont_check_global_grants)
   {
     DBUG_PRINT("error",("No database"));
@@ -5288,7 +5327,7 @@ void THD::reset_for_next_command()
   thd->stmt_da->reset_diagnostics_area();
   thd->warning_info->reset_for_next_command();
   thd->rand_used= 0;
-  thd->sent_row_count= thd->examined_row_count= 0;
+  thd->m_sent_row_count= thd->m_examined_row_count= 0;
   thd->thd_marker.emb_on_expr_nest= NULL;
 
   thd->reset_current_stmt_binlog_format_row();
@@ -5505,6 +5544,9 @@ void mysql_parse(THD *thd, char *rawbuf,
 
     if (!err)
     {
+      thd->m_statement_psi= MYSQL_REFINE_STATEMENT(thd->m_statement_psi,
+                                                   sql_statement_info[thd->lex->sql_command].m_key);
+
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
       if (mqh_used && thd->user_connect &&
 	  check_mqh(thd, lex->sql_command))
@@ -5553,17 +5595,27 @@ void mysql_parse(THD *thd, char *rawbuf,
     }
     else
     {
+      /* Instrument this broken statement as "statement/sql/error" */
+      thd->m_statement_psi= MYSQL_REFINE_STATEMENT(thd->m_statement_psi,
+                                                   sql_statement_info[SQLCOM_END].m_key);
+
       DBUG_ASSERT(thd->is_error());
       DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
 			 thd->is_fatal_error));
 
       query_cache_abort(&thd->query_cache_tls);
     }
-    thd_proc_info(thd, "freeing items");
+    THD_STAGE_INFO(thd, stage_freeing_items);
     thd->end_statement();
     thd->cleanup_after_query();
     DBUG_ASSERT(thd->change_list.is_empty());
   }
+  else
+  {
+    /* Only SELECT are cached in the query cache. */
+    thd->m_statement_psi= MYSQL_REFINE_STATEMENT(thd->m_statement_psi,
+                                                 sql_statement_info[SQLCOM_SELECT].m_key);
+  }
 
   DBUG_VOID_RETURN;
 }

=== modified file 'sql/sql_partition_admin.cc'
--- a/sql/sql_partition_admin.cc	2010-12-03 10:05:56 +0000
+++ b/sql/sql_partition_admin.cc	2011-02-15 17:14:15 +0000
@@ -532,7 +532,7 @@ bool Sql_cmd_alter_table_exchange_partit
   if (check_exchange_partition(swap_table, part_table))
     DBUG_RETURN(TRUE);
 
-  thd_proc_info(thd, "verifying table");
+  THD_STAGE_INFO(thd, stage_verifying_table);
 
   /* Will append the partition name later in part_info->get_part_elem() */
   part_file_name_len= build_table_filename(part_file_name,

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2010-12-29 00:38:59 +0000
+++ b/sql/sql_prepare.cc	2011-02-15 17:14:15 +0000
@@ -2962,6 +2962,7 @@ Execute_sql_statement(LEX_STRING sql_tex
 bool
 Execute_sql_statement::execute_server_code(THD *thd)
 {
+  PSI_statement_locker *parent_locker;
   bool error;
 
   if (alloc_query(thd, m_sql_text.str, m_sql_text.length))
@@ -2981,7 +2982,10 @@ Execute_sql_statement::execute_server_co
 
   thd->lex->set_trg_event_type_for_tables();
 
-  error= mysql_execute_command(thd);
+  parent_locker= thd->m_statement_psi;
+  thd->m_statement_psi= NULL;
+  error= mysql_execute_command(thd) ;
+  thd->m_statement_psi= parent_locker;
 
   /* report error issued during command execution */
   if (error == 0 && thd->spcont == NULL)
@@ -3757,13 +3761,17 @@ bool Prepared_statement::execute(String 
     if (query_cache_send_result_to_client(thd, thd->query(),
                                           thd->query_length()) <= 0)
     {
+      PSI_statement_locker *parent_locker;
       MYSQL_QUERY_EXEC_START(thd->query(),
                              thd->thread_id,
                              (char *) (thd->db ? thd->db : ""),
                              &thd->security_ctx->priv_user[0],
                              (char *) thd->security_ctx->host_or_ip,
                              1);
+      parent_locker= thd->m_statement_psi;
+      thd->m_statement_psi= NULL;
       error= mysql_execute_command(thd);
+      thd->m_statement_psi= parent_locker;
       MYSQL_QUERY_EXEC_DONE(error);
     }
   }

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-02-10 09:30:20 +0000
+++ b/sql/sql_select.cc	2011-02-15 17:14:15 +0000
@@ -1758,7 +1758,7 @@ JOIN::optimize()
   optimized= 1;
   DEBUG_SYNC(thd, "before_join_optimize");
 
-  thd_proc_info(thd, "optimizing");
+  THD_STAGE_INFO(thd, stage_optimizing);
 
   /* dump_TABLE_LIST_graph(select_lex, select_lex->leaf_tables); */
   if (flatten_subqueries())
@@ -1952,7 +1952,7 @@ JOIN::optimize()
   sort_by_table= get_sort_by_table(order, group_list, select_lex->leaf_tables);
 
   /* Calculate how to do the join */
-  thd_proc_info(thd, "statistics");
+  THD_STAGE_INFO(thd, stage_statistics);
   if (make_join_statistics(this, select_lex->leaf_tables, conds, &keyuse) ||
       thd->is_fatal_error)
   {
@@ -1974,7 +1974,7 @@ JOIN::optimize()
     select_distinct= select_distinct && (const_tables != tables);
   }
 
-  thd_proc_info(thd, "preparing");
+  THD_STAGE_INFO(thd, stage_preparing);
   if (result->initialize_tables(this))
   {
     DBUG_PRINT("error",("Error: initialize_tables() failed"));
@@ -2503,7 +2503,7 @@ JOIN::optimize()
   if (need_tmp)
   {
     DBUG_PRINT("info",("Creating tmp table"));
-    thd_proc_info(thd, "Creating tmp table");
+    THD_STAGE_INFO(thd, stage_creating_tmp_table);
 
     init_items_ref_array();
 
@@ -2548,7 +2548,7 @@ JOIN::optimize()
     if (group_list && simple_group)
     {
       DBUG_PRINT("info",("Sorting for group"));
-      thd_proc_info(thd, "Sorting for group");
+      THD_STAGE_INFO(thd, stage_sorting_for_group);
       if (create_sort_index(thd, this, group_list,
 			    HA_POS_ERROR, HA_POS_ERROR, FALSE) ||
 	  alloc_group_fields(this, group_list) ||
@@ -2572,7 +2572,7 @@ JOIN::optimize()
       if (!group_list && ! exec_tmp_table1->distinct && order && simple_order)
       {
         DBUG_PRINT("info",("Sorting for order"));
-        thd_proc_info(thd, "Sorting for order");
+        THD_STAGE_INFO(thd, stage_sorting_for_order);
         if (create_sort_index(thd, this, order,
                               HA_POS_ERROR, HA_POS_ERROR, TRUE))
         {
@@ -2754,7 +2754,7 @@ JOIN::exec()
 
   const bool has_group_by= this->group;
 
-  thd_proc_info(thd, "executing");
+  THD_STAGE_INFO(thd, stage_executing);
   error= 0;
   if (procedure)
   {
@@ -2762,7 +2762,8 @@ JOIN::exec()
     if (procedure->change_columns(procedure_fields_list) ||
 	result->prepare(procedure_fields_list, unit))
     {
-      thd->limit_found_rows= thd->examined_row_count= 0;
+      thd->set_examined_row_count(0);
+      thd->limit_found_rows= 0;
       DBUG_VOID_RETURN;
     }
     columns_list= &procedure_fields_list;
@@ -2803,7 +2804,7 @@ JOIN::exec()
 	{
 	  error= (int) result->send_eof();
 	  send_records= ((select_options & OPTION_FOUND_ROWS) ? 1 :
-                         thd->sent_row_count);
+                         thd->get_sent_row_count());
 	}
       }
       else
@@ -2814,7 +2815,7 @@ JOIN::exec()
     }
     /* Single select (without union) always returns 0 or 1 row */
     thd->limit_found_rows= send_records;
-    thd->examined_row_count= 0;
+    thd->set_examined_row_count(0);
     DBUG_VOID_RETURN;
   }
   /*
@@ -2901,7 +2902,7 @@ JOIN::exec()
     curr_tmp_table= exec_tmp_table1;
 
     /* Copy data to the temporary table */
-    thd_proc_info(thd, "Copying to tmp table");
+    THD_STAGE_INFO(thd, stage_copying_to_tmp_table);
     DBUG_PRINT("info", ("%s", thd->proc_info));
     /*
       If there is no sorting or grouping, one may turn off
@@ -3044,7 +3045,7 @@ JOIN::exec()
 	  DBUG_VOID_RETURN;
 	}
 	DBUG_PRINT("info",("Sorting for index"));
-	thd_proc_info(thd, "Creating sort index");
+	THD_STAGE_INFO(thd, stage_creating_sort_index);
 	if (create_sort_index(thd, curr_join, curr_join->group_list,
 			      HA_POS_ERROR, HA_POS_ERROR, FALSE) ||
 	    make_group_fields(this, curr_join))
@@ -3053,8 +3054,8 @@ JOIN::exec()
 	}
         sortorder= curr_join->sortorder;
       }
-      
-      thd_proc_info(thd, "Copying to group table");
+
+      THD_STAGE_INFO(thd, stage_copying_to_group_table);
       DBUG_PRINT("info", ("%s", thd->proc_info));
       tmp_error= -1;
       if (curr_join != this)
@@ -3118,7 +3119,7 @@ JOIN::exec()
     curr_join->join_free();			/* Free quick selects */
     if (curr_join->select_distinct && ! curr_join->group_list)
     {
-      thd_proc_info(thd, "Removing duplicates");
+      THD_STAGE_INFO(thd, stage_removing_duplicates);
       if (curr_join->tmp_having)
 	curr_join->tmp_having->update_used_tables();
       if (remove_duplicates(curr_join, curr_tmp_table,
@@ -3189,7 +3190,7 @@ JOIN::exec()
   if (curr_join->group_list || curr_join->order)
   {
     DBUG_PRINT("info",("Sorting for send_result_set_metadata"));
-    thd_proc_info(thd, "Sorting result");
+    THD_STAGE_INFO(thd, stage_sorting_result);
     /* If we have already done the group, add HAVING to sorted table */
     if (curr_join->tmp_having && ! curr_join->group_list && 
 	! curr_join->sort_and_group)
@@ -3353,7 +3354,7 @@ JOIN::exec()
   curr_join->fields= curr_fields_list;
   curr_join->procedure= procedure;
 
-  thd_proc_info(thd, "Sending data");
+  THD_STAGE_INFO(thd, stage_sending_data);
   DBUG_PRINT("info", ("%s", thd->proc_info));
   result->send_result_set_metadata((procedure ? curr_join->procedure_fields_list :
                                     *curr_fields_list),
@@ -3370,9 +3371,9 @@ JOIN::exec()
   }
 
   /* Accumulate the counts from all join iterations of all join parts. */
-  thd->examined_row_count+= curr_join->examined_rows;
+  thd->inc_examined_row_count(curr_join->examined_rows);
   DBUG_PRINT("counts", ("thd->examined_row_count: %lu",
-                        (ulong) thd->examined_row_count));
+                        (ulong) thd->get_examined_row_count()));
 
   /* 
     With EXPLAIN EXTENDED we have to restore original ref_array
@@ -3556,7 +3557,7 @@ mysql_select(THD *thd, Item ***rref_poin
   {
     if (!(join= new JOIN(thd, fields, select_options, result)))
 	DBUG_RETURN(TRUE); /* purecov: inspected */
-    thd_proc_info(thd, "init");
+    THD_STAGE_INFO(thd, stage_init);
     thd->used_tables=0;                         // Updated by setup_fields
     err= join->prepare(rref_pointer_array, tables, wild_num,
                        conds, og_num, order, group, having, proc_param,
@@ -3592,7 +3593,7 @@ mysql_select(THD *thd, Item ***rref_poin
 err:
   if (free_join)
   {
-    thd_proc_info(thd, "end");
+    THD_STAGE_INFO(thd, stage_end);
     err|= select_lex->cleanup();
     DBUG_RETURN(err || thd->is_error());
   }
@@ -11208,10 +11209,10 @@ make_join_readinfo(JOIN *join, ulonglong
       /* These init changes read_record */
       if (tab->use_quick == QS_DYNAMIC_RANGE)
       {
-	join->thd->server_status|=SERVER_QUERY_NO_GOOD_INDEX_USED;
+	join->thd->set_status_no_good_index_used();
 	tab->read_first_record= join_init_quick_read_record;
 	if (statistics)
-	  status_var_increment(join->thd->status_var.select_range_check_count);
+	  join->thd->inc_status_select_range_check();
       }
       else
       {
@@ -11221,13 +11222,13 @@ make_join_readinfo(JOIN *join, ulonglong
 	  if (tab->select && tab->select->quick)
 	  {
 	    if (statistics)
-	      status_var_increment(join->thd->status_var.select_range_count);
+	      join->thd->inc_status_select_range();
 	  }
 	  else
 	  {
-	    join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
+	    join->thd->set_status_no_index_used();
 	    if (statistics)
-	      status_var_increment(join->thd->status_var.select_scan_count);
+	      join->thd->inc_status_select_scan();
 	  }
 	}
 	else
@@ -11235,13 +11236,13 @@ make_join_readinfo(JOIN *join, ulonglong
 	  if (tab->select && tab->select->quick)
 	  {
 	    if (statistics)
-	      status_var_increment(join->thd->status_var.select_full_range_join_count);
+	      join->thd->inc_status_select_full_range_join();
 	  }
 	  else
 	  {
-	    join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
+	    join->thd->set_status_no_index_used();
 	    if (statistics)
-	      status_var_increment(join->thd->status_var.select_full_join_count);
+	      join->thd->inc_status_select_full_join();
 	  }
 	}
 	if (!table->no_keyread)
@@ -11891,7 +11892,8 @@ return_zero_rows(JOIN *join, select_resu
       result->send_eof();				// Should be safe
   }
   /* Update results for FOUND_ROWS */
-  join->thd->limit_found_rows= join->thd->examined_row_count= 0;
+  join->thd->set_examined_row_count(0);
+  join->thd->limit_found_rows= 0;
   DBUG_RETURN(0);
 }
 
@@ -15338,7 +15340,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARA
               (int) distinct, (int) save_sum_fields,
               (ulong) rows_limit,test(group)));
 
-  status_var_increment(thd->status_var.created_tmp_tables);
+  thd->inc_status_created_tmp_tables();
 
   if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
     temp_pool_slot = bitmap_lock_set_next(&temp_pool);
@@ -16078,7 +16080,7 @@ TABLE *create_duplicate_weedout_tmp_tabl
   /*
     STEP 1: Get temporary table name
   */
-  statistic_increment(thd->status_var.created_tmp_tables, &LOCK_status);
+  thd->inc_status_created_tmp_tables();
   if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
     temp_pool_slot = bitmap_lock_set_next(&temp_pool);
 
@@ -16625,7 +16627,7 @@ static bool create_myisam_tmp_table(TABL
     table->db_stat=0;
     goto err;
   }
-  status_var_increment(table->in_use->status_var.created_tmp_disk_tables);
+  table->in_use->inc_status_created_tmp_disk_tables();
   share->db_record_offset= 1;
   DBUG_RETURN(0);
  err:
@@ -16642,7 +16644,7 @@ free_tmp_table(THD *thd, TABLE *entry)
   DBUG_PRINT("enter",("table: %s",entry->alias));
 
   save_proc_info=thd->proc_info;
-  thd_proc_info(thd, "removing tmp table");
+  THD_STAGE_INFO(thd, stage_removing_tmp_table);
 
   // Release latches since this can take a long time
   ha_release_temporary_latches(thd);
@@ -16739,7 +16741,7 @@ bool create_myisam_from_heap(THD *thd, T
     DBUG_RETURN(1);				// End of memory
 
   save_proc_info=thd->proc_info;
-  thd_proc_info(thd, "converting HEAP to MyISAM");
+  THD_STAGE_INFO(thd, stage_converting_heap_to_myisam);
 
   if (create_myisam_tmp_table(&new_table, table->key_info, start_recinfo,
                               recinfo,

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2011-01-30 16:55:22 +0000
+++ b/sql/sql_table.cc	2011-02-15 17:14:15 +0000
@@ -4391,7 +4391,7 @@ bool mysql_create_table_no_lock(THD *thd
     }
   }
 
-  thd_proc_info(thd, "creating table");
+  THD_STAGE_INFO(thd, stage_creating_table);
 
 #ifdef HAVE_READLINK
   {
@@ -4507,7 +4507,7 @@ bool mysql_create_table_no_lock(THD *thd
 
   error= FALSE;
 err:
-  thd_proc_info(thd, "After create");
+  THD_STAGE_INFO(thd, stage_after_create);
   delete file;
   DBUG_RETURN(error);
 
@@ -4878,7 +4878,7 @@ mysql_discard_or_import_tablespace(THD *
     ALTER TABLE
   */
 
-  thd_proc_info(thd, "discard_or_import_tablespace");
+  THD_STAGE_INFO(thd, stage_discard_or_import_tablespace);
 
   discard= test(tablespace_op == DISCARD_TABLESPACE);
 
@@ -4896,7 +4896,7 @@ mysql_discard_or_import_tablespace(THD *
 
   error= table->file->ha_discard_or_import_tablespace(discard);
 
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
 
   if (error)
     goto err;
@@ -5938,7 +5938,7 @@ bool mysql_alter_table(THD *thd,char *ne
     to simplify further comparisions: we want to see if it's a RENAME
     later just by comparing the pointers, avoiding the need for strcmp.
   */
-  thd_proc_info(thd, "init");
+  THD_STAGE_INFO(thd, stage_init);
   table_name=table_list->table_name;
   alias= (lower_case_table_names == 2) ? table_list->alias : table_name;
   db=table_list->db;
@@ -6129,8 +6129,8 @@ bool mysql_alter_table(THD *thd,char *ne
     my_error(ER_ILLEGAL_HA, MYF(0), table_name);
     goto err;
   }
-  
-  thd_proc_info(thd, "setup");
+
+  THD_STAGE_INFO(thd, stage_setup);
   if (!(alter_info->flags & ~(ALTER_RENAME | ALTER_KEYS_ONOFF)) &&
       !table->s->tmp_table) // no need to touch frm
   {
@@ -6163,7 +6163,7 @@ bool mysql_alter_table(THD *thd,char *ne
 
     if (!error && (new_name != table_name || new_db != db))
     {
-      thd_proc_info(thd, "rename");
+      THD_STAGE_INFO(thd, stage_rename);
       /*
         Then do a 'simple' rename of the table. First we need to close all
         instances of 'source' table.
@@ -6609,7 +6609,7 @@ bool mysql_alter_table(THD *thd,char *ne
     /* We don't want update TIMESTAMP fields during ALTER TABLE. */
     new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
     new_table->next_number_field=new_table->found_next_number_field;
-    thd_proc_info(thd, "copy to tmp table");
+    THD_STAGE_INFO(thd, stage_copy_to_tmp_table);
     DBUG_EXECUTE_IF("abort_copy_table", {
         my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0));
         goto err_new_table_cleanup;
@@ -6632,7 +6632,7 @@ bool mysql_alter_table(THD *thd,char *ne
     if (!table->s->tmp_table && need_lock_for_indexes &&
         wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
       goto err_new_table_cleanup;
-    thd_proc_info(thd, "manage keys");
+    THD_STAGE_INFO(thd, stage_manage_keys);
     DEBUG_SYNC(thd, "alter_table_manage_keys");
     alter_table_manage_keys(table, table->file->indexes_are_disabled(),
                             alter_info->keys_onoff);
@@ -6794,7 +6794,7 @@ bool mysql_alter_table(THD *thd,char *ne
       (mysql_execute_command()) to release metadata locks.
   */
 
-  thd_proc_info(thd, "rename result table");
+  THD_STAGE_INFO(thd, stage_rename_result_table);
   my_snprintf(old_name, sizeof(old_name), "%s2-%lx-%lx", tmp_file_prefix,
 	      current_pid, thd->thread_id);
   if (lower_case_table_names)
@@ -6909,7 +6909,7 @@ bool mysql_alter_table(THD *thd,char *ne
   if (thd->locked_tables_list.reopen_tables(thd))
     goto err_with_mdl;
 
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
 
   DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000););
   DEBUG_SYNC(thd, "alter_table_before_main_binlog");

=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc	2010-11-11 09:40:06 +0000
+++ b/sql/sql_union.cc	2011-02-15 17:14:15 +0000
@@ -538,7 +538,7 @@ bool st_select_lex_unit::exec()
                                     0);
 	if (!saved_error)
 	{
-	  examined_rows+= thd->examined_row_count;
+	  examined_rows+= thd->get_examined_row_count();
 	  if (union_result->flush())
 	  {
 	    thd->lex->current_select= lex_select_save;
@@ -652,7 +652,7 @@ bool st_select_lex_unit::exec()
       if (!saved_error)
       {
 	thd->limit_found_rows = (ulonglong)table->file->stats.records + add_rows;
-        thd->examined_row_count+= examined_rows;
+        thd->inc_examined_row_count(examined_rows);
       }
       /*
 	Mark for slow query log if any of the union parts didn't use

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2010-12-29 00:38:59 +0000
+++ b/sql/sql_update.cc	2011-02-15 17:14:15 +0000
@@ -307,7 +307,7 @@ int mysql_update(THD *thd,
   }
   mysql_handle_derived(thd->lex, &mysql_derived_cleanup);
 
-  thd_proc_info(thd, "init");
+  THD_STAGE_INFO(thd, stage_init);
   table= table_list->table;
 
   /* Calculate "table->covering_keys" based on the WHERE */
@@ -492,7 +492,7 @@ int mysql_update(THD *thd,
       {
 	goto err;
       }
-      thd->examined_row_count+= examined_rows;
+      thd->inc_examined_row_count(examined_rows);
       /*
 	Filesort has already found and selected the rows we want to update,
 	so we don't need the where clause
@@ -534,12 +534,12 @@ int mysql_update(THD *thd,
       else
         init_read_record_idx(&info, thd, table, 1, used_index, reverse);
 
-      thd_proc_info(thd, "Searching rows for update");
+      THD_STAGE_INFO(thd, stage_searching_rows_for_update);
       ha_rows tmp_limit= limit;
 
       while (!(error=info.read_record(&info)) && !thd->killed)
       {
-        thd->examined_row_count++;
+        thd->inc_examined_row_count(1);
         bool skip_record= FALSE;
         if (select && select->skip_record(thd, &skip_record))
         {
@@ -613,7 +613,7 @@ int mysql_update(THD *thd,
   */
   thd->count_cuted_fields= CHECK_FIELD_WARN;
   thd->cuted_fields=0L;
-  thd_proc_info(thd, "Updating");
+  THD_STAGE_INFO(thd, stage_updating);
 
   transactional_table= table->file->has_transactions();
   thd->abort_on_warning= test(!ignore &&
@@ -644,7 +644,7 @@ int mysql_update(THD *thd,
 
   while (!(error=info.read_record(&info)) && !thd->killed)
   {
-    thd->examined_row_count++;
+    thd->inc_examined_row_count(1);
     bool skip_record;
     if (!select || (!select->skip_record(thd, &skip_record) && !skip_record))
     {
@@ -846,7 +846,7 @@ int mysql_update(THD *thd,
 
   end_read_record(&info);
   delete select;
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
   (void) table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
 
   /*
@@ -1298,7 +1298,7 @@ int multi_update::prepare(List<Item> &no
 
   thd->count_cuted_fields= CHECK_FIELD_WARN;
   thd->cuted_fields=0L;
-  thd_proc_info(thd, "updating main table");
+  THD_STAGE_INFO(thd, stage_updating_main_table);
 
   tables_to_update= get_table_map(fields);
 
@@ -2079,7 +2079,7 @@ bool multi_update::send_eof()
   ulonglong id;
   THD::killed_state killed_status= THD::NOT_KILLED;
   DBUG_ENTER("multi_update::send_eof");
-  thd_proc_info(thd, "updating reference tables");
+  THD_STAGE_INFO(thd, stage_updating_reference_tables);
 
   /* 
      Does updates for the last n - 1 tables, returns 0 if ok;
@@ -2093,7 +2093,7 @@ bool multi_update::send_eof()
     later carried out killing should not affect binlogging.
   */
   killed_status= (local_error == 0)? THD::NOT_KILLED : thd->killed;
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
 
   /* We must invalidate the query cache before binlog writing and
   ha_autocommit_... */

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2011-02-08 15:54:12 +0000
+++ b/sql/sql_view.cc	2011-02-15 17:14:15 +0000
@@ -704,7 +704,7 @@ bool mysql_create_view(THD *thd, TABLE_L
   DBUG_RETURN(0);
 
 err:
-  thd_proc_info(thd, "end");
+  THD_STAGE_INFO(thd, stage_end);
   lex->link_first_table_back(view, link_to_local);
   unit->cleanup();
   DBUG_RETURN(res || thd->is_error());

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (marc.alff:3208 to 3209) WL#2515 WL#4813Marc Alff15 Feb