You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
When I set user-defined variables in the WHERE clause, the optimizer doesn't use the index. Current behavior is different from MySQL.
1. Minimal reproduce step (Required)
CREATETABLEIF NOT EXISTS t (
id BIGINTPRIMARY KEY AUTO_INCREMENT,
dt DATE,
INDEX idx_dt (dt)
);
INSERT INTO t (dt) VALUES ('2024-01-01');
INSERT INTO t (dt) VALUES ('2024-01-02');
INSERT INTO t (dt) VALUES ('2024-01-03');
INSERT INTO t (dt) VALUES ('2024-01-04');
INSERT INTO t (dt) VALUES ('2024-01-05');
SET @a :='2024-01-01';
SET @b :='2024-01-03';
EXPLAIN SELECT*FROM t WHERE dt BETWEEN @a AND @b;
2. What did you expect to see? (Required)
The EXPLAIN should output the plan using the index on the dt column, as same as using literal values.
Bug Report
Please answer these questions before submitting your issue. Thanks!
When I set user-defined variables in the
WHERE
clause, the optimizer doesn't use the index. Current behavior is different from MySQL.1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
The
EXPLAIN
should output the plan using the index on thedt
column, as same as using literal values.3. What did you see instead (Required)
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: