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
6dea500f
Commit
6dea500f
authored
Jul 29, 2003
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevented finding references in item_list for non-SELECT st_select_lex
(fixed BUG#943)
parent
6a46d28e
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
56 additions
and
12 deletions
+56
-12
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+7
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+14
-1
sql/item.cc
sql/item.cc
+7
-4
sql/sql_lex.cc
sql/sql_lex.cc
+2
-1
sql/sql_lex.h
sql/sql_lex.h
+15
-2
sql/sql_parse.cc
sql/sql_parse.cc
+2
-0
sql/sql_yacc.yy
sql/sql_yacc.yy
+9
-4
No files found.
mysql-test/r/subselect.result
View file @
6dea500f
...
@@ -1225,3 +1225,10 @@ a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 an
...
@@ -1225,3 +1225,10 @@ a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 an
2 2
2 2
1 2
1 2
drop table t1,t2,t3;
drop table t1,t2,t3;
create table t1 (s1 int);
create table t2 (s1 int);
insert into t1 values (1);
insert into t2 values (1);
update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
ERROR 42S02: Unknown table 'x' in field list
DROP TABLE t1, t2;
mysql-test/t/subselect.test
View file @
6dea500f
...
@@ -817,4 +817,17 @@ insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
...
@@ -817,4 +817,17 @@ insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
insert
into
t2
values
(
0
,
0
),
(
1
,
1
),
(
2
,
1
),
(
3
,
1
),
(
4
,
1
);
insert
into
t2
values
(
0
,
0
),
(
1
,
1
),
(
2
,
1
),
(
3
,
1
),
(
4
,
1
);
insert
into
t3
values
(
3
,
3
),
(
2
,
2
),
(
1
,
1
);
insert
into
t3
values
(
3
,
3
),
(
2
,
2
),
(
1
,
1
);
select
a
,(
select
count
(
distinct
t1
.
b
)
as
sum
from
t1
,
t2
where
t1
.
a
=
t2
.
a
and
t2
.
b
>
0
and
t1
.
a
<=
t3
.
b
group
by
t1
.
a
order
by
sum
limit
1
)
from
t3
;
select
a
,(
select
count
(
distinct
t1
.
b
)
as
sum
from
t1
,
t2
where
t1
.
a
=
t2
.
a
and
t2
.
b
>
0
and
t1
.
a
<=
t3
.
b
group
by
t1
.
a
order
by
sum
limit
1
)
from
t3
;
drop
table
t1
,
t2
,
t3
;
s
drop
table
t1
,
t2
,
t3
;
#
# update subquery with wrong field (to force name resolving
# in UPDATE name space)
#
create
table
t1
(
s1
int
);
create
table
t2
(
s1
int
);
insert
into
t1
values
(
1
);
insert
into
t2
values
(
1
);
--
error
1109
update
t1
set
s1
=
s1
+
1
where
1
=
(
select
x
.
s1
as
A
from
t2
WHERE
t2
.
s1
>
t1
.
s1
order
by
A
);
DROP
TABLE
t1
,
t2
;
sql/item.cc
View file @
6dea500f
...
@@ -862,7 +862,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
...
@@ -862,7 +862,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
sl
=
sl
->
outer_select
())
sl
=
sl
->
outer_select
())
{
{
table_list
=
(
last
=
sl
)
->
get_table_list
();
table_list
=
(
last
=
sl
)
->
get_table_list
();
if
(
sl
->
insert_select
&&
table_list
)
if
(
sl
->
resolve_mode
==
SELECT_LEX
::
INSERT_MODE
&&
table_list
)
{
{
// it is primary INSERT st_select_lex => skip first table resolving
// it is primary INSERT st_select_lex => skip first table resolving
table_list
=
table_list
->
next
;
table_list
=
table_list
->
next
;
...
@@ -871,7 +871,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
...
@@ -871,7 +871,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
table_list
,
&
where
,
table_list
,
&
where
,
0
))
!=
not_found_field
)
0
))
!=
not_found_field
)
break
;
break
;
if
((
refer
=
find_item_in_list
(
this
,
sl
->
item_list
,
&
counter
,
if
(
sl
->
resolve_mode
==
SELECT_LEX
::
SELECT_MODE
&&
(
refer
=
find_item_in_list
(
this
,
sl
->
item_list
,
&
counter
,
REPORT_EXCEPT_NOT_FOUND
))
!=
REPORT_EXCEPT_NOT_FOUND
))
!=
(
Item
**
)
not_found_item
)
(
Item
**
)
not_found_item
)
break
;
break
;
...
@@ -1348,13 +1349,15 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
...
@@ -1348,13 +1349,15 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
SELECT_LEX
*
last
=
0
;
SELECT_LEX
*
last
=
0
;
for
(
;
sl
;
sl
=
sl
->
outer_select
())
for
(
;
sl
;
sl
=
sl
->
outer_select
())
{
{
if
((
ref
=
find_item_in_list
(
this
,
(
last
=
sl
)
->
item_list
,
last
=
sl
;
if
(
sl
->
resolve_mode
==
SELECT_LEX
::
SELECT_MODE
&&
(
ref
=
find_item_in_list
(
this
,
sl
->
item_list
,
&
counter
,
&
counter
,
REPORT_EXCEPT_NOT_FOUND
))
!=
REPORT_EXCEPT_NOT_FOUND
))
!=
(
Item
**
)
not_found_item
)
(
Item
**
)
not_found_item
)
break
;
break
;
table_list
=
sl
->
get_table_list
();
table_list
=
sl
->
get_table_list
();
if
(
sl
->
insert_select
&&
table_list
)
if
(
sl
->
resolve_mode
==
SELECT_LEX
::
INSERT_MODE
&&
table_list
)
{
{
// it is primary INSERT st_select_lex => skip first table resolving
// it is primary INSERT st_select_lex => skip first table resolving
table_list
=
table_list
->
next
;
table_list
=
table_list
->
next
;
...
...
sql/sql_lex.cc
View file @
6dea500f
...
@@ -986,7 +986,8 @@ void st_select_lex::init_query()
...
@@ -986,7 +986,8 @@ void st_select_lex::init_query()
join
=
0
;
join
=
0
;
where
=
0
;
where
=
0
;
olap
=
UNSPECIFIED_OLAP_TYPE
;
olap
=
UNSPECIFIED_OLAP_TYPE
;
insert_select
=
having_fix_field
=
0
;
having_fix_field
=
0
;
resolve_mode
=
NOMATTER_MODE
;
with_wild
=
0
;
with_wild
=
0
;
}
}
...
...
sql/sql_lex.h
View file @
6dea500f
...
@@ -360,14 +360,27 @@ public:
...
@@ -360,14 +360,27 @@ public:
bool
braces
;
/* SELECT ... UNION (SELECT ... ) <- this braces */
bool
braces
;
/* SELECT ... UNION (SELECT ... ) <- this braces */
/* TRUE when having fix field called in processing of this SELECT */
/* TRUE when having fix field called in processing of this SELECT */
bool
having_fix_field
;
bool
having_fix_field
;
/*
/*
TRUE for primary st_select_lex structure of simple INSERT/REPLACE
SELECT for SELECT command st_select_lex. Used to privent scaning
item_list of non-SELECT st_select_lex (no sense find to finding
reference in it (all should be in tables, it is dangerouse due
to order of fix_fields calling for non-SELECTs commands (item list
can be not fix_fieldsd)). This value will be assigned for
primary select (sql_yac.yy) and for any subquery and
UNION SELECT (sql_parse.cc mysql_new_select())
INSERT for primary st_select_lex structure of simple INSERT/REPLACE
(used for name resolution, see Item_fiels & Item_ref fix_fields,
(used for name resolution, see Item_fiels & Item_ref fix_fields,
FALSE for INSERT/REPLACE ... SELECT, because it's
FALSE for INSERT/REPLACE ... SELECT, because it's
st_select_lex->table_list will be preprocessed (first table removed)
st_select_lex->table_list will be preprocessed (first table removed)
before passing to handle_select)
before passing to handle_select)
NOMATTER for other
*/
*/
bool
insert_select
;
enum
{
NOMATTER_MODE
,
SELECT_MODE
,
INSERT_MODE
}
resolve_mode
;
void
init_query
();
void
init_query
();
void
init_select
();
void
init_select
();
...
...
sql/sql_parse.cc
View file @
6dea500f
...
@@ -3550,6 +3550,7 @@ mysql_new_select(LEX *lex, bool move_down)
...
@@ -3550,6 +3550,7 @@ mysql_new_select(LEX *lex, bool move_down)
unit
->
link_prev
=
0
;
unit
->
link_prev
=
0
;
unit
->
return_to
=
lex
->
current_select
;
unit
->
return_to
=
lex
->
current_select
;
select_lex
->
include_down
(
unit
);
select_lex
->
include_down
(
unit
);
// TODO: assign resolve_mode for fake subquery after merging with new tree
}
}
else
else
select_lex
->
include_neighbour
(
lex
->
current_select
);
select_lex
->
include_neighbour
(
lex
->
current_select
);
...
@@ -3557,6 +3558,7 @@ mysql_new_select(LEX *lex, bool move_down)
...
@@ -3557,6 +3558,7 @@ mysql_new_select(LEX *lex, bool move_down)
select_lex
->
master_unit
()
->
global_parameters
=
select_lex
;
select_lex
->
master_unit
()
->
global_parameters
=
select_lex
;
select_lex
->
include_global
((
st_select_lex_node
**
)
&
lex
->
all_selects_list
);
select_lex
->
include_global
((
st_select_lex_node
**
)
&
lex
->
all_selects_list
);
lex
->
current_select
=
select_lex
;
lex
->
current_select
=
select_lex
;
select_lex
->
resolve_mode
=
SELECT_LEX
::
SELECT_MODE
;
return
0
;
return
0
;
}
}
...
...
sql/sql_yacc.yy
View file @
6dea500f
...
@@ -1910,7 +1910,12 @@ opt_ignore_leaves:
...
@@ -1910,7 +1910,12 @@ opt_ignore_leaves:
select:
select:
select_init { Lex->sql_command=SQLCOM_SELECT; };
select_init
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE;
};
/* Need select_init2 for subselects. */
/* Need select_init2 for subselects. */
select_init:
select_init:
...
@@ -3401,7 +3406,7 @@ insert:
...
@@ -3401,7 +3406,7 @@ insert:
lex->sql_command = SQLCOM_INSERT;
lex->sql_command = SQLCOM_INSERT;
/* for subselects */
/* for subselects */
lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
lex->select_lex.
insert_select= 1
;
lex->select_lex.
resolve_mode= SELECT_LEX::INSERT_MODE
;
} insert_lock_option
} insert_lock_option
opt_ignore insert2
opt_ignore insert2
{
{
...
@@ -3417,7 +3422,7 @@ replace:
...
@@ -3417,7 +3422,7 @@ replace:
LEX *lex=Lex;
LEX *lex=Lex;
lex->sql_command = SQLCOM_REPLACE;
lex->sql_command = SQLCOM_REPLACE;
lex->duplicates= DUP_REPLACE;
lex->duplicates= DUP_REPLACE;
lex->select_lex.
insert_select= 1
;
lex->select_lex.
resolve_mode= SELECT_LEX::INSERT_MODE
;
}
}
replace_lock_option insert2
replace_lock_option insert2
{
{
...
@@ -3486,7 +3491,7 @@ insert_values:
...
@@ -3486,7 +3491,7 @@ insert_values:
it is not simple select => table list will be
it is not simple select => table list will be
preprocessed before passing to handle_select
preprocessed before passing to handle_select
*/
*/
lex->select_lex.
insert_select= 0
;
lex->select_lex.
resolve_mode= SELECT_LEX::NOMATTER_MODE
;
lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
lex->current_select->parsing_place= SELECT_LEX_NODE::SELECT_LIST;
}
}
select_options select_item_list
select_options select_item_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