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
425857f5
Commit
425857f5
authored
Sep 08, 2004
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test of updating and fetching from the same table check (BUG##5157)
parent
5d3f95b1
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
171 additions
and
32 deletions
+171
-32
mysql-test/r/lowercase_view.result
mysql-test/r/lowercase_view.result
+14
-0
mysql-test/r/view.result
mysql-test/r/view.result
+12
-0
mysql-test/t/lowercase_view.test
mysql-test/t/lowercase_view.test
+23
-1
mysql-test/t/view.test
mysql-test/t/view.test
+18
-0
sql/mysql_priv.h
sql/mysql_priv.h
+1
-0
sql/sql_base.cc
sql/sql_base.cc
+68
-4
sql/sql_delete.cc
sql/sql_delete.cc
+1
-2
sql/sql_insert.cc
sql/sql_insert.cc
+1
-2
sql/sql_parse.cc
sql/sql_parse.cc
+22
-19
sql/sql_update.cc
sql/sql_update.cc
+2
-3
sql/sql_view.cc
sql/sql_view.cc
+1
-1
sql/table.h
sql/table.h
+8
-0
No files found.
mysql-test/r/lowercase_view.result
View file @
425857f5
drop table if exists t1Aa,t2Aa,v1Aa,v2Aa;
drop view if exists t1Aa,t2Aa,v1Aa,v2Aa;
drop database if exists MySQLTest;
create database MySQLTest;
use MySQLTest;
...
...
@@ -8,3 +10,15 @@ Table Create Table
vie CREATE VIEW `mysqltest`.`vie` AS select `mysqltest`.`tab`.`Field` AS `Field` from `mysqltest`.`tab`
drop database MySQLTest;
use test;
create table t1Aa (col1 int);
create table t2Aa (col1 int);
create view v1Aa as select * from t1Aa;
create view v2Aa as select * from v1Aa;
update v2aA set col1 = (select max(col1) from v1aA);
ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause
delete from v2aA where col1 = (select max(col1) from v1aA);
ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause
insert into v2aA values ((select max(col1) from v1aA));
ERROR HY000: You can't specify target table 'v2aa' for update in FROM clause
drop view v2Aa,v1Aa;
drop table t1Aa,t2Aa;
mysql-test/r/view.result
View file @
425857f5
...
...
@@ -1270,3 +1270,15 @@ s1
7
drop view v1;
drop table t1;
create table t1 (col1 int);
create table t2 (col1 int);
create view v1 as select * from t1;
create view v2 as select * from v1;
update v2 set col1 = (select max(col1) from v1);
ERROR HY000: You can't specify target table 'v2' for update in FROM clause
delete from v2 where col1 = (select max(col1) from v1);
ERROR HY000: You can't specify target table 'v2' for update in FROM clause
insert into v2 values ((select max(col1) from v1));
ERROR HY000: You can't specify target table 'v2' for update in FROM clause
drop view v2,v1;
drop table t1,t2;
mysql-test/t/lowercase_view.test
View file @
425857f5
--
disable_warnings
drop
table
if
exists
t1Aa
,
t2Aa
,
v1Aa
,
v2Aa
;
drop
view
if
exists
t1Aa
,
t2Aa
,
v1Aa
,
v2Aa
;
drop
database
if
exists
MySQLTest
;
--
enable_warnings
#
# different cases in VIEW
#
create
database
MySQLTest
;
use
MySQLTest
;
create
table
TaB
(
Field
int
);
...
...
@@ -10,3 +14,21 @@ create view ViE as select * from TAb;
show
create
table
VIe
;
drop
database
MySQLTest
;
use
test
;
#
# test of updating and fetching from the same table check
#
create
table
t1Aa
(
col1
int
);
create
table
t2Aa
(
col1
int
);
create
view
v1Aa
as
select
*
from
t1Aa
;
create
view
v2Aa
as
select
*
from
v1Aa
;
--
error
1093
update
v2aA
set
col1
=
(
select
max
(
col1
)
from
v1aA
);
#update v2aA,t2aA set v2aA.col1 = (select max(col1) from v1aA) where v2aA.col1 = t2aA.col1;
--
error
1093
delete
from
v2aA
where
col1
=
(
select
max
(
col1
)
from
v1aA
);
#delete v2aA from v2aA,t2aA where (select max(col1) from v1aA) > 0 and v2aA.col1 = t2aA.col1;
--
error
1093
insert
into
v2aA
values
((
select
max
(
col1
)
from
v1aA
));
drop
view
v2Aa
,
v1Aa
;
drop
table
t1Aa
,
t2Aa
;
mysql-test/t/view.test
View file @
425857f5
...
...
@@ -1230,3 +1230,21 @@ insert into v1 values (1) on duplicate key update s1 = 7;
select
*
from
t1
;
drop
view
v1
;
drop
table
t1
;
#
# test of updating and fetching from the same table check
#
create
table
t1
(
col1
int
);
create
table
t2
(
col1
int
);
create
view
v1
as
select
*
from
t1
;
create
view
v2
as
select
*
from
v1
;
--
error
1093
update
v2
set
col1
=
(
select
max
(
col1
)
from
v1
);
#update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
--
error
1093
delete
from
v2
where
col1
=
(
select
max
(
col1
)
from
v1
);
#delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1;
--
error
1093
insert
into
v2
values
((
select
max
(
col1
)
from
v1
));
drop
view
v2
,
v1
;
drop
table
t1
,
t2
;
sql/mysql_priv.h
View file @
425857f5
...
...
@@ -772,6 +772,7 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
uint
offset_to_list
,
const
char
*
db_name
,
const
char
*
table_name
);
bool
unique_table
(
TABLE_LIST
*
table
,
TABLE_LIST
*
table_list
);
TABLE
**
find_temporary_table
(
THD
*
thd
,
const
char
*
db
,
const
char
*
table_name
);
bool
close_temporary_table
(
THD
*
thd
,
const
char
*
db
,
const
char
*
table_name
);
void
close_temporary
(
TABLE
*
table
,
bool
delete_table
=
1
);
...
...
sql/sql_base.cc
View file @
425857f5
...
...
@@ -574,16 +574,80 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
const
char
*
db_name
,
const
char
*
table_name
)
{
for
(;
table
;
table
=
*
(
TABLE_LIST
**
)
((
char
*
)
table
+
offset
)
)
if
(
lower_case_table_names
)
{
if
(
!
strcmp
(
table
->
db
,
db_name
)
&&
!
strcmp
(
table
->
real_name
,
table_name
))
break
;
for
(;
table
;
table
=
*
(
TABLE_LIST
**
)
((
char
*
)
table
+
offset
))
{
if
((
!
strcmp
(
table
->
db
,
db_name
)
&&
!
strcmp
(
table
->
real_name
,
table_name
))
||
(
table
->
view
&&
!
my_strcasecmp
(
table_alias_charset
,
table
->
table
->
table_cache_key
,
db_name
)
&&
!
my_strcasecmp
(
table_alias_charset
,
table
->
table
->
table_name
,
table_name
)))
break
;
}
}
else
{
for
(;
table
;
table
=
*
(
TABLE_LIST
**
)
((
char
*
)
table
+
offset
))
{
if
((
!
strcmp
(
table
->
db
,
db_name
)
&&
!
strcmp
(
table
->
real_name
,
table_name
))
||
(
table
->
view
&&
!
strcmp
(
table
->
table
->
table_cache_key
,
db_name
)
&&
!
strcmp
(
table
->
table
->
table_name
,
table_name
)))
break
;
}
}
return
table
;
}
/*
Test that table is unique
SYNOPSIS
unique_table()
table table which should be chaked
table_list list of tables
RETURN
TRUE test failed
FALSE table is unique
*/
bool
unique_table
(
TABLE_LIST
*
table
,
TABLE_LIST
*
table_list
)
{
char
d_name_buff
[
MAX_ALIAS_NAME
],
t_name_buff
[
MAX_ALIAS_NAME
];
const
char
*
d_name
=
table
->
db
,
*
t_name
=
table
->
real_name
;
if
(
table
->
view
)
{
/* it is view and table opened */
if
(
lower_case_table_names
)
{
strmov
(
t_name_buff
,
table
->
table
->
table_name
);
my_casedn_str
(
files_charset_info
,
t_name_buff
);
t_name
=
t_name_buff
;
strmov
(
d_name_buff
,
table
->
table
->
table_cache_key
);
my_casedn_str
(
files_charset_info
,
d_name_buff
);
d_name
=
d_name_buff
;
}
else
{
d_name
=
table
->
table
->
table_cache_key
;
t_name
=
table
->
table
->
table_name
;
}
if
(
d_name
==
0
)
{
/* it's temporary table */
return
FALSE
;
}
}
return
find_table_in_global_list
(
table_list
,
d_name
,
t_name
);
}
TABLE
**
find_temporary_table
(
THD
*
thd
,
const
char
*
db
,
const
char
*
table_name
)
{
char
key
[
MAX_DBKEY_LENGTH
];
...
...
sql/sql_delete.cc
View file @
425857f5
...
...
@@ -282,8 +282,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
my_error
(
ER_NON_UPDATABLE_TABLE
,
MYF
(
0
),
table_list
->
alias
,
"DELETE"
);
DBUG_RETURN
(
-
1
);
}
if
(
find_table_in_global_list
(
table_list
->
next_global
,
table_list
->
db
,
table_list
->
real_name
))
if
(
unique_table
(
table_list
,
table_list
->
next_independent
()))
{
my_error
(
ER_UPDATE_TABLE_USED
,
MYF
(
0
),
table_list
->
real_name
);
DBUG_RETURN
(
-
1
);
...
...
sql/sql_insert.cc
View file @
425857f5
...
...
@@ -599,8 +599,7 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
setup_fields
(
thd
,
0
,
table_list
,
update_values
,
0
,
0
,
0
))))
DBUG_RETURN
(
-
1
);
if
(
find_table_in_global_list
(
table_list
->
next_global
,
table_list
->
db
,
table_list
->
real_name
))
if
(
unique_table
(
table_list
,
table_list
->
next_independent
()))
{
my_error
(
ER_UPDATE_TABLE_USED
,
MYF
(
0
),
table_list
->
real_name
);
DBUG_RETURN
(
-
1
);
...
...
sql/sql_parse.cc
View file @
425857f5
...
...
@@ -2393,17 +2393,7 @@ mysql_execute_command(THD *thd)
if
(
select_lex
->
item_list
.
elements
)
// With select
{
select_result
*
result
;
/*
Is table which we are changing used somewhere in other parts
of query
*/
if
(
!
(
lex
->
create_info
.
options
&
HA_LEX_CREATE_TMP_TABLE
)
&&
find_table_in_global_list
(
select_tables
,
create_table
->
db
,
create_table
->
real_name
))
{
net_printf
(
thd
,
ER_UPDATE_TABLE_USED
,
create_table
->
real_name
);
goto
create_error
;
}
if
(
select_tables
&&
check_table_access
(
thd
,
SELECT_ACL
,
select_tables
,
0
))
goto
create_error
;
// Error message is given
...
...
@@ -2412,6 +2402,17 @@ mysql_execute_command(THD *thd)
if
(
!
(
res
=
open_and_lock_tables
(
thd
,
select_tables
)))
{
/*
Is table which we are changing used somewhere in other parts
of query
*/
if
(
!
(
lex
->
create_info
.
options
&
HA_LEX_CREATE_TMP_TABLE
)
&&
unique_table
(
create_table
,
select_tables
))
{
net_printf
(
thd
,
ER_UPDATE_TABLE_USED
,
create_table
->
real_name
);
goto
create_error
;
}
if
((
result
=
new
select_create
(
create_table
,
&
lex
->
create_info
,
lex
->
create_list
,
...
...
@@ -2767,16 +2768,18 @@ mysql_execute_command(THD *thd)
select_result
*
result
;
unit
->
set_limit
(
select_lex
,
select_lex
);
// is table which we are changing used somewhere in other parts of query
if
(
find_table_in_global_list
(
all_tables
->
next_global
,
first_table
->
db
,
first_table
->
real_name
))
{
/* Using same table for INSERT and SELECT */
select_lex
->
options
|=
OPTION_BUFFER_RESULT
;
}
if
(
!
(
res
=
open_and_lock_tables
(
thd
,
all_tables
)))
{
/*
Is table which we are changing used somewhere in other parts of
query
*/
if
(
unique_table
(
first_table
,
all_tables
->
next_independent
()))
{
/* Using same table for INSERT and SELECT */
select_lex
->
options
|=
OPTION_BUFFER_RESULT
;
}
if
((
res
=
mysql_insert_select_prepare
(
thd
)))
break
;
if
((
result
=
new
select_insert
(
first_table
,
first_table
->
table
,
...
...
sql/sql_update.cc
View file @
425857f5
...
...
@@ -496,8 +496,7 @@ int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN
(
-
1
);
/* Check that we are not using table that we are updating in a sub select */
if
(
find_table_in_global_list
(
table_list
->
next_global
,
table_list
->
db
,
table_list
->
real_name
))
if
(
unique_table
(
table_list
,
table_list
->
next_independent
()))
{
my_error
(
ER_UPDATE_TABLE_USED
,
MYF
(
0
),
table_list
->
real_name
);
DBUG_RETURN
(
-
1
);
...
...
@@ -788,7 +787,7 @@ int multi_update::prepare(List<Item> ¬_used_values,
{
TABLE
*
table
=
table_ref
->
table
;
if
(
!
(
tables_to_update
&
table
->
map
)
&&
find_table_in_
glob
al_list
(
update_tables
,
table_ref
->
db
,
find_table_in_
loc
al_list
(
update_tables
,
table_ref
->
db
,
table_ref
->
real_name
))
table
->
no_cache
=
1
;
// Disable row cache
}
...
...
sql/sql_view.cc
View file @
425857f5
...
...
@@ -618,7 +618,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
if
(
lex
->
spfuns
.
array
.
buffer
)
hash_free
(
&
lex
->
spfuns
);
old_next
=
table
->
next_global
;
old_next
=
table
->
old_next
=
table
->
next_global
;
if
((
table
->
next_global
=
lex
->
query_tables
))
table
->
next_global
->
prev_global
=
&
table
->
next_global
;
...
...
sql/table.h
View file @
425857f5
...
...
@@ -217,6 +217,8 @@ typedef struct st_table_list
st_table_list
*
ancestor
;
/* most upper view this table belongs to */
st_table_list
*
belong_to_view
;
/* next_global before adding VIEW tables */
st_table_list
*
old_next
;
Item
*
where
;
/* VIEW WHERE clause condition */
LEX_STRING
query
;
/* text of (CRETE/SELECT) statement */
LEX_STRING
md5
;
/* md5 of query tesxt */
...
...
@@ -260,6 +262,12 @@ typedef struct st_table_list
bool
setup_ancestor
(
THD
*
thd
,
Item
**
conds
);
bool
placeholder
()
{
return
derived
||
view
;
}
void
print
(
THD
*
thd
,
String
*
str
);
inline
st_table_list
*
next_independent
()
{
if
(
view
)
return
old_next
;
return
next_global
;
}
}
TABLE_LIST
;
class
Item
;
...
...
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