Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: Prune Update and Upsert input columns #34522

Merged
merged 4 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<tr><td><code>server.web_session_timeout</code></td><td>duration</td><td><code>168h0m0s</code></td><td>the duration that a newly created web session will be valid</td></tr>
<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]</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>default size of the buffer that accumulates results for a statement or a batch of statements before they are sent to the client. This can be overridden on an individual connection with the 'results_buffer_size' parameter. 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
2 changes: 1 addition & 1 deletion pkg/server/updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,13 @@ func TestReportUsage(t *testing.T) {
`[false,false,false] SET application_name = $1`,
`[false,false,false] SET application_name = DEFAULT`,
`[false,false,false] SET application_name = _`,
`[false,false,false] UPDATE _ SET _ = _ + _`,
`[true,false,false] CREATE TABLE _ (_ INT8, CONSTRAINT _ CHECK (_ > _))`,
`[true,false,false] INSERT INTO _ SELECT unnest(ARRAY[_, _, __more2__])`,
`[true,false,false] INSERT INTO _ VALUES (_), (__more2__)`,
`[true,false,false] INSERT INTO _ VALUES (length($1::STRING)), (__more1__)`,
`[true,false,false] INSERT INTO _(_, _) VALUES (_, _)`,
`[true,false,false] SELECT (_, _, __more2__) = (SELECT _, _, _, _ FROM _ LIMIT _)`,
`[true,false,false] UPDATE _ SET _ = _ + _`,
`[true,false,true] CREATE TABLE _ (_ INT8 PRIMARY KEY, _ INT8, INDEX (_) INTERLEAVE IN PARENT _ (_))`,
`[true,false,true] SELECT _ / $1`,
`[true,false,true] SELECT _ / _`,
Expand Down
7 changes: 3 additions & 4 deletions pkg/sql/descriptor_mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,9 @@ CREATE INDEX allidx ON t.test (k, v);
// The default value of "i" for column "i" is written.
afterInsert = [][]string{{"a", "z", "q"}, {"c", "x", "i"}}
if useUpsert {
// Update is not a noop for column "i". Column "i" gets updated
// with its default value (#9474).
afterUpdate = [][]string{{"a", "u", "i"}, {"c", "x", "i"}}
afterPKUpdate = [][]string{{"a", "u", "i"}, {"d", "x", "i"}}
// Update is not a noop for column "i".
afterUpdate = [][]string{{"a", "u", "q"}, {"c", "x", "i"}}
afterPKUpdate = [][]string{{"a", "u", "q"}, {"d", "x", "i"}}
} else {
// Update is a noop for column "i".
afterUpdate = [][]string{{"a", "u", "q"}, {"c", "x", "i"}}
Expand Down
12 changes: 0 additions & 12 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ var OptimizerClusterMode = settings.RegisterEnumSetting(
},
)

// 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,
)

// VectorizeClusterMode controls the cluster default for when automatic
// vectorization is enabled.
var VectorizeClusterMode = settings.RegisterEnumSetting(
Expand Down Expand Up @@ -1676,10 +1668,6 @@ func (m *sessionDataMutator) SetOptimizerMode(val sessiondata.OptimizerMode) {
m.data.OptimizerMode = val
}

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

func (m *sessionDataMutator) SetSerialNormalizationMode(val sessiondata.SerialNormalizationMode) {
m.data.SerialNormalizationMode = val
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,13 +933,6 @@ func (t *logicTest) setUser(user string) func() {
if _, err := db.Exec(fmt.Sprintf("SET OPTIMIZER = %s;", optMode)); err != nil {
t.Fatal(err)
}

// Use the cost-based-optimizer for planning mutation statements.
if optMode == "on" {
if _, err := db.Exec("SET experimental_optimizer_mutations = true"); err != nil {
t.Fatal(err)
}
}
}
// The default value for extra_float_digits assumed by tests is
// 0. However, lib/pq by default configures this to 2 during
Expand Down
13 changes: 0 additions & 13 deletions pkg/sql/logictest/testdata/logic_test/optimizer
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,3 @@ SELECT * FROM test.t
2 20
3 30
4 40

# Test the experimental_optimizer_mutations flag.
statement ok
SET experimental_optimizer_mutations = false

statement error pq: no data source matches prefix: t
UPDATE t SET v=(SELECT v+1 FROM t AS t2 WHERE t2.k=t.k)

statement ok
SET experimental_optimizer_mutations = true

statement ok
UPDATE t SET v=(SELECT v+1 FROM t AS t2 WHERE t2.k=t.k)
5 changes: 2 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ SELECT
FROM
pg_catalog.pg_settings
WHERE
name != 'optimizer' AND name != 'crdb_version' AND name != 'experimental_optimizer_mutations'
name != 'optimizer' AND name != 'crdb_version'
----
name setting category short_desc extra_desc vartype
application_name · NULL NULL NULL string
Expand Down Expand Up @@ -1372,7 +1372,7 @@ SELECT
FROM
pg_catalog.pg_settings
WHERE
name != 'optimizer' AND name != 'crdb_version' AND name != 'experimental_optimizer_mutations'
name != 'optimizer' AND name != 'crdb_version'
----
name setting unit context enumvals boot_val reset_val
application_name · NULL user NULL · ·
Expand Down Expand Up @@ -1429,7 +1429,6 @@ default_transaction_read_only NULL NULL NULL NULL NULL
distsql NULL NULL NULL NULL NULL
experimental_enable_zigzag_join NULL NULL NULL NULL NULL
experimental_force_split_at NULL NULL NULL NULL NULL
experimental_optimizer_mutations NULL NULL NULL NULL NULL
experimental_reorder_joins_limit NULL NULL NULL NULL NULL
experimental_serial_normalization NULL NULL NULL NULL NULL
experimental_vectorize NULL NULL NULL NULL NULL
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ UTF8 1
query TT colnames
SELECT *
FROM [SHOW ALL]
WHERE variable != 'optimizer' AND variable != 'crdb_version' AND variable != 'experimental_optimizer_mutations'
WHERE variable != 'optimizer' AND variable != 'crdb_version'
----
variable value
application_name ·
Expand Down
106 changes: 102 additions & 4 deletions pkg/sql/logictest/testdata/logic_test/upsert
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ statement count 0
INSERT INTO ex(foo,bar,baz) VALUES (2,1,1) ON CONFLICT DO NOTHING

# Do not insert conflicting first and last rows.
# TODO(knz): Enable the 1st statement and remove the 2nd once #33313 is fixed.
#statement count 2
#INSERT INTO ex(foo,bar,baz) VALUES (1,2,1), (3,2,2), (6,6,2), (2,1,1) ON CONFLICT DO NOTHING
statement count 2
INSERT INTO ex(foo,bar,baz) VALUES (3,2,2), (6,6,2), (2,1,1) ON CONFLICT DO NOTHING
INSERT INTO ex(foo,bar,baz) VALUES (1,2,1), (3,2,2), (6,6,2), (2,1,1) ON CONFLICT DO NOTHING

query III colnames
SELECT * from ex ORDER BY foo
Expand Down Expand Up @@ -753,3 +750,104 @@ SELECT * FROM ex33313 ORDER BY foo
foo bar baz
1 1 1
3 2 2

# Use Upsert with indexed table, default columns, computed columns, and check
# columns.
statement ok
CREATE TABLE indexed (
a DECIMAL PRIMARY KEY,
b DECIMAL,
c DECIMAL DEFAULT(10.0),
d DECIMAL AS (a + c) STORED,
UNIQUE INDEX secondary (d, b),
CHECK (c > 0)
)

statement ok
INSERT INTO indexed VALUES (1, 1, 1); INSERT INTO indexed VALUES (2, 2, 2)

# Use implicit target columns (should set default and computed values).
statement ok
UPSERT INTO indexed VALUES (1.0)

query TTTT colnames
SELECT * FROM indexed@secondary ORDER BY d, b
----
a b c d
2 2 2 4
1 NULL 10.0 11.0

# Explicitly specify all target columns. Ensure that primary key is not updated,
# even though an alternate but equal decimal form is in use (1.0 vs. 1).
statement ok
UPSERT INTO indexed (a, b, c) VALUES (1.0, 1.0, 1.0)

query TTTT colnames
SELECT * FROM indexed@secondary ORDER BY d, b
----
a b c d
1 1.0 1.0 2.0
2 2 2 4

# Ensure that explicit target column does not disturb existing "b" value, but
# does update the computed column.
statement ok
UPSERT INTO indexed (c, a) VALUES (2, 1)

query TTTT colnames
SELECT * FROM indexed@secondary ORDER BY d, b
----
a b c d
1 1.0 2 3
2 2 2 4

# Final check to ensure that primary index is correct.
query TTTT colnames
SELECT * FROM indexed@primary ORDER BY a
----
a b c d
1 1.0 2 3
2 2 2 4

# Drop the secondary index, allowing the "blind upsert" path to run.
statement ok
DROP INDEX indexed@secondary CASCADE

# Use implicit target columns (should set default and computed values).
statement ok
UPSERT INTO indexed VALUES (1, 1)

query TTTT colnames,rowsort
SELECT * FROM indexed
----
a b c d
1 1 10.0 11.0
2 2 2 4

# Explicitly specify all target columns.
statement ok
UPSERT INTO indexed (a, b, c) SELECT 1, 2, 3

query TTTT colnames,rowsort
SELECT * FROM indexed
----
a b c d
2 2 2 4
1 2 3 4

# Ensure that explicit target column does not disturb existing "b" value, but
# does update the computed column.
query TTTT
UPSERT INTO indexed (c, a) VALUES (2.0, 1.0) RETURNING *
----
1 2 2.0 3.0

query TTTT colnames,rowsort
SELECT * FROM indexed
----
a b c d
1 2 2.0 3.0
2 2 2 4

statement ok
DROP TABLE indexed
10 changes: 5 additions & 5 deletions pkg/sql/logictest/testdata/planner_test/explain
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ render · ·
└── filter · ·
│ filter variable = 'database'
└── values · ·
· size 3 columns, 41 rows
· size 3 columns, 40 rows

query TTT
EXPLAIN SHOW TIME ZONE
Expand All @@ -204,7 +204,7 @@ render · ·
└── filter · ·
│ filter variable = 'timezone'
└── values · ·
· size 3 columns, 41 rows
· size 3 columns, 40 rows

query TTT
EXPLAIN SHOW DEFAULT_TRANSACTION_ISOLATION
Expand All @@ -213,7 +213,7 @@ render · ·
└── filter · ·
│ filter variable = 'default_transaction_isolation'
└── values · ·
· size 3 columns, 41 rows
· size 3 columns, 40 rows

query TTT
EXPLAIN SHOW TRANSACTION ISOLATION LEVEL
Expand All @@ -222,7 +222,7 @@ render · ·
└── filter · ·
│ filter variable = 'transaction_isolation'
└── values · ·
· size 3 columns, 41 rows
· size 3 columns, 40 rows

query TTT
EXPLAIN SHOW TRANSACTION PRIORITY
Expand All @@ -231,7 +231,7 @@ render · ·
└── filter · ·
│ filter variable = 'transaction_priority'
└── values · ·
· size 3 columns, 41 rows
· size 3 columns, 40 rows

query TTT
EXPLAIN SHOW COLUMNS FROM foo
Expand Down
48 changes: 0 additions & 48 deletions pkg/sql/logictest/testdata/planner_test/upsert
Original file line number Diff line number Diff line change
Expand Up @@ -153,54 +153,6 @@ id a
statement ok
DROP TABLE test_table;

subtest regression_32834

statement ok
CREATE TABLE test_table (
id BIGINT PRIMARY KEY,
a BIGINT,
b BIGINT
);

statement ok
INSERT INTO test_table (id, a) VALUES
(123, 456), (123, 456)
ON CONFLICT (id) DO UPDATE SET a = EXCLUDED.a;

query II colnames
SELECT id, a
FROM test_table
----
id a
123 456

statement ok
INSERT INTO test_table (id, a) VALUES
(123, 1), (123, 2), (123, 1)
ON CONFLICT (id) DO UPDATE SET a = EXCLUDED.a;

query II colnames
SELECT id, a
FROM test_table
----
id a
123 1

statement ok
INSERT INTO test_table (id, a) VALUES
(123, 1), (123, 2), (123, 3)
ON CONFLICT (id) DO UPDATE SET a = EXCLUDED.a;

query II colnames
SELECT id, a
FROM test_table
----
id a
123 3

statement ok
DROP TABLE test_table;

subtest regression_32473

statement ok
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestQueryCounts(t *testing.T) {
{query: "SET OPTIMIZER = 'on'", miscCount: 1},
{query: "SELECT 3", selectCount: 1, optCount: 1},
{query: "CREATE TABLE mt.n (num INTEGER PRIMARY KEY)", ddlCount: 1, optCount: 1},
{query: "UPDATE mt.n SET num = num + 1", updateCount: 1, fallbackCount: 1},
{query: "UPDATE mt.n SET num = num + 1", updateCount: 1, optCount: 1},
{query: "SET OPTIMIZER = 'off'", miscCount: 1, fallbackCount: 1},
}

Expand Down
Loading