# Tests for PERFORMANCE_SCHEMA

--source include/not_embedded.inc
--source include/have_perfschema.inc

# Set to a known state
update performance_schema.setup_timers
  set timer_name='CYCLE' where name="wait";
update performance_schema.setup_timers
  set timer_name='NANOSECOND' where name="stage";
update performance_schema.setup_timers
  set timer_name='NANOSECOND' where name="statement";
update performance_schema.setup_timers
  set timer_name='MICROSECOND' where name="idle";

select * from performance_schema.setup_timers;

select * from performance_schema.setup_timers
  where name='Wait';

select * from performance_schema.setup_timers
  where timer_name='CYCLE';

--error ER_TABLEACCESS_DENIED_ERROR
insert into performance_schema.setup_timers
  set name='FOO', timer_name='CYCLE';

--error ER_WRONG_PERFSCHEMA_USAGE
update performance_schema.setup_timers
  set name='FOO';

update performance_schema.setup_timers
  set timer_name='MILLISECOND';

select * from performance_schema.setup_timers;

update performance_schema.setup_timers
  set timer_name='CYCLE';

--error ER_TABLEACCESS_DENIED_ERROR
delete from performance_schema.setup_timers;

--error ER_TABLEACCESS_DENIED_ERROR
delete from performance_schema.setup_timers
  where name='Wait';

LOCK TABLES performance_schema.setup_timers READ;
UNLOCK TABLES;

LOCK TABLES performance_schema.setup_timers WRITE;
UNLOCK TABLES;

# Cleanup, restore the default values

update performance_schema.setup_timers
 set timer_name='CYCLE' where name="wait";
update performance_schema.setup_timers
 set timer_name='NANOSECOND' where name="stage";
update performance_schema.setup_timers
 set timer_name='NANOSECOND' where name="statement";
update performance_schema.setup_timers
  set timer_name='MICROSECOND' where name="idle";

select * from performance_schema.setup_timers;

