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
0fa08520
Commit
0fa08520
authored
Jul 06, 2004
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Plain Diff
Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-5.0
into sanja.is.com.ua:/home/bell/mysql/bk/work-5.0
parents
731c2aca
1b54d08a
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
161 additions
and
127 deletions
+161
-127
mysql-test/r/join_nested.result
mysql-test/r/join_nested.result
+47
-22
mysql-test/t/join_nested.test
mysql-test/t/join_nested.test
+21
-12
sql/sql_lex.h
sql/sql_lex.h
+1
-1
sql/sql_select.cc
sql/sql_select.cc
+84
-86
sql/table.h
sql/table.h
+8
-6
No files found.
mysql-test/r/join_nested.result
View file @
0fa08520
This diff is collapsed.
Click to expand it.
mysql-test/t/join_nested.test
View file @
0fa08520
--
disable_warnings
DROP
TABLE
IF
EXISTS
t0
,
t1
,
t2
,
t3
,
t4
,
t5
,
t6
,
t7
,
t8
,
t9
;
--
enable_warnings
CREATE
TABLE
t0
(
a
int
,
b
int
,
c
int
);
CREATE
TABLE
t1
(
a
int
,
b
int
,
c
int
);
...
...
@@ -49,7 +50,7 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
(
t3
,
t4
)
ON
t3
.
a
=
1
AND
t2
.
b
=
t4
.
b
;
EXPLAIN
EXPLAIN
EXTENDED
SELECT
t2
.
a
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.
b
FROM
t0
,
t1
...
...
sql/sql_lex.h
View file @
0fa08520
sql/sql_select.cc
View file @
0fa08520
...
...
@@ -11178,6 +11178,88 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
}
/*
Print joins from the FROM clause
SYNOPSIS
print_join()
thd thread handler
str string where table should bbe printed
tables list of tables in join
*/
static
void
print_join
(
THD
*
thd
,
String
*
str
,
List
<
TABLE_LIST
>
*
tables
)
{
/* List is reversed => we should reverse it before using */
List_iterator_fast
<
TABLE_LIST
>
ti
(
*
tables
);
TABLE_LIST
**
table
=
(
TABLE_LIST
**
)
thd
->
alloc
(
sizeof
(
TABLE_LIST
*
)
*
tables
->
elements
);
if
(
table
==
0
)
return
;
// out of memory
for
(
TABLE_LIST
**
t
=
table
+
(
tables
->
elements
-
1
);
t
>=
table
;
t
--
)
*
t
=
ti
++
;
DBUG_ASSERT
(
tables
->
elements
>=
1
);
(
*
table
)
->
print
(
thd
,
str
);
TABLE_LIST
**
end
=
table
+
tables
->
elements
;
for
(
TABLE_LIST
**
tbl
=
table
+
1
;
tbl
<
end
;
tbl
++
)
{
TABLE_LIST
*
curr
=
*
tbl
;
if
(
curr
->
outer_join
)
str
->
append
(
" left join "
,
11
);
// MySQL converg right to left joins
else
if
(
curr
->
straight
)
str
->
append
(
" straight_join "
,
15
);
else
str
->
append
(
" join "
,
6
);
curr
->
print
(
thd
,
str
);
if
(
curr
->
on_expr
)
{
str
->
append
(
" on("
,
4
);
curr
->
on_expr
->
print
(
str
);
str
->
append
(
')'
);
}
}
}
/*
Print table as it should be in join list
SYNOPSIS
st_table_list::print();
str string where table should bbe printed
*/
void
st_table_list
::
print
(
THD
*
thd
,
String
*
str
)
{
if
(
nested_join
)
{
str
->
append
(
'('
);
print_join
(
thd
,
str
,
&
nested_join
->
join_list
);
str
->
append
(
')'
);
}
else
if
(
derived
)
{
str
->
append
(
'('
);
derived
->
print
(
str
);
str
->
append
(
") "
,
2
);
str
->
append
(
alias
);
}
else
{
str
->
append
(
db
);
str
->
append
(
'.'
);
str
->
append
(
real_name
);
if
(
my_strcasecmp
(
table_alias_charset
,
real_name
,
alias
))
{
str
->
append
(
' '
);
str
->
append
(
alias
);
}
}
}
void
st_select_lex
::
print
(
THD
*
thd
,
String
*
str
)
{
if
(
!
thd
)
...
...
@@ -11226,92 +11308,8 @@ void st_select_lex::print(THD *thd, String *str)
if
(
table_list
.
elements
)
{
str
->
append
(
" from "
,
6
);
for
(
TABLE_LIST
*
table
=
(
TABLE_LIST
*
)
table_list
.
first
;
table
;
table
=
table
->
next
)
{
TABLE_LIST
*
embedded
=
table
;
TABLE_LIST
*
embedding
=
table
->
embedding
;
while
(
embedding
)
{
TABLE_LIST
*
next
;
NESTED_JOIN
*
nested_join
=
table
->
embedding
->
nested_join
;
List_iterator_fast
<
TABLE_LIST
>
it
(
nested_join
->
join_list
);
TABLE_LIST
*
tab
=
it
++
;
while
((
next
=
it
++
))
tab
=
next
;
if
(
tab
!=
embedded
)
break
;
str
->
append
(
'('
);
if
(
embedded
->
outer_join
&
JOIN_TYPE_RIGHT
)
str
->
append
(
" right join "
,
12
);
else
if
(
embedded
->
outer_join
&
JOIN_TYPE_LEFT
)
str
->
append
(
" left join "
,
11
);
else
if
(
embedded
->
straight
)
str
->
append
(
" straight_join "
,
15
);
else
str
->
append
(
" join "
,
6
);
embedded
=
embedding
;
embedding
=
embedding
->
embedding
;
}
if
(
table
->
derived
)
{
str
->
append
(
'('
);
table
->
derived
->
print
(
str
);
str
->
append
(
") "
);
str
->
append
(
table
->
alias
);
}
else
{
str
->
append
(
table
->
db
);
str
->
append
(
'.'
);
str
->
append
(
table
->
real_name
);
if
(
my_strcasecmp
(
table_alias_charset
,
table
->
real_name
,
table
->
alias
))
{
str
->
append
(
' '
);
str
->
append
(
table
->
alias
);
}
}
if
(
table
->
on_expr
)
{
str
->
append
(
" on("
,
4
);
table
->
on_expr
->
print
(
str
);
str
->
append
(
')'
);
}
TABLE_LIST
*
next_table
;
if
((
next_table
=
table
->
next
))
{
if
(
next_table
->
outer_join
&
JOIN_TYPE_RIGHT
)
str
->
append
(
" right join "
,
12
);
else
if
(
next_table
->
outer_join
&
JOIN_TYPE_LEFT
)
str
->
append
(
" left join "
,
11
);
else
if
(
next_table
->
straight
)
str
->
append
(
" straight_join "
,
15
);
else
str
->
append
(
" join "
,
6
);
}
embedded
=
table
;
embedding
=
table
->
embedding
;
while
(
embedding
)
{
NESTED_JOIN
*
nested_join
=
table
->
embedding
->
nested_join
;
if
(
nested_join
->
join_list
.
head
()
!=
embedded
)
break
;
str
->
append
(
')'
);
if
(
embedding
->
on_expr
)
{
str
->
append
(
" on("
,
4
);
embedding
->
on_expr
->
print
(
str
);
str
->
append
(
')'
);
}
embedded
=
embedding
;
embedding
=
embedding
->
embedding
;
}
}
/* go through join tree */
print_join
(
thd
,
str
,
&
top_join_list
);
}
// Where
...
...
sql/table.h
View file @
0fa08520
...
...
@@ -198,6 +198,8 @@ typedef struct st_table_list
bool
cacheable_table
;
/* stop PS caching */
/* used in multi-upd privelege check */
bool
table_in_update_from_clause
;
void
print
(
THD
*
thd
,
String
*
str
);
}
TABLE_LIST
;
typedef
struct
st_nested_join
...
...
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