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
7dab4d10
Commit
7dab4d10
authored
Feb 04, 2014
by
Sergey Petrunya
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
42af7a27
75a35277
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
11 deletions
+112
-11
mysql-test/r/range.result
mysql-test/r/range.result
+31
-0
mysql-test/r/range_mrr_icp.result
mysql-test/r/range_mrr_icp.result
+31
-0
mysql-test/t/range.test
mysql-test/t/range.test
+21
-0
sql/opt_range.cc
sql/opt_range.cc
+29
-11
No files found.
mysql-test/r/range.result
View file @
7dab4d10
...
...
@@ -2046,3 +2046,34 @@ f1 f2 f3 f4
10 0 0 0
DROP TABLE t1;
DROP VIEW v3;
#
# MDEV-5606: range optimizer: "x < y" is sargable, while "y > x" is not
#
create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2(a int);
insert into t2 select A.a + B.a* 10 + C.a * 100 from t1 A, t1 B, t1 C;
alter table t2 add key(a);
# Should have "range checked for each table" for second table:
explain select * from t1, t2 where t2.a < t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
1 SIMPLE t2 ALL a NULL NULL NULL 1000 Range checked for each record (index map: 0x1)
# Should have "range checked for each table" for second table:
explain select * from t1, t2 where t1.a > t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
1 SIMPLE t2 ALL a NULL NULL NULL 1000 Range checked for each record (index map: 0x1)
create table t3 (a int primary key, b int);
insert into t3 select a,a from t1;
# The second table should use 'range':
explain select * from t3, t2 where t2.a < t3.b and t3.a=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range a a 5 NULL 1 Using where; Using index
# The second table should use 'range':
explain select * from t3, t2 where t3.b > t2.a and t3.a=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range a a 5 NULL 1 Using where; Using index
drop table t1,t2,t3;
mysql-test/r/range_mrr_icp.result
View file @
7dab4d10
...
...
@@ -2048,4 +2048,35 @@ f1 f2 f3 f4
10 0 0 0
DROP TABLE t1;
DROP VIEW v3;
#
# MDEV-5606: range optimizer: "x < y" is sargable, while "y > x" is not
#
create table t1(a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2(a int);
insert into t2 select A.a + B.a* 10 + C.a * 100 from t1 A, t1 B, t1 C;
alter table t2 add key(a);
# Should have "range checked for each table" for second table:
explain select * from t1, t2 where t2.a < t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
1 SIMPLE t2 ALL a NULL NULL NULL 1000 Range checked for each record (index map: 0x1)
# Should have "range checked for each table" for second table:
explain select * from t1, t2 where t1.a > t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10
1 SIMPLE t2 ALL a NULL NULL NULL 1000 Range checked for each record (index map: 0x1)
create table t3 (a int primary key, b int);
insert into t3 select a,a from t1;
# The second table should use 'range':
explain select * from t3, t2 where t2.a < t3.b and t3.a=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range a a 5 NULL 1 Using where; Using index
# The second table should use 'range':
explain select * from t3, t2 where t3.b > t2.a and t3.a=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range a a 5 NULL 1 Using where; Using index
drop table t1,t2,t3;
set optimizer_switch=@mrr_icp_extra_tmp;
mysql-test/t/range.test
View file @
7dab4d10
...
...
@@ -1639,3 +1639,24 @@ SELECT * FROM v3;
DROP
TABLE
t1
;
DROP
VIEW
v3
;
--
echo
#
--
echo
# MDEV-5606: range optimizer: "x < y" is sargable, while "y > x" is not
--
echo
#
create
table
t1
(
a
int
);
insert
into
t1
values
(
0
),(
1
),(
2
),(
3
),(
4
),(
5
),(
6
),(
7
),(
8
),(
9
);
create
table
t2
(
a
int
);
insert
into
t2
select
A
.
a
+
B
.
a
*
10
+
C
.
a
*
100
from
t1
A
,
t1
B
,
t1
C
;
alter
table
t2
add
key
(
a
);
--
echo
# Should have "range checked for each table" for second table:
explain
select
*
from
t1
,
t2
where
t2
.
a
<
t1
.
a
;
--
echo
# Should have "range checked for each table" for second table:
explain
select
*
from
t1
,
t2
where
t1
.
a
>
t2
.
a
;
create
table
t3
(
a
int
primary
key
,
b
int
);
insert
into
t3
select
a
,
a
from
t1
;
--
echo
# The second table should use 'range':
explain
select
*
from
t3
,
t2
where
t2
.
a
<
t3
.
b
and
t3
.
a
=
1
;
--
echo
# The second table should use 'range':
explain
select
*
from
t3
,
t2
where
t3
.
b
>
t2
.
a
and
t3
.
a
=
1
;
drop
table
t1
,
t2
,
t3
;
sql/opt_range.cc
View file @
7dab4d10
...
...
@@ -7684,7 +7684,8 @@ static SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param, Item_func *cond_func,
param PARAM from SQL_SELECT::test_quick_select
cond_func item for the predicate
field_item field in the predicate
value constant in the predicate
value constant in the predicate (or a field already read from
a table in the case of dynamic range access)
(for BETWEEN it contains the number of the field argument,
for IN it's always 0)
inv TRUE <> NOT cond_func is considered
...
...
@@ -7953,24 +7954,41 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond)
DBUG_RETURN
(
ftree
);
}
default:
DBUG_ASSERT
(
!
ftree
);
if
(
cond_func
->
arguments
()[
0
]
->
real_item
()
->
type
()
==
Item
::
FIELD_ITEM
)
{
field_item
=
(
Item_field
*
)
(
cond_func
->
arguments
()[
0
]
->
real_item
());
value
=
cond_func
->
arg_count
>
1
?
cond_func
->
arguments
()[
1
]
:
0
;
value
=
cond_func
->
arg_count
>
1
?
cond_func
->
arguments
()[
1
]
:
NULL
;
if
(
value
&&
value
->
is_expensive
())
DBUG_RETURN
(
0
);
ftree
=
get_full_func_mm_tree
(
param
,
cond_func
,
field_item
,
value
,
inv
);
}
else
if
(
cond_func
->
have_rev_func
()
&&
cond_func
->
arguments
()[
1
]
->
real_item
()
->
type
()
==
Item
::
FIELD_ITEM
)
/*
Even if get_full_func_mm_tree() was executed above and did not
return a range predicate it may still be possible to create one
by reversing the order of the operands. Note that this only
applies to predicates where both operands are fields. Example: A
query of the form
WHERE t1.a OP t2.b
In this case, arguments()[0] == t1.a and arguments()[1] == t2.b.
When creating range predicates for t2, get_full_func_mm_tree()
above will return NULL because 'field' belongs to t1 and only
predicates that applies to t2 are of interest. In this case a
call to get_full_func_mm_tree() with reversed operands (see
below) may succeed.
*/
if
(
!
ftree
&&
cond_func
->
have_rev_func
()
&&
cond_func
->
arguments
()[
1
]
->
real_item
()
->
type
()
==
Item
::
FIELD_ITEM
)
{
field_item
=
(
Item_field
*
)
(
cond_func
->
arguments
()[
1
]
->
real_item
());
value
=
cond_func
->
arguments
()[
0
];
if
(
value
&&
value
->
is_expensive
())
DBUG_RETURN
(
0
);
ftree
=
get_full_func_mm_tree
(
param
,
cond_func
,
field_item
,
value
,
inv
);
}
else
DBUG_RETURN
(
0
);
if
(
value
&&
value
->
is_expensive
())
DBUG_RETURN
(
0
);
ftree
=
get_full_func_mm_tree
(
param
,
cond_func
,
field_item
,
value
,
inv
);
}
DBUG_RETURN
(
ftree
);
...
...
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