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
a918a6a7
Commit
a918a6a7
authored
Dec 12, 2002
by
Sinisa@sinisa.nasamreza.org
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
derived tables with UNION's ...
Scrum task !!!!!
parent
2391b5cb
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
68 additions
and
74 deletions
+68
-74
mysql-test/r/analyse.result
mysql-test/r/analyse.result
+0
-33
mysql-test/r/derived.result
mysql-test/r/derived.result
+25
-0
mysql-test/t/analyse.test
mysql-test/t/analyse.test
+1
-28
mysql-test/t/derived.test
mysql-test/t/derived.test
+4
-0
sql/mysql_priv.h
sql/mysql_priv.h
+1
-1
sql/sql_analyse.cc
sql/sql_analyse.cc
+1
-1
sql/sql_derived.cc
sql/sql_derived.cc
+30
-4
sql/sql_lex.cc
sql/sql_lex.cc
+3
-2
sql/sql_select.cc
sql/sql_select.cc
+1
-1
sql/sql_union.cc
sql/sql_union.cc
+2
-4
No files found.
mysql-test/r/analyse.result
View file @
a918a6a7
This diff is collapsed.
Click to expand it.
mysql-test/r/derived.result
View file @
a918a6a7
...
...
@@ -63,6 +63,31 @@ a
select 1 from (select 1) as a;
1
1
select * from (select * from t1 union select * from t1) a;
a b
1 a
2 b
3 c
select * from (select * from t1 union all select * from t1) a;
a b
1 a
2 b
3 c
3 c
1 a
2 b
3 c
3 c
explain select * from (select * from t1 union select * from t1) a;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3
2 DERIVED t1 ALL NULL NULL NULL NULL 4
3 UNION t1 ALL NULL NULL NULL NULL 4
explain select * from (select * from t1 union all select * from t1) a;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 8
2 DERIVED t1 ALL NULL NULL NULL NULL 4
3 UNION t1 ALL NULL NULL NULL NULL 4
drop table if exists t1;
create table t1(a int not null, t char(8), index(a));
SELECT * FROM (SELECT * FROM t1) as b ORDER BY a ASC LIMIT 0,20;
...
...
mysql-test/t/analyse.test
View file @
a918a6a7
This diff is collapsed.
Click to expand it.
mysql-test/t/derived.test
View file @
a918a6a7
...
...
@@ -24,6 +24,10 @@ drop table if exists t1.t2,t3;
select
*
from
(
select
1
)
as
a
;
select
a
from
(
select
1
as
a
)
as
b
;
select
1
from
(
select
1
)
as
a
;
select
*
from
(
select
*
from
t1
union
select
*
from
t1
)
a
;
select
*
from
(
select
*
from
t1
union
all
select
*
from
t1
)
a
;
explain
select
*
from
(
select
*
from
t1
union
select
*
from
t1
)
a
;
explain
select
*
from
(
select
*
from
t1
union
all
select
*
from
t1
)
a
;
drop
table
if
exists
t1
;
create
table
t1
(
a
int
not
null
,
t
char
(
8
),
index
(
a
));
disable_query_log
;
...
...
sql/mysql_priv.h
View file @
a918a6a7
...
...
@@ -419,7 +419,7 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
select_result
*
result
);
int
mysql_explain_select
(
THD
*
thd
,
SELECT_LEX
*
sl
,
char
const
*
type
,
select_result
*
result
);
int
mysql_union
(
THD
*
thd
,
LEX
*
lex
,
select_result
*
result
);
int
mysql_union
(
THD
*
thd
,
LEX
*
lex
,
select_result
*
result
,
SELECT_LEX_UNIT
*
unit
);
int
mysql_derived
(
THD
*
thd
,
LEX
*
lex
,
SELECT_LEX_UNIT
*
s
,
TABLE_LIST
*
t
);
Field
*
create_tmp_field
(
THD
*
thd
,
TABLE
*
table
,
Item
*
item
,
Item
::
Type
type
,
Item_result_field
***
copy_func
,
Field
**
from_field
,
...
...
sql/sql_analyse.cc
View file @
a918a6a7
...
...
@@ -324,7 +324,7 @@ void field_str::add()
}
else
{
//
bzero((char*) &s, sizeof(s)); // Let tree handle free of this
bzero
((
char
*
)
&
s
,
sizeof
(
s
));
// Let tree handle free of this
if
((
treemem
+=
length
)
>
pc
->
max_treemem
)
{
room_in_tree
=
0
;
// Remove tree, too big tree
...
...
sql/sql_derived.cc
View file @
a918a6a7
...
...
@@ -41,8 +41,13 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
select_union
*
derived_result
;
TABLE_LIST
*
tables
=
(
TABLE_LIST
*
)
sl
->
table_list
.
first
;
TMP_TABLE_PARAM
tmp_table_param
;
bool
is_union
=
sl
->
next_select
()
&&
sl
->
next_select
()
->
linkage
==
UNION_TYPE
;
DBUG_ENTER
(
"mysql_derived"
);
if
(
is_union
&&
unit
->
create_total_list
(
thd
,
lex
,
&
tables
))
DBUG_RETURN
(
-
1
);
if
(
tables
)
res
=
check_table_access
(
thd
,
SELECT_ACL
,
tables
);
else
...
...
@@ -58,6 +63,19 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
if
(
!
(
res
=
open_and_lock_tables
(
thd
,
tables
)))
{
if
(
is_union
)
{
for
(
SELECT_LEX
*
sel
=
sl
;
sel
;
sel
=
sel
->
next_select
())
{
for
(
TABLE_LIST
*
cursor
=
(
TABLE_LIST
*
)
sel
->
table_list
.
first
;
cursor
;
cursor
=
cursor
->
next
)
cursor
->
table
=
cursor
->
table_list
->
table
;
}
}
if
(
setup_fields
(
thd
,
tables
,
item_list
,
0
,
0
,
1
))
{
res
=-
1
;
...
...
@@ -66,7 +84,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
bzero
((
char
*
)
&
tmp_table_param
,
sizeof
(
tmp_table_param
));
tmp_table_param
.
field_count
=
item_list
.
elements
;
if
(
!
(
table
=
create_tmp_table
(
thd
,
&
tmp_table_param
,
item_list
,
(
ORDER
*
)
0
,
0
,
1
,
(
ORDER
*
)
0
,
is_union
&&
!
unit
->
union_option
,
1
,
(
sl
->
options
|
thd
->
options
|
TMP_TABLE_ALL_COLUMNS
),
HA_POS_ERROR
)))
...
...
@@ -87,11 +105,14 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
SELECT_LEX_NODE
*
save_current_select
=
lex
->
current_select
;
lex
->
current_select
=
sl
;
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
if
(
is_union
)
res
=
mysql_union
(
thd
,
lex
,
derived_result
,
unit
);
else
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
sl
->
where
,
(
ORDER
*
)
sl
->
order_list
.
first
,
(
ORDER
*
)
sl
->
group_list
.
first
,
sl
->
having
,
(
ORDER
*
)
NULL
,
sl
->
options
|
thd
->
options
|
SELECT_NO_UNLOCK
,
sl
->
options
|
thd
->
options
|
SELECT_NO_UNLOCK
,
derived_result
,
unit
,
sl
,
0
);
lex
->
current_select
=
save_current_select
;
...
...
@@ -112,7 +133,12 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
tables
->
table_list
->
table
=
tables
->
table
;
// to fix a problem in EXPLAIN
}
else
sl
->
exclude
();
{
if
(
is_union
)
unit
->
exclude
();
else
sl
->
exclude
();
}
t
->
db
=
(
char
*
)
""
;
t
->
derived
=
(
SELECT_LEX
*
)
0
;
// just in case ...
table
->
file
->
info
(
HA_STATUS_VARIABLE
);
...
...
sql/sql_lex.cc
View file @
a918a6a7
...
...
@@ -995,7 +995,8 @@ void st_select_lex::init_select()
use_index
.
empty
();
ftfunc_list_alloc
.
empty
();
ftfunc_list
=
&
ftfunc_list_alloc
;
linkage
=
UNSPECIFIED_TYPE
;
if
(
linkage
!=
UNION_TYPE
)
linkage
=
UNSPECIFIED_TYPE
;
}
/*
...
...
@@ -1206,7 +1207,7 @@ bool st_select_lex_unit::create_total_list_n_last_return(THD *thd, st_lex *lex,
net_printf
(
thd
,
ER_WRONG_USAGE
,
"UNION"
,
"ORDER BY"
);
return
1
;
}
if
(
sl
->
linkage
==
DERIVED_TABLE_TYPE
)
if
(
sl
->
linkage
==
DERIVED_TABLE_TYPE
&&
!
sl
->
next_select
()
)
continue
;
for
(
SELECT_LEX_UNIT
*
inner
=
sl
->
first_inner_unit
();
inner
;
...
...
sql/sql_select.cc
View file @
a918a6a7
...
...
@@ -162,7 +162,7 @@ int handle_select(THD *thd, LEX *lex, select_result *result)
register
SELECT_LEX
*
select_lex
=
&
lex
->
select_lex
;
fix_tables_pointers
(
lex
->
all_selects_list
);
if
(
select_lex
->
next_select
())
res
=
mysql_union
(
thd
,
lex
,
result
);
res
=
mysql_union
(
thd
,
lex
,
result
,
&
lex
->
unit
);
else
res
=
mysql_select
(
thd
,(
TABLE_LIST
*
)
select_lex
->
table_list
.
first
,
select_lex
->
item_list
,
...
...
sql/sql_union.cc
View file @
a918a6a7
...
...
@@ -24,10 +24,9 @@
#include "mysql_priv.h"
#include "sql_select.h"
int
mysql_union
(
THD
*
thd
,
LEX
*
lex
,
select_result
*
result
)
int
mysql_union
(
THD
*
thd
,
LEX
*
lex
,
select_result
*
result
,
SELECT_LEX_UNIT
*
unit
)
{
DBUG_ENTER
(
"mysql_union"
);
SELECT_LEX_UNIT
*
unit
=
&
lex
->
unit
;
int
res
=
0
;
if
(
!
(
res
=
unit
->
prepare
(
thd
,
result
)))
res
=
unit
->
exec
();
...
...
@@ -125,8 +124,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result)
SELECT_LEX_NODE
*
lex_select_save
=
thd
->
lex
.
current_select
;
SELECT_LEX
*
sl
;
if
(
lex_select_save
->
linkage
!=
DERIVED_TABLE_TYPE
)
thd
->
lex
.
current_select
=
first_select
();
thd
->
lex
.
current_select
=
first_select
();
/* Global option */
if
(((
void
*
)(
global_parameters
))
==
((
void
*
)
this
))
{
...
...
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