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

sql: add columns to node_execution_insights #85131

Merged
merged 1 commit into from
Jul 29, 2022
Merged

sql: add columns to node_execution_insights #85131

merged 1 commit into from
Jul 29, 2022

Conversation

j82w
Copy link
Contributor

@j82w j82w commented Jul 27, 2022

This commit adds the following new columns
to crdb_internal.node_execution_insights table.

txn_id                     UUID NOT NULL,
txn_fingerprint_id         BYTES NOT NULL,
query                      STRING NOT NULL,
status                     STRING NOT NULL,
start_time                 TIMESTAMP NOT NULL,
end_time                   TIMESTAMP NOT NULL,
full_scan                  BOOL NOT NULL,
user_name                  STRING NOT NULL,
application_name           STRING NOT NULL,
database_name              STRING NOT NULL,
plan_gist                  STRING NOT NULL,
rows_read                  INT8 NOT NULL,
rows_written               INT8 NOT NULL,
priority                   FLOAT NOT NULL,
retries                    INT8 NOT NULL

Part of #81024

Release note (sql change): Adding txn_id,
txn_fingerprint_id, query, status, start_time,
end_time, full_scan, user_name, application_name,
database_name, plan_gist, rows_read, rows_written,
priority, and retries columns to
crdb_internal.node_execution_insights

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@j82w j82w requested a review from a team July 27, 2022 14:47
@j82w j82w marked this pull request as ready for review July 27, 2022 14:47
@j82w j82w requested a review from a team July 27, 2022 14:47
@j82w j82w requested a review from a team as a code owner July 27, 2022 14:47
Copy link
Contributor

@matthewtodd matthewtodd left a comment

Choose a reason for hiding this comment

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

🎉 Woo! Thanks, Jake! Left a few comments inline.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @j82w and @matthewtodd)


pkg/sql/executor_statement_metrics.go line 190 at r1 (raw file):

		StatementError:       stmtErr,
		IndexRecommendations: planner.instrumentation.indexRecommendations,
		Query:                stmt.StmtNoConstants,

I think "no constants" is a good choice for now. In #81023 we'll want to have the option to show the constants to users with permission. (The constants, though sensitive, can be helpful when understanding why the execution may have been slow.) cc @kevin-v-ngo


pkg/sql/sqlstats/ssprovider.go line 18 at r1 (raw file):

import (
	"context"
	"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"

You can dev build crlfmt and have Goland use it to keep these imports organized. (I think the linter will complain if you don't?)


pkg/sql/sqlstats/insights/insights.proto line 42 at r1 (raw file):

    (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.StmtFingerprintID"];
  double latency_in_seconds = 3;
  string transaction_id = 4;

Remove this one.


pkg/sql/sqlstats/insights/insights.proto line 45 at r1 (raw file):

  string query = 5;
  string status = 6;
  google.protobuf.Timestamp start_time = 7[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];

nit: add a space between the 7 and the [.


pkg/sql/sqlstats/insights/insights.proto line 53 at r1 (raw file):

  string plan_gist = 13;
  int64 rowsRead = 14;
  int64 rowsWritten = 15;

nit: rows_read and rows_written. (Snake case for protobuf field names.)


pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go line 45 at r1 (raw file):

var _ sqlstats.Writer = &Container{}

func GetStatusString(statementError error) string {

nit: getStatusString. (To make it private.)


pkg/sql/sqlstats/insights/integration/insights_test.go line 68 at r1 (raw file):

	require.NoError(t, err)

	// Execute a fast statement that is under the latencyThreshold to verify it does not get logged

We have other, more focused tests that do this. See detector_test.go. This broader integration test is here mostly to show something working end-to-end; the branching out details are tested in faster unit tests lower in the stack.


pkg/sql/sqlstats/insights/integration/insights_test.go line 84 at r1 (raw file):

	}, 1*time.Second)

	// Verify time

nit: I think our style guide requires that comments be full, punctuated sentences.


pkg/sql/sqlstats/insights/integration/insights_test.go line 92 at r1 (raw file):

			"end_time, "+
			"full_scan "+
			"FROM crdb_internal.node_execution_insights")

I feel ambivalent about testing the specifics of the data up here in this integration test, but I don't have any better ideas at the moment. :-)

@kevin-v-ngo
Copy link

@j82w and @maryliag - do you think we can integrate the CREATE index recommendations in this table as well? #83782 (comment)

Having Create index recommendations for 'outliers' and slow executions would really complete the e2e experience with being actionable for suboptimal plans.

Copy link
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.

@kevin-v-ngo once that feature is added, it can be added to this table. Right now it would be empty.

Reviewed 3 of 8 files at r1, 3 of 3 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @j82w, @maryliag, and @matthewtodd)


-- commits line 24 at r2:
nit: the release notes is used for the docs team, so try being more descriptive to help them out, listing the column name (you don't need to specify, just the names are enough)


pkg/sql/crdb_internal.go line 6235 at r2 (raw file):

	session_id                 STRING NOT NULL,
	txn_id                     UUID NOT NULL,
  txn_fingerprint_id         BYTES NOT NULL,

this line seems to be misaligned (space vs tabs perhaps?)


pkg/sql/sqlstats/insights/integration/insights_test.go line 109 at r2 (raw file):

	testutils.SucceedsWithin(t, func() error {
		rows, err := conn.QueryContext(ctx, "SELECT "+
			"crdb_internal.decode_plan_gist(plan_gist) "+

FYI, it is possible to have null values for plan_gist, so you would need to check if the value is not null, before calling this function.
But I don't think this test is necessary here, because it's testing the decode function, but we already have tests for that.

@kevin-v-ngo
Copy link

@kevin-v-ngo once that feature is added, it can be added to this table. Right now it would be empty.

I guess my question is more on when will it be available? And if possible, can we have it as part of the V1 experience here.

@matthewtodd
Copy link
Contributor

@maryliag @j82w regarding release notes, I've been a little lax on these PRs (since a lot was in flux as we were figuring things out), instead aiming to lay out a first cohesive overview in the eventual PR that flips the cluster settings on by default.

Copy link
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.

when will it be available? And if possible, can we have it as part of the V1 experience here
it will be available soon (by beginning of August), hopefully we can add to the V1

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @j82w, @maryliag, and @matthewtodd)

Copy link
Contributor Author

@j82w j82w 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 (waiting on @j82w, @maryliag, and @matthewtodd)


pkg/sql/crdb_internal.go line 6235 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

this line seems to be misaligned (space vs tabs perhaps?)

Fixed, it was using spaces instead of tabs.


pkg/sql/sqlstats/ssprovider.go line 18 at r1 (raw file):

Previously, matthewtodd (Matthew Todd) wrote…

You can dev build crlfmt and have Goland use it to keep these imports organized. (I think the linter will complain if you don't?)

Done.


pkg/sql/sqlstats/insights/insights.proto line 42 at r1 (raw file):

Previously, matthewtodd (Matthew Todd) wrote…

Remove this one.

Done.


pkg/sql/sqlstats/insights/integration/insights_test.go line 68 at r1 (raw file):

Previously, matthewtodd (Matthew Todd) wrote…

We have other, more focused tests that do this. See detector_test.go. This broader integration test is here mostly to show something working end-to-end; the branching out details are tested in faster unit tests lower in the stack.

Done.


pkg/sql/sqlstats/insights/integration/insights_test.go line 92 at r1 (raw file):

Previously, matthewtodd (Matthew Todd) wrote…

I feel ambivalent about testing the specifics of the data up here in this integration test, but I don't have any better ideas at the moment. :-)

If you don't verify the data in the integration test how can you be sure that the data did not get corrupted and/or incorrectly converted at some point?

Copy link
Contributor

@matthewtodd matthewtodd left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @j82w, @maryliag, and @matthewtodd)


pkg/sql/sqlstats/insights/integration/insights_test.go line 92 at r1 (raw file):

Previously, j82w wrote…

If you don't verify the data in the integration test how can you be sure that the data did not get corrupted and/or incorrectly converted at some point?

I think I figured out why I was feeling that -- I had written this test first as a design tool, to help me see when I had gotten the right bits connected end-to-end, where showing something working (a row in the table!) gave me the confidence I needed at the time.

But I think you're probably on to something here: it may make sense for this test to now shift into more of a regression coverage tool, where we use it to make sure nothing gets broken going forward. And in that context, checking the data is certainly useful.

Copy link
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.

:lgtm:

Reviewed 1 of 2 files at r3, 2 of 2 files at r4, 1 of 3 files at r5, 3 of 3 files at r6, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @j82w)

@j82w
Copy link
Contributor Author

j82w commented Jul 28, 2022

bors r+

query STRING NOT NULL,
status STRING NOT NULL,
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP NOT NULL,

Choose a reason for hiding this comment

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

When are we going to derive elapsed time?

end_time TIMESTAMP NOT NULL,
full_scan BOOL NOT NULL,
user_name STRING NOT NULL,
application_name STRING NOT NULL,

Choose a reason for hiding this comment

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

app_name

session_id STRING NOT NULL,
txn_id UUID NOT NULL,
txn_fingerprint_id BYTES NOT NULL,
statement_id STRING NOT NULL,

Choose a reason for hiding this comment

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

Let's abbreviate statement -> stmt

statement_id -> stmt_id
stmt_fingerprint_id -> stmt_fingerprint_id

Seems like that's the pattern: https://www.cockroachlabs.com/docs/stable/crdb-internal.html#statement_statistics

@@ -6233,20 +6233,60 @@ func populateClusterLocksWithFilter(
var crdbInternalNodeExecutionInsightsTable = virtualSchemaTable{
schema: `
CREATE TABLE crdb_internal.node_execution_insights (

Choose a reason for hiding this comment

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

From the brief, seems like we're just missing the following:

retryable
last_retry_reason
last_contended_row
index_recommendation

@j82w
Copy link
Contributor Author

j82w commented Jul 28, 2022

bors r-

@craig
Copy link
Contributor

craig bot commented Jul 28, 2022

Canceled.

@j82w
Copy link
Contributor Author

j82w commented Jul 28, 2022

bors r+

Copy link
Contributor Author

@j82w j82w 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! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @j82w and @kevin-v-ngo)


pkg/sql/crdb_internal.go line 6235 at r6 (raw file):

Previously, kevin-v-ngo wrote…

From the brief, seems like we're just missing the following:

retryable
last_retry_reason
last_contended_row
index_recommendation

This PR was marked as partial change for the issue. Those columns are more complicated to implement. To avoid making the PR to large I'm going to do a separate follow up PR. I will fix the column names specified in the other comments at that time too.


pkg/sql/crdb_internal.go line 6239 at r6 (raw file):

Previously, kevin-v-ngo wrote…

Let's abbreviate statement -> stmt

statement_id -> stmt_id
stmt_fingerprint_id -> stmt_fingerprint_id

Seems like that's the pattern: https://www.cockroachlabs.com/docs/stable/crdb-internal.html#statement_statistics

This will be fixed in a follow up PR. Merging this now to unblock other tasks.


pkg/sql/crdb_internal.go line 6244 at r6 (raw file):

Previously, kevin-v-ngo wrote…

When are we going to derive elapsed time?

Elapsed time can easily be computed when needed.


pkg/sql/crdb_internal.go line 6247 at r6 (raw file):

Previously, kevin-v-ngo wrote…

app_name

This will be fixed in a follow up PR. Merging this now to unblock other tasks.

@craig
Copy link
Contributor

craig bot commented Jul 28, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jul 29, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jul 29, 2022

Build failed:

This commit adds the following new columns
to crdb_internal.node_execution_insights table.

txn_id                     UUID NOT NULL,
txn_fingerprint_id         BYTES NOT NULL,
stmt_id                    STRING NOT NULL,
stmt_fingerprint_id        BYTES NOT NULL,
query                      STRING NOT NULL,
status                     STRING NOT NULL,
start_time                 TIMESTAMP NOT NULL,
end_time                   TIMESTAMP NOT NULL,
full_scan                  BOOL NOT NULL,
user_name                  STRING NOT NULL,
app_name                   STRING NOT NULL,
database_name              STRING NOT NULL,
plan_gist                  STRING NOT NULL,
rows_read                  INT8 NOT NULL,
rows_written               INT8 NOT NULL,
priority                   FLOAT NOT NULL,
retries                    INT8 NOT NULL

Part of #81024

Release note (sql change): Renaming statement to stmt,
  and transaction to txn in columns. Adding
  txn_fingerprint_id, query, status, start_time,
  end_time, full_scan, user_name, app_name,
  database_name, plan_gist, rows_read, rows_written,
  priority, and retries columns to
  crdb_internal.node_execution_insights
@matthewtodd
Copy link
Contributor

Since we've got a green build and I'm eager to ship my branch that depends on these changes, I'm going to go ahead and kick off the bors process again:

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 29, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jul 29, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jul 29, 2022

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.

5 participants