Skip to content

Stack overflow caused by checking constant wrongly #10156

@qw4990

Description

@qw4990

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
CREATE TABLE `t1` (
  `period_name` varchar(24) DEFAULT NULL ,
  `period_id` bigint(20) DEFAULT NULL ,
  `starttime` bigint(20) DEFAULT NULL 
);

CREATE TABLE `t2` (
  `bussid` bigint(20) DEFAULT NULL,
  `ct` bigint(20) DEFAULT NULL
);

select
    a.period_name,
    b.date8
from
    (select * from t1) a
left join
    (select bussid,date(from_unixtime(ct)) date8 from t2) b
on 
    a.period_id = b.bussid
where 
    datediff(b.date8, date(from_unixtime(a.starttime))) >= 0;
  1. What did you expect to see?
mysql> select
    ->     a.period_name,
    ->     b.date8
    -> from
    ->     (select * from t1) a
    -> left join
    ->     (select bussid,date(from_unixtime(ct)) date8 from t2) b
    -> on 
    ->     a.period_id = b.bussid
    -> where 
    ->     datediff(b.date8, date(from_unixtime(a.starttime))) >= 0;
Empty set (0.01 sec)
  1. What did you see instead?
    No result and eventually panic caused by stack overflow.
mysql> select     a.period_name,     b.date8 from     (select * from t1) a left join     (select bussid,date(from_unixtime(ct)) date8 from t2) b on      a.period_id = b.bussid where      datediff(b.date8, date(from_unixtime(a.starttime))) >= 0;
ERROR 2013 (HY000): Lost connection to MySQL server during query
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                                         |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v3.0.0-beta.1-109-g7666f688b
Git Commit Hash: 7666f688b3d91ea84fa6b0a20c2e784fff3c8945
Git Branch: master
UTC Build Time: 2019-04-15 12:14:36
GoVersion: go version go1.11.3 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Metadata

Metadata

Assignees

Labels

sig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions