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
34ec1572
Commit
34ec1572
authored
Jun 12, 2009
by
Georgi Kodinov
Browse files
Options
Browse Files
Download
Plain Diff
automerge
parents
a141a637
1f2b5b30
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
4 deletions
+90
-4
mysql-test/r/group_min_max.result
mysql-test/r/group_min_max.result
+39
-0
mysql-test/t/group_min_max.test
mysql-test/t/group_min_max.test
+35
-0
sql/opt_range.cc
sql/opt_range.cc
+16
-4
No files found.
mysql-test/r/group_min_max.result
View file @
34ec1572
...
...
@@ -2462,4 +2462,43 @@ c
1
2
DROP TABLE t1;
#
# Bug #45386: Wrong query result with MIN function in field list,
# WHERE and GROUP BY clause
#
CREATE TABLE t (a INT, b INT, INDEX (a,b));
INSERT INTO t VALUES (2,0), (2,0), (2,1), (2,1);
INSERT INTO t SELECT * FROM t;
# test MIN
#should use range with index for group by
EXPLAIN
SELECT a, MIN(b) FROM t WHERE b <> 0 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t range NULL a 10 NULL 9 Using where; Using index for group-by
#should return 1 row
SELECT a, MIN(b) FROM t WHERE b <> 0 GROUP BY a;
a MIN(b)
2 1
# test MAX
#should use range with index for group by
EXPLAIN
SELECT a, MAX(b) FROM t WHERE b <> 1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t range NULL a 10 NULL 9 Using where; Using index for group-by
#should return 1 row
SELECT a, MAX(b) FROM t WHERE b <> 1 GROUP BY a;
a MAX(b)
2 0
# test 3 ranges and use the middle one
INSERT INTO t SELECT a, 2 FROM t;
#should use range with index for group by
EXPLAIN
SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t range NULL a 10 NULL 9 Using where; Using index for group-by
#should return 1 row
SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a;
a MAX(b)
2 1
DROP TABLE t;
End of 5.0 tests
mysql-test/t/group_min_max.test
View file @
34ec1572
...
...
@@ -982,4 +982,39 @@ SELECT DISTINCT c FROM t1 WHERE d=4;
DROP
TABLE
t1
;
--
echo
#
--
echo
# Bug #45386: Wrong query result with MIN function in field list,
--
echo
# WHERE and GROUP BY clause
--
echo
#
CREATE
TABLE
t
(
a
INT
,
b
INT
,
INDEX
(
a
,
b
));
INSERT
INTO
t
VALUES
(
2
,
0
),
(
2
,
0
),
(
2
,
1
),
(
2
,
1
);
INSERT
INTO
t
SELECT
*
FROM
t
;
--
echo
# test MIN
--
echo
#should use range with index for group by
EXPLAIN
SELECT
a
,
MIN
(
b
)
FROM
t
WHERE
b
<>
0
GROUP
BY
a
;
--
echo
#should return 1 row
SELECT
a
,
MIN
(
b
)
FROM
t
WHERE
b
<>
0
GROUP
BY
a
;
--
echo
# test MAX
--
echo
#should use range with index for group by
EXPLAIN
SELECT
a
,
MAX
(
b
)
FROM
t
WHERE
b
<>
1
GROUP
BY
a
;
--
echo
#should return 1 row
SELECT
a
,
MAX
(
b
)
FROM
t
WHERE
b
<>
1
GROUP
BY
a
;
--
echo
# test 3 ranges and use the middle one
INSERT
INTO
t
SELECT
a
,
2
FROM
t
;
--
echo
#should use range with index for group by
EXPLAIN
SELECT
a
,
MAX
(
b
)
FROM
t
WHERE
b
>
0
AND
b
<
2
GROUP
BY
a
;
--
echo
#should return 1 row
SELECT
a
,
MAX
(
b
)
FROM
t
WHERE
b
>
0
AND
b
<
2
GROUP
BY
a
;
DROP
TABLE
t
;
--
echo
End
of
5.0
tests
sql/opt_range.cc
View file @
34ec1572
...
...
@@ -10886,8 +10886,14 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range()
/* Compare the found key with max_key. */
int
cmp_res
=
key_cmp
(
index_info
->
key_part
,
max_key
,
real_prefix_len
+
min_max_arg_len
);
if
(
!
(((
cur_range
->
flag
&
NEAR_MAX
)
&&
(
cmp_res
==
-
1
))
||
(
cmp_res
<=
0
)))
/*
The key is outside of the range if:
the interval is open and the key is equal to the maximum boundry
or
the key is greater than the maximum
*/
if
(((
cur_range
->
flag
&
NEAR_MAX
)
&&
cmp_res
==
0
)
||
cmp_res
>
0
)
{
result
=
HA_ERR_KEY_NOT_FOUND
;
continue
;
...
...
@@ -11004,8 +11010,14 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_max_in_range()
/* Compare the found key with min_key. */
int
cmp_res
=
key_cmp
(
index_info
->
key_part
,
min_key
,
real_prefix_len
+
min_max_arg_len
);
if
(
!
(((
cur_range
->
flag
&
NEAR_MIN
)
&&
(
cmp_res
==
1
))
||
(
cmp_res
>=
0
)))
/*
The key is outside of the range if:
the interval is open and the key is equal to the minimum boundry
or
the key is less than the minimum
*/
if
(((
cur_range
->
flag
&
NEAR_MIN
)
&&
cmp_res
==
0
)
||
cmp_res
<
0
)
continue
;
}
/* If we got to this point, the current key qualifies as MAX. */
...
...
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