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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
13f249a0
Commit
13f249a0
authored
Oct 28, 2004
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VIEW support for CHECK TABLE command (WL#1984)
parent
5bf7a8c3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
13 deletions
+110
-13
mysql-test/r/view.result
mysql-test/r/view.result
+15
-0
mysql-test/t/view.test
mysql-test/t/view.test
+10
-0
sql/handler.h
sql/handler.h
+1
-0
sql/sql_table.cc
sql/sql_table.cc
+54
-12
sql/sql_view.cc
sql/sql_view.cc
+28
-1
sql/sql_view.h
sql/sql_view.h
+2
-0
No files found.
mysql-test/r/view.result
View file @
13f249a0
...
@@ -1626,3 +1626,18 @@ Field 3,'Field 4|
...
@@ -1626,3 +1626,18 @@ Field 3,'Field 4|
|Field 6| | 'Field 7'|
|Field 6| | 'Field 7'|
drop view v1;
drop view v1;
drop table t1;
drop table t1;
create table t1 (a int);
create view v1 as select * from t1;
check table t1,v1;
Table Op Msg_type Msg_text
test.t1 check status OK
test.v1 check status OK
check table v1,t1;
Table Op Msg_type Msg_text
test.v1 check status OK
test.t1 check status OK
drop table t1;
check table v1;
Table Op Msg_type Msg_text
test.v1 check error View 'test.v1' references invalid table(s) or column(s)
drop view v1;
mysql-test/t/view.test
View file @
13f249a0
...
@@ -1554,3 +1554,13 @@ select concat('|',a,'|'), concat('|',b,'|') from v1;
...
@@ -1554,3 +1554,13 @@ select concat('|',a,'|'), concat('|',b,'|') from v1;
drop
view
v1
;
drop
view
v1
;
drop
table
t1
;
drop
table
t1
;
#
# CHECK TABLE with VIEW
#
create
table
t1
(
a
int
);
create
view
v1
as
select
*
from
t1
;
check
table
t1
,
v1
;
check
table
v1
,
t1
;
drop
table
t1
;
check
table
v1
;
drop
view
v1
;
sql/handler.h
View file @
13f249a0
...
@@ -44,6 +44,7 @@
...
@@ -44,6 +44,7 @@
#define HA_ADMIN_INVALID -5
#define HA_ADMIN_INVALID -5
#define HA_ADMIN_REJECT -6
#define HA_ADMIN_REJECT -6
#define HA_ADMIN_TRY_ALTER -7
#define HA_ADMIN_TRY_ALTER -7
#define HA_ADMIN_WRONG_CHECKSUM -8
/* Bits in table_flags() to show what database can do */
/* Bits in table_flags() to show what database can do */
#define HA_READ_RND_SAME (1 << 0)
/* can switch index during the scan
#define HA_READ_RND_SAME (1 << 0)
/* can switch index during the scan
...
...
sql/sql_table.cc
View file @
13f249a0
...
@@ -1731,12 +1731,15 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
...
@@ -1731,12 +1731,15 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
int
(
*
prepare_func
)(
THD
*
,
TABLE_LIST
*
,
int
(
*
prepare_func
)(
THD
*
,
TABLE_LIST
*
,
HA_CHECK_OPT
*
),
HA_CHECK_OPT
*
),
int
(
handler
::*
operator_func
)
int
(
handler
::*
operator_func
)
(
THD
*
,
HA_CHECK_OPT
*
))
(
THD
*
,
HA_CHECK_OPT
*
),
int
(
view_operator_func
)
(
THD
*
,
TABLE_LIST
*
))
{
{
TABLE_LIST
*
table
;
TABLE_LIST
*
table
,
*
next_global_table
;
List
<
Item
>
field_list
;
List
<
Item
>
field_list
;
Item
*
item
;
Item
*
item
;
Protocol
*
protocol
=
thd
->
protocol
;
Protocol
*
protocol
=
thd
->
protocol
;
int
result_code
;
DBUG_ENTER
(
"mysql_admin_table"
);
DBUG_ENTER
(
"mysql_admin_table"
);
field_list
.
push_back
(
item
=
new
Item_empty_string
(
"Table"
,
NAME_LEN
*
2
));
field_list
.
push_back
(
item
=
new
Item_empty_string
(
"Table"
,
NAME_LEN
*
2
));
...
@@ -1760,7 +1763,18 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
...
@@ -1760,7 +1763,18 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
strxmov
(
table_name
,
db
?
db
:
""
,
"."
,
table
->
real_name
,
NullS
);
strxmov
(
table_name
,
db
?
db
:
""
,
"."
,
table
->
real_name
,
NullS
);
thd
->
open_options
|=
extra_open_options
;
thd
->
open_options
|=
extra_open_options
;
table
->
table
=
open_ltable
(
thd
,
table
,
lock_type
);
table
->
lock_type
=
lock_type
;
/* open only one table from local list of command */
next_global_table
=
table
->
next_global
;
table
->
next_global
=
0
;
open_and_lock_tables
(
thd
,
table
);
table
->
next_global
=
next_global_table
;
/* if view are unsupported */
if
(
table
->
view
&&
!
view_operator_func
)
{
result_code
=
HA_ADMIN_NOT_IMPLEMENTED
;
goto
send_result
;
}
thd
->
open_options
&=
~
extra_open_options
;
thd
->
open_options
&=
~
extra_open_options
;
if
(
prepare_func
)
if
(
prepare_func
)
...
@@ -1772,8 +1786,13 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
...
@@ -1772,8 +1786,13 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
}
}
}
}
/*
for this command used only temporary table method (without
filling tables), so if opening succeed, table will be opened
*/
if
(
!
table
->
table
)
if
(
!
table
->
table
)
{
{
char
buf
[
ERRMSGSIZE
+
25
];
const
char
*
err_msg
;
const
char
*
err_msg
;
protocol
->
prepare_for_resend
();
protocol
->
prepare_for_resend
();
protocol
->
store
(
table_name
,
system_charset_info
);
protocol
->
store
(
table_name
,
system_charset_info
);
...
@@ -1781,12 +1800,26 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
...
@@ -1781,12 +1800,26 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
protocol
->
store
(
"error"
,
5
,
system_charset_info
);
protocol
->
store
(
"error"
,
5
,
system_charset_info
);
if
(
!
(
err_msg
=
thd
->
net
.
last_error
))
if
(
!
(
err_msg
=
thd
->
net
.
last_error
))
err_msg
=
ER
(
ER_CHECK_NO_SUCH_TABLE
);
err_msg
=
ER
(
ER_CHECK_NO_SUCH_TABLE
);
/* if it was a view will check md5 sum */
if
(
table
->
view
&&
view_checksum
(
thd
,
table
)
==
HA_ADMIN_WRONG_CHECKSUM
)
{
strxmov
(
buf
,
"View checksum failed and "
,
err_msg
,
NullS
);
err_msg
=
(
const
char
*
)
buf
;
}
protocol
->
store
(
err_msg
,
system_charset_info
);
protocol
->
store
(
err_msg
,
system_charset_info
);
thd
->
clear_error
();
thd
->
clear_error
();
if
(
protocol
->
write
())
if
(
protocol
->
write
())
goto
err
;
goto
err
;
continue
;
continue
;
}
}
if
(
table
->
view
)
{
result_code
=
(
*
view_operator_func
)(
thd
,
table
);
goto
send_result
;
}
table
->
table
->
pos_in_table_list
=
table
;
table
->
table
->
pos_in_table_list
=
table
;
if
((
table
->
table
->
db_stat
&
HA_READ_ONLY
)
&&
open_for_modify
)
if
((
table
->
table
->
db_stat
&
HA_READ_ONLY
)
&&
open_for_modify
)
{
{
...
@@ -1825,7 +1858,10 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
...
@@ -1825,7 +1858,10 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
open_for_modify
=
0
;
open_for_modify
=
0
;
}
}
int
result_code
=
(
table
->
table
->
file
->*
operator_func
)(
thd
,
check_opt
);
result_code
=
(
table
->
table
->
file
->*
operator_func
)(
thd
,
check_opt
);
send_result:
thd
->
clear_error
();
// these errors shouldn't get client
thd
->
clear_error
();
// these errors shouldn't get client
protocol
->
prepare_for_resend
();
protocol
->
prepare_for_resend
();
protocol
->
store
(
table_name
,
system_charset_info
);
protocol
->
store
(
table_name
,
system_charset_info
);
...
@@ -1901,6 +1937,12 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
...
@@ -1901,6 +1937,12 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
table
->
next_global
=
save_next_global
;
table
->
next_global
=
save_next_global
;
goto
send_result_message
;
goto
send_result_message
;
}
}
case
HA_ADMIN_WRONG_CHECKSUM
:
{
protocol
->
store
(
"note"
,
4
,
system_charset_info
);
protocol
->
store
(
"Checksum error"
,
14
,
system_charset_info
);
break
;
}
default:
// Probably HA_ADMIN_INTERNAL_ERROR
default:
// Probably HA_ADMIN_INTERNAL_ERROR
protocol
->
store
(
"error"
,
5
,
system_charset_info
);
protocol
->
store
(
"error"
,
5
,
system_charset_info
);
...
@@ -1941,7 +1983,7 @@ bool mysql_backup_table(THD* thd, TABLE_LIST* table_list)
...
@@ -1941,7 +1983,7 @@ bool mysql_backup_table(THD* thd, TABLE_LIST* table_list)
DBUG_ENTER
(
"mysql_backup_table"
);
DBUG_ENTER
(
"mysql_backup_table"
);
DBUG_RETURN
(
mysql_admin_table
(
thd
,
table_list
,
0
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
table_list
,
0
,
"backup"
,
TL_READ
,
0
,
0
,
0
,
"backup"
,
TL_READ
,
0
,
0
,
0
,
&
handler
::
backup
));
&
handler
::
backup
,
0
));
}
}
...
@@ -1951,7 +1993,7 @@ bool mysql_restore_table(THD* thd, TABLE_LIST* table_list)
...
@@ -1951,7 +1993,7 @@ bool mysql_restore_table(THD* thd, TABLE_LIST* table_list)
DBUG_RETURN
(
mysql_admin_table
(
thd
,
table_list
,
0
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
table_list
,
0
,
"restore"
,
TL_WRITE
,
1
,
0
,
"restore"
,
TL_WRITE
,
1
,
0
,
&
prepare_for_restore
,
&
prepare_for_restore
,
&
handler
::
restore
));
&
handler
::
restore
,
0
));
}
}
...
@@ -1961,7 +2003,7 @@ bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
...
@@ -1961,7 +2003,7 @@ bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
"repair"
,
TL_WRITE
,
1
,
HA_OPEN_FOR_REPAIR
,
"repair"
,
TL_WRITE
,
1
,
HA_OPEN_FOR_REPAIR
,
&
prepare_for_repair
,
&
prepare_for_repair
,
&
handler
::
repair
));
&
handler
::
repair
,
0
));
}
}
...
@@ -1970,7 +2012,7 @@ bool mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
...
@@ -1970,7 +2012,7 @@ bool mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
DBUG_ENTER
(
"mysql_optimize_table"
);
DBUG_ENTER
(
"mysql_optimize_table"
);
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
"optimize"
,
TL_WRITE
,
1
,
0
,
0
,
"optimize"
,
TL_WRITE
,
1
,
0
,
0
,
&
handler
::
optimize
));
&
handler
::
optimize
,
0
));
}
}
...
@@ -2006,7 +2048,7 @@ bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
...
@@ -2006,7 +2048,7 @@ bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
check_opt
.
key_cache
=
key_cache
;
check_opt
.
key_cache
=
key_cache
;
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
&
check_opt
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
&
check_opt
,
"assign_to_keycache"
,
TL_READ_NO_INSERT
,
0
,
"assign_to_keycache"
,
TL_READ_NO_INSERT
,
0
,
0
,
0
,
&
handler
::
assign_to_keycache
));
0
,
0
,
&
handler
::
assign_to_keycache
,
0
));
}
}
...
@@ -2067,7 +2109,7 @@ bool mysql_preload_keys(THD* thd, TABLE_LIST* tables)
...
@@ -2067,7 +2109,7 @@ bool mysql_preload_keys(THD* thd, TABLE_LIST* tables)
DBUG_ENTER
(
"mysql_preload_keys"
);
DBUG_ENTER
(
"mysql_preload_keys"
);
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
0
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
0
,
"preload_keys"
,
TL_READ
,
0
,
0
,
0
,
"preload_keys"
,
TL_READ
,
0
,
0
,
0
,
&
handler
::
preload_keys
));
&
handler
::
preload_keys
,
0
));
}
}
...
@@ -2232,7 +2274,7 @@ bool mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
...
@@ -2232,7 +2274,7 @@ bool mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
DBUG_ENTER
(
"mysql_analyze_table"
);
DBUG_ENTER
(
"mysql_analyze_table"
);
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
"analyze"
,
lock_type
,
1
,
0
,
0
,
"analyze"
,
lock_type
,
1
,
0
,
0
,
&
handler
::
analyze
));
&
handler
::
analyze
,
0
));
}
}
...
@@ -2248,7 +2290,7 @@ bool mysql_check_table(THD* thd, TABLE_LIST* tables,HA_CHECK_OPT* check_opt)
...
@@ -2248,7 +2290,7 @@ bool mysql_check_table(THD* thd, TABLE_LIST* tables,HA_CHECK_OPT* check_opt)
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
DBUG_RETURN
(
mysql_admin_table
(
thd
,
tables
,
check_opt
,
"check"
,
lock_type
,
"check"
,
lock_type
,
0
,
HA_OPEN_FOR_REPAIR
,
0
,
0
,
HA_OPEN_FOR_REPAIR
,
0
,
&
handler
::
check
));
&
handler
::
check
,
&
view_checksum
));
}
}
/* table_list should contain just one table */
/* table_list should contain just one table */
...
...
sql/sql_view.cc
View file @
13f249a0
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
#include "parse_file.h"
#include "parse_file.h"
#include "sp.h"
#include "sp.h"
#define MD5_BUFF_LENGTH 33
static
int
mysql_register_view
(
THD
*
thd
,
TABLE_LIST
*
view
,
static
int
mysql_register_view
(
THD
*
thd
,
TABLE_LIST
*
view
,
enum_view_create_mode
mode
);
enum_view_create_mode
mode
);
...
@@ -381,7 +383,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
...
@@ -381,7 +383,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
{
{
char
buff
[
4096
];
char
buff
[
4096
];
String
str
(
buff
,(
uint32
)
sizeof
(
buff
),
system_charset_info
);
String
str
(
buff
,(
uint32
)
sizeof
(
buff
),
system_charset_info
);
char
md5
[
33
];
char
md5
[
MD5_BUFF_LENGTH
];
bool
can_be_merged
;
bool
can_be_merged
;
char
dir_buff
[
FN_REFLEN
],
file_buff
[
FN_REFLEN
];
char
dir_buff
[
FN_REFLEN
],
file_buff
[
FN_REFLEN
];
LEX_STRING
dir
,
file
;
LEX_STRING
dir
,
file
;
...
@@ -1036,3 +1038,28 @@ void insert_view_fields(List<Item> *list, TABLE_LIST *view)
...
@@ -1036,3 +1038,28 @@ void insert_view_fields(List<Item> *list, TABLE_LIST *view)
}
}
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
}
}
/*
checking view md5 check suum
SINOPSYS
view_checksum()
thd threar handler
view view for check
RETUIRN
HA_ADMIN_OK OK
HA_ADMIN_NOT_IMPLEMENTED it is not VIEW
HA_ADMIN_WRONG_CHECKSUM check sum is wrong
*/
int
view_checksum
(
THD
*
thd
,
TABLE_LIST
*
view
)
{
char
md5
[
MD5_BUFF_LENGTH
];
if
(
!
view
->
view
||
view
->
md5
.
length
!=
32
)
return
HA_ADMIN_NOT_IMPLEMENTED
;
view
->
calc_md5
(
md5
);
return
(
strncmp
(
md5
,
view
->
md5
.
str
,
32
)
?
HA_ADMIN_WRONG_CHECKSUM
:
HA_ADMIN_OK
);
}
sql/sql_view.h
View file @
13f249a0
...
@@ -29,6 +29,8 @@ void insert_view_fields(List<Item> *list, TABLE_LIST *view);
...
@@ -29,6 +29,8 @@ void insert_view_fields(List<Item> *list, TABLE_LIST *view);
frm_type_enum
mysql_frm_type
(
char
*
path
);
frm_type_enum
mysql_frm_type
(
char
*
path
);
int
view_checksum
(
THD
*
thd
,
TABLE_LIST
*
view
);
extern
TYPELIB
updatable_views_with_limit_typelib
;
extern
TYPELIB
updatable_views_with_limit_typelib
;
#define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)
#define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)
...
...
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