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
3d9cd36f
Commit
3d9cd36f
authored
May 28, 2002
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
limit clause fixed
parent
807b5085
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
11 deletions
+33
-11
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+4
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+5
-2
sql/item_subselect.cc
sql/item_subselect.cc
+10
-3
sql/sql_class.cc
sql/sql_class.cc
+9
-2
sql/sql_parse.cc
sql/sql_parse.cc
+5
-4
No files found.
mysql-test/r/subselect.result
View file @
3d9cd36f
...
...
@@ -36,4 +36,8 @@ a b
1 7
2 7
3 8
select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
(select a from t3 where a<t2.a*4 order by 1 desc limit 1) a
3 1
7 2
drop table t1,t2,t3,t4;
mysql-test/t/subselect.test
View file @
3d9cd36f
...
...
@@ -14,7 +14,10 @@ select (select a from t1), a from t2;
select
(
select
a
from
t3
),
a
from
t2
;
select
*
from
t2
where
t2
.
a
=
(
select
a
from
t1
);
insert
into
t3
values
(
6
),(
7
),(
3
);
select
*
from
t2
where
t2
.
b
=
(
select
a
from
t3
order
by
1
limit
1
);
select
*
from
t2
where
t2
.
b
=
(
select
a
from
t3
order
by
1
limit
1
)
select
*
from
t2
where
t2
.
b
=
(
select
a
from
t3
order
by
1
desc
limit
1
);
select
*
from
t2
where
t2
.
b
=
(
select
a
from
t3
order
by
1
desc
limit
1
)
union
(
select
*
from
t4
order
by
a
limit
2
)
limit
3
;
select
(
select
a
from
t3
where
a
<
t2
.
a
*
4
order
by
1
desc
limit
1
),
a
from
t2
;
select
(
select
t3
.
a
from
t3
where
a
<
8
order
by
1
desc
limit
1
),
a
from
(
select
*
from
t2
where
a
>
1
)
as
tt
;
drop
table
t1
,
t2
,
t3
,
t4
;
sql/item_subselect.cc
View file @
3d9cd36f
...
...
@@ -24,7 +24,6 @@ SUBSELECT TODO:
(sql_select.h/sql_select.cc)
- add subselect union select (sql_union.cc)
- depended from outer select subselects
*/
...
...
@@ -41,6 +40,14 @@ Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex):
DBUG_ENTER
(
"Item_subselect::Item_subselect"
);
DBUG_PRINT
(
"subs"
,
(
"select_lex 0x%xl"
,
(
long
)
select_lex
));
result
=
new
select_subselect
(
this
);
SELECT_LEX_UNIT
*
unit
=
select_lex
->
master_unit
();
unit
->
offset_limit_cnt
=
unit
->
global_parameters
->
offset_limit
;
unit
->
select_limit_cnt
=
unit
->
global_parameters
->
select_limit
+
select_lex
->
offset_limit
;
if
(
unit
->
select_limit_cnt
<
unit
->
global_parameters
->
select_limit
)
unit
->
select_limit_cnt
=
HA_POS_ERROR
;
// no limit
if
(
unit
->
select_limit_cnt
==
HA_POS_ERROR
)
select_lex
->
options
&=
~
OPTION_FOUND_ROWS
;
join
=
new
JOIN
(
thd
,
select_lex
->
item_list
,
select_lex
->
options
,
result
);
this
->
select_lex
=
select_lex
;
maybe_null
=
1
;
...
...
@@ -141,9 +148,9 @@ int Item_subselect::exec()
join
->
thd
->
lex
.
select
=
select_lex
;
join
->
exec
();
join
->
thd
->
lex
.
select
=
save_select
;
if
(
!
executed
)
//
if (!executed)
//No rows returned => value is null (returned as inited)
executed
=
1
;
//
executed= 1;
return
join
->
error
;
}
return
0
;
...
...
sql/sql_class.cc
View file @
3d9cd36f
...
...
@@ -784,9 +784,15 @@ select_subselect::select_subselect(Item_subselect *item)
bool
select_subselect
::
send_data
(
List
<
Item
>
&
items
)
{
DBUG_ENTER
(
"select_subselect::send_data"
);
if
(
item
->
executed
){
my_printf_error
(
ER_SUBSELECT_NO_1_ROW
,
ER
(
ER_SUBSELECT_NO_1_ROW
),
MYF
(
0
));
return
1
;
DBUG_RETURN
(
1
);
}
if
(
unit
->
offset_limit_cnt
)
{
// using limit offset,count
unit
->
offset_limit_cnt
--
;
DBUG_RETURN
(
0
);
}
Item
*
val_item
=
(
Item
*
)
item
->
select_lex
->
item_list
.
head
();
if
((
item
->
null_value
=
val_item
->
is_null
()))
...
...
@@ -801,5 +807,6 @@ bool select_subselect::send_data(List<Item> &items)
item
->
real_value
=
val_item
->
val
();
item
->
res_type
=
val_item
->
result_type
();
}
return
0
;
item
->
executed
=
1
;
DBUG_RETURN
(
0
);
}
sql/sql_parse.cc
View file @
3d9cd36f
...
...
@@ -1275,9 +1275,10 @@ mysql_execute_command(void)
break
;
// Error message is given
}
unit
->
offset_limit_cnt
=
select_lex
->
offset_limit
;
unit
->
select_limit_cnt
=
select_lex
->
select_limit
+
select_lex
->
offset_limit
;
if
(
unit
->
select_limit_cnt
<
select_lex
->
select_limit
)
unit
->
offset_limit_cnt
=
unit
->
global_parameters
->
offset_limit
;
unit
->
select_limit_cnt
=
unit
->
global_parameters
->
select_limit
+
unit
->
global_parameters
->
offset_limit
;
if
(
unit
->
select_limit_cnt
<
unit
->
global_parameters
->
select_limit
)
unit
->
select_limit_cnt
=
HA_POS_ERROR
;
// no limit
if
(
unit
->
select_limit_cnt
==
HA_POS_ERROR
)
select_lex
->
options
&=
~
OPTION_FOUND_ROWS
;
...
...
@@ -2672,7 +2673,7 @@ mysql_init_query(THD *thd)
thd
->
lex
.
unit
.
init_select
();
thd
->
lex
.
select_lex
.
init_query
();
thd
->
lex
.
unit
.
slave
=
&
thd
->
lex
.
select_lex
;
thd
->
lex
.
unit
.
select_limit
=
thd
->
default_select_limit
;
//Global limit
thd
->
lex
.
unit
.
global_parameters
=
&
thd
->
lex
.
select_lex
;
//Global limit & order
thd
->
lex
.
select_lex
.
master
=
&
thd
->
lex
.
unit
;
thd
->
lex
.
select_lex
.
prev
=
&
thd
->
lex
.
unit
.
slave
;
thd
->
lex
.
value_list
.
empty
();
...
...
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