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
75b48e65
Commit
75b48e65
authored
May 28, 2003
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-4.1
into sanja.is.com.ua:/home/bell/mysql/bk/work-mem_root-4.1
parents
7f9788a2
1be87f66
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
11 deletions
+58
-11
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+14
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+14
-0
sql/item_subselect.cc
sql/item_subselect.cc
+27
-11
sql/item_subselect.h
sql/item_subselect.h
+3
-0
No files found.
mysql-test/r/subselect.result
View file @
75b48e65
...
...
@@ -1134,3 +1134,17 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref salary salary 5 const 1 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
drop table t1;
CREATE TABLE t1 (
ID int(10) unsigned NOT NULL auto_increment,
SUB_ID int(3) unsigned NOT NULL default '0',
REF_ID int(10) unsigned default NULL,
REF_SUB int(3) unsigned default '0',
PRIMARY KEY (ID,SUB_ID),
UNIQUE KEY t1_PK (ID,SUB_ID),
KEY t1_FK (REF_ID,REF_SUB),
KEY t1_REFID (REF_ID)
) TYPE=MyISAM CHARSET=cp1251;
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
REF_ID
DROP TABLE t1;
mysql-test/t/subselect.test
View file @
75b48e65
...
...
@@ -716,3 +716,17 @@ create table t1 (id int not null auto_increment primary key, salary int, key(sal
insert
into
t1
(
salary
)
values
(
100
),(
1000
),(
10000
),(
10
),(
500
),(
5000
),(
50000
);
explain
SELECT
id
FROM
t1
where
salary
=
(
SELECT
MAX
(
salary
)
FROM
t1
);
drop
table
t1
;
CREATE
TABLE
t1
(
ID
int
(
10
)
unsigned
NOT
NULL
auto_increment
,
SUB_ID
int
(
3
)
unsigned
NOT
NULL
default
'0'
,
REF_ID
int
(
10
)
unsigned
default
NULL
,
REF_SUB
int
(
3
)
unsigned
default
'0'
,
PRIMARY
KEY
(
ID
,
SUB_ID
),
UNIQUE
KEY
t1_PK
(
ID
,
SUB_ID
),
KEY
t1_FK
(
REF_ID
,
REF_SUB
),
KEY
t1_REFID
(
REF_ID
)
)
TYPE
=
MyISAM
CHARSET
=
cp1251
;
INSERT
INTO
t1
VALUES
(
1
,
0
,
NULL
,
NULL
),(
2
,
0
,
NULL
,
NULL
);
SELECT
DISTINCT
REF_ID
FROM
t1
WHERE
ID
=
(
SELECT
DISTINCT
REF_ID
FROM
t1
WHERE
ID
=
2
);
DROP
TABLE
t1
;
sql/item_subselect.cc
View file @
75b48e65
...
...
@@ -79,8 +79,10 @@ void Item_subselect::select_transformer(THD *thd, st_select_lex_unit *unit)
}
bool
Item_subselect
::
fix_fields
(
THD
*
thd
,
TABLE_LIST
*
tables
,
Item
**
ref
)
bool
Item_subselect
::
fix_fields
(
THD
*
thd
_param
,
TABLE_LIST
*
tables
,
Item
**
ref
)
{
thd
=
thd_param
;
if
(
substitution
)
{
(
*
ref
)
=
substitution
;
...
...
@@ -115,6 +117,20 @@ bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
return
res
;
}
bool
Item_subselect
::
exec
()
{
MEM_ROOT
*
old_root
=
my_pthread_getspecific_ptr
(
MEM_ROOT
*
,
THR_MALLOC
);
if
(
&
thd
->
mem_root
!=
old_root
)
{
my_pthread_setspecific_ptr
(
THR_MALLOC
,
&
thd
->
mem_root
);
int
res
=
engine
->
exec
();
my_pthread_setspecific_ptr
(
THR_MALLOC
,
old_root
);
return
(
res
);
}
else
return
engine
->
exec
();
}
Item
::
Type
Item_subselect
::
type
()
const
{
return
SUBSELECT_ITEM
;
...
...
@@ -253,12 +269,12 @@ bool Item_singlerow_subselect::null_inside()
void
Item_singlerow_subselect
::
bring_value
()
{
e
ngine
->
e
xec
();
exec
();
}
double
Item_singlerow_subselect
::
val
()
{
if
(
!
e
ngine
->
e
xec
()
&&
!
value
->
null_value
)
if
(
!
exec
()
&&
!
value
->
null_value
)
{
null_value
=
0
;
return
value
->
val
();
...
...
@@ -272,7 +288,7 @@ double Item_singlerow_subselect::val ()
longlong
Item_singlerow_subselect
::
val_int
()
{
if
(
!
e
ngine
->
e
xec
()
&&
!
value
->
null_value
)
if
(
!
exec
()
&&
!
value
->
null_value
)
{
null_value
=
0
;
return
value
->
val_int
();
...
...
@@ -286,7 +302,7 @@ longlong Item_singlerow_subselect::val_int ()
String
*
Item_singlerow_subselect
::
val_str
(
String
*
str
)
{
if
(
!
e
ngine
->
e
xec
()
&&
!
value
->
null_value
)
if
(
!
exec
()
&&
!
value
->
null_value
)
{
null_value
=
0
;
return
value
->
val_str
(
str
);
...
...
@@ -354,7 +370,7 @@ void Item_exists_subselect::fix_length_and_dec()
double
Item_exists_subselect
::
val
()
{
if
(
e
ngine
->
e
xec
())
if
(
exec
())
{
reset
();
return
0
;
...
...
@@ -364,7 +380,7 @@ double Item_exists_subselect::val ()
longlong
Item_exists_subselect
::
val_int
()
{
if
(
e
ngine
->
e
xec
())
if
(
exec
())
{
reset
();
return
0
;
...
...
@@ -374,7 +390,7 @@ longlong Item_exists_subselect::val_int ()
String
*
Item_exists_subselect
::
val_str
(
String
*
str
)
{
if
(
e
ngine
->
e
xec
())
if
(
exec
())
{
reset
();
return
0
;
...
...
@@ -385,7 +401,7 @@ String *Item_exists_subselect::val_str(String *str)
double
Item_in_subselect
::
val
()
{
if
(
e
ngine
->
e
xec
())
if
(
exec
())
{
reset
();
null_value
=
1
;
...
...
@@ -398,7 +414,7 @@ double Item_in_subselect::val ()
longlong
Item_in_subselect
::
val_int
()
{
if
(
e
ngine
->
e
xec
())
if
(
exec
())
{
reset
();
null_value
=
1
;
...
...
@@ -411,7 +427,7 @@ longlong Item_in_subselect::val_int ()
String
*
Item_in_subselect
::
val_str
(
String
*
str
)
{
if
(
e
ngine
->
e
xec
())
if
(
exec
())
{
reset
();
null_value
=
1
;
...
...
sql/item_subselect.h
View file @
75b48e65
...
...
@@ -36,6 +36,8 @@ class Item_subselect :public Item_result_field
my_bool
engine_owner
;
/* Is this item owner of engine */
my_bool
value_assigned
;
/* value already assigned to subselect */
protected:
/* thread handler, will be assigned in fix_fields only */
THD
*
thd
;
/* substitution instead of subselect in case of optimization */
Item
*
substitution
;
/* engine that perform execution of subselect (single select or union) */
...
...
@@ -81,6 +83,7 @@ class Item_subselect :public Item_result_field
return
null_value
;
}
bool
fix_fields
(
THD
*
thd
,
TABLE_LIST
*
tables
,
Item
**
ref
);
bool
exec
();
virtual
void
fix_length_and_dec
();
table_map
used_tables
()
const
;
...
...
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