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
8ae559d5
Commit
8ae559d5
authored
Jul 25, 2001
by
Sinisa@sinisa.nasamreza.org
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UNION's
parent
27caeeac
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
95 deletions
+87
-95
mysql-test/r/unions_one.result
mysql-test/r/unions_one.result
+15
-0
mysql-test/t/unions_one.test
mysql-test/t/unions_one.test
+16
-0
sql/sql_insert.cc
sql/sql_insert.cc
+6
-6
sql/sql_parse.cc
sql/sql_parse.cc
+2
-2
sql/sql_unions.cc
sql/sql_unions.cc
+48
-87
No files found.
mysql-test/r/unions_one.result
0 → 100644
View file @
8ae559d5
a b
1 a
2 b
3 c
4 d
5 e
6 f
a b
1 a
2 b
3 c
3 c
4 d
5 e
6 f
mysql-test/t/unions_one.test
0 → 100644
View file @
8ae559d5
#
# Test of unions
#
drop
table
if
exists
t1
,
t2
;
CREATE
TABLE
t1
(
a
int
not
null
,
b
char
(
10
)
not
null
);
insert
into
t1
values
(
1
,
"a"
),(
2
,
"b"
),(
3
,
"c"
);
CREATE
TABLE
t2
(
a
int
not
null
,
b
char
(
10
)
not
null
);
insert
into
t2
values
(
3
,
"c"
),(
4
,
"d"
),(
5
,
"e"
),(
6
,
"f"
);
select
a
,
b
from
t1
union
select
a
,
b
from
t2
;
select
a
,
b
from
t1
union
all
select
a
,
b
from
t2
;
drop
table
t1
,
t2
;
sql/sql_insert.cc
View file @
8ae559d5
sql/sql_parse.cc
View file @
8ae559d5
...
...
@@ -2426,7 +2426,7 @@ mysql_init_query(THD *thd)
thd
->
lex
.
select_lex
.
item_list
.
empty
();
thd
->
lex
.
value_list
.
empty
();
thd
->
lex
.
select_lex
.
table_list
.
elements
=
0
;
thd
->
free_list
=
0
;
thd
->
free_list
=
0
;
thd
->
lex
.
union_option
=
0
;
thd
->
lex
.
select
=
&
thd
->
lex
.
select_lex
;
thd
->
lex
.
select_lex
.
table_list
.
first
=
0
;
thd
->
lex
.
select_lex
.
table_list
.
next
=
(
byte
**
)
&
thd
->
lex
.
select_lex
.
table_list
.
first
;
...
...
@@ -2444,7 +2444,7 @@ mysql_init_select(LEX *lex)
select_lex
->
select_limit
=
current_thd
->
default_select_limit
;
select_lex
->
offset_limit
=
0
;
select_lex
->
options
=
0
;
select_lex
->
linkage
=
UNSPECIFIED_TYPE
;
select_lex
->
select_number
=
0
;
lex
->
exchange
=
0
;
lex
->
union_option
=
0
;
select_lex
->
select_number
=
0
;
lex
->
exchange
=
0
;
lex
->
proc_list
.
first
=
0
;
select_lex
->
order_list
.
elements
=
select_lex
->
group_list
.
elements
=
0
;
select_lex
->
order_list
.
first
=
0
;
...
...
sql/sql_unions.cc
View file @
8ae559d5
...
...
@@ -21,75 +21,46 @@
#include "mysql_priv.h"
#include "sql_select.h"
/* Union of selects */
int
mysql_union
(
THD
*
thd
,
LEX
*
lex
,
uint
no_of_selects
)
{
SELECT_LEX
*
sl
,
*
for_order
=&
lex
->
select_lex
;
uint
no
=
0
;
int
res
=
0
;
select_create
*
create_result
;
List
<
Item
>
fields
;
TABLE
*
table
=
(
TABLE
*
)
NULL
;
TABLE_LIST
*
resulting
=
(
TABLE_LIST
*
)
NULL
;
SELECT_LEX
*
sl
,
*
for_order
=&
lex
->
select_lex
;
int
res
=
0
;
TABLE
*
table
=
(
TABLE
*
)
NULL
;
TABLE_LIST
*
resulting
=
(
TABLE_LIST
*
)
NULL
;
for
(;
for_order
->
next
;
for_order
=
for_order
->
next
);
ORDER
*
some_order
=
(
ORDER
*
)
for_order
->
order_list
.
first
;
for
(
sl
=&
lex
->
select_lex
;
sl
;
sl
=
sl
->
next
,
no
++
)
{
TABLE_LIST
*
tables
=
(
TABLE_LIST
*
)
sl
->
table_list
.
first
;
if
(
!
no
)
// First we do CREATE from SELECT
{
lex
->
create_info
.
options
=
HA_LEX_CREATE_TMP_TABLE
;
lex
->
create_info
.
db_type
=
DB_TYPE_MYISAM
;
lex
->
create_info
.
row_type
=
ROW_TYPE_DEFAULT
;
lex
->
create_info
.
avg_row_length
=
0
;
lex
->
create_info
.
max_rows
=
INT_MAX
;
lex
->
create_info
.
min_rows
=
0
;
lex
->
create_info
.
comment
=
lex
->
create_info
.
password
=
NullS
;
lex
->
create_info
.
data_file_name
=
lex
->
create_info
.
index_file_name
=
NullS
;
lex
->
create_info
.
raid_type
=
lex
->
create_info
.
raid_chunks
=
0
;
lex
->
create_info
.
raid_chunksize
=
0
;
lex
->
create_info
.
if_not_exists
=
false
;
lex
->
create_info
.
used_fields
=
0
;
if
((
create_result
=
new
select_create
(
tables
->
db
?
tables
->
db
:
thd
->
db
,
"ZVEK"
,
&
lex
->
create_info
,
lex
->
create_list
,
lex
->
key_list
,
sl
->
item_list
,
DUP_IGNORE
,
true
)))
{
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
sl
->
where
,
sl
->
ftfunc_list
,
(
ORDER
*
)
NULL
,
(
ORDER
*
)
sl
->
group_list
.
first
,
sl
->
having
,
(
ORDER
*
)
some_order
,
sl
->
options
|
thd
->
options
,
create_result
);
if
(
res
)
{
create_result
->
abort
();
delete
create_result
;
return
res
;
}
table
=
create_result
->
table
;
/* List_iterator<Item> it(*(create_result->fields));
List
<
Item
>
list
;
List_iterator
<
Item
>
it
(
lex
->
select_lex
.
item_list
);
Item
*
item
;
TABLE_LIST
*
s
=
(
TABLE_LIST
*
)
lex
->
select_lex
.
table_list
.
first
;
while
((
item
=
it
++
))
fields.push_back(item);*/
if
(
list
.
push_back
(
item
))
return
-
1
;
if
(
setup_fields
(
thd
,
s
,
list
,
0
,
0
))
return
-
1
;
TMP_TABLE_PARAM
*
tmp_table_param
=
new
TMP_TABLE_PARAM
;
count_field_types
(
tmp_table_param
,
list
,
0
);
tmp_table_param
->
end_write_records
=
HA_POS_ERROR
;
tmp_table_param
->
copy_field
=
0
;
tmp_table_param
->
copy_field_count
=
tmp_table_param
->
field_count
=
tmp_table_param
->
sum_func_count
=
tmp_table_param
->
func_count
=
0
;
if
(
!
(
table
=
create_tmp_table
(
thd
,
tmp_table_param
,
list
,
(
ORDER
*
)
0
,
!
lex
->
union_option
,
0
,
0
,
lex
->
select_lex
.
options
|
thd
->
options
)))
return
1
;
if
(
!
(
resulting
=
(
TABLE_LIST
*
)
thd
->
calloc
(
sizeof
(
TABLE_LIST
))))
return
1
;
resulting
->
db
=
tables
->
db
?
table
s
->
db
:
thd
->
db
;
resulting
->
db
=
s
->
db
?
s
->
db
:
thd
->
db
;
resulting
->
real_name
=
table
->
real_name
;
resulting
->
name
=
table
->
table_name
;
resulting
->
table
=
table
;
}
else
return
-
1
;
}
else
// Then we do INSERT from SELECT
for
(
sl
=&
lex
->
select_lex
;
sl
;
sl
=
sl
->
next
)
{
TABLE_LIST
*
tables
=
(
TABLE_LIST
*
)
sl
->
table_list
.
first
;
select_insert
*
result
;
if
((
result
=
new
select_insert
(
table
,
create_result
->
fields
,
DUP_IGNORE
,
true
)))
if
((
result
=
new
select_insert
(
table
,
&
list
,
DUP_IGNORE
,
true
)))
{
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
sl
->
where
,
...
...
@@ -102,23 +73,14 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
result
);
delete
result
;
if
(
res
)
{
delete
create_result
;
return
res
;
}
}
else
{
delete
create_result
;
return
-
1
;
}
}
}
select_result
*
result
;
List
<
Item
>
item_list
;
List
<
Item_func_match
>
ftfunc_list
;
ftfunc_list
.
empty
();
void
(
item_list
.
push_back
(
new
Item_field
(
NULL
,
NULL
,
"*"
)));
if
(
lex
->
exchange
)
{
if
(
lex
->
exchange
->
dumpfile
)
...
...
@@ -129,7 +91,7 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
else
result
=
new
select_send
();
if
(
result
)
{
res
=
mysql_select
(
thd
,
resulting
,
item_
list
,
res
=
mysql_select
(
thd
,
resulting
,
list
,
NULL
,
ftfunc_list
,
(
ORDER
*
)
NULL
,
...
...
@@ -144,6 +106,5 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
}
else
res
=-
1
;
delete
create_result
;
return
res
;
}
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