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
74a9ca19
Commit
74a9ca19
authored
Feb 09, 2004
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ufter revview fix (BUG#2120)
parent
b99d1358
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
32 deletions
+62
-32
mysql-test/r/derived.result
mysql-test/r/derived.result
+4
-0
mysql-test/t/derived.test
mysql-test/t/derived.test
+4
-0
sql/mysql_priv.h
sql/mysql_priv.h
+2
-2
sql/sql_acl.cc
sql/sql_acl.cc
+4
-2
sql/sql_base.cc
sql/sql_base.cc
+36
-17
sql/sql_derived.cc
sql/sql_derived.cc
+8
-8
sql/sql_handler.cc
sql/sql_handler.cc
+2
-1
sql/sql_parse.cc
sql/sql_parse.cc
+2
-2
No files found.
mysql-test/r/derived.result
View file @
74a9ca19
...
...
@@ -267,12 +267,16 @@ N M
3 0
UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2, P2.N = 2;
ERROR HY000: The target table P2 of the UPDATE is not updatable.
UPDATE `t1` AS P1 INNER JOIN (SELECT aaaa FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2;
ERROR 42S22: Unknown column 'aaaa' in 'field list'
delete P1.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
select * from t1;
N M
3 0
delete P1.*,P2.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
ERROR HY000: The target table P2 of the DELETE is not updatable.
delete P1.* from `t1` AS P1 INNER JOIN (SELECT aaa FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
ERROR 42S22: Unknown column 'aaa' in 'field list'
drop table t1;
CREATE TABLE t1 (
OBJECTID int(11) NOT NULL default '0',
...
...
mysql-test/t/derived.test
View file @
74a9ca19
...
...
@@ -153,10 +153,14 @@ UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1)
select
*
from
t1
;
--
error
1287
UPDATE
`t1`
AS
P1
INNER
JOIN
(
SELECT
N
FROM
`t1`
GROUP
BY
N
HAVING
Count
(
M
)
>
1
)
AS
P2
ON
P1
.
N
=
P2
.
N
SET
P1
.
M
=
2
,
P2
.
N
=
2
;
--
error
1054
UPDATE
`t1`
AS
P1
INNER
JOIN
(
SELECT
aaaa
FROM
`t1`
GROUP
BY
N
HAVING
Count
(
M
)
>
1
)
AS
P2
ON
P1
.
N
=
P2
.
N
SET
P1
.
M
=
2
;
delete
P1
.*
from
`t1`
AS
P1
INNER
JOIN
(
SELECT
N
FROM
`t1`
GROUP
BY
N
HAVING
Count
(
M
)
>
1
)
AS
P2
ON
P1
.
N
=
P2
.
N
;
select
*
from
t1
;
--
error
1287
delete
P1
.*
,
P2
.*
from
`t1`
AS
P1
INNER
JOIN
(
SELECT
N
FROM
`t1`
GROUP
BY
N
HAVING
Count
(
M
)
>
1
)
AS
P2
ON
P1
.
N
=
P2
.
N
;
--
error
1054
delete
P1
.*
from
`t1`
AS
P1
INNER
JOIN
(
SELECT
aaa
FROM
`t1`
GROUP
BY
N
HAVING
Count
(
M
)
>
1
)
AS
P2
ON
P1
.
N
=
P2
.
N
;
drop
table
t1
;
#
...
...
sql/mysql_priv.h
View file @
74a9ca19
...
...
@@ -675,10 +675,10 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds);
int
setup_ftfuncs
(
SELECT_LEX
*
select
);
int
init_ftfuncs
(
THD
*
thd
,
SELECT_LEX
*
select
,
bool
no_order
);
void
wait_for_refresh
(
THD
*
thd
);
int
open_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
);
int
open_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
,
uint
*
counter
);
int
simple_open_n_lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
);
int
open_and_lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
);
int
lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
);
int
lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
,
uint
counter
);
TABLE
*
open_temporary_table
(
THD
*
thd
,
const
char
*
path
,
const
char
*
db
,
const
char
*
table_name
,
bool
link_in_list
);
bool
rm_temporary_table
(
enum
db_type
base
,
char
*
path
);
...
...
sql/sql_acl.cc
View file @
74a9ca19
...
...
@@ -173,7 +173,8 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
tables
[
0
].
lock_type
=
tables
[
1
].
lock_type
=
tables
[
2
].
lock_type
=
TL_READ
;
tables
[
0
].
db
=
tables
[
1
].
db
=
tables
[
2
].
db
=
thd
->
db
;
if
(
open_tables
(
thd
,
tables
))
uint
counter
;
if
(
open_tables
(
thd
,
tables
,
&
counter
))
{
sql_print_error
(
"Fatal error: Can't open privilege tables: %s"
,
thd
->
net
.
last_error
);
...
...
@@ -2524,7 +2525,8 @@ my_bool grant_init(THD *org_thd)
tables
[
0
].
lock_type
=
tables
[
1
].
lock_type
=
TL_READ
;
tables
[
0
].
db
=
tables
[
1
].
db
=
thd
->
db
;
if
(
open_tables
(
thd
,
tables
))
uint
counter
;
if
(
open_tables
(
thd
,
tables
,
&
counter
))
goto
end
;
TABLE
*
ptr
[
2
];
// Lock tables for quick update
...
...
sql/sql_base.cc
View file @
74a9ca19
...
...
@@ -1308,7 +1308,6 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
bzero
((
char
*
)
&
table_list
,
sizeof
(
table_list
));
// just for safe
table_list
.
db
=
(
char
*
)
db
;
table_list
.
real_name
=
(
char
*
)
name
;
table_list
.
next
=
0
;
safe_mutex_assert_owner
(
&
LOCK_open
);
if
((
error
=
lock_table_name
(
thd
,
&
table_list
)))
...
...
@@ -1357,24 +1356,40 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
DBUG_RETURN
(
1
);
}
/*****************************************************************************
** open all tables in list
*****************************************************************************/
/*
Open all tables in list
SYNOPSIS
open_tables()
thd - thread handler
start - list of tables
counter - number of opened tables will be return using this parameter
int
open_tables
(
THD
*
thd
,
TABLE_LIST
*
start
)
RETURN
0 - OK
-1 - error
*/
int
open_tables
(
THD
*
thd
,
TABLE_LIST
*
start
,
uint
*
counter
)
{
TABLE_LIST
*
tables
;
bool
refresh
;
int
result
=
0
;
DBUG_ENTER
(
"open_tables"
);
*
counter
=
0
;
thd
->
current_tablenr
=
0
;
restart:
thd
->
proc_info
=
"Opening tables"
;
for
(
tables
=
start
;
tables
;
tables
=
tables
->
next
)
{
/*
Ignore placeholders for derived tables. After derived tables
processing, link to created temporary table will be put here.
*/
if
(
tables
->
derived
)
continue
;
(
*
counter
)
++
;
if
(
!
tables
->
table
&&
!
(
tables
->
table
=
open_table
(
thd
,
tables
->
db
,
...
...
@@ -1533,14 +1548,19 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type)
thd - thread handler
tables - list of tables for open&locking
RETURN
0 - ok
-1 - error
NOTE
The lock will automaticly be freed by close_thread_tables()
*/
int
simple_open_n_lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
)
{
DBUG_ENTER
(
"open_n_lock_tables"
);
if
(
open_tables
(
thd
,
tables
)
||
lock_tables
(
thd
,
tables
))
DBUG_ENTER
(
"simple_open_n_lock_tables"
);
uint
counter
;
if
(
open_tables
(
thd
,
tables
,
&
counter
)
||
lock_tables
(
thd
,
tables
,
counter
))
DBUG_RETURN
(
-
1
);
/* purecov: inspected */
DBUG_RETURN
(
0
);
}
...
...
@@ -1551,10 +1571,14 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
tables processing.
SYNOPSIS
simple_open_n
_lock_tables()
open_and
_lock_tables()
thd - thread handler
tables - list of tables for open&locking
RETURN
0 - ok
-1 - error
NOTE
The lock will automaticly be freed by close_thread_tables()
*/
...
...
@@ -1562,7 +1586,8 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
int
open_and_lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
)
{
DBUG_ENTER
(
"open_and_lock_tables"
);
if
(
open_tables
(
thd
,
tables
)
||
lock_tables
(
thd
,
tables
))
uint
counter
;
if
(
open_tables
(
thd
,
tables
,
&
counter
)
||
lock_tables
(
thd
,
tables
,
counter
))
DBUG_RETURN
(
-
1
);
/* purecov: inspected */
fix_tables_pointers
(
thd
->
lex
->
all_selects_list
);
DBUG_RETURN
(
mysql_handle_derived
(
thd
->
lex
));
...
...
@@ -1576,6 +1601,7 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
lock_tables()
thd Thread handler
tables Tables to lock
count umber of opened tables
NOTES
You can't call lock_tables twice, as this would break the dead-lock-free
...
...
@@ -1587,7 +1613,7 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
-1 Error
*/
int
lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
)
int
lock_tables
(
THD
*
thd
,
TABLE_LIST
*
tables
,
uint
count
)
{
TABLE_LIST
*
table
;
if
(
!
tables
)
...
...
@@ -1596,12 +1622,6 @@ int lock_tables(THD *thd,TABLE_LIST *tables)
if
(
!
thd
->
locked_tables
)
{
DBUG_ASSERT
(
thd
->
lock
==
0
);
// You must lock everything at once
uint
count
=
0
;
for
(
table
=
tables
;
table
;
table
=
table
->
next
)
{
if
(
!
table
->
derived
)
count
++
;
}
TABLE
**
start
,
**
ptr
;
if
(
!
(
ptr
=
start
=
(
TABLE
**
)
sql_alloc
(
sizeof
(
TABLE
*
)
*
count
)))
return
-
1
;
...
...
@@ -2207,7 +2227,6 @@ insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/* Ensure that we have access right to all columns */
if
(
!
(
table
->
grant
.
privilege
&
SELECT_ACL
)
&&
!
tables
->
derived
&&
check_grant_all_columns
(
thd
,
SELECT_ACL
,
table
))
DBUG_RETURN
(
-
1
);
#endif
...
...
sql/sql_derived.cc
View file @
74a9ca19
...
...
@@ -25,7 +25,8 @@
#include "sql_select.h"
#include "sql_acl.h"
int
mysql_derived
(
THD
*
thd
,
LEX
*
lex
,
SELECT_LEX_UNIT
*
s
,
TABLE_LIST
*
t
);
static
int
mysql_derived
(
THD
*
thd
,
LEX
*
lex
,
SELECT_LEX_UNIT
*
s
,
TABLE_LIST
*
t
);
/*
Resolve derived tables in all queries
...
...
@@ -39,10 +40,10 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *s, TABLE_LIST *t);
-1 Error
1 Error and error message given
*/
int
mysql_handle_derived
(
LEX
*
lex
)
{
int
res
=
0
;
if
(
lex
->
derived_tables
)
{
for
(
SELECT_LEX
*
sl
=
lex
->
all_selects_list
;
...
...
@@ -53,13 +54,12 @@ mysql_handle_derived(LEX *lex)
cursor
;
cursor
=
cursor
->
next
)
{
int
res
;
if
(
cursor
->
derived
&&
(
res
=
mysql_derived
(
lex
->
thd
,
lex
,
cursor
->
derived
,
cursor
)))
{
if
(
res
<
0
||
lex
->
thd
->
net
.
report_error
)
send_error
(
lex
->
thd
,
lex
->
thd
->
killed
?
ER_SERVER_SHUTDOWN
:
0
);
return
1
;
return
res
;
}
}
if
(
lex
->
describe
)
...
...
@@ -108,8 +108,8 @@ mysql_handle_derived(LEX *lex)
*/
int
mysql_derived
(
THD
*
thd
,
LEX
*
lex
,
SELECT_LEX_UNIT
*
unit
,
TABLE_LIST
*
org_table_list
)
static
int
mysql_derived
(
THD
*
thd
,
LEX
*
lex
,
SELECT_LEX_UNIT
*
unit
,
TABLE_LIST
*
org_table_list
)
{
SELECT_LEX
*
first_select
=
unit
->
first_select
();
TABLE
*
table
;
...
...
@@ -197,7 +197,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit,
table
->
derived_select_number
=
first_select
->
select_number
;
table
->
tmp_table
=
TMP_TABLE
;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
org_table_list
->
grant
.
privilege
=
SELECT_ACL
;
table
->
grant
.
privilege
=
SELECT_ACL
;
#endif
org_table_list
->
db
=
(
char
*
)
""
;
// Force read of table stats in the optimizer
...
...
sql/sql_handler.cc
View file @
74a9ca19
...
...
@@ -48,7 +48,8 @@ static TABLE **find_table_ptr_by_name(THD *thd,const char *db,
int
mysql_ha_open
(
THD
*
thd
,
TABLE_LIST
*
tables
)
{
HANDLER_TABLES_HACK
(
thd
);
int
err
=
open_tables
(
thd
,
tables
);
uint
counter
;
int
err
=
open_tables
(
thd
,
tables
,
&
counter
);
HANDLER_TABLES_HACK
(
thd
);
if
(
err
)
return
-
1
;
...
...
sql/sql_parse.cc
View file @
74a9ca19
...
...
@@ -2669,8 +2669,8 @@ mysql_execute_command(THD *thd)
{
auxi
->
table
=
auxi
->
table_list
->
table
;
/*
Multi-delete can't be constucted over-union => we always have
single SELECT on top and have to check underlay
ed
SELECTs of it
Multi-delete can't be const
r
ucted over-union => we always have
single SELECT on top and have to check underlay
ing
SELECTs of it
*/
for
(
SELECT_LEX_UNIT
*
un
=
lex
->
select_lex
.
first_inner_unit
();
un
;
...
...
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