Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
f9c02d7c
Commit
f9c02d7c
authored
Apr 28, 2015
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'openquery/MDEV-6916-maria-5.5-check_view-r4408' into 5.5
parents
fbab0685
83ce3529
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
918 additions
and
78 deletions
+918
-78
client/client_priv.h
client/client_priv.h
+1
-0
client/mysql_upgrade.c
client/mysql_upgrade.c
+64
-5
client/mysqlcheck.c
client/mysqlcheck.c
+165
-21
include/myisamchk.h
include/myisamchk.h
+1
-0
mysql-test/r/mysql_upgrade.result
mysql-test/r/mysql_upgrade.result
+33
-25
mysql-test/r/mysql_upgrade_view.result
mysql-test/r/mysql_upgrade_view.result
+205
-0
mysql-test/std_data/mysql_upgrade/event.MYD
mysql-test/std_data/mysql_upgrade/event.MYD
+0
-0
mysql-test/std_data/mysql_upgrade/event.MYI
mysql-test/std_data/mysql_upgrade/event.MYI
+0
-0
mysql-test/std_data/mysql_upgrade/event.frm
mysql-test/std_data/mysql_upgrade/event.frm
+0
-0
mysql-test/std_data/mysql_upgrade/v1.frm
mysql-test/std_data/mysql_upgrade/v1.frm
+15
-0
mysql-test/std_data/mysql_upgrade/v1badcheck.frm
mysql-test/std_data/mysql_upgrade/v1badcheck.frm
+15
-0
mysql-test/std_data/mysql_upgrade/v2.frm
mysql-test/std_data/mysql_upgrade/v2.frm
+15
-0
mysql-test/std_data/mysql_upgrade/v3.frm
mysql-test/std_data/mysql_upgrade/v3.frm
+15
-0
mysql-test/std_data/mysql_upgrade/v4.frm
mysql-test/std_data/mysql_upgrade/v4.frm
+16
-0
mysql-test/t/mysql_upgrade_view.test
mysql-test/t/mysql_upgrade_view.test
+146
-0
sql/lex.h
sql/lex.h
+1
-0
sql/sql_admin.cc
sql/sql_admin.cc
+20
-8
sql/sql_base.cc
sql/sql_base.cc
+7
-2
sql/sql_table.cc
sql/sql_table.cc
+0
-1
sql/sql_view.cc
sql/sql_view.cc
+163
-14
sql/sql_view.h
sql/sql_view.h
+2
-0
sql/sql_yacc.yy
sql/sql_yacc.yy
+34
-2
No files found.
client/client_priv.h
View file @
f9c02d7c
...
...
@@ -79,6 +79,7 @@ enum options_client
OPT_SLAP_COMMIT
,
OPT_SLAP_DETACH
,
OPT_SLAP_NO_DROP
,
OPT_UPGRADE_VIEWS
,
OPT_MYSQL_REPLACE_INTO
,
OPT_BASE64_OUTPUT_MODE
,
OPT_SERVER_ID
,
OPT_FIX_TABLE_NAMES
,
OPT_FIX_DB_NAMES
,
OPT_SSL_VERIFY_SERVER_CERT
,
OPT_AUTO_VERTICAL_OUTPUT
,
...
...
client/mysql_upgrade.c
View file @
f9c02d7c
...
...
@@ -36,6 +36,8 @@
# endif
#endif
static
int
phase
=
1
;
static
int
phases_total
=
4
;
static
char
mysql_path
[
FN_REFLEN
];
static
char
mysqlcheck_path
[
FN_REFLEN
];
...
...
@@ -738,9 +740,10 @@ static void print_conn_args(const char *tool_name)
static
int
run_mysqlcheck_upgrade
(
void
)
{
verbose
(
"Phase 2/3: Checking and upgrading tables"
);
int
retch
;
verbose
(
"Phase %d/%d: Checking and upgrading tables"
,
phase
++
,
phases_total
);
print_conn_args
(
"mysqlcheck"
);
ret
urn
run_tool
(
mysqlcheck_path
,
ret
ch
=
run_tool
(
mysqlcheck_path
,
NULL
,
/* Send output from mysqlcheck directly to screen */
"--no-defaults"
,
ds_args
.
str
,
...
...
@@ -752,12 +755,67 @@ static int run_mysqlcheck_upgrade(void)
opt_write_binlog
?
"--write-binlog"
:
"--skip-write-binlog"
,
"2>&1"
,
NULL
);
if
(
retch
||
opt_systables_only
)
verbose
(
"Phase %d/%d: Skipping 'mysql_fix_privilege_tables'... not needed"
,
phase
++
,
phases_total
);
return
retch
;
}
#define EVENTS_STRUCT_LEN 7000
static
my_bool
is_mysql
()
{
my_bool
ret
=
TRUE
;
DYNAMIC_STRING
ds_events_struct
;
if
(
init_dynamic_string
(
&
ds_events_struct
,
NULL
,
EVENTS_STRUCT_LEN
,
EVENTS_STRUCT_LEN
))
die
(
"Out of memory"
);
if
(
run_query
(
"show create table mysql.event"
,
&
ds_events_struct
,
FALSE
)
||
strstr
(
ds_events_struct
.
str
,
"IGNORE_BAD_TABLE_OPTIONS"
)
!=
NULL
)
ret
=
FALSE
;
else
verbose
(
"MySQL upgrade detected"
);
dynstr_free
(
&
ds_events_struct
);
return
(
ret
);
}
static
int
run_mysqlcheck_views
(
void
)
{
const
char
*
upgrade_views
=
"--upgrade-views=YES"
;
if
(
is_mysql
())
{
upgrade_views
=
"--upgrade-views=FROM_MYSQL"
;
verbose
(
"Phase %d/%d: Fixing views from mysql"
,
phase
++
,
phases_total
);
}
else
if
(
opt_systables_only
)
{
verbose
(
"Phase %d/%d: Fixing views - skipped - not required"
,
phase
++
,
phases_total
);
return
0
;
}
else
verbose
(
"Phase %d/%d: Fixing views"
,
phase
++
,
phases_total
);
print_conn_args
(
"mysqlcheck"
);
return
run_tool
(
mysqlcheck_path
,
NULL
,
/* Send output from mysqlcheck directly to screen */
"--no-defaults"
,
ds_args
.
str
,
"--all-databases"
,
upgrade_views
,
"--skip-fix-tables"
,
opt_verbose
?
"--verbose"
:
""
,
opt_silent
?
"--silent"
:
""
,
opt_write_binlog
?
"--write-binlog"
:
"--skip-write-binlog"
,
"2>&1"
,
NULL
);
}
static
int
run_mysqlcheck_fixnames
(
void
)
{
verbose
(
"Phase
1/3: Fixing table and database names"
);
verbose
(
"Phase
%d/%d: Fixing table and database names"
,
phase
++
,
phases_total
);
print_conn_args
(
"mysqlcheck"
);
return
run_tool
(
mysqlcheck_path
,
NULL
,
/* Send output from mysqlcheck directly to screen */
...
...
@@ -838,7 +896,7 @@ static int run_sql_fix_privilege_tables(void)
if
(
init_dynamic_string
(
&
ds_result
,
""
,
512
,
512
))
die
(
"Out of memory"
);
verbose
(
"Phase
3/3: Running 'mysql_fix_privilege_tables'..."
);
verbose
(
"Phase
%d/%d: Running 'mysql_fix_privilege_tables'..."
,
phase
++
,
phases_total
);
run_query
(
mysql_fix_privilege_tables
,
&
ds_result
,
/* Collect result */
TRUE
);
...
...
@@ -1001,7 +1059,8 @@ int main(int argc, char **argv)
Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
*/
if
((
!
opt_systables_only
&&
(
run_mysqlcheck_fixnames
()
||
run_mysqlcheck_upgrade
()))
||
(
run_mysqlcheck_views
()
||
run_mysqlcheck_fixnames
()
||
run_mysqlcheck_upgrade
()))
||
run_sql_fix_privilege_tables
())
{
/*
...
...
client/mysqlcheck.c
View file @
f9c02d7c
This diff is collapsed.
Click to expand it.
include/myisamchk.h
View file @
f9c02d7c
...
...
@@ -34,6 +34,7 @@
#define TT_USEFRM 1
#define TT_FOR_UPGRADE 2
#define TT_FROM_MYSQL 4
/* Bits set in out_flag */
#define O_NEW_DATA 2
...
...
mysql-test/r/mysql_upgrade.result
View file @
f9c02d7c
Run mysql_upgrade once
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -31,13 +32,14 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
Run it again - should say already completed
This installation of MySQL is already upgraded to VERSION, use --force if you still need to run mysql_upgrade
Force should run it regardless of wether it's been run before
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -68,13 +70,14 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
CREATE USER mysqltest1@'%' IDENTIFIED by 'sakila';
GRANT ALL ON *.* TO mysqltest1@'%';
Run mysql_upgrade with password protected account
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -105,7 +108,7 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
DROP USER mysqltest1@'%';
Version check failed. Got the following error when calling the 'mysql' command line client
...
...
@@ -115,8 +118,9 @@ Run mysql_upgrade with a non existing server socket
mysqlcheck: Got error: 2005: Unknown MySQL server host 'not_existing_host' (errno) when trying to connect
FATAL ERROR: Upgrade failed
set GLOBAL sql_mode='STRICT_ALL_TABLES,ANSI_QUOTES,NO_ZERO_DATE';
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -147,7 +151,7 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
set GLOBAL sql_mode=default;
#
...
...
@@ -158,8 +162,9 @@ CREATE PROCEDURE testproc() BEGIN END;
UPDATE mysql.proc SET character_set_client = NULL WHERE name LIKE 'testproc';
UPDATE mysql.proc SET collation_connection = NULL WHERE name LIKE 'testproc';
UPDATE mysql.proc SET db_collation = NULL WHERE name LIKE 'testproc';
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -190,7 +195,7 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
CALL testproc();
DROP PROCEDURE testproc;
...
...
@@ -204,8 +209,9 @@ WARNING: NULL values of the 'db_collation' column ('mysql.proc' table) have been
GRANT USAGE ON *.* TO 'user3'@'%';
GRANT ALL PRIVILEGES ON `roelt`.`test2` TO 'user3'@'%';
Run mysql_upgrade with all privileges on a user
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -236,7 +242,7 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
SHOW GRANTS FOR 'user3'@'%';
Grants for user3@%
...
...
@@ -245,7 +251,7 @@ GRANT ALL PRIVILEGES ON `roelt`.`test2` TO 'user3'@'%'
DROP USER 'user3'@'%';
End of 5.1 tests
The --upgrade-system-tables option was used, databases won't be touched.
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
1/4
: Running 'mysql_fix_privilege_tables'...
OK
#
# Bug#11827359 60223: MYSQL_UPGRADE PROBLEM WITH OPTION
...
...
@@ -253,8 +259,9 @@ OK
#
# Droping the previously created mysql_upgrade_info file..
# Running mysql_upgrade with --skip-write-binlog..
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -285,7 +292,7 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
#
# MDEV-4332 Increase username length from 16 characters
...
...
@@ -313,8 +320,9 @@ GRANT INSERT ON mysql.user TO very_long_user_name_number_2;
GRANT UPDATE (User) ON mysql.db TO very_long_user_name_number_1;
GRANT UPDATE (User) ON mysql.db TO very_long_user_name_number_2;
CREATE PROCEDURE test.pr() BEGIN END;
Phase 1/3: Fixing table and database names
Phase 2/3: Checking and upgrading tables
Phase 1/4: Fixing views
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
...
...
@@ -345,7 +353,7 @@ mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
Phase
3/3
: Running 'mysql_fix_privilege_tables'...
Phase
4/4
: Running 'mysql_fix_privilege_tables'...
OK
SELECT definer FROM mysql.proc WHERE db = 'test' AND name = 'pr';
definer
...
...
mysql-test/r/mysql_upgrade_view.result
0 → 100644
View file @
f9c02d7c
set sql_log_bin=0;
drop table if exists t1,v1,v2,v3,v4,v1badcheck;
drop view if exists t1,v1,v2,v3,v4,v1badcheck;
create table t1(a int);
create table kv(k varchar(30) NOT NULL PRIMARY KEY,v varchar(50));
flush tables;
Phase 1/4: Fixing views
test.v1 OK
test.v1badcheck OK
test.v2 OK
test.v3 OK
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
test.kv OK
test.t1 OK
Phase 4/4: Running 'mysql_fix_privilege_tables'...
OK
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v2;
View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
set sql_log_bin=1;
REPAIR VIEW v1,v2;
Table Op Msg_type Msg_text
test.v1 repair status OK
test.v2 repair status OK
REPAIR VIEW v1badcheck;
Table Op Msg_type Msg_text
test.v1badcheck repair status OK
REPAIR NO_WRITE_TO_BINLOG VIEW v3;
Table Op Msg_type Msg_text
test.v3 repair status OK
set sql_log_bin=0;
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # use `test`; REPAIR VIEW v1,v2
master-bin.000001 # Query # # use `test`; REPAIR VIEW v1badcheck
LOAD DATA INFILE 'MYSQLD_DATADIR/test/v1.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '=';
SELECT k,v from kv where k in ('md5','algorithm');
k v
algorithm 1
md5 5e6eaf216e7b016fcedfd4e1113517af
SELECT k from kv where k ='mariadb-version';
k
mariadb-version
truncate table kv;
LOAD DATA INFILE 'MYSQLD_DATADIR/test/v2.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '=';
SELECT k,v from kv where k in ('md5','algorithm');
k v
algorithm 2
md5 5e6eaf216e7b016fcedfd4e1113517af
SELECT k from kv where k ='mariadb-version';
k
mariadb-version
truncate table kv;
LOAD DATA INFILE 'MYSQLD_DATADIR/test/v3.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '=';
SELECT k,v from kv where k in ('md5','algorithm');
k v
algorithm 0
md5 5e6eaf216e7b016fcedfd4e1113517af
SELECT k from kv where k ='mariadb-version';
k
mariadb-version
truncate table kv;
LOAD DATA INFILE 'MYSQLD_DATADIR/test/v1badcheck.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '=';
SELECT k,v from kv where k in ('md5','algorithm');
k v
algorithm 1
md5 5e6eaf216e7b016fcedfd4e1113517af
SELECT k from kv where k ='mariadb-version';
k
mariadb-version
truncate table kv;
drop view if exists v1,v2,v3,v1badcheck;
flush tables;
create algorithm=temptable view v4 as select a from t1;
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v2;
View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v4;
View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci
MySQL upgrade detected
Phase 1/4: Fixing views from mysql
test.v1 OK
test.v2 OK
test.v3 OK
test.v4 OK
Phase 2/4: Fixing table and database names
Phase 3/4: Checking and upgrading tables
Processing databases
information_schema
mtr
mtr.global_suppressions OK
mtr.test_suppressions OK
mysql
mysql.columns_priv OK
mysql.db OK
mysql.ev_bk OK
mysql.event OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.servers OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
performance_schema
test
test.kv OK
test.t1 OK
Phase 4/4: Running 'mysql_fix_privilege_tables'...
OK
show create view v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v2;
View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v3;
View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
show create view v4;
View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci
LOAD DATA INFILE 'MYSQLD_DATADIR/test/v1.frm' REPLACE INTO TABLE kv FIELDS TERMINATED BY '=';
SELECT k,v from kv where k in ('md5','algorithm');
k v
algorithm 2
md5 5e6eaf216e7b016fcedfd4e1113517af
SELECT k from kv where k ='mariadb-version';
k
mariadb-version
truncate table kv;
drop view if exists v1,v2,v3;
flush tables;
test.v1 OK
test.v2 OK
test.v3 OK
test.v4 OK
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # use `test`; REPAIR VIEW v1,v2
master-bin.000001 # Query # # use `test`; REPAIR VIEW v1badcheck
master-bin.000001 # Query # # use `test`; REPAIR VIEW `v1` FROM MYSQL
master-bin.000001 # Query # # use `test`; REPAIR VIEW `v2` FROM MYSQL
master-bin.000001 # Query # # use `test`; REPAIR VIEW `v3` FROM MYSQL
master-bin.000001 # Query # # use `test`; REPAIR VIEW `v4` FROM MYSQL
flush tables;
drop table if exists kv;
drop view v1,v2,v3,v4;
drop table t1;
mysql-test/std_data/mysql_upgrade/event.MYD
0 → 100644
View file @
f9c02d7c
mysql-test/std_data/mysql_upgrade/event.MYI
0 → 100644
View file @
f9c02d7c
File added
mysql-test/std_data/mysql_upgrade/event.frm
0 → 100644
View file @
f9c02d7c
File added
mysql-test/std_data/mysql_upgrade/v1.frm
0 → 100644
View file @
f9c02d7c
TYPE=VIEW
query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
md5=5e6eaf216e7b016fcedfd4e1113517af
updatable=0
algorithm=1
definer_user=root
definer_host=localhost
suid=2
with_check_option=0
timestamp=2014-12-11 15:26:20
create-version=1
source=select a from t1
client_cs_name=utf8
connection_cl_name=utf8_general_ci
view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`
mysql-test/std_data/mysql_upgrade/v1badcheck.frm
0 → 100644
View file @
f9c02d7c
TYPE=VIEW
query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
md5=00000000000000000000000000000000
updatable=0
algorithm=1
definer_user=root
definer_host=localhost
suid=2
with_check_option=0
timestamp=2014-12-11 15:26:20
create-version=1
source=select a from t1
client_cs_name=utf8
connection_cl_name=utf8_general_ci
view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`
mysql-test/std_data/mysql_upgrade/v2.frm
0 → 100644
View file @
f9c02d7c
TYPE=VIEW
query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
md5=5e6eaf216e7b016fcedfd4e1113517af
updatable=1
algorithm=2
definer_user=root
definer_host=localhost
suid=2
with_check_option=0
timestamp=2014-12-11 15:26:29
create-version=1
source=select a from t1
client_cs_name=utf8
connection_cl_name=utf8_general_ci
view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`
mysql-test/std_data/mysql_upgrade/v3.frm
0 → 100644
View file @
f9c02d7c
TYPE=VIEW
query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
md5=5e6eaf216e7b016fcedfd4e1113517af
updatable=0
algorithm=0
definer_user=root
definer_host=localhost
suid=2
with_check_option=0
timestamp=2014-12-11 15:26:20
create-version=1
source=select a from t1
client_cs_name=utf8
connection_cl_name=utf8_general_ci
view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`
mysql-test/std_data/mysql_upgrade/v4.frm
0 → 100644
View file @
f9c02d7c
TYPE=VIEW
query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
md5=5e6eaf216e7b016fcedfd4e1113517a0
updatable=1
algorithm=0
definer_user=root
definer_host=localhost
suid=2
with_check_option=0
timestamp=2015-02-08 19:21:14
create-version=1
source=select a from t1
client_cs_name=latin1
connection_cl_name=latin1_swedish_ci
view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`
mariadb-version=50542
mysql-test/t/mysql_upgrade_view.test
0 → 100644
View file @
f9c02d7c
--
source
include
/
have_log_bin
.
inc
set
sql_log_bin
=
0
;
--
disable_warnings
drop
table
if
exists
t1
,
v1
,
v2
,
v3
,
v4
,
v1badcheck
;
drop
view
if
exists
t1
,
v1
,
v2
,
v3
,
v4
,
v1badcheck
;
--
enable_warnings
create
table
t1
(
a
int
);
create
table
kv
(
k
varchar
(
30
)
NOT
NULL
PRIMARY
KEY
,
v
varchar
(
50
));
let
$MYSQLD_DATADIR
=
`select @@datadir`
;
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v1
.
frm
$MYSQLD_DATADIR
/
test
/
v1
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v1badcheck
.
frm
$MYSQLD_DATADIR
/
test
/
v1badcheck
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v2
.
frm
$MYSQLD_DATADIR
/
test
/
v2
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v3
.
frm
$MYSQLD_DATADIR
/
test
/
v3
.
frm
flush
tables
;
--
replace_result
$MYSQLTEST_VARDIR
var
--
exec
$MYSQL_UPGRADE
--
force
2
>&
1
# "Phase 1/4: Fixing views" expected (without from_mysql)
show
create
view
v1
;
show
create
view
v2
;
show
create
view
v3
;
# Now force a mariadb version to be added
set
sql_log_bin
=
1
;
REPAIR
VIEW
v1
,
v2
;
REPAIR
VIEW
v1badcheck
;
REPAIR
NO_WRITE_TO_BINLOG
VIEW
v3
;
set
sql_log_bin
=
0
;
--
source
include
/
show_binlog_events
.
inc
--
replace_result
$MYSQLD_DATADIR
MYSQLD_DATADIR
eval
LOAD
DATA
INFILE
'$MYSQLD_DATADIR/test/v1.frm'
REPLACE
INTO
TABLE
kv
FIELDS
TERMINATED
BY
'='
;
SELECT
k
,
v
from
kv
where
k
in
(
'md5'
,
'algorithm'
);
SELECT
k
from
kv
where
k
=
'mariadb-version'
;
truncate
table
kv
;
--
replace_result
$MYSQLD_DATADIR
MYSQLD_DATADIR
eval
LOAD
DATA
INFILE
'$MYSQLD_DATADIR/test/v2.frm'
REPLACE
INTO
TABLE
kv
FIELDS
TERMINATED
BY
'='
;
SELECT
k
,
v
from
kv
where
k
in
(
'md5'
,
'algorithm'
);
SELECT
k
from
kv
where
k
=
'mariadb-version'
;
truncate
table
kv
;
--
replace_result
$MYSQLD_DATADIR
MYSQLD_DATADIR
eval
LOAD
DATA
INFILE
'$MYSQLD_DATADIR/test/v3.frm'
REPLACE
INTO
TABLE
kv
FIELDS
TERMINATED
BY
'='
;
SELECT
k
,
v
from
kv
where
k
in
(
'md5'
,
'algorithm'
);
SELECT
k
from
kv
where
k
=
'mariadb-version'
;
truncate
table
kv
;
--
replace_result
$MYSQLD_DATADIR
MYSQLD_DATADIR
eval
LOAD
DATA
INFILE
'$MYSQLD_DATADIR/test/v1badcheck.frm'
REPLACE
INTO
TABLE
kv
FIELDS
TERMINATED
BY
'='
;
SELECT
k
,
v
from
kv
where
k
in
(
'md5'
,
'algorithm'
);
SELECT
k
from
kv
where
k
=
'mariadb-version'
;
truncate
table
kv
;
--
disable_warnings
drop
view
if
exists
v1
,
v2
,
v3
,
v1badcheck
;
--
enable_warnings
# Make it look like a MySQL directory now
--
copy_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYI
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
MYI
--
copy_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYD
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
MYD
--
copy_file
$MYSQLD_DATADIR
/
mysql
/
event
.
frm
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
frm
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYI
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYD
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
event
.
MYI
$MYSQLD_DATADIR
/
mysql
/
event
.
MYI
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
event
.
MYD
$MYSQLD_DATADIR
/
mysql
/
event
.
MYD
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
event
.
frm
$MYSQLD_DATADIR
/
mysql
/
event
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v1
.
frm
$MYSQLD_DATADIR
/
test
/
v1
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v2
.
frm
$MYSQLD_DATADIR
/
test
/
v2
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v3
.
frm
$MYSQLD_DATADIR
/
test
/
v3
.
frm
flush
tables
;
create
algorithm
=
temptable
view
v4
as
select
a
from
t1
;
show
create
view
v1
;
show
create
view
v2
;
show
create
view
v3
;
show
create
view
v4
;
# here we test the fixing views from mysql to occur
--
replace_result
$MYSQLTEST_VARDIR
var
--
exec
$MYSQL_UPGRADE
--
force
2
>&
1
show
create
view
v1
;
show
create
view
v2
;
show
create
view
v3
;
show
create
view
v4
;
--
replace_result
$MYSQLD_DATADIR
MYSQLD_DATADIR
eval
LOAD
DATA
INFILE
'$MYSQLD_DATADIR/test/v1.frm'
REPLACE
INTO
TABLE
kv
FIELDS
TERMINATED
BY
'='
;
SELECT
k
,
v
from
kv
where
k
in
(
'md5'
,
'algorithm'
);
SELECT
k
from
kv
where
k
=
'mariadb-version'
;
truncate
table
kv
;
--
disable_warnings
drop
view
if
exists
v1
,
v2
,
v3
;
--
enable_warnings
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYI
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYD
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
event
.
MYI
$MYSQLD_DATADIR
/
mysql
/
event
.
MYI
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
event
.
MYD
$MYSQLD_DATADIR
/
mysql
/
event
.
MYD
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
event
.
frm
$MYSQLD_DATADIR
/
mysql
/
event
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v1
.
frm
$MYSQLD_DATADIR
/
test
/
v1
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v2
.
frm
$MYSQLD_DATADIR
/
test
/
v2
.
frm
--
copy_file
$MYSQL_TEST_DIR
/
std_data
/
mysql_upgrade
/
v3
.
frm
$MYSQLD_DATADIR
/
test
/
v3
.
frm
flush
tables
;
# check of binlog
--
exec
$MYSQL_CHECK
--
write
-
binlog
--
upgrade
-
views
=
FROM_MYSQL
--
skip
-
fix
-
tables
--
all
-
databases
2
>&
1
--
source
include
/
show_binlog_events
.
inc
# back to mariadb default
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYI
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
MYD
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
event
.
frm
--
copy_file
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
MYI
$MYSQLD_DATADIR
/
mysql
/
event
.
MYI
--
copy_file
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
MYD
$MYSQLD_DATADIR
/
mysql
/
event
.
MYD
--
copy_file
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
frm
$MYSQLD_DATADIR
/
mysql
/
event
.
frm
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
MYI
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
MYD
--
remove_file
$MYSQLD_DATADIR
/
mysql
/
ev_bk
.
frm
flush
tables
;
drop
table
if
exists
kv
;
drop
view
v1
,
v2
,
v3
,
v4
;
drop
table
t1
;
sql/lex.h
View file @
f9c02d7c
...
...
@@ -376,6 +376,7 @@ static SYMBOL symbols[] = {
{
"MULTIPOINT"
,
SYM
(
MULTIPOINT
)},
{
"MULTIPOLYGON"
,
SYM
(
MULTIPOLYGON
)},
{
"MUTEX"
,
SYM
(
MUTEX_SYM
)},
{
"MYSQL"
,
SYM
(
MYSQL_SYM
)},
{
"MYSQL_ERRNO"
,
SYM
(
MYSQL_ERRNO_SYM
)},
{
"NAME"
,
SYM
(
NAME_SYM
)},
{
"NAMES"
,
SYM
(
NAMES_SYM
)},
...
...
sql/sql_admin.cc
View file @
f9c02d7c
...
...
@@ -314,7 +314,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
HA_CHECK_OPT
*
),
int
(
handler
::*
operator_func
)(
THD
*
,
HA_CHECK_OPT
*
),
int
(
view_operator_func
)(
THD
*
,
TABLE_LIST
*
))
int
(
view_operator_func
)(
THD
*
,
TABLE_LIST
*
,
HA_CHECK_OPT
*
))
{
TABLE_LIST
*
table
;
SELECT_LEX
*
select
=
&
thd
->
lex
->
select_lex
;
...
...
@@ -380,7 +381,18 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
lex
->
query_tables_own_last
=
0
;
if
(
view_operator_func
==
NULL
)
{
table
->
required_type
=
FRMTYPE_TABLE
;
DBUG_ASSERT
(
!
lex
->
only_view
);
}
else
if
(
lex
->
only_view
)
{
table
->
required_type
=
FRMTYPE_VIEW
;
}
else
if
(
!
lex
->
only_view
&&
lex
->
sql_command
==
SQLCOM_REPAIR
)
{
table
->
required_type
=
FRMTYPE_TABLE
;
}
if
(
lex
->
sql_command
==
SQLCOM_CHECK
||
lex
->
sql_command
==
SQLCOM_REPAIR
||
...
...
@@ -506,9 +518,9 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
}
/*
CHECK
TABLE command is only command where VIEW allowed here and this
command use only temporary teble method for VIEWs resolving => there
can't be VIEW tree substitition of join view => if opening table
CHECK
/REPAIR TABLE command is only command where VIEW allowed here and
this command use only temporary table method for VIEWs resolving =>
there
can't be VIEW tree substitition of join view => if opening table
succeed then table->table will have real TABLE pointer as value (in
case of join view substitution table->table can be 0, but here it is
impossible)
...
...
@@ -521,7 +533,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
ER_CHECK_NO_SUCH_TABLE
,
ER
(
ER_CHECK_NO_SUCH_TABLE
));
/* if it was a view will check md5 sum */
if
(
table
->
view
&&
view_check
sum
(
thd
,
table
)
==
HA_ADMIN_WRONG_CHECKSUM
)
view_check
(
thd
,
table
,
check_opt
)
==
HA_ADMIN_WRONG_CHECKSUM
)
push_warning
(
thd
,
MYSQL_ERROR
::
WARN_LEVEL_WARN
,
ER_VIEW_CHECKSUM
,
ER
(
ER_VIEW_CHECKSUM
));
if
(
thd
->
stmt_da
->
is_error
()
&&
...
...
@@ -536,7 +548,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
if
(
table
->
view
)
{
DBUG_PRINT
(
"admin"
,
(
"calling view_operator_func"
));
result_code
=
(
*
view_operator_func
)(
thd
,
table
);
result_code
=
(
*
view_operator_func
)(
thd
,
table
,
check_opt
);
goto
send_result
;
}
...
...
@@ -1071,7 +1083,7 @@ bool Check_table_statement::execute(THD *thd)
res
=
mysql_admin_table
(
thd
,
first_table
,
&
m_lex
->
check_opt
,
"check"
,
lock_type
,
0
,
0
,
HA_OPEN_FOR_REPAIR
,
0
,
&
handler
::
ha_check
,
&
view_check
sum
);
&
handler
::
ha_check
,
&
view_check
);
m_lex
->
select_lex
.
table_list
.
first
=
first_table
;
m_lex
->
query_tables
=
first_table
;
...
...
@@ -1126,7 +1138,7 @@ bool Repair_table_statement::execute(THD *thd)
TL_WRITE
,
1
,
test
(
m_lex
->
check_opt
.
sql_flags
&
TT_USEFRM
),
HA_OPEN_FOR_REPAIR
,
&
prepare_for_repair
,
&
handler
::
ha_repair
,
0
);
&
handler
::
ha_repair
,
&
view_repair
);
/* ! we write after unlocking the table */
if
(
!
res
&&
!
m_lex
->
no_write_to_binlog
)
...
...
sql/sql_base.cc
View file @
f9c02d7c
...
...
@@ -643,7 +643,8 @@ found:
open_table_error
(
share
,
share
->
error
,
share
->
open_errno
,
share
->
errarg
);
DBUG_RETURN
(
0
);
}
if
(
share
->
is_view
&&
!
(
db_flags
&
OPEN_VIEW
))
if
((
share
->
is_view
&&
!
(
db_flags
&
OPEN_VIEW
))
||
(
!
share
->
is_view
&&
(
db_flags
&
OPEN_VIEW_ONLY
)))
{
open_table_error
(
share
,
1
,
ENOENT
,
0
);
DBUG_RETURN
(
0
);
...
...
@@ -3027,7 +3028,11 @@ retry_share:
mysql_mutex_lock
(
&
LOCK_open
);
if
(
!
(
share
=
get_table_share_with_discover
(
thd
,
table_list
,
key
,
key_length
,
OPEN_VIEW
,
key_length
,
(
OPEN_VIEW
|
((
table_list
->
required_type
==
FRMTYPE_VIEW
)
?
OPEN_VIEW_ONLY
:
0
)),
&
error
,
hash_value
)))
{
...
...
sql/sql_table.cc
View file @
f9c02d7c
...
...
@@ -28,7 +28,6 @@
#include "sql_base.h" // open_table_uncached, lock_table_names
#include "lock.h" // mysql_unlock_tables
#include "strfunc.h" // find_type2, find_set
#include "sql_view.h" // view_checksum
#include "sql_truncate.h" // regenerate_locked_table
#include "sql_partition.h" // mem_alloc_error,
// generate_partition_syntax,
...
...
sql/sql_view.cc
View file @
f9c02d7c
...
...
@@ -729,6 +729,26 @@ err:
}
static
void
make_view_filename
(
LEX_STRING
*
dir
,
char
*
dir_buff
,
size_t
dir_buff_len
,
LEX_STRING
*
path
,
char
*
path_buff
,
size_t
path_buff_len
,
LEX_STRING
*
file
,
TABLE_LIST
*
view
)
{
/* print file name */
dir
->
length
=
build_table_filename
(
dir_buff
,
dir_buff_len
-
1
,
view
->
db
,
""
,
""
,
0
);
dir
->
str
=
dir_buff
;
path
->
length
=
build_table_filename
(
path_buff
,
path_buff_len
-
1
,
view
->
db
,
view
->
table_name
,
reg_ext
,
0
);
path
->
str
=
path_buff
;
file
->
str
=
path
->
str
+
dir
->
length
;
file
->
length
=
path
->
length
-
dir
->
length
;
}
/* number of required parameters for making view */
static
const
int
required_view_parameters
=
15
;
...
...
@@ -791,6 +811,86 @@ static File_option view_parameters[]=
static
LEX_STRING
view_file_type
[]
=
{{(
char
*
)
STRING_WITH_LEN
(
"VIEW"
)
}};
int
mariadb_fix_view
(
THD
*
thd
,
TABLE_LIST
*
view
,
bool
wrong_checksum
,
bool
swap_alg
)
{
char
dir_buff
[
FN_REFLEN
+
1
],
path_buff
[
FN_REFLEN
+
1
];
LEX_STRING
dir
,
file
,
path
;
DBUG_ENTER
(
"mariadb_fix_view"
);
if
(
!
wrong_checksum
&&
view
->
mariadb_version
)
DBUG_RETURN
(
HA_ADMIN_OK
);
make_view_filename
(
&
dir
,
dir_buff
,
sizeof
(
dir_buff
),
&
path
,
path_buff
,
sizeof
(
path_buff
),
&
file
,
view
);
/* init timestamp */
if
(
!
view
->
timestamp
.
str
)
view
->
timestamp
.
str
=
view
->
timestamp_buffer
;
/* check old .frm */
{
char
path_buff
[
FN_REFLEN
];
LEX_STRING
path
;
File_parser
*
parser
;
path
.
str
=
path_buff
;
fn_format
(
path_buff
,
file
.
str
,
dir
.
str
,
""
,
MY_UNPACK_FILENAME
);
path
.
length
=
strlen
(
path_buff
);
if
(
access
(
path
.
str
,
F_OK
))
DBUG_RETURN
(
HA_ADMIN_INVALID
);
if
(
!
(
parser
=
sql_parse_prepare
(
&
path
,
thd
->
mem_root
,
0
)))
DBUG_RETURN
(
HA_ADMIN_INTERNAL_ERROR
);
if
(
!
parser
->
ok
()
||
!
is_equal
(
&
view_type
,
parser
->
type
()))
DBUG_RETURN
(
HA_ADMIN_INVALID
);
}
if
(
swap_alg
&&
view
->
algorithm
!=
VIEW_ALGORITHM_UNDEFINED
)
{
DBUG_ASSERT
(
view
->
algorithm
==
VIEW_ALGORITHM_MERGE
||
view
->
algorithm
==
VIEW_ALGORITHM_TMPTABLE
);
if
(
view
->
algorithm
==
VIEW_ALGORITHM_MERGE
)
view
->
algorithm
=
VIEW_ALGORITHM_TMPTABLE
;
else
view
->
algorithm
=
VIEW_ALGORITHM_MERGE
;
}
else
swap_alg
=
0
;
if
(
wrong_checksum
)
{
if
(
view
->
md5
.
length
!=
32
)
{
if
((
view
->
md5
.
str
=
(
char
*
)
thd
->
alloc
(
32
+
1
))
==
NULL
)
DBUG_RETURN
(
HA_ADMIN_FAILED
);
}
view
->
calc_md5
(
view
->
md5
.
str
);
view
->
md5
.
length
=
32
;
}
view
->
mariadb_version
=
MYSQL_VERSION_ID
;
if
(
sql_create_definition_file
(
&
dir
,
&
file
,
view_file_type
,
(
uchar
*
)
view
,
view_parameters
))
{
sql_print_error
(
"View '%-.192s'.'%-.192s': algorithm swap error."
,
view
->
db
,
view
->
table_name
);
DBUG_RETURN
(
HA_ADMIN_INTERNAL_ERROR
);
}
sql_print_information
(
"View '%-.192s'.'%-.192s': versioned to %llu%s%s"
,
view
->
db
,
view
->
table_name
,
view
->
mariadb_version
,
(
wrong_checksum
?
", and checksum corrected"
:
""
),
(
swap_alg
?
((
view
->
algorithm
==
VIEW_ALGORITHM_MERGE
)
?
", and algorithm swapped to 'MERGE'"
:
", and algorithm swapped to 'TEMPTABLE'"
)
:
""
));
DBUG_RETURN
(
HA_ADMIN_OK
);
}
/*
Register VIEW (write .frm & process .frm's history backups)
...
...
@@ -927,17 +1027,9 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
}
loop_out:
/* print file name */
dir
.
length
=
build_table_filename
(
dir_buff
,
sizeof
(
dir_buff
)
-
1
,
view
->
db
,
""
,
""
,
0
);
dir
.
str
=
dir_buff
;
path
.
length
=
build_table_filename
(
path_buff
,
sizeof
(
path_buff
)
-
1
,
view
->
db
,
view
->
table_name
,
reg_ext
,
0
);
path
.
str
=
path_buff
;
file
.
str
=
path
.
str
+
dir
.
length
;
file
.
length
=
path
.
length
-
dir
.
length
;
make_view_filename
(
&
dir
,
dir_buff
,
sizeof
(
dir_buff
),
&
path
,
path_buff
,
sizeof
(
path_buff
),
&
file
,
view
);
/* init timestamp */
if
(
!
view
->
timestamp
.
str
)
view
->
timestamp
.
str
=
view
->
timestamp_buffer
;
...
...
@@ -1063,7 +1155,7 @@ err:
SYNOPSIS
mysql_make_view()
thd Thread handle
r
thd Thread handle
parser parser object
table TABLE_LIST structure for filling
flags flags
...
...
@@ -1634,7 +1726,7 @@ err:
SYNOPSIS
mysql_drop_view()
thd - thread handle
r
thd - thread handle
views - views to delete
drop_mode - cascade/check
...
...
@@ -1755,7 +1847,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
SYNOPSIS
check_key_in_view()
thd thread handle
r
thd thread handle
view view for check with opened table
DESCRIPTION
...
...
@@ -1941,6 +2033,63 @@ int view_checksum(THD *thd, TABLE_LIST *view)
HA_ADMIN_OK
);
}
/**
Check view
@param thd thread handle
@param view view for check
@param check_opt check options
@retval HA_ADMIN_OK OK
@retval HA_ADMIN_NOT_IMPLEMENTED it is not VIEW
@retval HA_ADMIN_WRONG_CHECKSUM check sum is wrong
*/
int
view_check
(
THD
*
thd
,
TABLE_LIST
*
view
,
HA_CHECK_OPT
*
check_opt
)
{
int
res
;
DBUG_ENTER
(
"view_check"
);
if
((
res
=
view_checksum
(
thd
,
view
))
!=
HA_ADMIN_OK
)
DBUG_RETURN
(
res
);
if
(((
check_opt
->
sql_flags
&
TT_FOR_UPGRADE
)
&&
!
view
->
mariadb_version
))
{
push_warning_printf
(
thd
,
MYSQL_ERROR
::
WARN_LEVEL_NOTE
,
ER_TABLE_NEEDS_UPGRADE
,
ER
(
ER_TABLE_NEEDS_UPGRADE
),
view
->
db
,
view
->
table_name
);
DBUG_RETURN
(
HA_ADMIN_NEEDS_UPGRADE
);
}
DBUG_RETURN
(
HA_ADMIN_OK
);
}
/**
Repair view
@param thd thread handle
@param view view for check
@param check_opt check options
@retval HA_ADMIN_OK OK
@retval HA_ADMIN_NOT_IMPLEMENTED it is not VIEW
@retval HA_ADMIN_WRONG_CHECKSUM check sum is wrong
*/
int
view_repair
(
THD
*
thd
,
TABLE_LIST
*
view
,
HA_CHECK_OPT
*
check_opt
)
{
DBUG_ENTER
(
"view_repair"
);
bool
swap_alg
=
(
check_opt
->
sql_flags
&
TT_FROM_MYSQL
);
bool
wrong_checksum
=
view_checksum
(
thd
,
view
);
int
ret
;
if
(
wrong_checksum
||
swap_alg
||
(
!
view
->
mariadb_version
))
{
ret
=
mariadb_fix_view
(
thd
,
view
,
wrong_checksum
,
swap_alg
);
DBUG_RETURN
(
ret
);
}
DBUG_RETURN
(
HA_ADMIN_OK
);
}
/*
rename view
...
...
sql/sql_view.h
View file @
f9c02d7c
...
...
@@ -44,6 +44,8 @@ bool check_key_in_view(THD *thd, TABLE_LIST * view);
bool
insert_view_fields
(
THD
*
thd
,
List
<
Item
>
*
list
,
TABLE_LIST
*
view
);
int
view_checksum
(
THD
*
thd
,
TABLE_LIST
*
view
);
int
view_check
(
THD
*
thd
,
TABLE_LIST
*
view
,
HA_CHECK_OPT
*
check_opt
);
int
view_repair
(
THD
*
thd
,
TABLE_LIST
*
view
,
HA_CHECK_OPT
*
check_opt
);
extern
TYPELIB
updatable_views_with_limit_typelib
;
...
...
sql/sql_yacc.yy
View file @
f9c02d7c
...
...
@@ -1145,6 +1145,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token MULTIPOINT
%token MULTIPOLYGON
%token MUTEX_SYM
%token MYSQL_SYM
%token MYSQL_ERRNO_SYM
%token NAMES_SYM /* SQL-2003-N */
%token NAME_SYM /* SQL-2003-N */
...
...
@@ -7191,7 +7192,7 @@ opt_checksum_type:
;
repair:
REPAIR opt_no_write_to_binlog table_or_
tables
REPAIR opt_no_write_to_binlog table_or_
view
{
LEX *lex=Lex;
lex->sql_command = SQLCOM_REPAIR;
...
...
@@ -7204,6 +7205,15 @@ repair:
table_list opt_mi_repair_type
{
LEX* lex= thd->lex;
if ((lex->only_view &&
((lex->check_opt.flags & (T_QUICK | T_EXTEND)) ||
(lex->check_opt.sql_flags & TT_USEFRM))) ||
(!lex->only_view &&
(lex->check_opt.sql_flags & TT_FROM_MYSQL)))
{
my_parse_error(ER(ER_SYNTAX_ERROR));
MYSQL_YYABORT;
}
DBUG_ASSERT(!lex->m_stmt);
lex->m_stmt= new (thd->mem_root) Repair_table_statement(lex);
if (lex->m_stmt == NULL)
...
...
@@ -7225,6 +7235,7 @@ mi_repair_type:
QUICK { Lex->check_opt.flags|= T_QUICK; }
| EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
| USE_FRM { Lex->check_opt.sql_flags|= TT_USEFRM; }
| FROM MYSQL_SYM { Lex->check_opt.sql_flags|= TT_FROM_MYSQL; }
;
analyze:
...
...
@@ -7257,7 +7268,7 @@ binlog_base64_event:
;
check:
CHECK_SYM table_or_
tables
CHECK_SYM table_or_
view
{
LEX *lex=Lex;
...
...
@@ -7275,6 +7286,13 @@ check:
table_list opt_mi_check_type
{
LEX* lex= thd->lex;
if (lex->only_view &&
(lex->check_opt.flags & (T_QUICK | T_FAST | T_EXTEND |
T_CHECK_ONLY_CHANGED)))
{
my_parse_error(ER(ER_SYNTAX_ERROR));
MYSQL_YYABORT;
}
DBUG_ASSERT(!lex->m_stmt);
lex->m_stmt= new (thd->mem_root) Check_table_statement(lex);
if (lex->m_stmt == NULL)
...
...
@@ -7382,6 +7400,7 @@ keycache:
LEX *lex=Lex;
lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
lex->ident= $6;
lex->only_view= FALSE;
}
;
...
...
@@ -7426,6 +7445,7 @@ preload:
LEX *lex=Lex;
lex->sql_command=SQLCOM_PRELOAD_KEYS;
lex->alter_info.reset();
lex->only_view= FALSE;
}
preload_list_or_parts
{}
...
...
@@ -13187,6 +13207,7 @@ keyword_sp:
| MULTIPOINT {}
| MULTIPOLYGON {}
| MUTEX_SYM {}
| MYSQL_SYM {}
| MYSQL_ERRNO_SYM {}
| NAME_SYM {}
| NAMES_SYM {}
...
...
@@ -13786,7 +13807,18 @@ lock:
table_or_tables:
TABLE_SYM
{ Lex->only_view= FALSE; }
| TABLES
{ Lex->only_view= FALSE; }
;
table_or_view:
TABLE_SYM
{ Lex->only_view= FALSE; }
| TABLES
{ Lex->only_view= FALSE; }
| VIEW_SYM
{ Lex->only_view= TRUE; }
;
table_lock_list:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment