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
cccb3aaf
Commit
cccb3aaf
authored
Jul 19, 2001
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes for the furtherment of UNIONS
parent
e0d818f3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
76 deletions
+106
-76
sql/sql_class.h
sql/sql_class.h
+5
-4
sql/sql_insert.cc
sql/sql_insert.cc
+5
-2
sql/sql_parse.cc
sql/sql_parse.cc
+19
-2
sql/sql_unions.cc
sql/sql_unions.cc
+77
-68
No files found.
sql/sql_class.h
View file @
cccb3aaf
...
...
@@ -481,12 +481,13 @@ class select_insert :public select_result {
uint
save_time_stamp
;
ulonglong
last_insert_id
;
COPY_INFO
info
;
bool
unions
;
select_insert
(
TABLE
*
table_par
,
List
<
Item
>
*
fields_par
,
enum_duplicates
duplic
)
select_insert
(
TABLE
*
table_par
,
List
<
Item
>
*
fields_par
,
enum_duplicates
duplic
,
bool
u
=
false
)
:
table
(
table_par
),
fields
(
fields_par
),
save_time_stamp
(
0
),
last_insert_id
(
0
)
{
bzero
((
char
*
)
&
info
,
sizeof
(
info
));
info
.
handle_duplicates
=
duplic
;
info
.
handle_duplicates
=
duplic
;
unions
=
u
;
}
~
select_insert
();
int
prepare
(
List
<
Item
>
&
list
);
...
...
@@ -511,8 +512,8 @@ public:
HA_CREATE_INFO
*
create_info_par
,
List
<
create_field
>
&
fields_par
,
List
<
Key
>
&
keys_par
,
List
<
Item
>
&
select_fields
,
enum_duplicates
duplic
)
:
select_insert
(
NULL
,
&
select_fields
,
duplic
),
db
(
db_name
),
List
<
Item
>
&
select_fields
,
enum_duplicates
duplic
,
bool
u
=
false
)
:
select_insert
(
NULL
,
&
select_fields
,
duplic
,
u
),
db
(
db_name
),
name
(
table_name
),
extra_fields
(
&
fields_par
),
keys
(
&
keys_par
),
create_info
(
create_info_par
),
lock
(
0
)
...
...
sql/sql_insert.cc
View file @
cccb3aaf
...
...
@@ -1318,6 +1318,7 @@ bool select_insert::send_eof()
thd
->
cuted_fields
);
if
(
last_insert_id
)
thd
->
insert_id
(
last_insert_id
);
// For update log
if
(
!
unions
)
::
send_ok
(
&
thd
->
net
,
info
.
copied
,
last_insert_id
,
buff
);
mysql_update_log
.
write
(
thd
,
thd
->
query
,
thd
->
query_length
);
if
(
mysql_bin_log
.
is_open
())
...
...
@@ -1400,7 +1401,9 @@ bool select_create::send_eof()
mysql_unlock_tables
(
thd
,
lock
);
if
(
!
table
->
tmp_table
)
hash_delete
(
&
open_cache
,(
byte
*
)
table
);
lock
=
0
;
table
=
0
;
lock
=
0
;
if
(
!
unions
)
table
=
0
;
VOID
(
pthread_mutex_unlock
(
&
LOCK_open
));
}
return
tmp
;
...
...
sql/sql_parse.cc
View file @
cccb3aaf
...
...
@@ -1754,7 +1754,15 @@ mysql_execute_command(void)
break
;
}
if
(
!
(
res
=
open_and_lock_tables
(
thd
,(
TABLE_LIST
*
)
total
->
first
)))
{
/* Fix tables--to-be-unioned-from list to point at opened tables */
for
(
SELECT_LEX
*
sl
=&
lex
->
select_lex
;
sl
;
sl
=
sl
->
next
)
{
for
(
TABLE_LIST
*
cursor
=
(
TABLE_LIST
*
)
sl
->
table_list
.
first
;
cursor
;
cursor
=
cursor
->
next
)
cursor
->
table
=
((
TABLE_LIST
*
)
cursor
->
table
)
->
table
;
}
res
=
mysql_union
(
thd
,
lex
,
select_lex
->
select_number
+
1
);
}
close_thread_tables
(
thd
);
break
;
}
...
...
@@ -2894,11 +2902,12 @@ TABLE_LIST *add_table_to_list(Table_ident *table, LEX_STRING *alias,
static
int
link_in_large_list_and_check_acl
(
THD
*
thd
,
LEX
*
lex
,
SQL_LIST
*
tables
)
{
SELECT_LEX
*
sl
;
const
char
*
current_db
=
thd
->
db
?
thd
->
db
:
""
;
TABLE_LIST
*
ptr
;
for
(
sl
=&
lex
->
select_lex
;
sl
;
sl
=
sl
->
next
)
{
if
((
lex
->
sql_command
==
SQLCOM_UNION_SELECT
)
&&
(
sl
->
order_list
.
first
!=
(
byte
*
)
NULL
)
&&
(
sl
->
next
!=
(
st_select_lex
*
)
NULL
))
{
net_printf
(
&
thd
->
net
,
ER_ILLEGAL_GRANT_FOR_TABLE
);
// correct error message will come here; only last SELEC
t
can have ORDER BY
net_printf
(
&
thd
->
net
,
ER_ILLEGAL_GRANT_FOR_TABLE
);
// correct error message will come here; only last SELEC
T
can have ORDER BY
return
-
1
;
}
if
(
sl
->
table_list
.
first
==
(
byte
*
)
NULL
)
continue
;
...
...
@@ -2919,7 +2928,15 @@ static int link_in_large_list_and_check_acl(THD *thd,LEX *lex,SQL_LIST *tables)
aux
->
lock_type
=
lex
->
lock_option
;
if
(
!
tables
->
next
)
tables
->
next
=
(
byte
**
)
&
tables
->
first
;
link_in_list
(
tables
,(
byte
*
)
aux
,(
byte
**
)
&
aux
->
next
);
if
(
!
(
ptr
=
(
TABLE_LIST
*
)
thd
->
calloc
(
sizeof
(
TABLE_LIST
))))
return
1
;
ptr
->
db
=
aux
->
db
;
ptr
->
real_name
=
aux
->
real_name
;
ptr
->
name
=
aux
->
name
;
ptr
->
lock_type
=
aux
->
lock_type
;
ptr
->
updating
=
aux
->
updating
;
ptr
->
use_index
=
aux
->
use_index
;
ptr
->
ignore_index
=
aux
->
use_index
;
aux
->
table
=
(
TABLE
*
)
ptr
;
link_in_list
(
tables
,(
byte
*
)
ptr
,(
byte
**
)
&
ptr
->
next
);
}
}
}
...
...
sql/sql_unions.cc
View file @
cccb3aaf
...
...
@@ -29,6 +29,7 @@
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
;
for
(;
for_order
->
next
;
for_order
=
for_order
->
next
);
ORDER
*
some_order
=
(
ORDER
*
)
for_order
->
order_list
.
first
;
...
...
@@ -37,13 +38,23 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
TABLE_LIST
*
tables
=
(
TABLE_LIST
*
)
sl
->
table_list
.
first
;
if
(
!
no
)
// First we do CREATE from SELECT
{
select_create
*
result
;
lex
->
create_info
.
options
=
HA_LEX_CREATE_TMP_TABLE
;
if
((
result
=
new
select_create
(
tables
->
db
?
tables
->
db
:
thd
->
db
,
NULL
,
&
lex
->
create_info
,
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
)))
sl
->
item_list
,
DUP_IGNORE
,
true
)))
{
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
sl
->
where
,
...
...
@@ -53,20 +64,18 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
sl
->
having
,
(
ORDER
*
)
some_order
,
sl
->
options
|
thd
->
options
,
result
);
create_
result
);
if
(
res
)
{
result
->
abort
();
delete
result
;
create_
result
->
abort
();
delete
create_
result
;
return
res
;
}
table
=
result
->
table
;
List_iterator
<
Item
>
it
(
*
(
result
->
fields
));
table
=
create_
result
->
table
;
List_iterator
<
Item
>
it
(
*
(
create_
result
->
fields
));
Item
*
item
;
while
((
item
=
it
++
))
fields
.
push_back
(
item
);
delete
result
;
if
(
!
reopen_table
(
table
))
return
1
;
if
(
!
(
resulting
=
(
TABLE_LIST
*
)
thd
->
calloc
(
sizeof
(
TABLE_LIST
))))
return
1
;
resulting
->
db
=
tables
->
db
?
tables
->
db
:
thd
->
db
;
...
...
@@ -80,7 +89,7 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
else
// Then we do INSERT from SELECT
{
select_result
*
result
;
if
((
result
=
new
select_insert
(
table
,
&
fields
,
DUP_IGNORE
)))
if
((
result
=
new
select_insert
(
table
,
&
fields
,
DUP_IGNORE
,
true
)))
{
res
=
mysql_select
(
thd
,
tables
,
sl
->
item_list
,
sl
->
where
,
...
...
@@ -92,34 +101,33 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
sl
->
options
|
thd
->
options
,
result
);
delete
result
;
if
(
res
)
return
1
;
if
(
res
)
{
delete
create_result
;
return
1
;
}
}
else
{
delete
create_result
;
return
-
1
;
}
}
}
select_result
*
result
;
List
<
Item
>
item_list
;
List
<
Item_func_match
>
ftfunc_list
;
ftfunc_list
.
empty
();
if
(
item_list
.
push_back
(
new
Item_field
(
NULL
,
NULL
,
"*"
)))
return
-
1
;
void
(
item_list
.
push_back
(
new
Item_field
(
NULL
,
NULL
,
"*"
)));
if
(
lex
->
exchange
)
{
if
(
lex
->
exchange
->
dumpfile
)
{
if
(
!
(
result
=
new
select_dump
(
lex
->
exchange
)))
return
-
1
;
}
result
=
new
select_dump
(
lex
->
exchange
);
else
{
if
(
!
(
result
=
new
select_export
(
lex
->
exchange
)))
return
-
1
;
result
=
new
select_export
(
lex
->
exchange
);
}
}
else
if
(
!
(
result
=
new
select_send
()))
return
-
1
;
else
else
result
=
new
select_send
();
if
(
result
)
{
res
=
mysql_select
(
thd
,
resulting
,
item_list
,
NULL
,
...
...
@@ -132,7 +140,8 @@ int mysql_union(THD *thd,LEX *lex,uint no_of_selects)
result
);
if
(
res
)
result
->
abort
();
}
delete
result
;
}
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