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
912aef95
Commit
912aef95
authored
Sep 08, 2005
by
timour@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for BUG#12977.
parent
83b5f1a3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
7 deletions
+58
-7
mysql-test/r/select.result
mysql-test/r/select.result
+15
-0
mysql-test/t/select.test
mysql-test/t/select.test
+22
-0
sql/sql_base.cc
sql/sql_base.cc
+21
-7
No files found.
mysql-test/r/select.result
View file @
912aef95
...
...
@@ -2897,3 +2897,18 @@ select * from t1 natural join t2 where a = 'b';
a
b
drop table t1, t2;
CREATE TABLE t1 (`id` TINYINT);
CREATE TABLE t2 (`id` TINYINT);
CREATE TABLE t3 (`id` TINYINT);
INSERT INTO t1 VALUES (1),(2),(3);
INSERT INTO t2 VALUES (2);
INSERT INTO t3 VALUES (3);
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.notacolumn=t1.id) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
SELECT id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
SELECT id,t3.id FROM (t1 JOIN t2 ON (t2.id=t1.id)) LEFT JOIN t3 USING (id);
ERROR 23000: Column 'id' in from clause is ambiguous
drop table t1, t2, t3;
mysql-test/t/select.test
View file @
912aef95
...
...
@@ -2465,3 +2465,25 @@ insert into t2 values ('b'),('c'),('d');
select
a
from
t1
natural
join
t2
;
select
*
from
t1
natural
join
t2
where
a
=
'b'
;
drop
table
t1
,
t2
;
#
# Bug #12977 Compare table names with qualifying field tables only
# for base tables, search all nested join operands of natural joins.
#
CREATE
TABLE
t1
(
`id`
TINYINT
);
CREATE
TABLE
t2
(
`id`
TINYINT
);
CREATE
TABLE
t3
(
`id`
TINYINT
);
INSERT
INTO
t1
VALUES
(
1
),(
2
),(
3
);
INSERT
INTO
t2
VALUES
(
2
);
INSERT
INTO
t3
VALUES
(
3
);
--
error
1052
SELECT
t1
.
id
,
t3
.
id
FROM
t1
JOIN
t2
ON
(
t2
.
id
=
t1
.
id
)
LEFT
JOIN
t3
USING
(
id
);
--
error
1052
SELECT
t1
.
id
,
t3
.
id
FROM
t1
JOIN
t2
ON
(
t2
.
notacolumn
=
t1
.
id
)
LEFT
JOIN
t3
USING
(
id
);
--
error
1052
SELECT
id
,
t3
.
id
FROM
t1
JOIN
t2
ON
(
t2
.
id
=
t1
.
id
)
LEFT
JOIN
t3
USING
(
id
);
--
error
1052
SELECT
id
,
t3
.
id
FROM
(
t1
JOIN
t2
ON
(
t2
.
id
=
t1
.
id
))
LEFT
JOIN
t3
USING
(
id
);
drop
table
t1
,
t2
,
t3
;
sql/sql_base.cc
View file @
912aef95
...
...
@@ -2877,14 +2877,15 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
/*
Check that the table and database that qualify the current field name
are the same as the table we are going to search for the field.
This is done differently for NATURAL/USING joins because there we can't
simply compare the qualifying table and database names with the ones of
This is done differently for NATURAL/USING joins or nested joins that
are operands of NATURAL/USING joins because there we can't simply
compare the qualifying table and database names with the ones of
'table_list' because each field in such a join may originate from a
different table.
TODO: Ensure that table_name, db_name and tables->db always points to
something !
*/
if
(
!
table_list
->
is_natural_join
&&
if
(
!
(
table_list
->
nested_join
&&
table_list
->
join_columns
)
&&
table_name
&&
table_name
[
0
]
&&
(
my_strcasecmp
(
table_alias_charset
,
table_list
->
alias
,
table_name
)
||
(
db_name
&&
db_name
[
0
]
&&
table_list
->
db
&&
table_list
->
db
[
0
]
&&
...
...
@@ -2899,8 +2900,13 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
register_tree_change
)))
*
actual_table
=
table_list
;
}
else
if
(
table_list
->
is_natural_join
)
else
if
(
table_list
->
nested_join
&&
table_list
->
join_columns
)
{
/*
If this is a NATURAL/USING join, or an operand of such join which is a
join itself, and the field name is qualified, then search for the field
in the operands of the join.
*/
if
(
table_name
&&
table_name
[
0
])
{
/*
...
...
@@ -2922,7 +2928,9 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
}
/*
Non-qualified field, search directly in the result columns of the
natural join.
natural join. The condition of the outer IF is true for the top-most
natural join, thus if the field is not qualified, we will search
directly the top-most NATURAL/USING join.
*/
fld
=
find_field_in_natural_join
(
thd
,
table_list
,
name
,
length
,
ref
,
/* TIMOUR_TODO: check this with Sanja */
...
...
@@ -3528,10 +3536,16 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
if
(
add_columns
&&
is_created_2
)
table_ref_2
->
join_columns
->
push_back
(
cur_nj_col_2
);
/* Compare the two columns and check for duplicate common fields. */
/*
Compare the two columns and check for duplicate common fields.
A common field is duplicate either if it was already found in
table_ref_2 (then found == TRUE), or if a field in table_ref_2
was already matched by some previous field in table_ref_1
(then cur_nj_col_2->is_common == TRUE).
*/
if
(
!
my_strcasecmp
(
system_charset_info
,
field_name_1
,
cur_field_name_2
))
{
if
(
found
)
if
(
found
||
cur_nj_col_2
->
is_common
)
{
my_error
(
ER_NON_UNIQ_ERROR
,
MYF
(
0
),
field_name_1
,
thd
->
where
);
goto
err
;
...
...
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