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
bf30585e
Commit
bf30585e
authored
Sep 09, 2014
by
Sergei Petrunia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-465: Optimizer : wrong index choice: Add a testcase.
parent
8bd47162
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
mysql-test/r/order_by.result
mysql-test/r/order_by.result
+36
-0
mysql-test/t/order_by.test
mysql-test/t/order_by.test
+39
-0
No files found.
mysql-test/r/order_by.result
View file @
bf30585e
...
...
@@ -2949,3 +2949,39 @@ explain update t1 set key1=key1+1 where key1 between 10 and 110 order by key1 li
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range key1 key1 5 NULL 2 Using where; Using buffer
drop table t1,t2;
#
# MDEV-465: Optimizer : wrong index choice, leading to strong performances issues
#
CREATE TABLE t1 (
id1 int(10) unsigned NOT NULL auto_increment,
id2 tinyint(3) unsigned NOT NULL default '0',
id3 tinyint(3) unsigned NOT NULL default '0',
id4 int(10) unsigned NOT NULL default '0',
date timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (id1),
KEY id_234_date (id2,id3,id4,date),
KEY id_23_date (id2,id3,date)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
# t1 has "bad" index declaration order..
CREATE TABLE t2 (
id1 int(10) unsigned NOT NULL auto_increment,
id2 tinyint(3) unsigned NOT NULL default '0',
id3 tinyint(3) unsigned NOT NULL default '0',
id4 int(10) unsigned NOT NULL default '0',
date timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (id1),
KEY id_23_date (id2,id3,date),
KEY id_234_date (id2,id3,id4,date)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
# t2 has a "good" index declaration order
INSERT INTO t1 (id2,id3,id4) VALUES (1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,0,1),(1,2,1),(1,3,1);
INSERT INTO t2 (id2,id3,id4) VALUES (1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,0,1),(1,2,1),(1,3,1);
# The following two must both use id_23_date and no "using filesort":
EXPLAIN SELECT id1 FROM t1 WHERE id2=1 AND id3=1 ORDER BY date DESC LIMIT 0,4;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range id_234_date,id_23_date id_23_date 2 NULL 3 Using where
# See above query
EXPLAIN SELECT id1 FROM t2 WHERE id2=1 AND id3=1 ORDER BY date DESC LIMIT 0,4;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref id_23_date,id_234_date id_23_date 2 const,const 3 Using where
drop table t1,t2;
mysql-test/t/order_by.test
View file @
bf30585e
...
...
@@ -1958,3 +1958,42 @@ select A.a + 10 * B.a + 100 * C.a, 1234 from t2 A, t2 B, t2 C;
--
echo
# Should show rows=2, not rows=100
explain
update
t1
set
key1
=
key1
+
1
where
key1
between
10
and
110
order
by
key1
limit
2
;
drop
table
t1
,
t2
;
--
echo
#
--
echo
# MDEV-465: Optimizer : wrong index choice, leading to strong performances issues
--
echo
#
CREATE
TABLE
t1
(
id1
int
(
10
)
unsigned
NOT
NULL
auto_increment
,
id2
tinyint
(
3
)
unsigned
NOT
NULL
default
'0'
,
id3
tinyint
(
3
)
unsigned
NOT
NULL
default
'0'
,
id4
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
date
timestamp
NOT
NULL
default
CURRENT_TIMESTAMP
,
PRIMARY
KEY
(
id1
),
KEY
id_234_date
(
id2
,
id3
,
id4
,
date
),
KEY
id_23_date
(
id2
,
id3
,
date
)
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
latin1
;
--
echo
# t1 has "bad" index declaration order..
CREATE
TABLE
t2
(
id1
int
(
10
)
unsigned
NOT
NULL
auto_increment
,
id2
tinyint
(
3
)
unsigned
NOT
NULL
default
'0'
,
id3
tinyint
(
3
)
unsigned
NOT
NULL
default
'0'
,
id4
int
(
10
)
unsigned
NOT
NULL
default
'0'
,
date
timestamp
NOT
NULL
default
CURRENT_TIMESTAMP
,
PRIMARY
KEY
(
id1
),
KEY
id_23_date
(
id2
,
id3
,
date
),
KEY
id_234_date
(
id2
,
id3
,
id4
,
date
)
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
latin1
;
--
echo
# t2 has a "good" index declaration order
INSERT
INTO
t1
(
id2
,
id3
,
id4
)
VALUES
(
1
,
1
,
1
),(
1
,
1
,
1
),(
1
,
1
,
1
),(
1
,
1
,
1
),(
1
,
0
,
1
),(
1
,
2
,
1
),(
1
,
3
,
1
);
INSERT
INTO
t2
(
id2
,
id3
,
id4
)
VALUES
(
1
,
1
,
1
),(
1
,
1
,
1
),(
1
,
1
,
1
),(
1
,
1
,
1
),(
1
,
0
,
1
),(
1
,
2
,
1
),(
1
,
3
,
1
);
--
echo
# The following two must both use id_23_date and no "using filesort":
EXPLAIN
SELECT
id1
FROM
t1
WHERE
id2
=
1
AND
id3
=
1
ORDER
BY
date
DESC
LIMIT
0
,
4
;
--
echo
# See above query
EXPLAIN
SELECT
id1
FROM
t2
WHERE
id2
=
1
AND
id3
=
1
ORDER
BY
date
DESC
LIMIT
0
,
4
;
drop
table
t1
,
t2
;
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