Skip to content

Commit

Permalink
Merge #35805
Browse files Browse the repository at this point in the history
35805: sql: create a span per sql statement r=andreimatei a=andreimatei

Before this patch, statements did not have their own spans. Instead,
transactions had spans. This dates from a time when the TxnCoordSender
would capture the span of the first write and expect it to live for the
duration of the transaction, but that stopped being the case a while
ago.
This patch makes each statement create its own span.

Release note: None

Co-authored-by: Andrei Matei <[email protected]>
  • Loading branch information
craig[bot] and andreimatei committed Apr 1, 2019
2 parents 711beb9 + 82c6ec0 commit 9d85a98
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 368 deletions.
458 changes: 248 additions & 210 deletions pkg/sql/conn_executor.go

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions pkg/sql/conn_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ type StmtBuf struct {
// buffer.
type Command interface {
fmt.Stringer
command()
// command returns a string representation of the command type (e.g.
// "prepare", "exec stmt").
command() string
}

// ExecStmt is the command for running a query sent through the "simple" pgwire
Expand All @@ -138,7 +140,7 @@ type ExecStmt struct {
}

// command implements the Command interface.
func (ExecStmt) command() {}
func (ExecStmt) command() string { return "exec stmt" }

func (e ExecStmt) String() string {
// We have the original SQL, but we still use String() because it obfuscates
Expand All @@ -160,7 +162,7 @@ type ExecPortal struct {
}

// command implements the Command interface.
func (ExecPortal) command() {}
func (ExecPortal) command() string { return "exec portal" }

func (e ExecPortal) String() string {
return fmt.Sprintf("ExecPortal name: %q", e.Name)
Expand All @@ -187,7 +189,7 @@ type PrepareStmt struct {
}

// command implements the Command interface.
func (PrepareStmt) command() {}
func (PrepareStmt) command() string { return "prepare" }

func (p PrepareStmt) String() string {
// We have the original SQL, but we still use String() because it obfuscates
Expand All @@ -205,7 +207,7 @@ type DescribeStmt struct {
}

// command implements the Command interface.
func (DescribeStmt) command() {}
func (DescribeStmt) command() string { return "describe" }

func (d DescribeStmt) String() string {
return fmt.Sprintf("Describe: %q", d.Name)
Expand Down Expand Up @@ -245,7 +247,7 @@ type BindStmt struct {
}

// command implements the Command interface.
func (BindStmt) command() {}
func (BindStmt) command() string { return "bind" }

func (b BindStmt) String() string {
return fmt.Sprintf("BindStmt: %q->%q", b.PreparedStatementName, b.PortalName)
Expand All @@ -260,7 +262,7 @@ type DeletePreparedStmt struct {
}

// command implements the Command interface.
func (DeletePreparedStmt) command() {}
func (DeletePreparedStmt) command() string { return "delete" }

func (d DeletePreparedStmt) String() string {
return fmt.Sprintf("DeletePreparedStmt: %q", d.Name)
Expand All @@ -280,7 +282,7 @@ var _ Command = DeletePreparedStmt{}
type Sync struct{}

// command implements the Command interface.
func (Sync) command() {}
func (Sync) command() string { return "sync" }

func (Sync) String() string {
return "Sync"
Expand All @@ -293,7 +295,7 @@ var _ Command = Sync{}
type Flush struct{}

// command implements the Command interface.
func (Flush) command() {}
func (Flush) command() string { return "flush" }

func (Flush) String() string {
return "Flush"
Expand All @@ -313,7 +315,7 @@ type CopyIn struct {
}

// command implements the Command interface.
func (CopyIn) command() {}
func (CopyIn) command() string { return "copy" }

func (CopyIn) String() string {
return "CopyIn"
Expand All @@ -328,7 +330,7 @@ var _ Command = CopyIn{}
type DrainRequest struct{}

// command implements the Command interface.
func (DrainRequest) command() {}
func (DrainRequest) command() string { return "drain" }

func (DrainRequest) String() string {
return "Drain"
Expand All @@ -345,7 +347,7 @@ type SendError struct {
}

// command implements the Command interface.
func (SendError) command() {}
func (SendError) command() string { return "send error" }

func (s SendError) String() string {
return fmt.Sprintf("SendError: %s", s.Err)
Expand Down
28 changes: 17 additions & 11 deletions pkg/sql/logictest/testdata/planner_test/select
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ FROM [SHOW TRACE FOR SESSION]
WHERE message LIKE '%SPAN START%' OR message LIKE '%pos%executing%';
----
0 === SPAN START: session recording === session recording
1 === SPAN START: exec cmd: exec stmt === exec cmd: exec stmt
0 [NoTxn pos:?] executing ExecStmt: BEGIN TRANSACTION session recording
1 === SPAN START: sql txn === sql txn
1 [Open pos:?] executing ExecStmt: SELECT 1 sql txn
2 === SPAN START: consuming rows === consuming rows
3 === SPAN START: flow === flow
7 === SPAN START: values ===
2 === SPAN START: sql txn === sql txn
3 === SPAN START: exec cmd: exec stmt === exec cmd: exec stmt
2 [Open pos:?] executing ExecStmt: SELECT 1 sql txn
4 === SPAN START: consuming rows === consuming rows
5 === SPAN START: flow === flow
13 === SPAN START: values ===
cockroach.processorid: 0 values
1 [Open pos:?] executing ExecStmt: COMMIT TRANSACTION sql txn
6 === SPAN START: exec cmd: exec stmt === exec cmd: exec stmt
2 [Open pos:?] executing ExecStmt: COMMIT TRANSACTION sql txn
7 === SPAN START: exec cmd: exec stmt === exec cmd: exec stmt
0 [NoTxn pos:?] executing ExecStmt: SELECT 2 session recording
4 === SPAN START: sql txn === sql txn
4 [Open pos:?] executing ExecStmt: SELECT 2 sql txn
5 === SPAN START: consuming rows === consuming rows
6 === SPAN START: flow === flow
8 === SPAN START: values ===
8 === SPAN START: sql txn === sql txn
9 === SPAN START: exec cmd: exec stmt === exec cmd: exec stmt
8 [Open pos:?] executing ExecStmt: SELECT 2 sql txn
10 === SPAN START: consuming rows === consuming rows
11 === SPAN START: flow === flow
14 === SPAN START: values ===
cockroach.processorid: 0 values
12 === SPAN START: exec cmd: exec stmt === exec cmd: exec stmt
0 [NoTxn pos:?] executing ExecStmt: SET TRACING = off session recording

# ------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 9d85a98

Please sign in to comment.