pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.85k stars 5.8k forks source link

runaway: change `RUNAWAY_WATCHES` time type to UTC #54770

Closed HuSharp closed 1 month ago

HuSharp commented 1 month ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Currently tidb_runaway_watch relies on struct QuarantineRecord to store time as UTC, while RUNAWAY_WATCHES directly selects tidb_runaway_watch to convert to local time.

mysql> SELECT * FROM mysql.tidb_runaway_watch limit 1\G
*************************** 1. row ***************************
                 id: 1
resource_group_name: default
         start_time: 2024-07-16 07:34:14.137009
           end_time: 2024-07-16 07:44:14.137009
              watch: 1
         watch_text: select  count(*) from orders where o_orderdate = '1994-11-12'
             source: 127.0.0.1:4000
             action: 3
1 row in set (0.00 sec)

mysql> SELECT * FROM INFORMATION_SCHEMA.RUNAWAY_WATCHES where id =1\G
*************************** 1. row ***************************
                 ID: 1
RESOURCE_GROUP_NAME: default
         START_TIME: 2024-07-16 15:34:14
           END_TIME: 2024-07-16 15:44:14
              WATCH: Exact
         WATCH_TEXT: select  count(*) from orders where o_orderdate = '1994-11-12'
             SOURCE: 127.0.0.1:4000
             ACTION: Kill
1 row in set (0.01 sec)

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

RUNAWAY_WATCHES displays UTC as well.

3. What did you see instead (Required)

RUNAWAY_WATCHES displays local time while tidb_runaway_watch displays UTC

4. What is your TiDB version? (Required)

master

HuSharp commented 1 month ago

why not change tidb_runaway_watch to local time? because tidb_runaway_watch is datetime, which is different from timestamp, and can not convert UTC to local time automatically. https://github.com/pingcap/tidb/blob/e5a8a23e836a99b95db201f412cb7fdd9c811c5f/pkg/session/bootstrap.go#L635-L646 This means the timezone information will be lost, and the user will not know which timezone to switch to when in crossing time zones (the user needs to confirm the local time zone on the server side).