# Tests for PERFORMANCE_SCHEMA

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

--disable_warnings
drop table if exists test.setup_objects;
--enable_warnings

# Save the setup
create table test.setup_objects as
  select * from performance_schema.setup_objects;
truncate table performance_schema.setup_objects;

# Test

select * from performance_schema.setup_objects;

select * from performance_schema.setup_objects
  order by object_type, object_schema, object_name;

select * from performance_schema.setup_objects
  where object_type = 'TABLE'
  order by object_type, object_schema, object_name;

select * from performance_schema.setup_objects
  order by object_type, object_schema, object_name;

--error ER_NO_REFERENCED_ROW_2
insert into performance_schema.setup_objects
  set object_type='ILLEGAL', object_schema='FOO', object_name='BAR',
  enabled='YES', timed='YES';

insert into performance_schema.setup_objects
  set object_type='TABLE', object_schema='FOO', object_name='BAR',
  enabled='YES', timed='YES';

--error ER_DUP_KEY
insert into performance_schema.setup_objects
  set object_type='TABLE', object_schema='FOO', object_name='BAR',
  enabled='YES', timed='NO';

delete from performance_schema.setup_objects
  where object_type='TABLE' and object_schema='FOO';

select * from performance_schema.setup_objects
  order by object_type, object_schema, object_name;

insert into performance_schema.setup_objects
  set object_type='TABLE', object_schema='FOO', object_name='BAR',
  enabled='NO', timed='YES';

select * from performance_schema.setup_objects
  order by object_type, object_schema, object_name;

--error ER_WRONG_PERFSCHEMA_USAGE
update performance_schema.setup_objects
  set object_type='ILLEGAL';

--error ER_WRONG_PERFSCHEMA_USAGE
update performance_schema.setup_objects
  set object_schema='ILLEGAL';

--error ER_WRONG_PERFSCHEMA_USAGE
update performance_schema.setup_objects
  set object_name='ILLEGAL';

update performance_schema.setup_objects
  set enabled='NO', timed='NO';

select * from performance_schema.setup_objects
  order by object_type, object_schema, object_name;

update performance_schema.setup_objects
  set enabled='YES', timed='YES';

delete from performance_schema.setup_objects
  where object_type = 'TABLE';

delete from performance_schema.setup_objects;

LOCK TABLES performance_schema.setup_objects READ;
UNLOCK TABLES;

LOCK TABLES performance_schema.setup_objects WRITE;
UNLOCK TABLES;

# Restore the setup
truncate table performance_schema.setup_objects;
insert into performance_schema.setup_objects
  select * from test.setup_objects;
drop table test.setup_objects;

