Skip to content

Commit 2828c2b

Browse files
committed
MDEV-9124 mysqldump does not dump data if table name is same as view earlier on
While querying INFORMATION SCHEMA, check for a table's engine only used table name, but not schema name; so, if there were different rows with the same table name, a wrong one could be retrieved. The result of the check affected the decision whether the contents of the table should be dumped, and whether a DELAYED option can be used. Fixed by adding a clause for table_schema to the query.
1 parent a430df3 commit 2828c2b

File tree

3 files changed

+198
-1
lines changed

3 files changed

+198
-1
lines changed

client/mysqldump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5468,7 +5468,7 @@ char check_if_ignore_table(const char *table_name, char *table_type)
54685468
DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff));
54695469
my_snprintf(buff, sizeof(buff),
54705470
"SELECT engine FROM INFORMATION_SCHEMA.TABLES "
5471-
"WHERE table_name = %s",
5471+
"WHERE table_schema = DATABASE() AND table_name = %s",
54725472
quote_for_equal(table_name, show_name_buff));
54735473
if (mysql_query_with_error_report(mysql, &res, buff))
54745474
{

mysql-test/r/mysqldump.result

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,3 +5329,165 @@ select * from t1;
53295329
a
53305330
1
53315331
drop table t1;
5332+
#
5333+
# MDEV-9124 mysqldump does not dump data if table name is same as view earlier on
5334+
#
5335+
CREATE DATABASE db1 CHARSET=utf8;
5336+
CREATE DATABASE db2 CHARSET=utf8;
5337+
USE db2;
5338+
CREATE TABLE nonunique_table_name (i1 serial) ENGINE=MEMORY;
5339+
INSERT INTO nonunique_table_name VALUES (1),(2);
5340+
CREATE TABLE nonunique_table_view_name (i2 int) ENGINE=InnoDB;
5341+
INSERT INTO nonunique_table_view_name VALUES (3),(4);
5342+
use db1;
5343+
CREATE TABLE basetable (id smallint) ENGINE=MyISAM;
5344+
CREATE TABLE nonunique_table_name (i3 smallint) ENGINE=MERGE UNION (basetable) INSERT_METHOD=LAST;
5345+
INSERT INTO nonunique_table_name VALUES (5),(6);
5346+
CREATE VIEW nonunique_table_view_name AS SELECT 1;
5347+
5348+
##################################################
5349+
# --compact --databases db1 db2
5350+
5351+
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `db1` /*!40100 DEFAULT CHARACTER SET utf8 */;
5352+
5353+
USE `db1`;
5354+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5355+
/*!40101 SET character_set_client = utf8 */;
5356+
CREATE TABLE `basetable` (
5357+
`id` smallint(6) DEFAULT NULL
5358+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
5359+
/*!40101 SET character_set_client = @saved_cs_client */;
5360+
INSERT INTO `basetable` VALUES (5),(6);
5361+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5362+
/*!40101 SET character_set_client = utf8 */;
5363+
CREATE TABLE `nonunique_table_name` (
5364+
`i3` smallint(6) DEFAULT NULL
5365+
) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 INSERT_METHOD=LAST UNION=(`basetable`);
5366+
/*!40101 SET character_set_client = @saved_cs_client */;
5367+
SET @saved_cs_client = @@character_set_client;
5368+
SET character_set_client = utf8;
5369+
/*!50001 CREATE TABLE `nonunique_table_view_name` (
5370+
`1` tinyint NOT NULL
5371+
) ENGINE=MyISAM */;
5372+
SET character_set_client = @saved_cs_client;
5373+
5374+
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `db2` /*!40100 DEFAULT CHARACTER SET utf8 */;
5375+
5376+
USE `db2`;
5377+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5378+
/*!40101 SET character_set_client = utf8 */;
5379+
CREATE TABLE `nonunique_table_name` (
5380+
`i1` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
5381+
UNIQUE KEY `i1` (`i1`)
5382+
) ENGINE=MEMORY AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
5383+
/*!40101 SET character_set_client = @saved_cs_client */;
5384+
INSERT INTO `nonunique_table_name` VALUES (1),(2);
5385+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5386+
/*!40101 SET character_set_client = utf8 */;
5387+
CREATE TABLE `nonunique_table_view_name` (
5388+
`i2` int(11) DEFAULT NULL
5389+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5390+
/*!40101 SET character_set_client = @saved_cs_client */;
5391+
INSERT INTO `nonunique_table_view_name` VALUES (3),(4);
5392+
5393+
USE `db1`;
5394+
/*!50001 DROP TABLE IF EXISTS `nonunique_table_view_name`*/;
5395+
/*!50001 SET @saved_cs_client = @@character_set_client */;
5396+
/*!50001 SET @saved_cs_results = @@character_set_results */;
5397+
/*!50001 SET @saved_col_connection = @@collation_connection */;
5398+
/*!50001 SET character_set_client = utf8 */;
5399+
/*!50001 SET character_set_results = utf8 */;
5400+
/*!50001 SET collation_connection = utf8_general_ci */;
5401+
/*!50001 CREATE ALGORITHM=UNDEFINED */
5402+
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
5403+
/*!50001 VIEW `nonunique_table_view_name` AS select 1 AS `1` */;
5404+
/*!50001 SET character_set_client = @saved_cs_client */;
5405+
/*!50001 SET character_set_results = @saved_cs_results */;
5406+
/*!50001 SET collation_connection = @saved_col_connection */;
5407+
5408+
USE `db2`;
5409+
5410+
##################################################
5411+
# --compact db2
5412+
5413+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5414+
/*!40101 SET character_set_client = utf8 */;
5415+
CREATE TABLE `nonunique_table_name` (
5416+
`i1` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
5417+
UNIQUE KEY `i1` (`i1`)
5418+
) ENGINE=MEMORY AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
5419+
/*!40101 SET character_set_client = @saved_cs_client */;
5420+
INSERT INTO `nonunique_table_name` VALUES (1),(2);
5421+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5422+
/*!40101 SET character_set_client = utf8 */;
5423+
CREATE TABLE `nonunique_table_view_name` (
5424+
`i2` int(11) DEFAULT NULL
5425+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5426+
/*!40101 SET character_set_client = @saved_cs_client */;
5427+
INSERT INTO `nonunique_table_view_name` VALUES (3),(4);
5428+
5429+
##################################################
5430+
# --compact --delayed-insert --no-data-med=0 --databases db2 db1
5431+
5432+
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `db2` /*!40100 DEFAULT CHARACTER SET utf8 */;
5433+
5434+
USE `db2`;
5435+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5436+
/*!40101 SET character_set_client = utf8 */;
5437+
CREATE TABLE `nonunique_table_name` (
5438+
`i1` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
5439+
UNIQUE KEY `i1` (`i1`)
5440+
) ENGINE=MEMORY AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
5441+
/*!40101 SET character_set_client = @saved_cs_client */;
5442+
INSERT DELAYED INTO `nonunique_table_name` VALUES (1),(2);
5443+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5444+
/*!40101 SET character_set_client = utf8 */;
5445+
CREATE TABLE `nonunique_table_view_name` (
5446+
`i2` int(11) DEFAULT NULL
5447+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5448+
/*!40101 SET character_set_client = @saved_cs_client */;
5449+
INSERT INTO `nonunique_table_view_name` VALUES (3),(4);
5450+
5451+
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `db1` /*!40100 DEFAULT CHARACTER SET utf8 */;
5452+
5453+
USE `db1`;
5454+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5455+
/*!40101 SET character_set_client = utf8 */;
5456+
CREATE TABLE `basetable` (
5457+
`id` smallint(6) DEFAULT NULL
5458+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
5459+
/*!40101 SET character_set_client = @saved_cs_client */;
5460+
INSERT DELAYED INTO `basetable` VALUES (5),(6);
5461+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5462+
/*!40101 SET character_set_client = utf8 */;
5463+
CREATE TABLE `nonunique_table_name` (
5464+
`i3` smallint(6) DEFAULT NULL
5465+
) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 INSERT_METHOD=LAST UNION=(`basetable`);
5466+
/*!40101 SET character_set_client = @saved_cs_client */;
5467+
INSERT INTO `nonunique_table_name` VALUES (5),(6);
5468+
SET @saved_cs_client = @@character_set_client;
5469+
SET character_set_client = utf8;
5470+
/*!50001 CREATE TABLE `nonunique_table_view_name` (
5471+
`1` tinyint NOT NULL
5472+
) ENGINE=MyISAM */;
5473+
SET character_set_client = @saved_cs_client;
5474+
5475+
USE `db2`;
5476+
5477+
USE `db1`;
5478+
/*!50001 DROP TABLE IF EXISTS `nonunique_table_view_name`*/;
5479+
/*!50001 SET @saved_cs_client = @@character_set_client */;
5480+
/*!50001 SET @saved_cs_results = @@character_set_results */;
5481+
/*!50001 SET @saved_col_connection = @@collation_connection */;
5482+
/*!50001 SET character_set_client = utf8 */;
5483+
/*!50001 SET character_set_results = utf8 */;
5484+
/*!50001 SET collation_connection = utf8_general_ci */;
5485+
/*!50001 CREATE ALGORITHM=UNDEFINED */
5486+
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
5487+
/*!50001 VIEW `nonunique_table_view_name` AS select 1 AS `1` */;
5488+
/*!50001 SET character_set_client = @saved_cs_client */;
5489+
/*!50001 SET character_set_results = @saved_cs_results */;
5490+
/*!50001 SET collation_connection = @saved_col_connection */;
5491+
5492+
DROP DATABASE db1;
5493+
DROP DATABASE db2;

mysql-test/t/mysqldump.test

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,3 +2516,38 @@ drop table t1;
25162516
--remove_file $MYSQLTEST_VARDIR/tmp/mysqldump-test.out
25172517
#select * from mysql.user;
25182518
#checksum table mysql.user;
2519+
2520+
--echo #
2521+
--echo # MDEV-9124 mysqldump does not dump data if table name is same as view earlier on
2522+
--echo #
2523+
2524+
CREATE DATABASE db1 CHARSET=utf8;
2525+
CREATE DATABASE db2 CHARSET=utf8;
2526+
USE db2;
2527+
CREATE TABLE nonunique_table_name (i1 serial) ENGINE=MEMORY;
2528+
INSERT INTO nonunique_table_name VALUES (1),(2);
2529+
CREATE TABLE nonunique_table_view_name (i2 int) ENGINE=InnoDB;
2530+
INSERT INTO nonunique_table_view_name VALUES (3),(4);
2531+
use db1;
2532+
CREATE TABLE basetable (id smallint) ENGINE=MyISAM;
2533+
CREATE TABLE nonunique_table_name (i3 smallint) ENGINE=MERGE UNION (basetable) INSERT_METHOD=LAST;
2534+
INSERT INTO nonunique_table_name VALUES (5),(6);
2535+
CREATE VIEW nonunique_table_view_name AS SELECT 1;
2536+
2537+
--echo
2538+
--echo ##################################################
2539+
--echo # --compact --databases db1 db2
2540+
--exec $MYSQL_DUMP --compact --databases db1 db2
2541+
--echo
2542+
--echo ##################################################
2543+
--echo # --compact db2
2544+
--echo
2545+
--exec $MYSQL_DUMP --compact db2
2546+
--echo
2547+
--echo ##################################################
2548+
--echo # --compact --delayed-insert --no-data-med=0 --databases db2 db1
2549+
--exec $MYSQL_DUMP --compact --delayed-insert --no-data-med=0 --databases db2 db1
2550+
--echo
2551+
2552+
DROP DATABASE db1;
2553+
DROP DATABASE db2;

0 commit comments

Comments
 (0)