cockroachdb / cockroachdb/cockroach

Treat SHOW DATABASE as an observer statement

Open
#154,172 3 comments 0 reactions 0 assignees View on GitHub
branch-master C-cleanup T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

`SHOW DATABASE` is not recognized as an observer statement (see connExecutor.runObserverStatement [1]), leading to a clunky experience in the DB console, especially when viewing transactions that were executed via the cli shell `cockroach sql`.

The shell performs many intermediate statements with each statement input by the user. Specifically `SHOW SYNTAX`, `SHOW LAST QUERY STATISTICS`, `SHOW TRANSACTION STATUS` and finally `SHOW DATABASE`

All these get categorized as observer statements, and thus they don't get to the point in the conn executor where they get recorded to statement statistics (`connExecutor.recordStatementSummary` [2]), except for `SHOW DATABASE` leading to a confusing experience when viewing the transaction fingerprint (see screenshot)

**To Reproduce**

Open a SQL shell w/ `cockroach sql` and perform an explicit transaction with a few statements.
In this example, i did
```
BEGIN;
INSERT INTO foo VALUES (1);
SELECT * FROM foo;
COMMIT;
```

Go to SQL activity page in DB console > Transactions, click on your transaction, notice that there are intermediate `SHOW DATABASE` statements that are included in the transaction fingerprint.

Image

**Expected behavior**
Expecting not to see `SHOW DATABASE`

**Environment:**
All versions of CRDB.

[1] https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/conn_executor_exec.go#L3669-L3695
[2] https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/executor_statement_metrics.go#L134-L144

Jira issue: CRDB-54770

Contributor guide

Open the contributing guide

Research direction

Start in pkg/sql/conn_executor_exec.go at connExecutor.runObserverStatement and compare SHOW DATABASE with the other observer statements described in the issue. Check pkg/sql/executor_statement_metrics.go to understand the recording path; done means SHOW DATABASE is excluded from the transaction fingerprint like SHOW SYNTAX, SHOW LAST QUERY STATISTICS, and SHOW TRANSACTION STATUS.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.