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

value of tidb_sysdate_is_now seems cached in expression in planCache and not respect the current setting #49299

Closed
lcwangchao opened this issue Dec 8, 2023 · 0 comments · Fixed by #49949
Assignees
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@lcwangchao
Copy link
Collaborator

lcwangchao commented Dec 8, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

TiDB [email protected]:test> create table t (a int);
Query OK, 0 rows affected
Time: 0.088s
TiDB [email protected]:test> insert into t values(1);
Query OK, 1 row affected
Time: 0.005s
TiDB [email protected]:test> set @@tidb_sysdate_is_now=0;
Query OK, 0 rows affected
Time: 0.000s
TiDB [email protected]:test> prepare s from "select sleep(a), now(6), sysdate(6), sysdate(6)=now(6) from t";
Query OK, 0 rows affected
Time: 0.001s
TiDB [email protected]:test> execute s;
+----------+----------------------------+----------------------------+-------------------+
| sleep(a) | now(6)                     | sysdate(6)                 | sysdate(6)=now(6) |
+----------+----------------------------+----------------------------+-------------------+
| 0        | 2023-12-08 17:55:36.618077 | 2023-12-08 17:55:36.618089 | 0                 |
+----------+----------------------------+----------------------------+-------------------+
1 row in set
Time: 1.009s
TiDB [email protected]:test> set @@tidb_sysdate_is_now=1;
Query OK, 0 rows affected
Time: 0.001s
TiDB [email protected]:test> execute s;
+----------+----------------------------+----------------------------+-------------------+
| sleep(a) | now(6)                     | sysdate(6)                 | sysdate(6)=now(6) |
+----------+----------------------------+----------------------------+-------------------+
| 0        | 2023-12-08 17:55:43.594673 | 2023-12-08 17:55:43.594688 | 0                 |
+----------+----------------------------+----------------------------+-------------------+
1 row in set
Time: 1.013s

2. What did you expect to see? (Required)

It should respect the current value of tidb_sysdate_is_now like no use plan cache:

TiDB [email protected]:test> set @@tidb_enable_prepared_plan_cache=0;
Query OK, 0 rows affected
Time: 0.001s
TiDB [email protected]:test> set @@tidb_sysdate_is_now=0;
Query OK, 0 rows affected
Time: 0.001s
TiDB [email protected]:test> prepare s from "select sleep(a), now(6), sysdate(6), sysdate(6)=now(6) from t";
Query OK, 0 rows affected
Time: 0.001s
TiDB [email protected]:test> execute s;
+----------+----------------------------+----------------------------+-------------------+
| sleep(a) | now(6)                     | sysdate(6)                 | sysdate(6)=now(6) |
+----------+----------------------------+----------------------------+-------------------+
| 0        | 2023-12-08 17:59:51.246963 | 2023-12-08 17:59:52.248985 | 0                 |
+----------+----------------------------+----------------------------+-------------------+
1 row in set

TiDB [email protected]:test> set @@tidb_sysdate_is_now=1;
Query OK, 0 rows affected
Time: 0.001s
TiDB [email protected]:test> execute s;
+----------+----------------------------+----------------------------+-------------------+
| sleep(a) | now(6)                     | sysdate(6)                 | sysdate(6)=now(6) |
+----------+----------------------------+----------------------------+-------------------+
| 0        | 2023-12-08 18:00:28.162819 | 2023-12-08 18:00:28.162819 | 1                 |
+----------+----------------------------+----------------------------+-------------------+
1 row in set

3. What did you see instead (Required)

The sysdate(6) = now(6) is false even we change tidb_sysdate_is_now to 1 when plan cache enabled.

4. What is your TiDB version? (Required)

Tested in nightly build

TiDB [email protected]:test> select tidb_version();
+-----------------------------------------------------------+
| tidb_version()                                            |
+-----------------------------------------------------------+
| Release Version: v7.6.0-alpha                             |
| Edition: Community                                        |
| Git Commit Hash: b74d64c7a48189f00fbae0c29ad1435b60b8c51d |
| Git Branch: heads/refs/tags/v7.6.0-alpha                  |
| UTC Build Time: 2023-12-07 14:25:39                       |
| GoVersion: go1.21.4                                       |
| Race Enabled: false                                       |
| Check Table Before Drop: false                            |
| Store: tikv                                               |
+-----------------------------------------------------------+
1 row in set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants