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
23476afd
Commit
23476afd
authored
Oct 07, 2019
by
Varun Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduced an optimizer_switch for ORDER BY LIMIT
parent
e0ee80c1
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
20 additions
and
1212 deletions
+20
-1212
mysql-test/main/sort_nest.result
mysql-test/main/sort_nest.result
+2
-432
mysql-test/main/sort_nest.test
mysql-test/main/sort_nest.test
+2
-127
mysql-test/main/sort_nest_dbt3.result
mysql-test/main/sort_nest_dbt3.result
+2
-296
mysql-test/main/sort_nest_dbt3.test
mysql-test/main/sort_nest_dbt3.test
+2
-49
mysql-test/main/sort_nest_dbt3_innodb.result
mysql-test/main/sort_nest_dbt3_innodb.result
+8
-301
sql/sql_priv.h
sql/sql_priv.h
+1
-0
sql/sql_sort_nest.cc
sql/sql_sort_nest.cc
+2
-1
sql/sys_vars.cc
sql/sys_vars.cc
+1
-6
No files found.
mysql-test/main/sort_nest.result
View file @
23476afd
This diff is collapsed.
Click to expand it.
mysql-test/main/sort_nest.test
View file @
23476afd
--
source
include
/
have_sequence
.
inc
--
source
include
/
have_sequence
.
inc
set
use_sort_nest
=
1
;
set
optimizer_switch
=
'cost_based_order_by_limit=on'
;
CREATE
TABLE
t0
(
a
int
);
CREATE
TABLE
t0
(
a
int
);
INSERT
INTO
t0
SELECT
seq
-
1
from
seq_1_to_10
;
INSERT
INTO
t0
SELECT
seq
-
1
from
seq_1_to_10
;
...
@@ -594,7 +594,6 @@ WHERE t1.a=t2.a and t1.b= 4
...
@@ -594,7 +594,6 @@ WHERE t1.a=t2.a and t1.b= 4
ORDER
BY
t1
.
b
DESC
ORDER
BY
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
...
@@ -627,13 +626,9 @@ WHERE t1.a=t2.b and t2.a=t3.a
...
@@ -627,13 +626,9 @@ WHERE t1.a=t2.b and t2.a=t3.a
ORDER
BY
abs
(
t3
.
a
+
t1
.
b
)
DESC
ORDER
BY
abs
(
t3
.
a
+
t1
.
b
)
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# No sort nest where ORDER BY item are expensive to compute like
--
echo
# No sort nest where ORDER BY item are expensive to compute like
--
echo
# stored functions, subqueries etc
--
echo
# stored functions, subqueries etc
...
@@ -654,12 +649,6 @@ WHERE t1.a=t2.b and t2.a=t3.a
...
@@ -654,12 +649,6 @@ WHERE t1.a=t2.b and t2.a=t3.a
ORDER
BY
f1
(
t3
.
a
+
t1
.
b
)
DESC
ORDER
BY
f1
(
t3
.
a
+
t1
.
b
)
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
...
@@ -676,12 +665,7 @@ WHERE t1.a=t2.b AND t2.a=t3.a
...
@@ -676,12 +665,7 @@ WHERE t1.a=t2.b AND t2.a=t3.a
ORDER
BY
row_number
()
OVER
(
ORDER
BY
t1
.
a
)
DESC
ORDER
BY
row_number
()
OVER
(
ORDER
BY
t1
.
a
)
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
eval
$query
;
--
echo
#
--
echo
#
...
@@ -700,13 +684,9 @@ t1.b = (select t2.b from t2,t3,t4
...
@@ -700,13 +684,9 @@ t1.b = (select t2.b from t2,t3,t4
where
t2
.
a
=
t1
.
a
and
t3
.
b
=
t4
.
b
where
t2
.
a
=
t1
.
a
and
t3
.
b
=
t4
.
b
ORDER
BY
t2
.
c
,
t3
.
c
limit
1
);
ORDER
BY
t2
.
c
,
t3
.
c
limit
1
);
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# Independent subqueries can have a sort-nest
--
echo
# Independent subqueries can have a sort-nest
--
echo
#
--
echo
#
...
@@ -719,14 +699,9 @@ t1.b = (select t2.b from t2,t3,t4
...
@@ -719,14 +699,9 @@ t1.b = (select t2.b from t2,t3,t4
where
t2
.
a
=
t3
.
a
and
t3
.
b
=
t4
.
b
where
t2
.
a
=
t3
.
a
and
t3
.
b
=
t4
.
b
ORDER
BY
t2
.
c
,
t3
.
c
limit
1
);
ORDER
BY
t2
.
c
,
t3
.
c
limit
1
);
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# Sort nest inside a derived table
--
echo
# Sort nest inside a derived table
--
echo
#
--
echo
#
...
@@ -739,13 +714,9 @@ FROM (SELECT t1.a as t, t2.b as u, t1.b as v, t3.a as x
...
@@ -739,13 +714,9 @@ FROM (SELECT t1.a as t, t2.b as u, t1.b as v, t3.a as x
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
)
q
;
LIMIT
5
)
q
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# sort-nest(t2,t1) and independent subquery in the SELECT list
--
echo
# sort-nest(t2,t1) and independent subquery in the SELECT list
--
echo
#
--
echo
#
...
@@ -758,7 +729,6 @@ WHERE t1.a = t2.a
...
@@ -758,7 +729,6 @@ WHERE t1.a = t2.a
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
...
@@ -774,13 +744,9 @@ WHERE t1.a = t2.a and t2.c=t3.c
...
@@ -774,13 +744,9 @@ WHERE t1.a = t2.a and t2.c=t3.c
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# Dependent Subquery attached outside the sort-nest, references inside
--
echo
# Dependent Subquery attached outside the sort-nest, references inside
--
echo
# subquery changed to sort-nest field items
--
echo
# subquery changed to sort-nest field items
...
@@ -794,14 +760,10 @@ t1.b=(SELECT A.a FROM t3 A WHERE A.b > 1 and t3.b=t1.b limit 1)
...
@@ -794,14 +760,10 @@ t1.b=(SELECT A.a FROM t3 A WHERE A.b > 1 and t3.b=t1.b limit 1)
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# sort-nest(t2,t1) and independent subquery in the ORDER BY clause
--
echo
# sort-nest(t2,t1) and independent subquery in the ORDER BY clause
--
echo
#
--
echo
#
...
@@ -816,13 +778,9 @@ ORDER BY t2.b, t1.b,
...
@@ -816,13 +778,9 @@ ORDER BY t2.b, t1.b,
(
SELECT
A
.
a
FROM
t3
A
WHERE
A
.
a
<
5
limit
1
)
(
SELECT
A
.
a
FROM
t3
A
WHERE
A
.
a
<
5
limit
1
)
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# sort-nest(t2,t1) and dependent subquery in the ORDER BY clause
--
echo
# sort-nest(t2,t1) and dependent subquery in the ORDER BY clause
--
echo
#
--
echo
#
...
@@ -837,13 +795,9 @@ ORDER BY t2.b, t1.b,
...
@@ -837,13 +795,9 @@ ORDER BY t2.b, t1.b,
(
SELECT
A
.
a
FROM
t3
A
WHERE
A
.
a
=
t1
.
c
limit
1
)
(
SELECT
A
.
a
FROM
t3
A
WHERE
A
.
a
=
t1
.
c
limit
1
)
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
drop
table
t0
,
t1
,
t2
,
t3
,
t4
;
drop
table
t0
,
t1
,
t2
,
t3
,
t4
;
CREATE
TABLE
t1
(
a
int
,
b
int
,
c
int
,
KEY
a_b
(
a
,
b
),
KEY
a_c
(
a
,
c
));
CREATE
TABLE
t1
(
a
int
,
b
int
,
c
int
,
KEY
a_b
(
a
,
b
),
KEY
a_c
(
a
,
c
));
...
@@ -858,12 +812,9 @@ insert into t1 values (1,7,2), (1,8,2), (1,9,2), (1,10,2), (1,11,2), (1,12,2);
...
@@ -858,12 +812,9 @@ insert into t1 values (1,7,2), (1,8,2), (1,9,2), (1,10,2), (1,11,2), (1,12,2);
--
echo
#
--
echo
#
let
$query
=
select
a
,
b
,
c
from
t1
where
a
=
1
and
c
=
2
order
by
b
limit
5
;
let
$query
=
select
a
,
b
,
c
from
t1
where
a
=
1
and
c
=
2
order
by
b
limit
5
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
explain
$query
;
eval
explain
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
drop
table
t1
;
drop
table
t1
;
--
echo
#
--
echo
#
...
@@ -880,18 +831,14 @@ insert into t1 values (1,1,2);
...
@@ -880,18 +831,14 @@ insert into t1 values (1,1,2);
--
echo
#
--
echo
#
--
echo
# index key a_b, no need for filesort
--
echo
# index key a_b, no need for filesort
--
echo
# Also index condition pushdown is used
with use_sort_nest=1
--
echo
# Also index condition pushdown is used
here
--
echo
#
--
echo
#
let
$query
=
select
a
,
b
from
t1
where
a
=
1
and
c
=
2
order
by
b
limit
10
;
let
$query
=
select
a
,
b
from
t1
where
a
=
1
and
c
=
2
order
by
b
limit
10
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
explain
$query
;
eval
explain
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
drop
table
t1
;
drop
table
t1
;
CREATE
TABLE
t1
(
CREATE
TABLE
t1
(
...
@@ -908,26 +855,18 @@ INSERT INTO t1 VALUES (1,'a'), (2,'b'), (3,'c'), (4,'d');
...
@@ -908,26 +855,18 @@ INSERT INTO t1 VALUES (1,'a'), (2,'b'), (3,'c'), (4,'d');
let
$query
=
SELECT
*
FROM
t1
WHERE
a
BETWEEN
1
and
2
ORDER
BY
a
LIMIT
2
;
let
$query
=
SELECT
*
FROM
t1
WHERE
a
BETWEEN
1
and
2
ORDER
BY
a
LIMIT
2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Should not use index condition as ORDER by DESC is used
--
echo
# Should not use index condition as ORDER by DESC is used
--
echo
#
--
echo
#
let
$query
=
SELECT
*
FROM
t1
WHERE
a
BETWEEN
1
and
2
ORDER
BY
a
DESC
LIMIT
2
;
let
$query
=
SELECT
*
FROM
t1
WHERE
a
BETWEEN
1
and
2
ORDER
BY
a
DESC
LIMIT
2
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
drop
table
t1
;
drop
table
t1
;
create
table
t1
(
a
int
,
b
int
,
c
int
,
key
(
a
),
key
a_b
(
a
,
b
));
# 10 rows
create
table
t1
(
a
int
,
b
int
,
c
int
,
key
(
a
),
key
a_b
(
a
,
b
));
# 10 rows
...
@@ -954,13 +893,9 @@ WHERE
...
@@ -954,13 +893,9 @@ WHERE
t1
.
b
=
t2
.
b
t1
.
b
=
t2
.
b
ORDER
BY
t1
.
b
LIMIT
10
;
ORDER
BY
t1
.
b
LIMIT
10
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Using ref access
--
echo
# Using ref access
--
echo
#
--
echo
#
...
@@ -971,19 +906,14 @@ WHERE
...
@@ -971,19 +906,14 @@ WHERE
t1
.
b
=
t2
.
b
t1
.
b
=
t2
.
b
ORDER
BY
t1
.
b
LIMIT
10
;
ORDER
BY
t1
.
b
LIMIT
10
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
drop
table
t1
,
t2
;
drop
table
t1
,
t2
;
--
echo
# TESTS with INDEX HINTS
--
echo
# TESTS with INDEX HINTS
set
use_sort_nest
=
1
;
create
table
t0
(
a
int
);
create
table
t0
(
a
int
);
insert
into
t0
values
(
0
),(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
),(
8
),(
9
);
insert
into
t0
values
(
0
),(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
),(
8
),(
9
);
create
table
t1
(
a
int
,
b
int
,
c
int
,
key
idx1
(
a
),
key
idx2
(
a
,
b
),
key
idx3
(
c
));
create
table
t1
(
a
int
,
b
int
,
c
int
,
key
idx1
(
a
),
key
idx2
(
a
,
b
),
key
idx3
(
c
));
...
@@ -998,25 +928,17 @@ analyze table t1 persistent for all;
...
@@ -998,25 +928,17 @@ analyze table t1 persistent for all;
--
echo
#
--
echo
#
let
$query
=
SELECT
*
from
t1
where
b
>
0
order
by
t1
.
a
limit
2
;
let
$query
=
SELECT
*
from
t1
where
b
>
0
order
by
t1
.
a
limit
2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Index idx2 to be used for index scan(USE INDEX is used)
--
echo
# Index idx2 to be used for index scan(USE INDEX is used)
--
echo
#
--
echo
#
let
$query
=
SELECT
*
from
t1
USE
INDEX
(idx2) WHERE b > 0 ORDER BY t1.a LIMIT 2
;
let
$query
=
SELECT
*
from
t1
USE
INDEX
(idx2) WHERE b > 0 ORDER BY t1.a LIMIT 2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Index idx2 to be used for index scan(USE INDEX for ORDER BY is used)
--
echo
# Index idx2 to be used for index scan(USE INDEX for ORDER BY is used)
--
echo
#
--
echo
#
...
@@ -1026,13 +948,9 @@ SELECT * from t1 USE INDEX FOR ORDER BY(idx2)
...
@@ -1026,13 +948,9 @@ SELECT * from t1 USE INDEX FOR ORDER BY(idx2)
WHERE b > 0
WHERE b > 0
ORDER BY t1.a LIMIT 2
;
ORDER BY t1.a LIMIT 2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Use Filesort as idx3 does not resolve ORDER BY clause
--
echo
# Use Filesort as idx3 does not resolve ORDER BY clause
--
echo
#
--
echo
#
...
@@ -1042,13 +960,9 @@ SELECT * from t1 USE INDEX FOR ORDER BY(idx3)
...
@@ -1042,13 +960,9 @@ SELECT * from t1 USE INDEX FOR ORDER BY(idx3)
WHERE b > 0
WHERE b > 0
ORDER BY t1.a LIMIT 2
;
ORDER BY t1.a LIMIT 2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Using index idx2 as idx1 is ignored
--
echo
# Using index idx2 as idx1 is ignored
--
echo
#
--
echo
#
...
@@ -1058,13 +972,9 @@ SELECT * from t1 IGNORE INDEX(idx1)
...
@@ -1058,13 +972,9 @@ SELECT * from t1 IGNORE INDEX(idx1)
WHERE
b
>
0
WHERE
b
>
0
ORDER
BY
t1
.
a
LIMIT
2
;
ORDER
BY
t1
.
a
LIMIT
2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Use index idx2 for sorting, it is forced here
--
echo
# Use index idx2 for sorting, it is forced here
--
echo
#
--
echo
#
...
@@ -1074,13 +984,9 @@ SELECT * from t1 FORCE INDEX(idx2)
...
@@ -1074,13 +984,9 @@ SELECT * from t1 FORCE INDEX(idx2)
WHERE
b
>
0
WHERE
b
>
0
ORDER
BY
t1
.
a
LIMIT
2
;
ORDER
BY
t1
.
a
LIMIT
2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
--
echo
#
--
echo
#
--
echo
# Use FILESORT as idx3 cannot resolve ORDER BY clause
--
echo
# Use FILESORT as idx3 cannot resolve ORDER BY clause
--
echo
#
--
echo
#
...
@@ -1090,13 +996,9 @@ SELECT * from t1 FORCE INDEX FOR ORDER BY(idx3)
...
@@ -1090,13 +996,9 @@ SELECT * from t1 FORCE INDEX FOR ORDER BY(idx3)
WHERE
b
>
0
WHERE
b
>
0
ORDER
BY
t1
.
a
LIMIT
2
;
ORDER
BY
t1
.
a
LIMIT
2
;
set
use_sort_nest
=
1
;
eval
$query
;
eval
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
drop
table
t0
,
t1
;
drop
table
t0
,
t1
;
--
echo
#
--
echo
#
...
@@ -1138,14 +1040,10 @@ FROM t1, t2, t2 ot
...
@@ -1138,14 +1040,10 @@ FROM t1, t2, t2 ot
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# SJM Lookup with sort-nest, where SJM lookup table is outside the
--
echo
# SJM Lookup with sort-nest, where SJM lookup table is outside the
--
echo
# sort-nest
--
echo
# sort-nest
...
@@ -1160,14 +1058,10 @@ FROM t1, t2, t2 ot
...
@@ -1160,14 +1058,10 @@ FROM t1, t2, t2 ot
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
drop
table
t0
,
t1
,
t2
,
t3
,
t4
;
drop
table
t0
,
t1
,
t2
,
t3
,
t4
;
...
@@ -1205,15 +1099,9 @@ FROM t1, t2
...
@@ -1205,15 +1099,9 @@ FROM t1, t2
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# Duplicate weedout
--
echo
# Duplicate weedout
--
echo
#
--
echo
#
...
@@ -1229,11 +1117,6 @@ FROM t1, t2
...
@@ -1229,11 +1117,6 @@ FROM t1, t2
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
ORDER
BY
t2
.
b
DESC
,
t1
.
b
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
$query
;
eval
$query
;
...
@@ -1262,14 +1145,10 @@ t1.a IN (SELECT max(t3.a) FROM t3 GROUP BY t3.b)
...
@@ -1262,14 +1145,10 @@ t1.a IN (SELECT max(t3.a) FROM t3 GROUP BY t3.b)
ORDER
BY
t2
.
a
DESC
,
t1
.
a
DESC
ORDER
BY
t2
.
a
DESC
,
t1
.
a
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
--
echo
<
subquery2
>
inside
the
sort
-
nest
--
echo
<
subquery2
>
inside
the
sort
-
nest
let
$query
=
let
$query
=
...
@@ -1279,12 +1158,8 @@ t3.a IN (SELECT max(t1.a) FROM t1 GROUP BY t1.b)
...
@@ -1279,12 +1158,8 @@ t3.a IN (SELECT max(t1.a) FROM t1 GROUP BY t1.b)
ORDER
BY
t3
.
a
DESC
,
t2
.
a
DESC
ORDER
BY
t3
.
a
DESC
,
t2
.
a
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
EXPLAIN
FORMAT
=
JSON
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
$query
;
DROP
TABLE
t0
,
t1
,
t2
,
t3
;
DROP
TABLE
t0
,
t1
,
t2
,
t3
;
mysql-test/main/sort_nest_dbt3.result
View file @
23476afd
This diff is collapsed.
Click to expand it.
mysql-test/main/sort_nest_dbt3.test
View file @
23476afd
...
@@ -10,9 +10,9 @@ analyze table lineitem persistent for all;
...
@@ -10,9 +10,9 @@ analyze table lineitem persistent for all;
analyze
table
nation
persistent
for
all
;
analyze
table
nation
persistent
for
all
;
--
enable_query_log
--
enable_query_log
--
echo
# done
to avoid
filter for now
--
echo
# done
use
filter for now
set
optimizer_switch
=
'rowid_filter=off'
;
set
optimizer_switch
=
'rowid_filter=off'
;
set
use_sort_nest
=
1
;
set
optimizer_switch
=
'cost_based_order_by_limit=on'
;
--
echo
#
--
echo
#
--
echo
# USING INDEXES FOR ORDERING
--
echo
# USING INDEXES FOR ORDERING
...
@@ -32,11 +32,6 @@ let $query= SELECT
...
@@ -32,11 +32,6 @@ let $query= SELECT
ORDER
BY
o_orderDATE
DESC
ORDER
BY
o_orderDATE
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
explain
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
eval
explain
$query
;
eval
$query
;
eval
$query
;
...
@@ -57,18 +52,11 @@ let $query= SELECT
...
@@ -57,18 +52,11 @@ let $query= SELECT
ORDER
BY
o_orderDATE
,
o_custkey
DESC
ORDER
BY
o_orderDATE
,
o_custkey
DESC
LIMIT
5
;
LIMIT
5
;
set
use_sort_nest
=
1
;
eval
explain
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
eval
explain
$query
;
eval
$query
;
eval
$query
;
alter
table
orders
drop
key
o_orderDate
;
alter
table
orders
drop
key
o_orderDate
;
###############################################################################
--
echo
#
--
echo
#
--
echo
# USING FILESORT
--
echo
# USING FILESORT
--
echo
#
--
echo
#
...
@@ -87,11 +75,6 @@ let $query= SELECT
...
@@ -87,11 +75,6 @@ let $query= SELECT
ORDER
BY
o_totalprice
DESC
ORDER
BY
o_totalprice
DESC
LIMIT
10
;
LIMIT
10
;
set
use_sort_nest
=
1
;
eval
explain
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
eval
explain
$query
;
eval
$query
;
eval
$query
;
...
@@ -100,8 +83,6 @@ eval $query;
...
@@ -100,8 +83,6 @@ eval $query;
--
echo
# Filesort on first table (lineitem)
--
echo
# Filesort on first table (lineitem)
--
echo
#
--
echo
#
show
create
table
orders
;
let
$query
=
SELECT
let
$query
=
SELECT
l_extendedprice
,
o_orderkey
,
o_totalprice
,
l_shipDATE
l_extendedprice
,
o_orderkey
,
o_totalprice
,
l_shipDATE
FROM
FROM
...
@@ -112,17 +93,9 @@ let $query= SELECT
...
@@ -112,17 +93,9 @@ let $query= SELECT
ORDER
BY
l_extendedprice
DESC
ORDER
BY
l_extendedprice
DESC
LIMIT
10
;
LIMIT
10
;
set
use_sort_nest
=
1
;
eval
explain
$query
;
eval
explain
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
eval
$query
;
###############################################################################
--
echo
#
--
echo
#
--
echo
# Using Filesort with Sort Nest
--
echo
# Using Filesort with Sort Nest
--
echo
#
--
echo
#
...
@@ -141,16 +114,9 @@ let $query= SELECT
...
@@ -141,16 +114,9 @@ let $query= SELECT
ORDER
BY
o_orderDATE
DESC
,
c_acctbal
DESC
ORDER
BY
o_orderDATE
DESC
,
c_acctbal
DESC
LIMIT
10
;
LIMIT
10
;
set
use_sort_nest
=
1
;
eval
explain
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
eval
explain
$query
;
eval
$query
;
eval
$query
;
--
echo
#
--
echo
#
--
echo
# Sort-nest on table (lineitem, orders)
--
echo
# Sort-nest on table (lineitem, orders)
--
echo
#
--
echo
#
...
@@ -171,16 +137,9 @@ let $query= SELECT
...
@@ -171,16 +137,9 @@ let $query= SELECT
LIMIT
20
;
LIMIT
20
;
set
use_sort_nest
=
1
;
eval
explain
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
eval
explain
$query
;
eval
$query
;
eval
$query
;
--
echo
########################################################################
--
echo
#
--
echo
#
--
echo
# Sort-nest on table (customer, orders, lineitem)
--
echo
# Sort-nest on table (customer, orders, lineitem)
--
echo
#
--
echo
#
...
@@ -204,13 +163,7 @@ let $query= SELECT
...
@@ -204,13 +163,7 @@ let $query= SELECT
LIMIT
20
;
LIMIT
20
;
set
use_sort_nest
=
1
;
eval
explain
$query
;
eval
explain
$query
;
eval
$query
;
eval
$query
;
set
use_sort_nest
=
0
;
eval
explain
$query
;
eval
$query
;
drop
database
dbt3
;
drop
database
dbt3
;
mysql-test/main/sort_nest_dbt3_innodb.result
View file @
23476afd
This diff is collapsed.
Click to expand it.
sql/sql_priv.h
View file @
23476afd
...
@@ -230,6 +230,7 @@
...
@@ -230,6 +230,7 @@
#define OPTIMIZER_SWITCH_USE_ROWID_FILTER (1ULL << 33)
#define OPTIMIZER_SWITCH_USE_ROWID_FILTER (1ULL << 33)
#define OPTIMIZER_SWITCH_COND_PUSHDOWN_FROM_HAVING (1ULL << 34)
#define OPTIMIZER_SWITCH_COND_PUSHDOWN_FROM_HAVING (1ULL << 34)
#define OPTIMIZER_SWITCH_NOT_NULL_RANGE_SCAN (1ULL << 35)
#define OPTIMIZER_SWITCH_NOT_NULL_RANGE_SCAN (1ULL << 35)
#define OPTIMIZER_SWITCH_COST_BASED_ORDER_BY_LIMIT (1ULL << 36)
#define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
#define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
...
...
sql/sql_sort_nest.cc
View file @
23476afd
...
@@ -1407,7 +1407,8 @@ void JOIN::set_fraction_output_for_nest()
...
@@ -1407,7 +1407,8 @@ void JOIN::set_fraction_output_for_nest()
bool
JOIN
::
sort_nest_allowed
()
bool
JOIN
::
sort_nest_allowed
()
{
{
return
thd
->
variables
.
use_sort_nest
&&
order
&&
return
optimizer_flag
(
thd
,
OPTIMIZER_SWITCH_COST_BASED_ORDER_BY_LIMIT
)
&&
order
&&
!
(
const_tables
==
table_count
||
!
(
const_tables
==
table_count
||
(
select_distinct
||
group_list
)
||
(
select_distinct
||
group_list
)
||
having
||
having
||
...
...
sql/sys_vars.cc
View file @
23476afd
...
@@ -2590,6 +2590,7 @@ export const char *optimizer_switch_names[]=
...
@@ -2590,6 +2590,7 @@ export const char *optimizer_switch_names[]=
"rowid_filter"
,
"rowid_filter"
,
"condition_pushdown_from_having"
,
"condition_pushdown_from_having"
,
"not_null_range_scan"
,
"not_null_range_scan"
,
"cost_based_order_by_limit"
,
"default"
,
"default"
,
NullS
NullS
};
};
...
@@ -6438,9 +6439,3 @@ static Sys_var_ulonglong Sys_max_rowid_filter_size(
...
@@ -6438,9 +6439,3 @@ static Sys_var_ulonglong Sys_max_rowid_filter_size(
SESSION_VAR
(
max_rowid_filter_size
),
CMD_LINE
(
REQUIRED_ARG
),
SESSION_VAR
(
max_rowid_filter_size
),
CMD_LINE
(
REQUIRED_ARG
),
VALID_RANGE
(
1024
,
(
ulonglong
)
~
(
intptr
)
0
),
DEFAULT
(
128
*
1024
),
VALID_RANGE
(
1024
,
(
ulonglong
)
~
(
intptr
)
0
),
DEFAULT
(
128
*
1024
),
BLOCK_SIZE
(
1
));
BLOCK_SIZE
(
1
));
static
Sys_var_mybool
Sys_use_sort_nest
(
"use_sort_nest"
,
"Enable the sort nest"
,
SESSION_VAR
(
use_sort_nest
),
CMD_LINE
(
OPT_ARG
),
DEFAULT
(
FALSE
));
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