summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Crews <patrick.crews@sun.com>2009-05-21 16:03:53 -0400
committerPatrick Crews <patrick.crews@sun.com>2009-05-21 16:03:53 -0400
commit2a47699cad56952ff5d22e18b080a2aacf4c91b4 (patch)
treec94e5d77c9864f220e7268ed7d5b53e273c93e38
parent336028da76376f29e106cdce9807ad93d67aa722 (diff)
downloadmariadb-git-2a47699cad56952ff5d22e18b080a2aacf4c91b4.tar.gz
Bug#40465: mysqldump.test does no checking of dump or restore.
Created new .test file - mysqldump_restore that does this for a limited number of basic cases. Created new .inc file - mysqldump.inc - renames original table and uses mysqldump output to recreate the table, then uses diff_tables.inc to compare the two tables. Backported include/diff_tables.inc to facilitate this testing.
-rw-r--r--mysql-test/include/diff_tables.inc122
-rw-r--r--mysql-test/include/mysqldump.inc41
-rw-r--r--mysql-test/r/mysqldump_restore.result110
-rw-r--r--mysql-test/t/mysqldump_restore.test120
4 files changed, 393 insertions, 0 deletions
diff --git a/mysql-test/include/diff_tables.inc b/mysql-test/include/diff_tables.inc
new file mode 100644
index 00000000000..d15dd56b35d
--- /dev/null
+++ b/mysql-test/include/diff_tables.inc
@@ -0,0 +1,122 @@
+# ==== Purpose ====
+#
+# Check if the two given tables (possibly residing on different
+# master/slave servers) are equal.
+#
+# ==== Usage ====
+#
+# The tables to check are given by the test language variables
+# $diff_table_1 and $diff_table_2. They must be of the
+# following form:
+#
+# [master:|slave:]database.table
+#
+# I.e., both database and table must be speicified. Optionally, you
+# can prefix the name with 'master:' (to read the table on master) or
+# with 'slave:' (to read the table on slave). If no prefix is given,
+# reads the table from the current connection. If one of these
+# variables has a prefix, both should have a prefix.
+#
+# ==== Side effects ====
+#
+# - Prints "Comparing tables $diff_table_1 and $diff_tables_2".
+#
+# - If the tables are different, prints the difference in a
+# system-specific format (unified diff if supported) and generates
+# an error.
+#
+# - If $diff_table_1 or $diff_table_2 begins with 'master:' or
+# 'slave:', it will stay connected to one of those hosts after
+# execution. The host is only guaranteed to remain unchanged if
+# none of $diff_table_1 or $diff_table_2 begins with 'master:' or
+# 'slave:'.
+#
+# ==== Bugs ====
+#
+# - It is currently not possible to use this for tables that are
+# supposed to be different, because if the files are different:
+# - 'diff' produces system-dependent output,
+# - the output includes the absolute path of the compared files,
+# - the output includes a timestamp.
+# To fix that, we'd probably have to use SQL to compute the
+# symmetric difference between the tables. I'm not sure how to do
+# that efficiently. If we implement this, it would be nice to
+# compare the table definitions too.
+#
+# - It actually compares the result of "SELECT * FROM table ORDER BY
+# col1, col2, ..., colN INTO OUTFILE 'file'". Hence, it is assumed
+# that the comparison orders for both tables are equal and that two
+# rows that are equal in the comparison order cannot differ, e.g.,
+# by character case.
+
+
+# ==== Save both tables to file ====
+
+--echo Comparing tables $diff_table_1 and $diff_table_2
+disable_query_log;
+
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
+
+let $_diff_table=$diff_table_2;
+let $_diff_i=2;
+while ($_diff_i) {
+
+ # Parse out any leading "master:" or "slave:" from the table
+ # specification and connect the appropriate server.
+ let $_diff_conn_master=`SELECT SUBSTR('$_diff_table', 1, 7) = 'master:'`;
+ if ($_diff_conn_master) {
+ let $_diff_table=`SELECT SUBSTR('$_diff_table', 8)`;
+ connection master;
+ }
+ let $_diff_conn_slave=`SELECT SUBSTR('$_diff_table', 1, 6) = 'slave:'`;
+ if ($_diff_conn_slave) {
+ let $_diff_table=`SELECT SUBSTR('$_diff_table', 7)`;
+ connection slave;
+ }
+
+ # Sanity-check the input.
+ let $_diff_error= `SELECT '$_diff_table' NOT LIKE '_%._%'`;
+ if ($_diff_error) {
+ --echo !!!ERROR IN TEST: \$diff_table_$_diff_i='$_diff_table' is not in the form database.table
+ exit;
+ }
+
+ # We need the output files to be sorted (so that diff_files does not
+ # think the files are different just because they are differently
+ # ordered). To this end, we first generate a query that sorts the
+ # table by all columns. Since ORDER BY accept column indices, we
+ # just generate a comma-separated list of all numbers from 1 to the
+ # number of columns in the table.
+ let $_diff_column_index=`SELECT MAX(ordinal_position)
+ FROM information_schema.columns
+ WHERE CONCAT(table_schema, '.', table_name) =
+ '$_diff_table'`;
+ let $_diff_column_list=$_diff_column_index;
+ dec $_diff_column_index;
+ while ($_diff_column_index) {
+ let $_diff_column_list=$_diff_column_index, $_diff_column_list;
+ dec $_diff_column_index;
+ }
+
+ # Now that we have the comma-separated list of columns, we can write
+ # the table to a file.
+ eval SELECT * FROM $_diff_table ORDER BY $_diff_column_list
+ INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/diff_table_$_diff_i';
+
+ # Do the same for $diff_table_1.
+ dec $_diff_i;
+ let $_diff_table=$diff_table_1;
+}
+
+
+# ==== Compare the generated files ====
+
+diff_files $MYSQLTEST_VARDIR/tmp/diff_table_1 $MYSQLTEST_VARDIR/tmp/diff_table_2;
+
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
+
+enable_query_log;
diff --git a/mysql-test/include/mysqldump.inc b/mysql-test/include/mysqldump.inc
new file mode 100644
index 00000000000..fb22ab0bc74
--- /dev/null
+++ b/mysql-test/include/mysqldump.inc
@@ -0,0 +1,41 @@
+################################################################################
+# mysqldump.inc
+# SUMMARY: include file to facilitate testing the quality of mysqldump output
+# INPUTS: Two variables:
+# $table_name - the name of the table that was dumped
+# $mysqldumpfile - the name of the file that captured mysqldump output
+# OUTPUTS: minor echo data:
+# We 'echo' some stage information to the .result file:
+# 'altering original table', 'restoring from dumpfile', 'comparing'
+# OTHER FILES: We use include/diff_tables.inc to compare the original, renamed
+# table with the 'restored' one.
+# DESCRIPTION: This file works by being fed the name of the original table
+# and a mysqldump output file. The original table is then renamed
+# to <table_name>_orig, the mysqldump file is used to recreate the
+# table, then diff_tables.inc is called to compare them.
+# LIMITATIONS: Does *NOT* work with xml output!
+# AUTHOR: pcrews
+# LAST CHANGE: 2009-05-21
+# PURPOSE: Bug#40465: mysqldump.test does no checking of dump or restore
+################################################################################
+
+--echo # Begin testing mysqldump output + restore
+--echo # Create 'original table name - <table>_orig
+# NOTE: We use SET then let as query_get_value has issues with the extra commas
+# used in the CONCAT statement.
+eval SET @orig_table_name = CONCAT('$table_name', '_orig');
+let $orig_table_name = query_get_value(SELECT @orig_table_name,@orig_table_name,1);
+--echo # Rename original table
+eval ALTER TABLE $table_name RENAME to $orig_table_name;
+--echo # Recreate table from mysqldump output
+--exec $MYSQL test < $mysqldumpfile
+--echo # Compare original and recreated tables
+--echo # Recreated table: $table_name
+--echo # Original table: $orig_table_name
+let $diff_table_1 = $table_name;
+let $diff_table_2 = $orig_table_name;
+--source include/diff_tables.inc
+--echo # Cleanup
+--remove_file $mysqldumpfile
+eval DROP TABLE $table_name, $orig_table_name;
+
diff --git a/mysql-test/r/mysqldump_restore.result b/mysql-test/r/mysqldump_restore.result
new file mode 100644
index 00000000000..1e106c3be11
--- /dev/null
+++ b/mysql-test/r/mysqldump_restore.result
@@ -0,0 +1,110 @@
+# Set concurrent_insert = 0 to prevent random errors
+# will reset to original value at the end of the test
+SET @old_concurrent_insert = @@global.concurrent_insert;
+SET @@global.concurrent_insert = 0;
+# Pre-test cleanup
+DROP TABLE IF EXISTS t1;
+# Begin tests
+#
+# Bug#2005 Long decimal comparison bug.
+#
+CREATE TABLE t1 (a decimal(64, 20));
+INSERT INTO t1 VALUES ("1234567890123456789012345678901234567890"),
+("0987654321098765432109876543210987654321");
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+#
+# Bug#3361 mysqldump quotes DECIMAL values inconsistently
+#
+CREATE TABLE t1 (a DECIMAL(10,5), b FLOAT);
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ANSI_QUOTES';
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+ERROR 42S22: Unknown column '1.2345' in 'field list'
+SET SQL_MODE=@OLD_SQL_MODE;
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+#
+# Bug#1994 mysqldump does not correctly dump UCS2 data
+# Bug#4261 mysqldump 10.7 (mysql 4.1.2) --skip-extended-insert drops NULL from inserts
+#
+CREATE TABLE t1 (a VARCHAR(255)) DEFAULT CHARSET koi8r;
+INSERT INTO t1 VALUES (_koi8r x'C1C2C3C4C5'), (NULL);
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+#
+# WL#2319 Exclude Tables from dump
+#
+CREATE TABLE t1 (a int);
+CREATE TABLE t2 (a int);
+INSERT INTO t1 VALUES (1),(2),(3);
+INSERT INTO t2 VALUES (4),(5),(6);
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t2', '_orig');
+# Rename original table
+ALTER TABLE test.t2 RENAME to test.t2_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t2
+# Original table: test.t2_orig
+Comparing tables test.t2 and test.t2_orig
+# Cleanup
+DROP TABLE test.t2, test.t2_orig;
+DROP TABLE t1;
+#
+# Bug#8830 mysqldump --skip-extended-insert causes --hex-blob to dump wrong values
+#
+CREATE TABLE t1 (`b` blob);
+INSERT INTO `t1` VALUES (0x602010000280100005E71A);
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+# End tests
+# Cleanup
+# Reset concurrent_insert to its original value
+SET @@global.concurrent_insert = @old_concurrent_insert;
+# remove mysqldumpfile
diff --git a/mysql-test/t/mysqldump_restore.test b/mysql-test/t/mysqldump_restore.test
new file mode 100644
index 00000000000..c5220e5de69
--- /dev/null
+++ b/mysql-test/t/mysqldump_restore.test
@@ -0,0 +1,120 @@
+###############################################################################
+# mysqldump_restore.test
+# Purpose: Tests if mysqldump output can be used to successfully restore
+# tables and data.
+# We CREATE a table, mysqldump it to a file, ALTER the original
+# table's name, recreate the table from the mysqldump file, then
+# utilize include/diff_tables to compare the original and recreated
+# tables.
+#
+# We use several examples from mysqldump.test here and include
+# the relevant bug numbers and headers from that test.
+#
+# NOTE: This test is not currently complete and offers only basic
+# cases of mysqldump output being restored.
+# Also, does NOT work with -X (xml) output!
+#
+# Author: pcrews
+# Created: 2009-05-21
+# Last Change:
+# Change date:
+###############################################################################
+
+# Embedded server doesn't support external clients
+--source include/not_embedded.inc
+--source include/have_log_bin.inc
+
+--echo # Set concurrent_insert = 0 to prevent random errors
+--echo # will reset to original value at the end of the test
+SET @old_concurrent_insert = @@global.concurrent_insert;
+SET @@global.concurrent_insert = 0;
+
+# Define mysqldumpfile here. It is used to capture mysqldump output
+# in order to test the output's ability to restore an exact copy of the table
+let $mysqldumpfile = $MYSQLTEST_VARDIR/tmp/mysqldumpfile.sql;
+
+--echo # Pre-test cleanup
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo # Begin tests
+--echo #
+--echo # Bug#2005 Long decimal comparison bug.
+--echo #
+
+CREATE TABLE t1 (a decimal(64, 20));
+INSERT INTO t1 VALUES ("1234567890123456789012345678901234567890"),
+("0987654321098765432109876543210987654321");
+--exec $MYSQL_DUMP --compact test t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+--echo #
+--echo # Bug#3361 mysqldump quotes DECIMAL values inconsistently
+--echo #
+
+CREATE TABLE t1 (a DECIMAL(10,5), b FLOAT);
+
+# check at first how mysql work with quoted decimal
+
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+
+SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ANSI_QUOTES';
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+--error ER_BAD_FIELD_ERROR
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+SET SQL_MODE=@OLD_SQL_MODE;
+
+# check how mysqldump make quoting
+--exec $MYSQL_DUMP --compact test t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+--echo #
+--echo # Bug#1994 mysqldump does not correctly dump UCS2 data
+--echo # Bug#4261 mysqldump 10.7 (mysql 4.1.2) --skip-extended-insert drops NULL from inserts
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(255)) DEFAULT CHARSET koi8r;
+INSERT INTO t1 VALUES (_koi8r x'C1C2C3C4C5'), (NULL);
+--exec $MYSQL_DUMP --skip-comments --skip-extended-insert test t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+--echo #
+--echo # WL#2319 Exclude Tables from dump
+--echo #
+
+CREATE TABLE t1 (a int);
+CREATE TABLE t2 (a int);
+INSERT INTO t1 VALUES (1),(2),(3);
+INSERT INTO t2 VALUES (4),(5),(6);
+--exec $MYSQL_DUMP --skip-comments --ignore-table=test.t1 test > $mysqldumpfile
+let $table_name = test.t2;
+--source include/mysqldump.inc
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#8830 mysqldump --skip-extended-insert causes --hex-blob to dump wrong values
+--echo #
+
+CREATE TABLE t1 (`b` blob);
+INSERT INTO `t1` VALUES (0x602010000280100005E71A);
+--exec $MYSQL_DUMP --skip-extended-insert --hex-blob test --skip-comments t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+
+
+--echo # End tests
+
+--echo # Cleanup
+--echo # Reset concurrent_insert to its original value
+SET @@global.concurrent_insert = @old_concurrent_insert;
+--echo # remove mysqldumpfile
+--error 0,1
+--remove_file $mysqldumpfile