Skip to content

Commit b614b04

Browse files
alectric-trrafiss
authored andcommitted
Added syntactic support for ALTER TABLE ... SET {LOGGED | UNLOGGED}
Release note: None
1 parent 2c6916a commit b614b04

File tree

14 files changed

+132
-1
lines changed

14 files changed

+132
-1
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/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{},

pkg/sql/parser/sql.y

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ func (u *sqlSymUnion) doBlockOption() tree.DoBlockOption {
10251025
%token <str> LABEL LANGUAGE LAST LATERAL LATEST LC_CTYPE LC_COLLATE
10261026
%token <str> LEADING LEASE LEAST LEAKPROOF LEFT LESS LEVEL LIKE LIMIT
10271027
%token <str> LINESTRING LINESTRINGM LINESTRINGZ LINESTRINGZM
1028-
%token <str> LIST LOCAL LOCALITY LOCALTIME LOCALTIMESTAMP LOCKED LOGICAL LOGICALLY LOGIN LOOKUP LOW LSHIFT
1028+
%token <str> LIST LOCAL LOCALITY LOCALTIME LOCALTIMESTAMP LOCKED LOGGED LOGICAL LOGICALLY LOGIN LOOKUP LOW LSHIFT
10291029

10301030
%token <str> MATCH MATERIALIZED MERGE MINVALUE MAXVALUE METHOD MINUTE MODIFYCLUSTERSETTING MODIFYSQLCLUSTERSETTING MODE MONTH MOVE
10311031
%token <str> MULTILINESTRING MULTILINESTRINGM MULTILINESTRINGZ MULTILINESTRINGZM
@@ -1150,6 +1150,7 @@ func (u *sqlSymUnion) doBlockOption() tree.DoBlockOption {
11501150
%type <tree.Statement> alter_zone_table_stmt
11511151
%type <tree.Statement> alter_table_set_schema_stmt
11521152
%type <tree.Statement> alter_table_locality_stmt
1153+
%type <tree.Statement> alter_table_logged_stmt
11531154
%type <tree.Statement> alter_table_owner_stmt
11541155

11551156
// ALTER VIRTUAL CLUSTER
@@ -2012,6 +2013,7 @@ alter_table_stmt:
20122013
| alter_rename_table_stmt
20132014
| alter_table_set_schema_stmt
20142015
| alter_table_locality_stmt
2016+
| alter_table_logged_stmt
20152017
| alter_table_owner_stmt
20162018
// ALTER TABLE has its error help token here because the ALTER TABLE
20172019
// prefix is spread over multiple non-terminals.
@@ -12646,6 +12648,40 @@ locality:
1264612648
}
1264712649
}
1264812650

12651+
alter_table_logged_stmt:
12652+
ALTER TABLE relation_expr SET LOGGED
12653+
{
12654+
$$.val = &tree.AlterTableSetLogged{
12655+
Name: $3.unresolvedObjectName(),
12656+
IsLogged: true,
12657+
IfExists: false,
12658+
}
12659+
}
12660+
| ALTER TABLE IF EXISTS relation_expr SET LOGGED
12661+
{
12662+
$$.val = &tree.AlterTableSetLogged{
12663+
Name: $5.unresolvedObjectName(),
12664+
IsLogged: true,
12665+
IfExists: true,
12666+
}
12667+
}
12668+
| ALTER TABLE relation_expr SET UNLOGGED
12669+
{
12670+
$$.val = &tree.AlterTableSetLogged{
12671+
Name: $3.unresolvedObjectName(),
12672+
IsLogged: false,
12673+
IfExists: false,
12674+
}
12675+
}
12676+
| ALTER TABLE IF EXISTS relation_expr SET UNLOGGED
12677+
{
12678+
$$.val = &tree.AlterTableSetLogged{
12679+
Name: $5.unresolvedObjectName(),
12680+
IsLogged: false,
12681+
IfExists: true,
12682+
}
12683+
}
12684+
1264912685
alter_table_owner_stmt:
1265012686
ALTER TABLE relation_expr OWNER TO role_spec
1265112687
{
@@ -18301,6 +18337,7 @@ unreserved_keyword:
1830118337
| LOGICALLY
1830218338
| LOGIN
1830318339
| LOCALITY
18340+
| LOGGED
1830418341
| LOOKUP
1830518342
| LOW
1830618343
| MATCH
@@ -18869,6 +18906,7 @@ bare_label_keywords:
1886918906
| LOCALTIME
1887018907
| LOCALTIMESTAMP
1887118908
| LOCKED
18909+
| LOGGED
1887218910
| LOGICAL
1887318911
| LOGICALLY
1887418912
| LOGIN

0 commit comments

Comments
 (0)