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
063ffd2d
Commit
063ffd2d
authored
Nov 11, 2002
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent using expernal fields in derived tables
parent
46a74ce7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
10 deletions
+29
-10
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+2
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+2
-0
sql/item.cc
sql/item.cc
+20
-9
sql/sql_derived.cc
sql/sql_derived.cc
+5
-1
No files found.
mysql-test/r/subselect.result
View file @
063ffd2d
...
@@ -240,4 +240,6 @@ SELECT numeropost,maxnumrep FROM forumconthardwarefr7 WHERE exists (SELECT 1 FRO
...
@@ -240,4 +240,6 @@ SELECT numeropost,maxnumrep FROM forumconthardwarefr7 WHERE exists (SELECT 1 FRO
numeropost maxnumrep
numeropost maxnumrep
43506 2
43506 2
40143 1
40143 1
SELECT (SELECT 1) as a FROM (SELECT 1 FROM forumconthardwarefr7 HAVING a=1);
Unknown column 'a' in 'having clause'
drop table forumconthardwarefr7, searchconthardwarefr7;
drop table forumconthardwarefr7, searchconthardwarefr7;
mysql-test/t/subselect.test
View file @
063ffd2d
...
@@ -137,5 +137,7 @@ CREATE TABLE `searchconthardwarefr7` (
...
@@ -137,5 +137,7 @@ CREATE TABLE `searchconthardwarefr7` (
INSERT
INTO
searchconthardwarefr7
(
mot
,
topic
,
date
,
pseudo
)
VALUES
(
'joce'
,
'40143'
,
'2002-10-22'
,
'joce'
),
(
'joce'
,
'43506'
,
'2002-10-22'
,
'joce'
);
INSERT
INTO
searchconthardwarefr7
(
mot
,
topic
,
date
,
pseudo
)
VALUES
(
'joce'
,
'40143'
,
'2002-10-22'
,
'joce'
),
(
'joce'
,
'43506'
,
'2002-10-22'
,
'joce'
);
SELECT
numeropost
,
maxnumrep
FROM
forumconthardwarefr7
WHERE
exists
(
SELECT
1
FROM
searchconthardwarefr7
WHERE
(
mot
=
'joce'
)
AND
date
>=
'2002-10-21'
AND
forumconthardwarefr7
.
numeropost
=
searchconthardwarefr7
.
topic
)
ORDER
BY
maxnumrep
DESC
LIMIT
0
,
20
;
SELECT
numeropost
,
maxnumrep
FROM
forumconthardwarefr7
WHERE
exists
(
SELECT
1
FROM
searchconthardwarefr7
WHERE
(
mot
=
'joce'
)
AND
date
>=
'2002-10-21'
AND
forumconthardwarefr7
.
numeropost
=
searchconthardwarefr7
.
topic
)
ORDER
BY
maxnumrep
DESC
LIMIT
0
,
20
;
--
error
1054
SELECT
(
SELECT
1
)
as
a
FROM
(
SELECT
1
FROM
forumconthardwarefr7
HAVING
a
=
1
);
drop
table
forumconthardwarefr7
,
searchconthardwarefr7
;
drop
table
forumconthardwarefr7
,
searchconthardwarefr7
;
\ No newline at end of file
sql/item.cc
View file @
063ffd2d
...
@@ -444,13 +444,16 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
...
@@ -444,13 +444,16 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
cause error ER_NON_UNIQ_ERROR in find_field_in_tables.
cause error ER_NON_UNIQ_ERROR in find_field_in_tables.
*/
*/
SELECT_LEX
*
last
=
0
;
SELECT_LEX
*
last
=
0
;
for
(
SELECT_LEX
*
sl
=
thd
->
lex
.
current_select
->
outer_select
();
sl
;
// Prevent using outer fields in subselects, that is not supported now
sl
=
sl
->
outer_select
())
if
(
thd
->
lex
.
current_select
->
linkage
!=
DERIVED_TABLE_TYPE
)
if
((
tmp
=
find_field_in_tables
(
thd
,
this
,
for
(
SELECT_LEX
*
sl
=
thd
->
lex
.
current_select
->
outer_select
();
(
last
=
sl
)
->
get_table_list
(),
sl
;
0
))
!=
not_found_field
)
sl
=
sl
->
outer_select
())
break
;
if
((
tmp
=
find_field_in_tables
(
thd
,
this
,
(
last
=
sl
)
->
get_table_list
(),
0
))
!=
not_found_field
)
break
;
if
(
!
tmp
)
if
(
!
tmp
)
return
-
1
;
return
-
1
;
else
if
(
tmp
==
not_found_field
)
else
if
(
tmp
==
not_found_field
)
...
@@ -812,10 +815,18 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
...
@@ -812,10 +815,18 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
if
(
!
ref
)
if
(
!
ref
)
{
{
SELECT_LEX
*
sl
=
thd
->
lex
.
current_select
->
outer_select
();
SELECT_LEX
*
sl
=
thd
->
lex
.
current_select
->
outer_select
();
/*
Finding only in current select will be performed for selects that have
not outer one and for derived tables (which not support using outer
fields for now)
*/
if
((
ref
=
find_item_in_list
(
this
,
if
((
ref
=
find_item_in_list
(
this
,
*
(
thd
->
lex
.
current_select
->
get_item_list
()),
*
(
thd
->
lex
.
current_select
->
get_item_list
()),
(
sl
?
REPORT_EXCEPT_NOT_FOUND
:
((
sl
&&
REPORT_ALL_ERRORS
)))
==
thd
->
lex
.
current_select
->
linkage
!=
DERIVED_TABLE_TYPE
)
?
REPORT_EXCEPT_NOT_FOUND
:
REPORT_ALL_ERRORS
)))
==
(
Item
**
)
not_found_item
)
(
Item
**
)
not_found_item
)
{
{
/*
/*
...
...
sql/sql_derived.cc
View file @
063ffd2d
...
@@ -94,13 +94,17 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
...
@@ -94,13 +94,17 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
unit
->
select_limit_cnt
=
HA_POS_ERROR
;
unit
->
select_limit_cnt
=
HA_POS_ERROR
;
if
(
unit
->
select_limit_cnt
==
HA_POS_ERROR
)
if
(
unit
->
select_limit_cnt
==
HA_POS_ERROR
)
sl
->
options
&=
~
OPTION_FOUND_ROWS
;
sl
->
options
&=
~
OPTION_FOUND_ROWS
;
SELECT_LEX_NODE
*
save_current_select
=
lex
->
current_select
;
lex
->
current_select
=
sl
;
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
sl
->
where
,
(
ORDER
*
)
sl
->
order_list
.
first
,
sl
->
where
,
(
ORDER
*
)
sl
->
order_list
.
first
,
(
ORDER
*
)
sl
->
group_list
.
first
,
(
ORDER
*
)
sl
->
group_list
.
first
,
sl
->
having
,
(
ORDER
*
)
NULL
,
sl
->
having
,
(
ORDER
*
)
NULL
,
sl
->
options
|
thd
->
options
|
SELECT_NO_UNLOCK
,
sl
->
options
|
thd
->
options
|
SELECT_NO_UNLOCK
,
derived_result
,
unit
,
sl
,
0
);
derived_result
,
unit
,
sl
,
0
);
lex
->
current_select
=
save_current_select
;
if
(
!
res
)
if
(
!
res
)
{
{
// Here we entirely fix both TABLE_LIST and list of SELECT's as there were no derived tables
// Here we entirely fix both TABLE_LIST and list of SELECT's as there were no derived tables
...
...
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