Skip to content

Commit

Permalink
Merge #33524
Browse files Browse the repository at this point in the history
33524: opt: Add support for DELETE operator r=andy-kimball a=andy-kimball

This commit adds support for the DELETE operator to the cost-based
optimizer. The DELETE operator is similar to the UPDATE operator. It
fetches existing values from the deletion table using the clauses
specified in the DELETE statement:

  CREATE TABLE abc (a INT PRIMARY KEY, b INT, c INT)
  DELETE FROM abc WHERE b=10

Then an input expression equivalent to this would be built:

  SELECT a, b, c
  FROM abc
  WHERE b=10

At runtime, the Delete execution operator will iterate over each input
row and use its key to delete each row in turn.


Co-authored-by: Andrew Kimball <[email protected]>
  • Loading branch information
craig[bot] and andy-kimball committed Jan 8, 2019
2 parents 9b8b3c5 + 78b6068 commit 3822d51
Show file tree
Hide file tree
Showing 38 changed files with 2,348 additions and 610 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<tr><td><code>sql.defaults.default_int_size</code></td><td>integer</td><td><code>8</code></td><td>the size, in bytes, of an INT type</td></tr>
<tr><td><code>sql.defaults.distsql</code></td><td>enumeration</td><td><code>1</code></td><td>default distributed SQL execution mode [off = 0, auto = 1, on = 2, 2.0-off = 3, 2.0-auto = 4]</td></tr>
<tr><td><code>sql.defaults.experimental_automatic_statistics</code></td><td>boolean</td><td><code>false</code></td><td>default experimental automatic statistics mode</td></tr>
<tr><td><code>sql.defaults.experimental_optimizer_updates</code></td><td>boolean</td><td><code>false</code></td><td>default experimental_optimizer_updates mode</td></tr>
<tr><td><code>sql.defaults.experimental_optimizer_mutations</code></td><td>boolean</td><td><code>false</code></td><td>default experimental_optimizer_mutations mode</td></tr>
<tr><td><code>sql.defaults.experimental_vectorize</code></td><td>enumeration</td><td><code>0</code></td><td>default experimental_vectorize mode [off = 0, on = 1, always = 2]</td></tr>
<tr><td><code>sql.defaults.optimizer</code></td><td>enumeration</td><td><code>1</code></td><td>default cost-based optimizer mode [off = 0, on = 1, local = 2]</td></tr>
<tr><td><code>sql.defaults.results_buffer.size</code></td><td>byte size</td><td><code>16 KiB</code></td><td>size of the buffer that accumulates results for a statement or a batch of statements before they are sent to the client. Note that auto-retries generally only happen while no results have been delivered to the client, so reducing this size can increase the number of retriable errors a client receives. On the other hand, increasing the buffer size can increase the delay until the client receives the first result row. Updating the setting only affects new connections. Setting to 0 disables any buffering.</td></tr>
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ var OptimizerClusterMode = settings.RegisterEnumSetting(
},
)

// OptimizerUpdatesClusterMode controls the cluster default for when the cost-
// based optimizer is planning UPDATE statements.
var OptimizerUpdatesClusterMode = settings.RegisterBoolSetting(
"sql.defaults.experimental_optimizer_updates",
"default experimental_optimizer_updates mode",
// OptimizerMutationsClusterMode controls the cluster default for when the cost-
// based optimizer is planning mutation statements.
var OptimizerMutationsClusterMode = settings.RegisterBoolSetting(
"sql.defaults.experimental_optimizer_mutations",
"default experimental_optimizer_mutations mode",
false,
)

Expand Down Expand Up @@ -1690,8 +1690,8 @@ func (m *sessionDataMutator) SetOptimizerMode(val sessiondata.OptimizerMode) {
m.data.OptimizerMode = val
}

func (m *sessionDataMutator) SetOptimizerUpdates(val bool) {
m.data.OptimizerUpdates = val
func (m *sessionDataMutator) SetOptimizerMutations(val bool) {
m.data.OptimizerMutations = val
}

func (m *sessionDataMutator) SetSerialNormalizationMode(val sessiondata.SerialNormalizationMode) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,9 @@ func (t *logicTest) setUser(user string) func() {
t.Fatal(err)
}

// Use the cost-based-optimizer for planning UPDATE statements.
// Use the cost-based-optimizer for planning mutation statements.
if optMode == "on" {
if _, err := db.Exec("SET experimental_optimizer_updates = true"); err != nil {
if _, err := db.Exec("SET experimental_optimizer_mutations = true"); err != nil {
t.Fatal(err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/delete
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ statement ok
INSERT INTO unindexed VALUES (1, 9), (8, 2), (3, 7), (6, 4)

query II
DELETE FROM unindexed WHERE k > 1 AND v < 7 ORDER BY v DESC RETURNING v,k
DELETE FROM unindexed WHERE k > 1 AND v < 7 ORDER BY v DESC LIMIT 2 RETURNING v,k
----
4 6
2 8

query II
DELETE FROM unindexed ORDER BY v RETURNING k,v
DELETE FROM unindexed ORDER BY v LIMIT 2 RETURNING k,v
----
3 7
1 9
Expand Down
Loading

0 comments on commit 3822d51

Please sign in to comment.