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

sql: support ALTER TABLE ... ALTER COLUMN ... {ADD | SET} GENERATED ... #110010

Closed
giangpham712 opened this issue Sep 5, 2023 · 4 comments
Closed
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-tools-efcore C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) X-blathers-triaged blathers was able to find an owner

Comments

@giangpham712
Copy link

giangpham712 commented Sep 5, 2023

Is your feature request related to a problem? Please describe.
support ALTER TABLE ... ALTER COLUMN ... {ADD | SET} GENERATED ...

Describe the solution you'd like
Similar to PostgreSQL

ALTER [ COLUMN ] column_name ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]

ALTER [ COLUMN ] column_name { SET GENERATED { ALWAYS | BY DEFAULT } | SET sequence_option | RESTART [ [ WITH ] restart ] }

Also, the related syntax should be covered:
ALTER TABLE "People" ALTER COLUMN "Id" SET INCREMENT BY 2

https://www.postgresql.org/docs/current/sql-altertable.html

Additional context
This affects efcore.pg tests

@fqazi

Jira issue: CRDB-31217

@giangpham712 giangpham712 added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Sep 5, 2023
@blathers-crl
Copy link

blathers-crl bot commented Sep 5, 2023

Hello, I am Blathers. I am here to help you get the issue triaged.

I have CC'd a few people who may be able to assist you:

  • @cockroachdb/sql-foundations (found keywords: ALTER TABLE)

If we have not gotten back to your issue within a few business days, you can try the following:

  • Join our community slack channel and ask on #cockroachdb.
  • Try find someone from here if you know they worked closely on the area and CC them.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Sep 5, 2023
@giangpham712 giangpham712 changed the title sql: support ALTER TABLE ... ALTER COLUMN ... ADD GENERATED ... sql: support ALTER TABLE ... ALTER COLUMN ... {ADD | SET} GENERATED ... Sep 5, 2023
@fqazi fqazi added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) A-tools-efcore labels Sep 5, 2023
@fqazi
Copy link
Collaborator

fqazi commented Sep 5, 2023

@giangpham712 Let's skip this test for now, and we can definitely add this syntax, but not realistic for 23.1

@rafiss rafiss added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Sep 5, 2023
@andrew-delph
Copy link
Contributor

Working on this.

@andrew-delph
Copy link
Contributor

It seems there are some other commands that can be included such as "DROP IDENTITY"

andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Dec 8, 2023
Part of: cockroachdb#110010

This change adds a new command, 'ALTER TABLE t
ALTER COLUMN c SET GENERATED ALWAYS' and 'ALTER
TABLE t ALTER COLUMN c SET GENERATED BY DEFAULT',
which changes the 'GeneratedAsIdentityType' of
that column's definition, respectively.

Release note (sql change): Identity columns can
have their IdentityType altered by running 'ALTER
TABLE t ALTER COLUMN c SET GENERATED ALWAYS' or
'ALTER TABLE t ALTER COLUMN c SET GENERATED BY DEFAULT'.
andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Dec 12, 2023
Part of: cockroachdb#110010

This change adds a new command, 'ALTER TABLE t
ALTER COLUMN c SET GENERATED ALWAYS' and 'ALTER
TABLE t ALTER COLUMN c SET GENERATED BY DEFAULT',
which changes the 'GeneratedAsIdentityType' of
that column's definition, respectively.

Release note (sql change): Identity columns can
have their IdentityType altered by running 'ALTER
TABLE t ALTER COLUMN c SET GENERATED ALWAYS' or
'ALTER TABLE t ALTER COLUMN c SET GENERATED BY DEFAULT'.
andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Dec 23, 2023
Part of: cockroachdb#110010

This change adds a new command, 'ALTER TABLE t
ALTER COLUMN c SET GENERATED ALWAYS' and 'ALTER
TABLE t ALTER COLUMN c SET GENERATED BY DEFAULT',
which changes the 'GeneratedAsIdentityType' of
that column's definition, respectively.

Release note (sql change): Identity columns can
have their IdentityType altered by running 'ALTER
TABLE t ALTER COLUMN c SET GENERATED ALWAYS' or
'ALTER TABLE t ALTER COLUMN c SET GENERATED BY DEFAULT'.
andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Feb 22, 2024
Informs: cockroachdb#110010

This change adds a new command, 'ALTER TABLE
ALTER [COLUMN] DROP IDENTITY [ IF EXISTS ]',
which allows an IDENTITY column to drop its
Identity constraint and related sequence.
'IF EXISTS' is optional and will provide a notice
if the column is not an identity.

Release note (sql change): Identity Columns can
drop the Identity constraint by running 'ALTER
TABLE t ALTER COLUMN c DROP IDENTITY [ IF EXISTS ]'.
craig bot pushed a commit that referenced this issue Mar 11, 2024
115889: sql: Allow Identity Column to Change Generation Type r=rafiss a=andrew-delph

sql: Allow Alter Column to ADD and SET Identity
Informs: #110010

This change adds a new command, 'ALTER TABLE
ALTER [COLUMN] <colname> ADD GENERATED
{ ALWAYS | BY DEFAULT } [( <opt_sequence_option_list> )]'
and 'ALTER TABLE ALTER [COLUMN] <colname> SET
GENERATED { ALWAYS | BY DEFAULT }',
which allows a column to become an Identity
or change the generation type of the the
identity.

Release note (sql change): Columns can have
become an IdentityType by running 'ALTER
TABLE t ALTER COLUMN c ADD GENERATED ALWAYS
[( <opt_sequence_option_list> )]' or 'ALTER TABLE t ALTER
COLUMN c ADD GENERATED BY DEFAULT [( <opt_sequence_option_list> )]'.
Identity columns can have their IdentityType altered
by running 'ALTER TABLE t ALTER COLUMN c SET GENERATED ALWAYS'
or 'ALTER TABLE t ALTER COLUMN c SET GENERATED BY DEFAULT'.

119799: sql: fix a couple of memory leaks around memory monitors r=yuzefovich a=yuzefovich

See individual commits for details.

Epic: None

Release note (bug fix): A slow memory leak that can accumulate when opening many new connections has been fixed. The bug is present in 22.2.9+ and 23.1+ versions.

120141: roachprod: only register services when applicable r=renatolabs,srosenberg a=herkolategan

Previously, DNS services for clusters would be registered in all cases. This can lead to some scenarios where `roachprod` is unable to correctly determine the port of a service.

When a cluster is created in a custom GCP project (non-default project) the `roachprod` garbage collector will destroy the records as it determines it has nothing to tie the resources to since it has no visibility of the custom project.

As we currently do not test virtual clusters on AWS or Azure, these have also been excluded, because these providers do not specify using the Google Cloud DNS Provider yet. For that reason, there is no point in trying to register services.

Epic: None
Release Note: None

Co-authored-by: Andrew Delph <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: Herko Lategan <[email protected]>
@craig craig bot closed this as completed in 387e464 Mar 11, 2024
andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Mar 13, 2024
Informs: cockroachdb#110010

This change introduces the 'ALTER [COLUMN] column_name SET
sequence_option | RESTART [ [ WITH ] restart ] }' command.
This enhancement allows for the modification of identity column
sequence options, thereby providing more precise control over
the behavior of identity columns.

Release note (sql change): Identity columns now support enhanced
sequence management through the 'ALTER [COLUMN] column_name SET
sequence_option' and 'ALTER [COLUMN] column_name RESTART [WITH
restart]' commands. This update facilitates the fine-tuning of
identity column sequences.
andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Mar 13, 2024
Informs: cockroachdb#110010

This change introduces the 'ALTER [COLUMN] column_name SET
sequence_option | RESTART [ [ WITH ] restart ] }' command.
This enhancement allows for the modification of identity column
sequence options, thereby providing more precise control over
the behavior of identity columns.

Release note (sql change): Identity columns now support enhanced
sequence management through the 'ALTER [COLUMN] column_name SET
sequence_option' and 'ALTER [COLUMN] column_name RESTART [WITH
restart]' commands. This update facilitates the fine-tuning of
identity column sequences.
craig bot pushed a commit that referenced this issue Mar 14, 2024
119432: sql: Add support for altering sequence options identity columns r=fqazi a=andrew-delph

Informs: #110010

This change introduces the 'ALTER [COLUMN] column_name SET sequence_option | RESTART [ [ WITH ] restart ] }' command. This enhancement allows for the modification of identity column sequence options, thereby providing more precise control over the behavior of identity columns.

Release note (sql change): Identity columns now support enhanced sequence management through the 'ALTER [COLUMN] column_name SET sequence_option' and 'ALTER [COLUMN] column_name RESTART [WITH restart]' commands. This update facilitates the fine-tuning of identity column sequences.

120135: admission: adjust token computation during WAL failover r=aadityasondhi a=sumeerbhola

During WAL failover, possibly caused by a disk stall in the primary location, flushes and compactions can also be stalled. This can cause admission control to compute artificially low token counts for compaction bandwidth out of L0 (if L0 has elevated score), and flush tokens (which are meant to prevent memtable write stalls).

The solution outlined here detects WAL failover by looking at increases in the pebble metric WAL.Failover.SecondaryWriteDuration. If an increase happened in the last 15s interval (the token computation interval), the current flush and compaction bytes are ignored for the purpose of smoothing and therefore ignored for computing tokens. For regular work, the previous smoothed compaction tokens continue to be used, and flush tokens are unlimited. For elastic work, the tokens are reduced to near zero. An alternative is to allow unlimited tokens during the stall, but it runs the risk of over-admitting. We allow this alternative to be configured by changing the cluster setting
admission.wal.failover.unlimited_tokens.enabled to true.

Informs cockroachdb/pebble#3230

Informs CRDB-35401

Epic: none

Release note (ops change): The cluster setting
admission.wal.failover.unlimited_tokens.enabled can be set to true to cause unlimited admission tokens during WAL failover. This should not be changed without consulting admission control team since the default, which preserves the token counts from the preceding non-WAL-failover interval, is expected to be safer.

Co-authored-by: Andrew Delph <[email protected]>
Co-authored-by: sumeerbhola <[email protected]>
andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Mar 19, 2024
Informs: cockroachdb#110010

This change adds a new command, 'ALTER TABLE
ALTER [COLUMN] DROP IDENTITY [ IF EXISTS ]',
which allows an IDENTITY column to drop its
Identity constraint and related sequence.
'IF EXISTS' is optional and will provide a notice
if the column is not an identity.

Release note (sql change): Identity Columns can
drop the Identity constraint and related sequence by running:
-'ALTER TABLE t ALTER COLUMN c DROP IDENTITY'.

Option 'IF EXISTS' can be added to skip the command
if the column in not an identity:
-'ALTER TABLE t ALTER COLUMN c DROP IDENTITY [ IF EXISTS ]'.
andrew-delph added a commit to andrew-delph/cockroach that referenced this issue Mar 19, 2024
Informs: cockroachdb#110010

This change adds a new command, 'ALTER TABLE
ALTER [COLUMN] DROP IDENTITY [ IF EXISTS ]',
which allows an IDENTITY column to drop its
Identity constraint and related sequence.
'IF EXISTS' is optional and will provide a notice
if the column is not an identity.

Release note (sql change): Identity Columns can
drop the Identity constraint and related sequence by running:
-'ALTER TABLE t ALTER COLUMN c DROP IDENTITY'.

Option 'IF EXISTS' can be added to skip the command
if the column in not an identity:
-'ALTER TABLE t ALTER COLUMN c DROP IDENTITY [ IF EXISTS ]'.
annrpom pushed a commit to andrew-delph/cockroach that referenced this issue Mar 22, 2024
Informs: cockroachdb#110010

This change adds a new command, 'ALTER TABLE
ALTER [COLUMN] DROP IDENTITY [ IF EXISTS ]',
which allows an IDENTITY column to drop its
Identity constraint and related sequence.
'IF EXISTS' is optional and will provide a notice
if the column is not an identity.

Release note (sql change): Identity Columns can
drop the Identity constraint and related sequence by running:
-'ALTER TABLE t ALTER COLUMN c DROP IDENTITY'.

Option 'IF EXISTS' can be added to skip the command
if the column in not an identity:
-'ALTER TABLE t ALTER COLUMN c DROP IDENTITY [ IF EXISTS ]'.
craig bot pushed a commit that referenced this issue Mar 22, 2024
119263: sql: Allow Alter Column Drop Identity Command r=annrpom a=andrew-delph

Informs: #110010

This change adds a new command, 'ALTER TABLE
ALTER [COLUMN] DROP IDENTITY [ IF EXISTS ]',
which allows an ID column to drop the related
its Identity constraint and related sequence.
'IF EXISTS' is optional and will provide a notice
if the column is not an identity.

Release note (sql change): Identity Columns can
drop the Identity constraint by running 'ALTER
TABLE t ALTER COLUMN c DROP IDENTITY [ IF EXISTS ]'.

120893: changefeedccl: skip `TestChangefeedWithSimpleDistributionStrategy` r=andyyang890 a=rickystewart

This test is flaky.

See #120870

Epic: none
Release note: None

Co-authored-by: Andrew Delph <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-tools-efcore C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) X-blathers-triaged blathers was able to find an owner
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants