Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: datetime SELECT statement did not query the test result #300

Closed
1 task
shangyanwen opened this issue Jul 22, 2022 · 5 comments
Closed
1 task

bug: datetime SELECT statement did not query the test result #300

shangyanwen opened this issue Jul 22, 2022 · 5 comments
Assignees
Labels
A-bug Something isn't working

Comments

@shangyanwen
Copy link
Contributor

Describe the problem

CREATE TABLE t1(a DATETIME NOT NULL, b VARCHAR(20) NOT NULL)engine=stonedb;
INSERT INTO t1 VALUES('2001-01-01', '2001-01-01');
SELECT * FROM t1 WHERE a='2001-01-01 00:00:00' AND a=b AND b='2001-01-01';
##The error results are as follows
Empty set (0.00 sec)

Expected behavior

##The following is:innodb test result
SELECT * FROM t1 WHERE a='2001-01-01 00:00:00' AND a=b AND b='2001-01-01';
+---------------------+------------+
| a                   | b          |
+---------------------+------------+
| 2001-01-01 00:00:00 | 2001-01-01 |
+---------------------+------------+
1 row in set (0.00 sec)

How To Reproduce

CREATE TABLE t1(a DATETIME NOT NULL, b VARCHAR(20) NOT NULL)engine=stonedb;
INSERT INTO t1 VALUES('2001-01-01', '2001-01-01');
SELECT * FROM t1 WHERE a='2001-01-01 00:00:00' AND a=b AND b='2001-01-01';

Environment

  1. StoneDB for mysql5.7 (release)
  2. Ubuntu 20.04.4

Are you interested in submitting a PR to solve the problem?

  • Yes, I will!
@shangyanwen shangyanwen added the A-bug Something isn't working label Jul 22, 2022
@hustjieke hustjieke added this to the stonedb_5.7_v1.0.0 milestone Jul 24, 2022
@hustjieke hustjieke self-assigned this Jul 25, 2022
@hustjieke
Copy link
Collaborator

Wrong execute plan on and contition:

mysql> explain SELECT * FROM t1 WHERE a='2001-01-01 00:00:00' AND a=b AND b='2001-01-01'\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: t1
   partitions: NULL
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 1
     filtered: 100.00
        Extra: Using where with pushed condition ((`test`.`t1`.`a` = '2001-01-01 00:00:00') and ('2001-01-01 00:00:00' = `test`.`t1`.`b`) and (`test`.`t1`.`b` = '2001-01-01'))(t0) Pckrows: 1, susp. 1 (0 empty 0 full). Conditions: 3
1 row in set, 1 warning (2.83 sec)

@shangyanwen
Copy link
Contributor Author

stonedb 5.7_v1.0.1,Regression This bug still exists

@duanfuxiang0
Copy link
Contributor

ACK

@duanfuxiang0
Copy link
Contributor

duanfuxiang0 commented Oct 11, 2022

simplifying the sql to SELECT * FROM t1 WHERE a='2001-01-01 00:00:00' AND a=b; the result is wrong because the Optimizer turns the original filter condition(a='2001-01-01 00:00:00' AND a=b) into a='2001-01-01 00:00:00' AND b=2001-01-01 00:00:00, and b is a string type, value is 2001-01-01(!='2001-01-01 00:00:00'), while innodb is correct because its term contains extra information (Arg_comparator::compare_datetime), tianmu's CQTerm does not have this information.
This query can currently be supported by modifying the sql to

SELECT * FROM t1 WHERE a='2001-01-01' AND a=b AND b='2001-01-01';

@shangyanwen
Copy link
Contributor Author

As described in the above research and development, the verification passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants