Skip to content

Commit

Permalink
Merge pull request cockroachdb#84679 from otan-cockroach/backport21.2…
Browse files Browse the repository at this point in the history
…-79011

release-21.2: sql: various logging improvements
  • Loading branch information
otan authored Jul 19, 2022
2 parents 840df39 + cb5deed commit b0b7bda
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,19 @@ func isCopyToExternalStorage(cmd CopyIn) bool {
// and writing up to the CommandComplete message.
func (ex *connExecutor) execCopyIn(
ctx context.Context, cmd CopyIn,
) (fsm.Event, fsm.EventPayload, error) {
) (_ fsm.Event, retPayload fsm.EventPayload, retErr error) {
logStatements := logStatementsExecuteEnabled.Get(ex.planner.execCfg.SV())

ex.incrementStartedStmtCounter(cmd.Stmt)
defer func() {
if retErr != nil {
log.SqlExec.Errorf(ctx, "error executing %s: %+v", cmd, retErr)
}
}()

if logStatements {
log.SqlExec.Infof(ctx, "executing %s", cmd)
}

// When we're done, unblock the network connection.
defer cmd.CopyDone.Done()
Expand Down
8 changes: 6 additions & 2 deletions pkg/sql/conn_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,12 @@ type CopyIn struct {
// command implements the Command interface.
func (CopyIn) command() string { return "copy" }

func (CopyIn) String() string {
return "CopyIn"
func (c CopyIn) String() string {
s := "(empty)"
if c.Stmt != nil {
s = c.Stmt.String()
}
return fmt.Sprintf("CopyIn: %s", s)
}

var _ Command = CopyIn{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/pgwire/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ func (c *conn) handleSimpleQuery(
startParse := timeutil.Now()
stmts, err := c.parser.ParseWithInt(query, unqualifiedIntSize)
if err != nil {
log.SqlExec.Errorf(ctx, "failed to parse simple query: %s", query)
return c.stmtBuf.Push(ctx, sql.SendError{Err: err})
}
endParse := timeutil.Now()
Expand Down Expand Up @@ -839,6 +840,7 @@ func (c *conn) handleParse(
startParse := timeutil.Now()
stmts, err := c.parser.ParseWithInt(query, nakedIntSize)
if err != nil {
log.SqlExec.Errorf(ctx, "failed to parse: %s", query)
return c.stmtBuf.Push(ctx, sql.SendError{Err: err})
}
if len(stmts) > 1 {
Expand Down

0 comments on commit b0b7bda

Please sign in to comment.