diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index 8cb4cbc1bb1a..8cd443842381 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -2457,6 +2457,7 @@ func (ex *connExecutor) execCopyIn( ex.planner.maybeLogStatement( ctx, ex.executorType, + true, /* isCopy */ int(ex.state.mu.autoRetryCounter), ex.extraTxnState.txnCounter, numInsertedRows, diff --git a/pkg/sql/conn_executor_exec.go b/pkg/sql/conn_executor_exec.go index 1b629524d061..18fd8aed7ef4 100644 --- a/pkg/sql/conn_executor_exec.go +++ b/pkg/sql/conn_executor_exec.go @@ -1070,6 +1070,7 @@ func (ex *connExecutor) dispatchToExecutionEngine( planner.maybeLogStatement( ctx, ex.executorType, + false, /* isCopy */ int(ex.state.mu.autoRetryCounter), ex.extraTxnState.txnCounter, res.RowsAffected(), diff --git a/pkg/sql/event_log.go b/pkg/sql/event_log.go index 1a747ef18465..258dc72a9bd5 100644 --- a/pkg/sql/event_log.go +++ b/pkg/sql/event_log.go @@ -164,6 +164,9 @@ type eventLogOptions struct { // Additional redaction options, if necessary. rOpts redactionOptions + + // isCopy notes whether the current event is related to COPY. + isCopy bool } // redactionOptions contains instructions on how to redact the SQL @@ -276,7 +279,10 @@ func logEventInternalForSQLStatements( ) error { // Inject the common fields into the payload provided by the caller. injectCommonFields := func(event logpb.EventPayload) error { - if txn != nil { + if opts.isCopy { + // No txn is set for COPY, so use now instead. + event.CommonDetails().Timestamp = timeutil.Now().UnixNano() + } else { event.CommonDetails().Timestamp = txn.ReadTimestamp().WallTime } sqlCommon, ok := event.(eventpb.EventWithCommonSQLPayload) diff --git a/pkg/sql/exec_log.go b/pkg/sql/exec_log.go index 6280af624553..f65762aa550c 100644 --- a/pkg/sql/exec_log.go +++ b/pkg/sql/exec_log.go @@ -154,6 +154,7 @@ var sqlPerfInternalLogger log.ChannelLogger = log.SqlInternalPerf func (p *planner) maybeLogStatement( ctx context.Context, execType executorType, + isCopy bool, numRetries, txnCounter, rows int, err error, queryReceived time.Time, @@ -162,12 +163,13 @@ func (p *planner) maybeLogStatement( stmtFingerprintID roachpb.StmtFingerprintID, queryStats *topLevelQueryStats, ) { - p.maybeLogStatementInternal(ctx, execType, numRetries, txnCounter, rows, err, queryReceived, hasAdminRoleCache, telemetryLoggingMetrics, stmtFingerprintID, queryStats) + p.maybeLogStatementInternal(ctx, execType, isCopy, numRetries, txnCounter, rows, err, queryReceived, hasAdminRoleCache, telemetryLoggingMetrics, stmtFingerprintID, queryStats) } func (p *planner) maybeLogStatementInternal( ctx context.Context, execType executorType, + isCopy bool, numRetries, txnCounter, rows int, err error, startTime time.Time, @@ -373,6 +375,7 @@ func (p *planner) maybeLogStatementInternal( // see a copy of the execution on the DEV Channel. dst: LogExternally | LogToDevChannelIfVerbose, verboseTraceLevel: execType.vLevel(), + isCopy: isCopy, }, &eventpb.QueryExecute{CommonSQLExecDetails: execDetails}) }