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
02ada417
Commit
02ada417
authored
May 07, 2017
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-12721 Wrong execution plan for WHERE (date_field <=> timestamp_expr AND TRUE)
parent
4e9022b4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
37 deletions
+102
-37
mysql-test/r/type_date.result
mysql-test/r/type_date.result
+34
-1
mysql-test/t/type_date.test
mysql-test/t/type_date.test
+25
-0
sql/opt_range.cc
sql/opt_range.cc
+32
-36
sql/opt_range.h
sql/opt_range.h
+11
-0
No files found.
mysql-test/r/type_date.result
View file @
02ada417
...
...
@@ -429,17 +429,26 @@ select @a;
#
# BUG LP:1008487 virtual bool Item_cache::is_expensive(): Assertion `example' failed
#
SET TIMESTAMP=UNIX_TIMESTAMP('2017-01-03 00:00:00');
create table t1(a date,key(a));
insert into t1 values ('2012-01-01'),('2012-02-02');
explain
select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1_0 ref a a 4 const
0
Using where; Using index
1 SIMPLE t1_0 ref a a 4 const
1
Using where; Using index
1 SIMPLE t2 index NULL a 4 NULL 2 Using index; Using join buffer (flat, BNL join)
1 SIMPLE t1 index NULL a 4 NULL 2 Using index; Using join buffer (incremental, BNL join)
select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
1
SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-03 00:00:01');
explain
select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
1
drop table t1;
SET TIMESTAMP=DEFAULT;
#
# MDEV-9521 Least function returns 0000-00-00 for null date columns instead of null
# MDEV-9972 Least function retuns date in date time format
...
...
@@ -845,3 +854,27 @@ DROP TABLE t1;
#
# End of 10.1 tests
#
#
# Start of 10.3 tests
#
#
# MDEV-12721 Wrong execution plan for WHERE (date_field <=> timestamp_expr AND TRUE)
#
CREATE TABLE t1(a DATE,KEY(a));
INSERT INTO t1 VALUES ('2012-01-01'),('2012-02-02');
EXPLAIN SELECT 1 FROM t1 WHERE t1.a <=> TIMESTAMP'2001-01-01 00:00:01' AND TRUE;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
EXPLAIN SELECT 1 FROM t1 WHERE t1.a <=> TIMESTAMP('2001-01-01', '00:00:01') AND TRUE;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
EXPLAIN SELECT 1 FROM t1 WHERE t1.a <=> TIMESTAMP'2001-01-01 00:00:00' AND TRUE;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a a 4 const 1 Using where; Using index
EXPLAIN SELECT 1 FROM t1 WHERE t1.a <=> TIMESTAMP('2001-01-01', '00:00:00') AND TRUE;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a a 4 const 1 Using where; Using index
DROP TABLE t1;
#
# End of 10.3 tests
#
mysql-test/t/type_date.test
View file @
02ada417
...
...
@@ -369,12 +369,18 @@ select @a;
--
echo
#
--
echo
# BUG LP:1008487 virtual bool Item_cache::is_expensive(): Assertion `example' failed
--
echo
#
SET
TIMESTAMP
=
UNIX_TIMESTAMP
(
'2017-01-03 00:00:00'
);
create
table
t1
(
a
date
,
key
(
a
));
insert
into
t1
values
(
'2012-01-01'
),(
'2012-02-02'
);
explain
select
1
from
t1
as
t1_0
inner
join
t1
as
t2
on
(
t1_0
.
a
<=>
now
())
join
t1
on
1
;
select
1
from
t1
as
t1_0
inner
join
t1
as
t2
on
(
t1_0
.
a
<=>
now
())
join
t1
on
1
;
SET
TIMESTAMP
=
UNIX_TIMESTAMP
(
'2012-01-03 00:00:01'
);
explain
select
1
from
t1
as
t1_0
inner
join
t1
as
t2
on
(
t1_0
.
a
<=>
now
())
join
t1
on
1
;
select
1
from
t1
as
t1_0
inner
join
t1
as
t2
on
(
t1_0
.
a
<=>
now
())
join
t1
on
1
;
drop
table
t1
;
SET
TIMESTAMP
=
DEFAULT
;
--
echo
#
--
echo
# MDEV-9521 Least function returns 0000-00-00 for null date columns instead of null
...
...
@@ -580,3 +586,22 @@ DROP TABLE t1;
--
echo
#
--
echo
# End of 10.1 tests
--
echo
#
--
echo
#
--
echo
# Start of 10.3 tests
--
echo
#
--
echo
#
--
echo
# MDEV-12721 Wrong execution plan for WHERE (date_field <=> timestamp_expr AND TRUE)
--
echo
#
CREATE
TABLE
t1
(
a
DATE
,
KEY
(
a
));
INSERT
INTO
t1
VALUES
(
'2012-01-01'
),(
'2012-02-02'
);
EXPLAIN
SELECT
1
FROM
t1
WHERE
t1
.
a
<=>
TIMESTAMP
'2001-01-01 00:00:01'
AND
TRUE
;
EXPLAIN
SELECT
1
FROM
t1
WHERE
t1
.
a
<=>
TIMESTAMP
(
'2001-01-01'
,
'00:00:01'
)
AND
TRUE
;
EXPLAIN
SELECT
1
FROM
t1
WHERE
t1
.
a
<=>
TIMESTAMP
'2001-01-01 00:00:00'
AND
TRUE
;
EXPLAIN
SELECT
1
FROM
t1
WHERE
t1
.
a
<=>
TIMESTAMP
(
'2001-01-01'
,
'00:00:00'
)
AND
TRUE
;
DROP
TABLE
t1
;
--
echo
#
--
echo
# End of 10.3 tests
--
echo
#
sql/opt_range.cc
View file @
02ada417
...
...
@@ -8030,33 +8030,53 @@ Item_bool_func::get_mm_leaf(RANGE_OPT_PARAM *param,
field
->
type_handler
()
==
&
type_handler_set
)
{
if
(
type
==
EQ_FUNC
||
type
==
EQUAL_FUNC
)
{
tree
=
new
(
alloc
)
SEL_ARG
(
field
,
0
,
0
);
tree
->
type
=
SEL_ARG
::
IMPOSSIBLE
;
}
tree
=
new
(
alloc
)
SEL_ARG_IMPOSSIBLE
(
field
);
goto
end
;
}
if
(
err
==
2
&&
field
->
cmp_type
()
==
STRING_RESULT
)
{
if
(
type
==
EQ_FUNC
||
type
==
EQUAL_FUNC
)
{
tree
=
new
(
alloc
)
SEL_ARG
(
field
,
0
,
0
);
tree
->
type
=
SEL_ARG
::
IMPOSSIBLE
;
}
tree
=
new
(
alloc
)
SEL_ARG_IMPOSSIBLE
(
field
);
else
tree
=
NULL
;
/* Cannot infer anything */
goto
end
;
}
if
(
field
->
cmp_type
()
!=
value
->
result_type
())
if
(
err
==
3
&&
field
->
type
()
==
FIELD_TYPE_DATE
)
{
/*
We were saving DATETIME into a DATE column, the conversion went ok
but a non-zero time part was cut off.
In MySQL's SQL dialect, DATE and DATETIME are compared as datetime
values. Index over a DATE column uses DATE comparison. Changing
from one comparison to the other is possible:
datetime(date_col)< '2007-12-10 12:34:55' -> date_col<='2007-12-10'
datetime(date_col)<='2007-12-10 12:34:55' -> date_col<='2007-12-10'
datetime(date_col)> '2007-12-10 12:34:55' -> date_col>='2007-12-10'
datetime(date_col)>='2007-12-10 12:34:55' -> date_col>='2007-12-10'
but we'll need to convert '>' to '>=' and '<' to '<='. This will
be done together with other types at the end of this function
(grep for stored_field_cmp_to_item)
*/
if
(
type
==
EQ_FUNC
||
type
==
EQUAL_FUNC
)
{
tree
=
new
(
alloc
)
SEL_ARG_IMPOSSIBLE
(
field
);
goto
end
;
}
// Continue with processing non-equality ranges
}
else
if
(
field
->
cmp_type
()
!=
value
->
result_type
())
{
if
((
type
==
EQ_FUNC
||
type
==
EQUAL_FUNC
)
&&
value
->
result_type
()
==
item_cmp_type
(
field
->
result_type
(),
value
->
result_type
()))
{
tree
=
new
(
alloc
)
SEL_ARG
(
field
,
0
,
0
);
tree
->
type
=
SEL_ARG
::
IMPOSSIBLE
;
tree
=
new
(
alloc
)
SEL_ARG_IMPOSSIBLE
(
field
);
goto
end
;
}
else
...
...
@@ -8066,31 +8086,7 @@ Item_bool_func::get_mm_leaf(RANGE_OPT_PARAM *param,
for the cases like int_field > 999999999999999999999999 as well.
*/
tree
=
0
;
if
(
err
==
3
&&
field
->
type
()
==
FIELD_TYPE_DATE
&&
(
type
==
GT_FUNC
||
type
==
GE_FUNC
||
type
==
LT_FUNC
||
type
==
LE_FUNC
)
)
{
/*
We were saving DATETIME into a DATE column, the conversion went ok
but a non-zero time part was cut off.
In MySQL's SQL dialect, DATE and DATETIME are compared as datetime
values. Index over a DATE column uses DATE comparison. Changing
from one comparison to the other is possible:
datetime(date_col)< '2007-12-10 12:34:55' -> date_col<='2007-12-10'
datetime(date_col)<='2007-12-10 12:34:55' -> date_col<='2007-12-10'
datetime(date_col)> '2007-12-10 12:34:55' -> date_col>='2007-12-10'
datetime(date_col)>='2007-12-10 12:34:55' -> date_col>='2007-12-10'
but we'll need to convert '>' to '>=' and '<' to '<='. This will
be done together with other types at the end of this function
(grep for stored_field_cmp_to_item)
*/
}
else
goto
end
;
goto
end
;
}
}
...
...
sql/opt_range.h
View file @
02ada417
...
...
@@ -594,6 +594,17 @@ class SEL_ARG :public Sql_alloc
};
class
SEL_ARG_IMPOSSIBLE
:
public
SEL_ARG
{
public:
SEL_ARG_IMPOSSIBLE
(
Field
*
field
)
:
SEL_ARG
(
field
,
0
,
0
)
{
type
=
SEL_ARG
::
IMPOSSIBLE
;
}
};
class
RANGE_OPT_PARAM
{
public:
...
...
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