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
4cf3621d
Commit
4cf3621d
authored
Aug 10, 2009
by
Martin Hansson
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
2c190aea
1164f8a6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
13 deletions
+118
-13
mysql-test/r/order_by.result
mysql-test/r/order_by.result
+57
-0
mysql-test/t/order_by.test
mysql-test/t/order_by.test
+41
-0
sql/sql_select.cc
sql/sql_select.cc
+13
-12
sql/table.h
sql/table.h
+7
-1
No files found.
mysql-test/r/order_by.result
View file @
4cf3621d
...
...
@@ -1500,3 +1500,60 @@ id1
15
16
DROP TABLE t1;
CREATE TABLE t1 (
a INT,
b INT NOT NULL,
c char(100),
KEY (b, c),
KEY (b, a, c)
)
DEFAULT CHARSET = utf8;
INSERT INTO t1 VALUES
(1, 1, 1),
(2, 2, 2),
(3, 3, 3),
(4, 4, 4),
(5, 5, 5),
(6, 6, 6),
(7, 7, 7),
(8, 8, 8),
(9, 9, 9);
INSERT INTO t1 SELECT a + 10, b, c FROM t1;
INSERT INTO t1 SELECT a + 20, b, c FROM t1;
INSERT INTO t1 SELECT a + 40, b, c FROM t1;
INSERT INTO t1 SELECT a + 80, b, c FROM t1;
INSERT INTO t1 SELECT a + 160, b, c FROM t1;
INSERT INTO t1 SELECT a + 320, b, c FROM t1;
INSERT INTO t1 SELECT a + 640, b, c FROM t1;
INSERT INTO t1 SELECT a + 1280, b, c FROM t1 LIMIT 80;
EXPLAIN
SELECT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 9;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range b,b_2 b 4 NULL 226 Using where
SELECT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 9;
a
2071
2061
2051
2041
2031
2021
2011
2001
1991
EXPLAIN
SELECT DISTINCT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 0, 9;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range b,b_2 b 4 NULL 226 Using where; Using temporary
SELECT DISTINCT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 0, 9;
a
2071
2061
2051
2041
2031
2021
2011
2001
1991
DROP TABLE t1;
mysql-test/t/order_by.test
View file @
4cf3621d
...
...
@@ -1361,3 +1361,44 @@ DROP TABLE t1;
#
# Bug#46454: MySQL wrong index optimisation leads to incorrect result & crashes
#
CREATE
TABLE
t1
(
a
INT
,
b
INT
NOT
NULL
,
c
char
(
100
),
KEY
(
b
,
c
),
KEY
(
b
,
a
,
c
)
)
DEFAULT
CHARSET
=
utf8
;
INSERT
INTO
t1
VALUES
(
1
,
1
,
1
),
(
2
,
2
,
2
),
(
3
,
3
,
3
),
(
4
,
4
,
4
),
(
5
,
5
,
5
),
(
6
,
6
,
6
),
(
7
,
7
,
7
),
(
8
,
8
,
8
),
(
9
,
9
,
9
);
INSERT
INTO
t1
SELECT
a
+
10
,
b
,
c
FROM
t1
;
INSERT
INTO
t1
SELECT
a
+
20
,
b
,
c
FROM
t1
;
INSERT
INTO
t1
SELECT
a
+
40
,
b
,
c
FROM
t1
;
INSERT
INTO
t1
SELECT
a
+
80
,
b
,
c
FROM
t1
;
INSERT
INTO
t1
SELECT
a
+
160
,
b
,
c
FROM
t1
;
INSERT
INTO
t1
SELECT
a
+
320
,
b
,
c
FROM
t1
;
INSERT
INTO
t1
SELECT
a
+
640
,
b
,
c
FROM
t1
;
INSERT
INTO
t1
SELECT
a
+
1280
,
b
,
c
FROM
t1
LIMIT
80
;
EXPLAIN
SELECT
a
FROM
t1
WHERE
b
=
1
ORDER
BY
c
DESC
LIMIT
9
;
SELECT
a
FROM
t1
WHERE
b
=
1
ORDER
BY
c
DESC
LIMIT
9
;
EXPLAIN
SELECT
DISTINCT
a
FROM
t1
WHERE
b
=
1
ORDER
BY
c
DESC
LIMIT
0
,
9
;
SELECT
DISTINCT
a
FROM
t1
WHERE
b
=
1
ORDER
BY
c
DESC
LIMIT
0
,
9
;
DROP
TABLE
t1
;
sql/sql_select.cc
View file @
4cf3621d
...
...
@@ -6151,7 +6151,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
}
}
if
(
tmp
||
!
cond
)
if
(
tmp
||
!
cond
||
tab
->
type
==
JT_REF
)
{
DBUG_EXECUTE
(
"where"
,
print_where
(
tmp
,
tab
->
table
->
alias
,
QT_ORDINARY
););
SQL_SELECT
*
sel
=
tab
->
select
=
((
SQL_SELECT
*
)
...
...
@@ -6165,7 +6165,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
The guard will turn the predicate on only after
the first match for outer tables is encountered.
*/
if
(
cond
)
if
(
cond
&&
tmp
)
{
/*
Because of QUICK_GROUP_MIN_MAX_SELECT there may be a select without
...
...
@@ -12946,6 +12946,8 @@ find_field_in_item_list (Field *field, void *data)
The index must cover all fields in <order>, or it will not be considered.
@param no_changes No changes will be made to the query plan.
@todo
- sergeyp: Results of all index merge selects actually are ordered
by clustered PK values.
...
...
@@ -13280,6 +13282,15 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
}
if
(
!
no_changes
)
{
/*
If ref_key used index tree reading only ('Using index' in EXPLAIN),
and best_key doesn't, then revert the decision.
*/
if
(
!
table
->
covering_keys
.
is_set
(
best_key
)
&&
table
->
key_read
)
{
table
->
key_read
=
0
;
table
->
file
->
extra
(
HA_EXTRA_NO_KEYREAD
);
}
if
(
!
quick_created
)
{
tab
->
index
=
best_key
;
...
...
@@ -13296,16 +13307,6 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
table
->
key_read
=
1
;
table
->
file
->
extra
(
HA_EXTRA_KEYREAD
);
}
else
if
(
table
->
key_read
)
{
/*
Clear the covering key read flags that might have been
previously set for some key other than the current best_key.
*/
table
->
key_read
=
0
;
table
->
file
->
extra
(
HA_EXTRA_NO_KEYREAD
);
}
table
->
file
->
ha_index_or_rnd_end
();
if
(
join
->
select_options
&
SELECT_DESCRIBE
)
{
...
...
sql/table.h
View file @
4cf3621d
...
...
@@ -755,7 +755,13 @@ struct st_table {
*/
my_bool
force_index
;
my_bool
distinct
,
const_table
,
no_rows
;
my_bool
key_read
,
no_keyread
;
/**
If set, the optimizer has found that row retrieval should access index
tree only.
*/
my_bool
key_read
;
my_bool
no_keyread
;
/*
Placeholder for an open table which prevents other connections
from taking name-locks on this table. Typically used with
...
...
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