mariadb/mysql-test/t/log_tables.test
unknown 79b03c66bf Merge pchardin@bk-internal.mysql.com:/home/bk/mysql-5.1-runtime
into  mysql.com:/home/cps/mysql/devel/5.1-curs-bug


sql/ha_myisam.cc:
  Auto merged
sql/handler.h:
  Auto merged
sql/sql_table.cc:
  Auto merged
mysql-test/r/log_tables.result:
  SCCS merged
mysql-test/t/log_tables.test:
  SCCS merged
2006-08-04 14:48:51 +04:00

321 lines
7.9 KiB
Text

# this test needs multithreaded mysqltest
-- source include/not_embedded.inc
#
# Basic log tables test
#
# check that CSV engine was compiled in
--source include/have_csv.inc
--disable_ps_protocol
use mysql;
#
# Check that log tables work and we can do basic selects. This also
# tests truncate, which works in a special mode with the log tables
#
truncate table general_log;
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
select * from general_log;
truncate table slow_log;
--replace_column 1 TIMESTAMP 2 USER_HOST
select * from slow_log;
#
# We want to check that a record newly written to a log table shows up for
# the query: since log tables use concurrent insert machinery and log tables
# are always locked by artificial THD, this feature requires additional
# check in ha_tina::write_row. This simple test should prove that the
# log table flag in the table handler is triggered and working.
#
truncate table general_log;
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
select * from general_log where argument like '%general_log%';
#
# Check some basic queries interfering with the log tables.
# In our test we'll use a tbale with verbose comments to the short
# command type names, used in the tables
#
create table join_test (verbose_comment varchar (80), command_type varchar(64));
insert into join_test values ("User performed a usual SQL query", "Query");
insert into join_test values ("New DB connection was registered", "Connect");
insert into join_test values ("Get the table info", "Field List");
--replace_column 2 USER_HOST
select verbose_comment, user_host, argument
from mysql.general_log join join_test
on (mysql.general_log.command_type = join_test.command_type);
drop table join_test;
#
# check that flush of the log table work fine
#
flush logs;
#
# check locking of the log tables
#
--error ER_CANT_WRITE_LOCK_LOG_TABLE
lock tables mysql.general_log WRITE;
--error ER_CANT_WRITE_LOCK_LOG_TABLE
lock tables mysql.slow_log WRITE;
#
# This attemts to get TL_READ_NO_INSERT lock, which is incompatible with
# TL_WRITE_CONCURRENT_INSERT. This should fail. We issue this error as log
# tables are always opened and locked by the logger.
#
--error ER_CANT_READ_LOCK_LOG_TABLE
lock tables mysql.general_log READ;
--error ER_CANT_READ_LOCK_LOG_TABLE
lock tables mysql.slow_log READ;
#
# This call should result in TL_READ lock on the log table. This is ok and
# should pass.
#
lock tables mysql.slow_log READ LOCAL, mysql.general_log READ LOCAL;
unlock tables;
#
# check that FLUSH LOGS waits for all readers of the log table to vanish
#
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con1;
lock tables mysql.general_log READ LOCAL;
connection con2;
# this should wait for log tables to unlock
send flush logs;
connection con1;
unlock tables;
# this connection should be alive by the time
connection con2;
reap;
select "Mark that we woke up from flush logs in the test"
as "test passed";
#
# perform the same check for TRUNCATE: it should also wait for readers
# to disappear
#
connection con1;
lock tables mysql.general_log READ LOCAL;
connection con2;
# this should wait for log tables to unlock
send truncate mysql.general_log;
connection con1;
unlock tables;
# this connection should be alive by the time
connection con2;
reap;
select "Mark that we woke up from TRUNCATE in the test"
as "test passed";
connection con1;
use test;
#
# Bug #16905 Log tables: unicode statements are logged incorrectly
#
truncate table mysql.general_log;
set names utf8;
create table bug16905 (s char(15) character set utf8 default 'пусто');
insert into bug16905 values ('новое');
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
select * from mysql.general_log;
drop table bug16905;
#
# Bug #17600: Invalid data logged into mysql.slow_log
#
truncate table mysql.slow_log;
set session long_query_time=1;
select sleep(2);
--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME
select * from mysql.slow_log;
#
# Bug #18559 log tables cannot change engine, and gets deadlocked when
# dropping w/ log on
#
# check that appropriate error messages are given when one attempts to alter
# or drop a log tables, while corresponding logs are enabled
--error ER_CANT_ALTER_LOG_TABLE
alter table mysql.general_log engine=myisam;
--error ER_CANT_ALTER_LOG_TABLE
alter table mysql.slow_log engine=myisam;
--error ER_CANT_DROP_LOG_TABLE
drop table mysql.general_log;
--error ER_CANT_DROP_LOG_TABLE
drop table mysql.slow_log;
# check that one can alter log tables to MyISAM
set global general_log='OFF';
# cannot convert another log table
--error ER_CANT_ALTER_LOG_TABLE
alter table mysql.slow_log engine=myisam;
# alter both tables
set global slow_query_log='OFF';
# check that both tables use CSV engine
show create table mysql.general_log;
show create table mysql.slow_log;
alter table mysql.general_log engine=myisam;
alter table mysql.slow_log engine=myisam;
# check that the tables were converted
show create table mysql.general_log;
show create table mysql.slow_log;
# enable log tables and chek that new tables indeed work
set global general_log='ON';
set global slow_query_log='ON';
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
select * from mysql.general_log;
# check that flush of myisam-based log tables work fine
flush logs;
# check locking of myisam-based log tables
--error ER_CANT_WRITE_LOCK_LOG_TABLE
lock tables mysql.general_log WRITE;
--error ER_CANT_WRITE_LOCK_LOG_TABLE
lock tables mysql.slow_log WRITE;
#
# This attemts to get TL_READ_NO_INSERT lock, which is incompatible with
# TL_WRITE_CONCURRENT_INSERT. This should fail. We issue this error as log
# tables are always opened and locked by the logger.
#
--error ER_CANT_READ_LOCK_LOG_TABLE
lock tables mysql.general_log READ;
--error ER_CANT_READ_LOCK_LOG_TABLE
lock tables mysql.slow_log READ;
#
# This call should result in TL_READ lock on the log table. This is ok and
# should pass.
#
lock tables mysql.slow_log READ LOCAL, mysql.general_log READ LOCAL;
unlock tables;
# check that we can drop them
set global general_log='OFF';
set global slow_query_log='OFF';
# check that alter table doesn't work for other engines
--error ER_BAD_LOG_ENGINE
alter table mysql.slow_log engine=ndb;
--error ER_BAD_LOG_ENGINE
alter table mysql.slow_log engine=innodb;
--error ER_BAD_LOG_ENGINE
alter table mysql.slow_log engine=archive;
--error ER_BAD_LOG_ENGINE
alter table mysql.slow_log engine=blackhole;
drop table mysql.slow_log;
drop table mysql.general_log;
# check that table share cleanup is performed correctly (double drop)
--error ER_BAD_TABLE_ERROR
drop table mysql.general_log;
--error ER_BAD_TABLE_ERROR
drop table mysql.slow_log;
# recreate tables and enable logs
use mysql;
CREATE TABLE `general_log` (
`event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext,
`thread_id` int(11) DEFAULT NULL,
`server_id` int(11) DEFAULT NULL,
`command_type` varchar(64) DEFAULT NULL,
`argument` mediumtext
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log';
CREATE TABLE `slow_log` (
`start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext NOT NULL,
`query_time` time NOT NULL,
`lock_time` time NOT NULL,
`rows_sent` int(11) NOT NULL,
`rows_examined` int(11) NOT NULL,
`db` varchar(512) DEFAULT NULL,
`last_insert_id` int(11) DEFAULT NULL,
`insert_id` int(11) DEFAULT NULL,
`server_id` int(11) DEFAULT NULL,
`sql_text` mediumtext NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log';
set global general_log='ON';
set global slow_query_log='ON';
use test;
#
# Bug #20139 Infinite loop after "FLUSH" and "LOCK tabX, general_log"
#
flush tables with read lock;
unlock tables;
use mysql;
lock tables general_log read local, help_category read local;
unlock tables;
# kill all connections
disconnect con1;
disconnect con2;
--enable_ps_protocol