Skip to content

Commit 9e01d7b

Browse files
committed
sql: respect timezone for SHOW QUERIES/SESSIONS
Release note (sql change): The SHOW QUERIES and SHOW SESSIONS commands now will display timestamps using the session's timezone setting.
1 parent f6c4d9d commit 9e01d7b

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

pkg/sql/crdb_internal.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ CREATE TABLE crdb_internal.%s (
22822282
node_id INT NOT NULL, -- the node on which the query is running
22832283
session_id STRING, -- the ID of the session
22842284
user_name STRING, -- the user running the query
2285-
start TIMESTAMP, -- the start time of the query
2285+
start TIMESTAMPTZ, -- the start time of the query
22862286
query STRING, -- the SQL code of the query
22872287
client_address STRING, -- the address of the client that issued the query
22882288
application_name STRING, -- the name of the application as per SET application_name
@@ -2439,7 +2439,7 @@ func populateQueriesTable(
24392439
txnID = tree.NewDUuid(tree.DUuid{UUID: query.TxnID})
24402440
}
24412441

2442-
ts, err := tree.MakeDTimestamp(query.Start, time.Microsecond)
2442+
ts, err := tree.MakeDTimestampTZ(query.Start, time.Microsecond)
24432443
if err != nil {
24442444
return err
24452445
}
@@ -2541,13 +2541,13 @@ CREATE TABLE crdb_internal.%s (
25412541
active_queries STRING, -- the currently running queries as SQL
25422542
last_active_query STRING, -- the query that finished last on this session as SQL
25432543
num_txns_executed INT, -- the number of transactions that were executed so far on this session
2544-
session_start TIMESTAMP, -- the time when the session was opened
2545-
active_query_start TIMESTAMP, -- the time when the current active query in the session was started
2544+
session_start TIMESTAMPTZ, -- the time when the session was opened
2545+
active_query_start TIMESTAMPTZ, -- the time when the current active query in the session was started
25462546
kv_txn STRING, -- the ID of the current KV transaction
25472547
alloc_bytes INT, -- the number of bytes allocated by the session
25482548
max_alloc_bytes INT, -- the high water mark of bytes allocated by the session
25492549
status STRING, -- the status of the session (open, closed)
2550-
session_end TIMESTAMP -- the time when the session was closed
2550+
session_end TIMESTAMPTZ -- the time when the session was closed
25512551
)
25522552
`
25532553

@@ -2609,7 +2609,7 @@ func populateSessionsTable(
26092609
if activeQueryStart.IsZero() {
26102610
activeQueryStartDatum = tree.DNull
26112611
} else {
2612-
activeQueryStartDatum, err = tree.MakeDTimestamp(activeQueryStart, time.Microsecond)
2612+
activeQueryStartDatum, err = tree.MakeDTimestampTZ(activeQueryStart, time.Microsecond)
26132613
if err != nil {
26142614
return err
26152615
}
@@ -2621,13 +2621,13 @@ func populateSessionsTable(
26212621
}
26222622

26232623
sessionID := getSessionID(session)
2624-
startTSDatum, err := tree.MakeDTimestamp(session.Start, time.Microsecond)
2624+
startTSDatum, err := tree.MakeDTimestampTZ(session.Start, time.Microsecond)
26252625
if err != nil {
26262626
return err
26272627
}
26282628
endTSDatum := tree.DNull
26292629
if session.End != nil {
2630-
endTSDatum, err = tree.MakeDTimestamp(*session.End, time.Microsecond)
2630+
endTSDatum, err = tree.MakeDTimestampTZ(*session.End, time.Microsecond)
26312631
if err != nil {
26322632
return err
26332633
}

0 commit comments

Comments
 (0)