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
602d26b9
Commit
602d26b9
authored
Mar 07, 2023
by
Rex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-30605 Wrong result while using index for group-by
incorrect result when group function applied on a primary key
parent
b1646d04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
+30
-3
mysql-test/main/group_min_max.result
mysql-test/main/group_min_max.result
+14
-2
mysql-test/main/group_min_max.test
mysql-test/main/group_min_max.test
+11
-0
sql/opt_range.cc
sql/opt_range.cc
+5
-1
No files found.
mysql-test/main/group_min_max.result
View file @
602d26b9
...
...
@@ -881,10 +881,10 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by
explain select a1,a2,b, max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1
range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by
1 SIMPLE t1
index NULL idx_t1_1 163 NULL 512 Using where; Using index
explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1
range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by
1 SIMPLE t1
index NULL idx_t1_1 163 NULL 512 Using where; Using index
explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b111') and (c <= 'g112') group by a1,a2,b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL idx_t1_1 163 NULL 17 Using where; Using index for group-by
...
...
@@ -4083,5 +4083,17 @@ MIN(pk)
1
DROP TABLE t1, t2;
#
# MDEV-30605 Wrong result while using index for group-by
#
CREATE TABLE t (pk INT primary key, a int, key(a));
INSERT INTO t VALUES (1,-1),(2,8),(3,5),(4,-1),(5,10), (6,-1);
SELECT MIN(pk), a FROM t WHERE pk <> 1 GROUP BY a;
MIN(pk) a
4 -1
3 5
2 8
5 10
DROP TABLE t;
#
# End of 10.5 tests
#
mysql-test/main/group_min_max.test
View file @
602d26b9
...
...
@@ -1737,6 +1737,17 @@ SELECT SQL_BUFFER_RESULT MIN(pk) FROM t1, t2;
SELECT
MIN
(
pk
)
FROM
t1
,
t2
;
DROP
TABLE
t1
,
t2
;
--
echo
#
--
echo
# MDEV-30605 Wrong result while using index for group-by
--
echo
#
CREATE
TABLE
t
(
pk
INT
primary
key
,
a
int
,
key
(
a
));
INSERT
INTO
t
VALUES
(
1
,
-
1
),(
2
,
8
),(
3
,
5
),(
4
,
-
1
),(
5
,
10
),
(
6
,
-
1
);
SELECT
MIN
(
pk
),
a
FROM
t
WHERE
pk
<>
1
GROUP
BY
a
;
DROP
TABLE
t
;
--
echo
#
--
echo
# End of 10.5 tests
--
echo
#
sql/opt_range.cc
View file @
602d26b9
...
...
@@ -3037,7 +3037,11 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
if
(
unlikely
(
thd
->
trace_started
()))
group_trp
->
trace_basic_info
(
&
param
,
&
grp_summary
);
if
(
group_trp
->
read_cost
<
best_read_time
||
force_group_by
)
// if there is no range tree and there IS an attached cond
// QUICK_GROUP_MIN_MAX_SELECT will not filter results correctly
// do not choose it
if
((
group_trp
->
read_cost
<
best_read_time
||
force_group_by
)
&&
(
tree
||
!
cond
)
)
{
grp_summary
.
add
(
"chosen"
,
true
);
best_trp
=
group_trp
;
...
...
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