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
4d0430c8
Commit
4d0430c8
authored
Sep 04, 2006
by
msvensson@neptunus.(none)
Browse files
Options
Browse Files
Download
Plain Diff
Merge dl145s:/data/tkatchaounov/5.0-bug-21787
into neptunus.(none):/home/msvensson/mysql/mysql-5.0
parents
1bea6cf1
462c22c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
+38
-7
mysql-test/r/limit.result
mysql-test/r/limit.result
+14
-0
mysql-test/t/limit.test
mysql-test/t/limit.test
+10
-0
sql/sql_select.cc
sql/sql_select.cc
+14
-7
No files found.
mysql-test/r/limit.result
View file @
4d0430c8
...
@@ -76,3 +76,17 @@ a
...
@@ -76,3 +76,17 @@ a
a
a
1
1
drop table t1;
drop table t1;
create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6),(7);
explain select count(*) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where; Using temporary
select count(*) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
c
7
explain select sum(a) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where; Using temporary
select sum(a) c FROM t1 WHERE a > 0 ORDER BY c LIMIT 3;
c
28
mysql-test/t/limit.test
View file @
4d0430c8
...
@@ -60,4 +60,14 @@ select 1 as a from t1 union all select 1 from dual limit 1;
...
@@ -60,4 +60,14 @@ select 1 as a from t1 union all select 1 from dual limit 1;
(
select
1
as
a
from
t1
)
union
all
(
select
1
from
dual
)
limit
1
;
(
select
1
as
a
from
t1
)
union
all
(
select
1
from
dual
)
limit
1
;
drop
table
t1
;
drop
table
t1
;
#
# Bug #21787: COUNT(*) + ORDER BY + LIMIT returns wrong result
#
create
table
t1
(
a
int
);
insert
into
t1
values
(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
);
explain
select
count
(
*
)
c
FROM
t1
WHERE
a
>
0
ORDER
BY
c
LIMIT
3
;
select
count
(
*
)
c
FROM
t1
WHERE
a
>
0
ORDER
BY
c
LIMIT
3
;
explain
select
sum
(
a
)
c
FROM
t1
WHERE
a
>
0
ORDER
BY
c
LIMIT
3
;
select
sum
(
a
)
c
FROM
t1
WHERE
a
>
0
ORDER
BY
c
LIMIT
3
;
# End of 4.1 tests
# End of 4.1 tests
sql/sql_select.cc
View file @
4d0430c8
...
@@ -8994,11 +8994,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
...
@@ -8994,11 +8994,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
keyinfo
->
key_length
+=
key_part_info
->
length
;
keyinfo
->
key_length
+=
key_part_info
->
length
;
}
}
}
}
else
{
set_if_smaller
(
table
->
s
->
max_rows
,
rows_limit
);
param
->
end_write_records
=
rows_limit
;
}
if
(
distinct
&&
field_count
!=
param
->
hidden_field_count
)
if
(
distinct
&&
field_count
!=
param
->
hidden_field_count
)
{
{
...
@@ -9013,8 +9008,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
...
@@ -9013,8 +9008,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
null_pack_length
-=
hidden_null_pack_length
;
null_pack_length
-=
hidden_null_pack_length
;
keyinfo
->
key_parts
=
((
field_count
-
param
->
hidden_field_count
)
+
keyinfo
->
key_parts
=
((
field_count
-
param
->
hidden_field_count
)
+
test
(
null_pack_length
));
test
(
null_pack_length
));
set_if_smaller
(
table
->
s
->
max_rows
,
rows_limit
);
param
->
end_write_records
=
rows_limit
;
table
->
distinct
=
1
;
table
->
distinct
=
1
;
table
->
s
->
keys
=
1
;
table
->
s
->
keys
=
1
;
if
(
blob_count
)
if
(
blob_count
)
...
@@ -9066,6 +9059,20 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
...
@@ -9066,6 +9059,20 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
0
:
FIELDFLAG_BINARY
;
0
:
FIELDFLAG_BINARY
;
}
}
}
}
/*
Push the LIMIT clause to the temporary table creation, so that we
materialize only up to 'rows_limit' records instead of all result records.
This optimization is not applicable when there is GROUP BY or there is
no GROUP BY, but there are aggregate functions, because both must be
computed for all result rows.
*/
if
(
!
group
&&
!
thd
->
lex
->
current_select
->
with_sum_func
)
{
set_if_smaller
(
table
->
s
->
max_rows
,
rows_limit
);
param
->
end_write_records
=
rows_limit
;
}
if
(
thd
->
is_fatal_error
)
// If end of memory
if
(
thd
->
is_fatal_error
)
// If end of memory
goto
err
;
/* purecov: inspected */
goto
err
;
/* purecov: inspected */
table
->
s
->
db_record_offset
=
1
;
table
->
s
->
db_record_offset
=
1
;
...
...
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