Skip to content

Commit

Permalink
sql: add COPY to sampled_query logging
Browse files Browse the repository at this point in the history
As requested by product, we want COPY to show up on sampled_query. This
commit adds this, whilst fudging a few things presumably more relevant
to "regular" DDL statements.

Release justification: telemetry only change

Release note: None
  • Loading branch information
otan committed Aug 23, 2022
1 parent 31bd044 commit 5f24073
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,26 @@ func (ex *connExecutor) execCopyIn(
payload := eventNonRetriableErrPayload{err: err}
return ev, payload, nil
}
defer cm.Close(ctx)
defer func() {
cm.Close(ctx)

// These fields are not available in COPY, so use the empty value.
var stmtFingerprintID roachpb.StmtFingerprintID
var stats topLevelQueryStats
ex.planner.maybeLogStatement(
ctx,
ex.executorType,
int(ex.state.mu.autoRetryCounter),
ex.extraTxnState.txnCounter,
cm.numInsertedRows(),
retErr,
ex.statsCollector.PhaseTimes().GetSessionPhaseTime(sessionphase.SessionQueryReceived),
&ex.extraTxnState.hasAdminRoleCache,
ex.server.TelemetryLoggingMetrics,
stmtFingerprintID,
&stats,
)
}()

if err := ex.execWithProfiling(ctx, cmd.Stmt, nil, func(ctx context.Context) error {
return cm.run(ctx)
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var copyBatchRowSize = util.ConstantWithMetamorphicTestRange("copy-batch-size",

type copyMachineInterface interface {
run(ctx context.Context) error
numInsertedRows() int

// Close closes memory accounts associated with copy.
Close(ctx context.Context)
Expand Down Expand Up @@ -266,6 +267,10 @@ func newCopyMachine(
return c, nil
}

func (c *copyMachine) numInsertedRows() int {
return c.insertedRows
}

func (c *copyMachine) initMonitoring(ctx context.Context, parentMon *mon.BytesMonitor) {
// Create a monitor for the COPY command so it can be tracked separate from transaction or session.
memMetrics := &MemoryMetrics{}
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/copy_file_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func CopyInFileStmt(destination, schema, table string) string {
)
}

func (f *fileUploadMachine) numInsertedRows() int {
return f.c.numInsertedRows()
}

func (f *fileUploadMachine) Close(ctx context.Context) {
f.c.Close(ctx)
}
Expand Down

0 comments on commit 5f24073

Please sign in to comment.