Skip to content
Permalink
Browse files

Merge #35959

35959: sql: remove parallel statement execution r=nvanbenschoten a=nvanbenschoten

Fixes #34789.
Closes #17504.
Closes #18226.
Closes #35780.

This commit removes all logic supporting parallel statement execution.
It does so following the removal plan described in #34789. There is only
one deviation from the plan, which is that we don't do anything to
prevent statements with `RETURNING NOTHING` syntax from returning valid
results. Specifically, statements with `RETURNING NOTHING` may return
the actual number of rows affected instead of the dummy value of 1. It's
highly unlikely that anyone was relying on this behavior and it wasn't
documented.

Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
  • Loading branch information...
craig[bot] and nvanbenschoten committed Apr 22, 2019
2 parents d3e8e44 + d03ad96 commit aa799d370467e4a1ed8a9071ac8a72be596f6895
Showing with 168 additions and 2,168 deletions.
  1. +2 −96 pkg/sql/conn_executor.go
  2. +3 −228 pkg/sql/conn_executor_exec.go
  3. +2 −2 pkg/sql/exec_util.go
  4. +2 −0 pkg/sql/explain.go
  5. +1 −1 pkg/sql/internal_test.go
  6. +1 −33 pkg/sql/logictest/logic.go
  7. +1 −1 pkg/sql/logictest/testdata/logic_test/aggregate
  8. +1 −1 pkg/sql/logictest/testdata/logic_test/alter_column_type
  9. +1 −1 pkg/sql/logictest/testdata/logic_test/alter_sequence
  10. +1 −1 pkg/sql/logictest/testdata/logic_test/alter_table
  11. +1 −1 pkg/sql/logictest/testdata/logic_test/bit
  12. +1 −1 pkg/sql/logictest/testdata/logic_test/builtin_function
  13. +1 −1 pkg/sql/logictest/testdata/logic_test/bytes
  14. +1 −1 pkg/sql/logictest/testdata/logic_test/cascade
  15. +1 −1 pkg/sql/logictest/testdata/logic_test/check_constraints
  16. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring
  17. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring_constraint
  18. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring_index1
  19. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring_index2
  20. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring_normalization
  21. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring_nullinindex
  22. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring_uniqueindex1
  23. +1 −1 pkg/sql/logictest/testdata/logic_test/collatedstring_uniqueindex2
  24. +1 −1 pkg/sql/logictest/testdata/logic_test/computed
  25. +1 −1 pkg/sql/logictest/testdata/logic_test/conditional
  26. +1 −1 pkg/sql/logictest/testdata/logic_test/create_index
  27. +1 −1 pkg/sql/logictest/testdata/logic_test/create_statements
  28. +1 −1 pkg/sql/logictest/testdata/logic_test/custom_escape_character
  29. +1 −1 pkg/sql/logictest/testdata/logic_test/datetime
  30. +1 −1 pkg/sql/logictest/testdata/logic_test/decimal
  31. +1 −1 pkg/sql/logictest/testdata/logic_test/default
  32. +1 −1 pkg/sql/logictest/testdata/logic_test/delete
  33. +1 −1 pkg/sql/logictest/testdata/logic_test/distinct
  34. +1 −1 pkg/sql/logictest/testdata/logic_test/distinct_on
  35. +1 −1 pkg/sql/logictest/testdata/logic_test/drop_sequence
  36. +1 −1 pkg/sql/logictest/testdata/logic_test/family
  37. +1 −1 pkg/sql/logictest/testdata/logic_test/fk
  38. +1 −1 pkg/sql/logictest/testdata/logic_test/float
  39. +1 −1 pkg/sql/logictest/testdata/logic_test/inet
  40. +1 −1 pkg/sql/logictest/testdata/logic_test/insert
  41. +1 −1 pkg/sql/logictest/testdata/logic_test/int_size
  42. +1 −1 pkg/sql/logictest/testdata/logic_test/interleaved
  43. +1 −1 pkg/sql/logictest/testdata/logic_test/inverted_index
  44. +1 −1 pkg/sql/logictest/testdata/logic_test/join
  45. +1 −1 pkg/sql/logictest/testdata/logic_test/json
  46. +1 −1 pkg/sql/logictest/testdata/logic_test/json_builtins
  47. +1 −1 pkg/sql/logictest/testdata/logic_test/manual_retry
  48. +1 −1 pkg/sql/logictest/testdata/logic_test/multi_statement
  49. +1 −1 pkg/sql/logictest/testdata/logic_test/no_primary_key
  50. +1 −1 pkg/sql/logictest/testdata/logic_test/order_by
  51. +1 −1 pkg/sql/logictest/testdata/logic_test/ordinal_references
  52. +1 −1 pkg/sql/logictest/testdata/logic_test/ordinality
  53. +1 −1 pkg/sql/logictest/testdata/logic_test/orms
  54. +41 −96 pkg/sql/logictest/testdata/logic_test/{parallel_stmts → parallel_stmts_compat}
  55. +1 −1 pkg/sql/logictest/testdata/logic_test/pg_catalog
  56. +1 −1 pkg/sql/logictest/testdata/logic_test/poison_after_push
  57. +1 −1 pkg/sql/logictest/testdata/logic_test/postgres_jsonb
  58. +1 −1 pkg/sql/logictest/testdata/logic_test/postgresjoin
  59. +1 −1 pkg/sql/logictest/testdata/logic_test/privileges_table
  60. +1 −1 pkg/sql/logictest/testdata/logic_test/rename_column
  61. +1 −1 pkg/sql/logictest/testdata/logic_test/rename_constraint
  62. +1 −1 pkg/sql/logictest/testdata/logic_test/rename_database
  63. +1 −1 pkg/sql/logictest/testdata/logic_test/rename_index
  64. +1 −1 pkg/sql/logictest/testdata/logic_test/rename_sequence
  65. +1 −1 pkg/sql/logictest/testdata/logic_test/rename_table
  66. +1 −1 pkg/sql/logictest/testdata/logic_test/rename_view
  67. +1 −1 pkg/sql/logictest/testdata/logic_test/returning
  68. +1 −1 pkg/sql/logictest/testdata/logic_test/rows_from
  69. +1 −1 pkg/sql/logictest/testdata/logic_test/run_control
  70. +1 −1 pkg/sql/logictest/testdata/logic_test/scale
  71. +1 −1 pkg/sql/logictest/testdata/logic_test/schema_change_in_txn
  72. +1 −1 pkg/sql/logictest/testdata/logic_test/schema_change_retry
  73. +1 −1 pkg/sql/logictest/testdata/logic_test/scrub
  74. +1 −1 pkg/sql/logictest/testdata/logic_test/select
  75. +1 −1 pkg/sql/logictest/testdata/logic_test/select_index
  76. +1 −1 pkg/sql/logictest/testdata/logic_test/select_index_flags
  77. +1 −1 pkg/sql/logictest/testdata/logic_test/select_index_span_ranges
  78. +2 −2 pkg/sql/logictest/testdata/logic_test/sequences
  79. +1 −1 pkg/sql/logictest/testdata/logic_test/serial
  80. +1 −1 pkg/sql/logictest/testdata/logic_test/serializable_eager_restart
  81. +1 −1 pkg/sql/logictest/testdata/logic_test/shift
  82. +1 −1 pkg/sql/logictest/testdata/logic_test/show_fingerprints
  83. +1 −1 pkg/sql/logictest/testdata/logic_test/srfs
  84. +1 −1 pkg/sql/logictest/testdata/logic_test/statement_source
  85. +1 −1 pkg/sql/logictest/testdata/logic_test/storing
  86. +1 −1 pkg/sql/logictest/testdata/logic_test/suboperators
  87. +1 −1 pkg/sql/logictest/testdata/logic_test/subquery
  88. +1 −1 pkg/sql/logictest/testdata/logic_test/system
  89. +1 −1 pkg/sql/logictest/testdata/logic_test/table
  90. +1 −1 pkg/sql/logictest/testdata/logic_test/time
  91. +1 −1 pkg/sql/logictest/testdata/logic_test/timestamp
  92. +1 −1 pkg/sql/logictest/testdata/logic_test/truncate
  93. +1 −1 pkg/sql/logictest/testdata/logic_test/tuple
  94. +1 −1 pkg/sql/logictest/testdata/logic_test/txn
  95. +1 −1 pkg/sql/logictest/testdata/logic_test/update
  96. +1 −1 pkg/sql/logictest/testdata/logic_test/upsert
  97. +1 −1 pkg/sql/logictest/testdata/logic_test/uuid
  98. +1 −1 pkg/sql/logictest/testdata/logic_test/views
  99. +1 −1 pkg/sql/logictest/testdata/logic_test/where
  100. +1 −1 pkg/sql/logictest/testdata/logic_test/window
  101. +1 −1 pkg/sql/logictest/testdata/logic_test/with
  102. +1 −1 pkg/sql/logictest/testdata/logic_test/zero
  103. +0 −363 pkg/sql/parallel_stmts.go
  104. +0 −539 pkg/sql/parallel_stmts_test.go
  105. +1 −1 pkg/sql/pgwire/pgerror/internal_errors.go
  106. +0 −17 pkg/sql/plan.go
  107. +0 −225 pkg/sql/plan_spans.go
  108. +0 −13 pkg/sql/row/fk_existence_delete.go
  109. +0 −13 pkg/sql/row/fk_existence_insert.go
  110. +0 −23 pkg/sql/row/fk_existence_update.go
  111. +0 −50 pkg/sql/row/fk_spans.go
  112. +0 −9 pkg/sql/row/inserter.go
  113. +1 −98 pkg/sql/run_control_test.go
  114. +2 −32 pkg/sql/sem/tree/stmt.go
  115. +0 −5 pkg/sql/sqlbase/errors.go
  116. +0 −3 pkg/sql/tablewriter.go
  117. +0 −4 pkg/sql/tablewriter_delete.go
  118. +0 −5 pkg/sql/tablewriter_insert.go
  119. +0 −5 pkg/sql/tablewriter_update.go
  120. +0 −5 pkg/sql/tablewriter_upsert.go
  121. +1 −1 pkg/sql/trace_test.go
  122. +0 −153 pkg/sql/txn_restart_test.go
  123. +2 −30 pkg/sql/values.go
  124. +1 −1 pkg/storage/replica_gc_queue.go
  125. +4 −4 pkg/testutils/lint/lint_test.go
  126. +0 −2 pkg/workload/ledger/ledger.go
  127. +8 −15 pkg/workload/ledger/ops_util.go
@@ -19,7 +19,6 @@ import (
"fmt"
"io"
"math"
"sort"
"strings"
"sync/atomic"
"time"
@@ -521,9 +520,8 @@ func (s *Server) newConnExecutor(
tracer: s.cfg.AmbientCtx.Tracer,
settings: s.cfg.Settings,
},
parallelizeQueue: MakeParallelizeQueue(NewSpanBasedDependencyAnalyzer()),
memMetrics: memMetrics,
planner: planner{execCfg: s.cfg},
memMetrics: memMetrics,
planner: planner{execCfg: s.cfg},

// ctxHolder will be reset at the start of run(). We only define
// it here so that an early call to close() doesn't panic.
@@ -728,21 +726,6 @@ func (ex *connExecutor) closeWrapper(ctx context.Context, recovered interface{})
func (ex *connExecutor) close(ctx context.Context, closeType closeType) {
ex.sessionEventf(ctx, "finishing connExecutor")

// Make sure that no statements remain in the ParallelizeQueue. If no statements
// are in the queue, this will be a no-op. If there are statements in the
// queue, they would have eventually drained on their own, but if we don't
// wait here, we risk alarming the MemoryMonitor. We ignore the error because
// it will only ever be non-nil if there are statements in the queue, meaning
// that the Session was abandoned in the middle of a transaction, in which
// case the error doesn't matter.
//
// TODO(nvanbenschoten): Once we have better support for canceling ongoing
// statement execution by the infrastructure added to support CancelRequest,
// we should try to actively drain this queue instead of passively waiting
// for it to drain. (andrei, 2017/09) - We now have support for statement
// cancellation. Now what?
_ = ex.synchronizeParallelStmts(ctx)

if closeType == normalClose {
// We'll cleanup the SQL txn by creating a non-retriable (commit:true) event.
// This event is guaranteed to be accepted in every state.
@@ -920,10 +903,6 @@ type connExecutor struct {
// to each planner in session.newPlanner.
phaseTimes phaseTimes

// parallelizeQueue is a queue managing all parallelized SQL statements
// running on this connection.
parallelizeQueue ParallelizeQueue

// mu contains of all elements of the struct that can be changed
// after initialization, and may be accessed from another thread.
mu struct {
@@ -1720,65 +1699,6 @@ func (ex *connExecutor) makeErrEvent(err error, stmt tree.Statement) (fsm.Event,
return ev, payload
}

// synchronizeParallelStmts waits for all statements in the parallelizeQueue to
// finish. If errors are seen in the parallel batch, we attempt to turn these
// errors into a single error we can send to the client. We do this by prioritizing
// non-retryable errors over retryable errors.
// Note that the returned error is to always be considered a "query execution
// error". This means that it should never interrupt the connection.
func (ex *connExecutor) synchronizeParallelStmts(ctx context.Context) error {
if errs := ex.parallelizeQueue.Wait(); len(errs) > 0 {
ex.state.mu.Lock()
defer ex.state.mu.Unlock()

// Sort the errors according to their importance.
curTxnID := ex.state.mu.txn.ID()
curTxnEpoch := ex.state.mu.txn.Epoch()
sort.Slice(errs, func(i, j int) bool {
errPriority := func(err error) int {
switch t := err.(type) {
case *roachpb.TransactionRetryWithProtoRefreshError:
errTxn := t.Transaction
if errTxn.ID == curTxnID && errTxn.Epoch == curTxnEpoch {
// A retryable error for the current transaction
// incarnation is given the highest priority.
return 1
}
return 2
case *roachpb.TxnAlreadyEncounteredErrorError:
// Another parallel stmt got an error that caused this one.
return 5
default:
// Any other error. We sort these behind retryable errors
// and errors we know to be their symptoms because it is
// impossible to conclusively determine in all cases whether
// one of these errors is a symptom of a concurrent retry or
// not. If the error is a symptom then we want to ignore it.
// If it is not, we expect to see the same error during a
// transaction retry.
return 4
}
}
return errPriority(errs[i]) < errPriority(errs[j])
})

// Return the "best" error.
bestErr := errs[0]
switch bestErr.(type) {
case *roachpb.TransactionRetryWithProtoRefreshError:
// If any of the errors are retryable, we need to bump the transaction
// epoch to invalidate any writes performed by any workers after the
// retry updated the txn's proto but before we synchronized (some of
// these writes might have been performed at the wrong epoch). Note
// that we don't need to lock the client.Txn because we're synchronized.
// See #17197.
ex.state.mu.txn.ManualRestart(ctx, hlc.Timestamp{})
}
return bestErr
}
return nil
}

// setTransactionModes implements the txnModesSetter interface.
func (ex *connExecutor) setTransactionModes(
modes tree.TransactionModes, asOfTs hlc.Timestamp,
@@ -1929,20 +1849,6 @@ func (ex *connExecutor) implicitTxn() bool {
return ok && os.ImplicitTxn.Get()
}

// newPlanner creates a planner inside the scope of the given Session. The
// statement executed by the planner will be executed in txn. The planner
// should only be used to execute one statement.
//
// txn can be nil.
func (ex *connExecutor) newPlanner(
ctx context.Context, txn *client.Txn, stmtTS time.Time,
) *planner {
p := &planner{execCfg: ex.server.cfg}
ex.initPlanner(ctx, p)
ex.resetPlanner(ctx, p, txn, stmtTS)
return p
}

// initPlanner initializes a planner so it can can be used for planning a
// query in the context of this session.
func (ex *connExecutor) initPlanner(ctx context.Context, p *planner) {

0 comments on commit aa799d3

Please sign in to comment.
You can’t perform that action at this time.