Skip to content

sql: add transaction_fingerprint_id to system.statement_statistics pk#69320

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
Azhng:sqlstats-txn-fingerprint-id-pk-column
Aug 26, 2021
Merged

sql: add transaction_fingerprint_id to system.statement_statistics pk#69320
craig[bot] merged 1 commit intocockroachdb:masterfrom
Azhng:sqlstats-txn-fingerprint-id-pk-column

Conversation

@Azhng
Copy link
Copy Markdown
Contributor

@Azhng Azhng commented Aug 24, 2021

Previously, statements belong to different transaction fingerprints but
has same statement fingerprint IDs get rolled up into a single entry
in system.statement_statistics.
This commit introduce additional transaction_fingerprint_id column in the
system.statement_statistics primary key to enable that differentiation.
This commit does not implement filling the new columns. Therefore, the
new column is currently left as blank. This will be addressed in the later
PRs.

Release justification: Category 4: Low risk, high benefit changes to existing
functionality

Release note (sql change): add transaction_fingerprint_id to
system.statement_statistics primary key.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@Azhng Azhng force-pushed the sqlstats-txn-fingerprint-id-pk-column branch from dbca9f9 to 3440eab Compare August 24, 2021 20:14
@Azhng Azhng requested a review from a team August 24, 2021 20:15
@Azhng Azhng marked this pull request as ready for review August 24, 2021 20:15
@Azhng Azhng requested a review from a team August 24, 2021 20:15
Copy link
Copy Markdown
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an observability perspective :lgtm:
But get the approval from SQL Schema too

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @Azhng)

@Azhng Azhng force-pushed the sqlstats-txn-fingerprint-id-pk-column branch from 3440eab to f708a8c Compare August 26, 2021 16:22
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng and @maryliag)


pkg/sql/catalog/systemschema/system.go, line 480 at r2 (raw file):

    plan JSONB NOT NULL,

    PRIMARY KEY (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id)

How did you decide where to put this in the primary key? Is the expectation that people will be looking up statements by transaction_fingerprint_id most often?


pkg/sql/catalog/systemschema/system.go, line 482 at r2 (raw file):

    PRIMARY KEY (aggregated_ts, fingerprint_id, transaction_fingerprint_id, plan_hash, app_name, node_id)
      USING HASH WITH BUCKET_COUNT = 8,
    INDEX "fingerprint_stats_idx" (fingerprint_id, aggregated_ts, transaction_fingerprint_id, plan_hash, app_name, node_id),

I should have caught this earlier, it's a bit unconventional to explicitly state these primary key columns in the index definition. All secondary indexes have all of the primary index columns in their key. I think that this should just be INDEX (fingerprint_id) to better capture its intention.

@Azhng Azhng force-pushed the sqlstats-txn-fingerprint-id-pk-column branch from f708a8c to 0684691 Compare August 26, 2021 17:11
Copy link
Copy Markdown
Contributor Author

@Azhng Azhng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner and @maryliag)


pkg/sql/catalog/systemschema/system.go, line 480 at r2 (raw file):

Previously, ajwerner wrote…

How did you decide where to put this in the primary key? Is the expectation that people will be looking up statements by transaction_fingerprint_id most often?

My reasoning here is that this is primary for Transaction Detail Page in the DB Console. Since there we will be looking at the statements belonging to a transaction_fingerprint_id.


pkg/sql/catalog/systemschema/system.go, line 482 at r2 (raw file):

Previously, ajwerner wrote…

I should have caught this earlier, it's a bit unconventional to explicitly state these primary key columns in the index definition. All secondary indexes have all of the primary index columns in their key. I think that this should just be INDEX (fingerprint_id) to better capture its intention.

Done.

Copy link
Copy Markdown
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @maryliag)


pkg/sql/catalog/systemschema/system.go, line 480 at r2 (raw file):

Previously, Azhng (Archer Zhang) wrote…

My reasoning here is that this is primary for Transaction Detail Page in the DB Console. Since there we will be looking at the statements belonging to a transaction_fingerprint_id.

In that case, do we want to change the secondary index to be (fingerprint_id, transaction_fingerprint_id)? Or do we want it to be (fingerprint_id, aggregated_ts)? I assume that the way this query will work is by looking up the transaction, which, I assume, has the set of statement fingerprints. Then, we'd go fetch each statement fingerprint. That means we want. an index based on fingerprint_id, transaction_fingerprint_id regardless of the timestamp, no?

@Azhng Azhng force-pushed the sqlstats-txn-fingerprint-id-pk-column branch from 0684691 to 503091c Compare August 26, 2021 18:30
Copy link
Copy Markdown
Contributor Author

@Azhng Azhng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner and @maryliag)


pkg/sql/catalog/systemschema/system.go, line 480 at r2 (raw file):

Previously, ajwerner wrote…

In that case, do we want to change the secondary index to be (fingerprint_id, transaction_fingerprint_id)? Or do we want it to be (fingerprint_id, aggregated_ts)? I assume that the way this query will work is by looking up the transaction, which, I assume, has the set of statement fingerprints. Then, we'd go fetch each statement fingerprint. That means we want. an index based on fingerprint_id, transaction_fingerprint_id regardless of the timestamp, no?

Good point. Updated the secondary index to include transaction_fingerprint_id.

Previously, statements belong to different transaction fingerprints but
has same statement fingerprint IDs get rolled up into a single entry
in system.statement_statistics.
This commit introduce additional transaction_fingerprint_id column in the
system.statement_statistics primary key to enable that differentiation.
This commit does not implement filling the new columns. Therefore, the
new column is currently left as blank. This will be addressed in the later
PRs.

Release justification: Category 4: Low risk, high benefit changes to existing
 functionality

Release note (sql change): add transaction_fingerprint_id to
 system.statement_statistics primary key.
@Azhng Azhng force-pushed the sqlstats-txn-fingerprint-id-pk-column branch from 503091c to 5b5c301 Compare August 26, 2021 19:44
@Azhng
Copy link
Copy Markdown
Contributor Author

Azhng commented Aug 26, 2021

@ajwerner RFAL

Copy link
Copy Markdown
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner and @maryliag)

@Azhng
Copy link
Copy Markdown
Contributor Author

Azhng commented Aug 26, 2021

TFTR!

bors r=ajwerner,maryliag

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 26, 2021

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants