Skip to content

Commit 92b0a36

Browse files
committed
MDEV-26447: mysqldump to use temporary view instead of tables.
This is particularly important for Azure where there is no MyISAM support in their MariaDB cloud product. Like mysqldumper does, a view can satisfy the requirement like a table, without constraints. The views in frm files are text form and don't have column limits. Thanks Thomas Casteleyn for the suggestion.
1 parent 53c4e4d commit 92b0a36

File tree

5 files changed

+103
-172
lines changed

5 files changed

+103
-172
lines changed

client/mysqldump.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,9 +3072,8 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
30723072
if (strcmp(field->name, "View") == 0)
30733073
{
30743074
char *scv_buff= NULL;
3075-
my_ulonglong n_cols;
30763075

3077-
verbose_msg("-- It's a view, create dummy table for view\n");
3076+
verbose_msg("-- It's a view, create dummy view for view\n");
30783077

30793078
/* save "show create" statement for later */
30803079
if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
@@ -3083,9 +3082,9 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
30833082
mysql_free_result(result);
30843083

30853084
/*
3086-
Create a table with the same name as the view and with columns of
3085+
Create a view with the same name as the view and with columns of
30873086
the same name in order to satisfy views that depend on this view.
3088-
The table will be removed when the actual view is created.
3087+
The view will be removed when the actual view is created.
30893088
30903089
The properties of each column, are not preserved in this temporary
30913090
table, because they are not necessary.
@@ -3117,23 +3116,9 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
31173116
else
31183117
my_free(scv_buff);
31193118

3120-
n_cols= mysql_num_rows(result);
3121-
if (0 != n_cols)
3119+
if (mysql_num_rows(result) != 0)
31223120
{
31233121

3124-
/*
3125-
The actual formula is based on the column names and how the .FRM
3126-
files are stored and is too volatile to be repeated here.
3127-
Thus we simply warn the user if the columns exceed a limit we
3128-
know works most of the time.
3129-
*/
3130-
if (n_cols >= 1000)
3131-
fprintf(stderr,
3132-
"-- Warning: Creating a stand-in table for view %s may"
3133-
" fail when replaying the dump file produced because "
3134-
"of the number of columns exceeding 1000. Exercise "
3135-
"caution when replaying the produced dump file.\n",
3136-
table);
31373122
if (opt_drop)
31383123
{
31393124
/*
@@ -3149,7 +3134,7 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
31493134
fprintf(sql_file,
31503135
"SET @saved_cs_client = @@character_set_client;\n"
31513136
"SET character_set_client = utf8;\n"
3152-
"/*!50001 CREATE TABLE %s (\n",
3137+
"/*!50001 CREATE VIEW %s AS SELECT\n",
31533138
result_table);
31543139

31553140
/*
@@ -3161,28 +3146,21 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
31613146
row= mysql_fetch_row(result);
31623147

31633148
/*
3164-
The actual column type doesn't matter anyway, since the table will
3149+
The actual column value doesn't matter anyway, since the view will
31653150
be dropped at run time.
3166-
We do tinyint to avoid hitting the row size limit.
31673151
*/
3168-
fprintf(sql_file, " %s tinyint NOT NULL",
3152+
fprintf(sql_file, " 1 AS %s",
31693153
quote_name(row[0], name_buff, 0));
31703154

31713155
while((row= mysql_fetch_row(result)))
31723156
{
31733157
/* col name, col type */
3174-
fprintf(sql_file, ",\n %s tinyint NOT NULL",
3158+
fprintf(sql_file, ",\n 1 AS %s",
31753159
quote_name(row[0], name_buff, 0));
31763160
}
31773161

3178-
/*
3179-
Stand-in tables are always MyISAM tables as the default
3180-
engine might have a column-limit that's lower than the
3181-
number of columns in the view, and MyISAM support is
3182-
guaranteed to be in the server anyway.
3183-
*/
31843162
fprintf(sql_file,
3185-
"\n) ENGINE=MyISAM */;\n"
3163+
" */;\n"
31863164
"SET character_set_client = @saved_cs_client;\n");
31873165

31883166
check_io(sql_file);
@@ -6642,15 +6620,8 @@ static my_bool get_view_structure(char *table, char* db)
66426620
"\n--\n-- Final view structure for view %s\n--\n\n",
66436621
fix_for_comment(result_table));
66446622

6645-
/* Table might not exist if this view was dumped with --tab. */
6646-
fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", opt_quoted_table);
6647-
if (opt_drop)
6648-
{
6649-
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n",
6650-
opt_quoted_table);
6651-
check_io(sql_file);
6652-
}
6653-
6623+
/* View might not exist if this view was dumped with --tab. */
6624+
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", opt_quoted_table);
66546625

66556626
my_snprintf(query, sizeof(query),
66566627
"SELECT CHECK_OPTION, DEFINER, SECURITY_TYPE, "

mysql-test/main/lock_view.result

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,43 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysqltest2` /*!40100 DEFAULT CHARACTER
3232
USE `mysqltest2`;
3333
SET @saved_cs_client = @@character_set_client;
3434
SET character_set_client = utf8;
35-
/*!50001 CREATE TABLE `v2` (
36-
`a` tinyint NOT NULL
37-
) ENGINE=MyISAM */;
35+
/*!50001 CREATE VIEW `v2` AS SELECT
36+
1 AS `a` */;
3837
SET character_set_client = @saved_cs_client;
3938

4039
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysqltest3` /*!40100 DEFAULT CHARACTER SET latin1 */;
4140

4241
USE `mysqltest3`;
4342
SET @saved_cs_client = @@character_set_client;
4443
SET character_set_client = utf8;
45-
/*!50001 CREATE TABLE `v3` (
46-
`a` tinyint NOT NULL
47-
) ENGINE=MyISAM */;
44+
/*!50001 CREATE VIEW `v3` AS SELECT
45+
1 AS `a` */;
4846
SET character_set_client = @saved_cs_client;
4947
SET @saved_cs_client = @@character_set_client;
5048
SET character_set_client = utf8;
51-
/*!50001 CREATE TABLE `v3i` (
52-
`a` tinyint NOT NULL
53-
) ENGINE=MyISAM */;
49+
/*!50001 CREATE VIEW `v3i` AS SELECT
50+
1 AS `a` */;
5451
SET character_set_client = @saved_cs_client;
5552
SET @saved_cs_client = @@character_set_client;
5653
SET character_set_client = utf8;
57-
/*!50001 CREATE TABLE `v3is` (
58-
`schema_name` tinyint NOT NULL
59-
) ENGINE=MyISAM */;
54+
/*!50001 CREATE VIEW `v3is` AS SELECT
55+
1 AS `schema_name` */;
6056
SET character_set_client = @saved_cs_client;
6157
SET @saved_cs_client = @@character_set_client;
6258
SET character_set_client = utf8;
63-
/*!50001 CREATE TABLE `v3nt` (
64-
`1` tinyint NOT NULL
65-
) ENGINE=MyISAM */;
59+
/*!50001 CREATE VIEW `v3nt` AS SELECT
60+
1 AS `1` */;
6661
SET character_set_client = @saved_cs_client;
6762
SET @saved_cs_client = @@character_set_client;
6863
SET character_set_client = utf8;
69-
/*!50001 CREATE TABLE `v3ps` (
70-
`user` tinyint NOT NULL
71-
) ENGINE=MyISAM */;
64+
/*!50001 CREATE VIEW `v3ps` AS SELECT
65+
1 AS `user` */;
7266
SET character_set_client = @saved_cs_client;
7367

7468
USE `mysqltest1`;
7569

7670
USE `mysqltest2`;
77-
/*!50001 DROP TABLE IF EXISTS `v2`*/;
71+
/*!50001 DROP VIEW IF EXISTS `v2`*/;
7872
/*!50001 SET @saved_cs_client = @@character_set_client */;
7973
/*!50001 SET @saved_cs_results = @@character_set_results */;
8074
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -89,7 +83,7 @@ USE `mysqltest2`;
8983
/*!50001 SET collation_connection = @saved_col_connection */;
9084

9185
USE `mysqltest3`;
92-
/*!50001 DROP TABLE IF EXISTS `v3`*/;
86+
/*!50001 DROP VIEW IF EXISTS `v3`*/;
9387
/*!50001 SET @saved_cs_client = @@character_set_client */;
9488
/*!50001 SET @saved_cs_results = @@character_set_results */;
9589
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -102,7 +96,7 @@ USE `mysqltest3`;
10296
/*!50001 SET character_set_client = @saved_cs_client */;
10397
/*!50001 SET character_set_results = @saved_cs_results */;
10498
/*!50001 SET collation_connection = @saved_col_connection */;
105-
/*!50001 DROP TABLE IF EXISTS `v3i`*/;
99+
/*!50001 DROP VIEW IF EXISTS `v3i`*/;
106100
/*!50001 SET @saved_cs_client = @@character_set_client */;
107101
/*!50001 SET @saved_cs_results = @@character_set_results */;
108102
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -115,7 +109,7 @@ USE `mysqltest3`;
115109
/*!50001 SET character_set_client = @saved_cs_client */;
116110
/*!50001 SET character_set_results = @saved_cs_results */;
117111
/*!50001 SET collation_connection = @saved_col_connection */;
118-
/*!50001 DROP TABLE IF EXISTS `v3is`*/;
112+
/*!50001 DROP VIEW IF EXISTS `v3is`*/;
119113
/*!50001 SET @saved_cs_client = @@character_set_client */;
120114
/*!50001 SET @saved_cs_results = @@character_set_results */;
121115
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -128,7 +122,7 @@ USE `mysqltest3`;
128122
/*!50001 SET character_set_client = @saved_cs_client */;
129123
/*!50001 SET character_set_results = @saved_cs_results */;
130124
/*!50001 SET collation_connection = @saved_col_connection */;
131-
/*!50001 DROP TABLE IF EXISTS `v3nt`*/;
125+
/*!50001 DROP VIEW IF EXISTS `v3nt`*/;
132126
/*!50001 SET @saved_cs_client = @@character_set_client */;
133127
/*!50001 SET @saved_cs_results = @@character_set_results */;
134128
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -141,7 +135,7 @@ USE `mysqltest3`;
141135
/*!50001 SET character_set_client = @saved_cs_client */;
142136
/*!50001 SET character_set_results = @saved_cs_results */;
143137
/*!50001 SET collation_connection = @saved_col_connection */;
144-
/*!50001 DROP TABLE IF EXISTS `v3ps`*/;
138+
/*!50001 DROP VIEW IF EXISTS `v3ps`*/;
145139
/*!50001 SET @saved_cs_client = @@character_set_client */;
146140
/*!50001 SET @saved_cs_results = @@character_set_results */;
147141
/*!50001 SET @saved_col_connection = @@collation_connection */;
@@ -243,11 +237,10 @@ disconnect con1;
243237
connection default;
244238
SET @saved_cs_client = @@character_set_client;
245239
SET character_set_client = utf8;
246-
/*!50001 CREATE TABLE `v1` (
247-
`id` tinyint NOT NULL
248-
) ENGINE=MyISAM */;
240+
/*!50001 CREATE VIEW `v1` AS SELECT
241+
1 AS `id` */;
249242
SET character_set_client = @saved_cs_client;
250-
/*!50001 DROP TABLE IF EXISTS `v1`*/;
243+
/*!50001 DROP VIEW IF EXISTS `v1`*/;
251244
/*!50001 SET @saved_cs_client = @@character_set_client */;
252245
/*!50001 SET @saved_cs_results = @@character_set_results */;
253246
/*!50001 SET @saved_col_connection = @@collation_connection */;

mysql-test/main/mysqldump-nl.result

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ raboof` int(11) DEFAULT NULL
5353

5454
SET @saved_cs_client = @@character_set_client;
5555
SET character_set_client = utf8;
56-
/*!50001 CREATE TABLE `v1
57-
1v` (
58-
`foobar
59-
raboof` tinyint NOT NULL
60-
) ENGINE=MyISAM */;
56+
/*!50001 CREATE VIEW `v1
57+
1v` AS SELECT
58+
1 AS `foobar
59+
raboof` */;
6160
SET character_set_client = @saved_cs_client;
6261

6362
--
@@ -95,7 +94,7 @@ USE `mysqltest1
9594
-- 1v`
9695
--
9796

98-
/*!50001 DROP TABLE IF EXISTS `v1
97+
/*!50001 DROP VIEW IF EXISTS `v1
9998
1v`*/;
10099
/*!50001 SET @saved_cs_client = @@character_set_client */;
101100
/*!50001 SET @saved_cs_results = @@character_set_results */;

0 commit comments

Comments
 (0)