Skip to content

Commit 642081f

Browse files
craig[bot]alectric-trjeffswenson
committed
142572: sql: syntactic for support SET LOGGED, SET UNLOGGED r=rafiss a=xelathan Fixes: #109951 Jira issue: [CRDB-31177](https://cockroachlabs.atlassian.net/browse/CRDB-31177) This PR only adds syntactic support for setting logged and unlogged tables. SET LOGGED/UNLOGGED syntax will be a no-op. 144646: bulk: disable async flush code path r=jeffswenson a=jeffswenson his PR disables the async flush path in the SST batcher due to a correctness bug. When a flush crosses a range boundary, it triggers an async goroutine to handle the RPC. Previously, any error from this goroutine would propagate through the top-level Flush call. However, PR #110218 modified Reset to wait for all async tasks to complete. This change assumed Reset was only used in cleanup, but it is also called by flushIfNeeded after each doFlush. As a result, any error is consumed and silently dropped before Flush is invoked. Disabling async flush won't impact performance because Reset already waits for the async flush, making every flush effectively synchronous. Informs: #143690 Informs: #144650 Release note: Fix rare corruption bug that impacts import and materialized views. Co-authored-by: xelathan <[email protected]> Co-authored-by: Jeff Swenson <[email protected]>
3 parents 5d71bf5 + b614b04 + 27942e9 commit 642081f

File tree

15 files changed

+143
-2
lines changed

15 files changed

+143
-2
lines changed

docs/generated/sql/bnf/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ FILES = [
5757
"alter_table",
5858
"alter_table_cmds",
5959
"alter_table_locality_stmt",
60+
"alter_table_logged_stmt",
6061
"alter_table_owner_stmt",
6162
"alter_table_partition_by",
6263
"alter_table_reset_storage_param",

docs/generated/sql/bnf/alter_table.bnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ alter_table_stmt ::=
1414
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'SET' 'SCHEMA' schema_name
1515
| 'ALTER' 'TABLE' table_name 'SET' locality
1616
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'SET' locality
17+
| alter_table_logged_stmt
1718
| 'ALTER' 'TABLE' table_name 'OWNER' 'TO' role_spec
1819
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'OWNER' 'TO' role_spec
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
alter_table_logged_stmt ::=
2+
'ALTER' 'TABLE' relation_expr 'SET' 'LOGGED'
3+
| 'ALTER' 'TABLE' 'IF' 'EXISTS' relation_expr 'SET' 'LOGGED'
4+
| 'ALTER' 'TABLE' relation_expr 'SET' 'UNLOGGED'
5+
| 'ALTER' 'TABLE' 'IF' 'EXISTS' relation_expr 'SET' 'UNLOGGED'

docs/generated/sql/bnf/stmt_block.bnf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ unreserved_keyword ::=
12821282
| 'LOGICALLY'
12831283
| 'LOGIN'
12841284
| 'LOCALITY'
1285+
| 'LOGGED'
12851286
| 'LOOKUP'
12861287
| 'LOW'
12871288
| 'MATCH'
@@ -1702,6 +1703,7 @@ alter_table_stmt ::=
17021703
| alter_rename_table_stmt
17031704
| alter_table_set_schema_stmt
17041705
| alter_table_locality_stmt
1706+
| alter_table_logged_stmt
17051707
| alter_table_owner_stmt
17061708

17071709
alter_index_stmt ::=
@@ -2274,6 +2276,12 @@ alter_table_locality_stmt ::=
22742276
'ALTER' 'TABLE' relation_expr 'SET' locality
22752277
| 'ALTER' 'TABLE' 'IF' 'EXISTS' relation_expr 'SET' locality
22762278

2279+
alter_table_logged_stmt ::=
2280+
'ALTER' 'TABLE' relation_expr 'SET' 'LOGGED'
2281+
| 'ALTER' 'TABLE' 'IF' 'EXISTS' relation_expr 'SET' 'LOGGED'
2282+
| 'ALTER' 'TABLE' relation_expr 'SET' 'UNLOGGED'
2283+
| 'ALTER' 'TABLE' 'IF' 'EXISTS' relation_expr 'SET' 'UNLOGGED'
2284+
22772285
alter_table_owner_stmt ::=
22782286
'ALTER' 'TABLE' relation_expr 'OWNER' 'TO' role_spec
22792287
| 'ALTER' 'TABLE' 'IF' 'EXISTS' relation_expr 'OWNER' 'TO' role_spec
@@ -4088,6 +4096,7 @@ bare_label_keywords ::=
40884096
| 'LOCALTIME'
40894097
| 'LOCALTIMESTAMP'
40904098
| 'LOCKED'
4099+
| 'LOGGED'
40914100
| 'LOGICAL'
40924101
| 'LOGICALLY'
40934102
| 'LOGIN'

pkg/gen/bnf.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ BNF_SRCS = [
5757
"//docs/generated/sql/bnf:alter_table.bnf",
5858
"//docs/generated/sql/bnf:alter_table_cmds.bnf",
5959
"//docs/generated/sql/bnf:alter_table_locality_stmt.bnf",
60+
"//docs/generated/sql/bnf:alter_table_logged_stmt.bnf",
6061
"//docs/generated/sql/bnf:alter_table_owner_stmt.bnf",
6162
"//docs/generated/sql/bnf:alter_table_partition_by.bnf",
6263
"//docs/generated/sql/bnf:alter_table_reset_storage_param.bnf",

pkg/gen/diagrams.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ DIAGRAMS_SRCS = [
5757
"//docs/generated/sql/bnf:alter_table.html",
5858
"//docs/generated/sql/bnf:alter_table_cmds.html",
5959
"//docs/generated/sql/bnf:alter_table_locality.html",
60+
"//docs/generated/sql/bnf:alter_table_logged.html",
6061
"//docs/generated/sql/bnf:alter_table_owner.html",
6162
"//docs/generated/sql/bnf:alter_table_partition_by.html",
6263
"//docs/generated/sql/bnf:alter_table_reset_storage_param.html",

pkg/gen/docs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ DOCS_SRCS = [
6767
"//docs/generated/sql/bnf:alter_table.bnf",
6868
"//docs/generated/sql/bnf:alter_table_cmds.bnf",
6969
"//docs/generated/sql/bnf:alter_table_locality_stmt.bnf",
70+
"//docs/generated/sql/bnf:alter_table_logged_stmt.bnf",
7071
"//docs/generated/sql/bnf:alter_table_owner_stmt.bnf",
7172
"//docs/generated/sql/bnf:alter_table_partition_by.bnf",
7273
"//docs/generated/sql/bnf:alter_table_reset_storage_param.bnf",

pkg/kv/bulk/sst_batcher.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,17 @@ func (b *SSTBatcher) doFlush(ctx context.Context, reason int) error {
692692
// the next one; if memory is not available we'll just block on the send
693693
// and then move on to the next send after this SST is no longer being held
694694
// in memory.
695-
flushAsync := reason == rangeFlush
695+
//
696+
// TODO(jeffswenson): re-enable flush async after fixing performance and
697+
// correctness issues.
698+
//
699+
// CORRECTNESS: Something has to surface the error from the async flush to
700+
// the caller. Right now the error is logged by `Reset`.
701+
// PERFORMANCE: The only caller that sets `rangeFlush` calls Reset immediatly
702+
// after, which blocks on all in flight requests. So there is no performance
703+
// benefit to the async flush.
704+
//flushAsync := reason == rangeFlush
705+
flushAsync := false
696706

697707
var reserved int64
698708
if flushAsync {

pkg/sql/importer/read_import_pgdump.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,9 @@ func readPostgresStmt(
757757
return unsupportedStmtLogger.log(stmt.String(), false /* isParseError */)
758758
}
759759
return wrapErrorWithUnsupportedHint(errors.Errorf("unsupported statement: %s", stmt))
760+
case *tree.AlterTableSetLogged:
761+
// No-op: CockroachDB does not support unlogged tables, tables are logged by default
762+
return nil
760763
case *tree.CreateSequence:
761764
schemaQualifiedTableName, err := getSchemaAndTableName(&stmt.Name)
762765
if err != nil {

pkg/sql/opaque.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ func planOpaque(ctx context.Context, p *planner, stmt tree.Statement) (planNode,
126126
return p.AlterTableLocality(ctx, n)
127127
case *tree.AlterTableOwner:
128128
return p.AlterTableOwner(ctx, n)
129+
case *tree.AlterTableSetLogged:
130+
return p.AlterTableSetLogged(ctx, n)
129131
case *tree.AlterTableSetSchema:
130132
return p.AlterTableSetSchema(ctx, n)
131133
case *tree.AlterTenantCapability:
@@ -346,6 +348,7 @@ func init() {
346348
&tree.AlterTable{},
347349
&tree.AlterTableLocality{},
348350
&tree.AlterTableOwner{},
351+
&tree.AlterTableSetLogged{},
349352
&tree.AlterTableSetSchema{},
350353
&tree.AlterTenantCapability{},
351354
&tree.AlterTenantRename{},

0 commit comments

Comments
 (0)