diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index 69811d1d3d7d..c5797c07dd0a 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -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) diff --git a/pkg/sql/copy.go b/pkg/sql/copy.go index ae23cd29296e..cb967ff359a2 100644 --- a/pkg/sql/copy.go +++ b/pkg/sql/copy.go @@ -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) @@ -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{} diff --git a/pkg/sql/copy_file_upload.go b/pkg/sql/copy_file_upload.go index 97773354798b..cb7a525973fe 100644 --- a/pkg/sql/copy_file_upload.go +++ b/pkg/sql/copy_file_upload.go @@ -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) }