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: move alter column type general support out of experimental #49329

Closed
2 of 5 tasks
Tracked by #91223
RichardJCai opened this issue May 20, 2020 · 11 comments
Closed
2 of 5 tasks
Tracked by #91223

sql: move alter column type general support out of experimental #49329

RichardJCai opened this issue May 20, 2020 · 11 comments
Assignees
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) meta-issue Contains a list of several other issues. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@RichardJCai
Copy link
Contributor

RichardJCai commented May 20, 2020

This serves as the final cleanup for the MVP implementation of ALTER COLUMN TYPE.

  • Block data-destructive changes unless sql_safe_updates is disabled.
  • Deprecate and block legacy schema changer support for ALTER COLUMN TYPE operations requiring rewrites.
  • Ensure all blocked ALTER COLUMN TYPE scenarios in the MVP have associated GitHub issues, clear error messages, and actionable hints for resolution.
  • Block ALTER TABLE operations in explicit transactions.
  • Remove the feature gate for ALTER COLUMN TYPE.

Jira issue: CRDB-4238

Epic CRDB-25314

@blathers-crl
Copy link

blathers-crl bot commented May 20, 2020

Hi @RichardJCai, I've guessed the C-ategory of your issue and suitably labeled it. Please re-label if inaccurate.

While you're here, please consider adding an A- label to help keep our repository tidy.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label May 20, 2020
@RichardJCai RichardJCai self-assigned this May 20, 2020
@RichardJCai RichardJCai changed the title sql: move alter column type non-trivial out of experimental sql: move alter column type general support out of experimental May 21, 2020
@timgraham
Copy link
Contributor

When running Django's test suite, I'm seeing FeatureNotSupported errors pointing to this issue that weren't present before 20.2 alpha 2.

  • ALTER COLUMN TYPE from varchar to string is only supported experimentally
  • ALTER COLUMN TYPE from int to int is only supported experimentally
  • ALTER COLUMN TYPE from int2 to int2 is only supported experimentally

Is this a regression? I'll provide the exact SQL statements if needed.

@RichardJCai
Copy link
Contributor Author

When running Django's test suite, I'm seeing FeatureNotSupported errors pointing to this issue that weren't present before 20.2 alpha 2.

  • ALTER COLUMN TYPE from varchar to string is only supported experimentally
  • ALTER COLUMN TYPE from int to int is only supported experimentally
  • ALTER COLUMN TYPE from int2 to int2 is only supported experimentally

Is this a regression? I'll provide the exact SQL statements if needed.

Yeah this is a regression, while adding experimental support for other cases of alter column type, I wrapped all uses of alter column type with the error, will fix this soon.

@RichardJCai
Copy link
Contributor Author

When running Django's test suite, I'm seeing FeatureNotSupported errors pointing to this issue that weren't present before 20.2 alpha 2.

  • ALTER COLUMN TYPE from varchar to string is only supported experimentally
  • ALTER COLUMN TYPE from int to int is only supported experimentally
  • ALTER COLUMN TYPE from int2 to int2 is only supported experimentally

Is this a regression? I'll provide the exact SQL statements if needed.

Actually can you provide the statements please? Curious if you're providing an expression to alter the column type or not.

@timgraham
Copy link
Contributor

ALTER TABLE "schema_author" ALTER COLUMN "name" TYPE text USING "name"::text;
ALTER TABLE "schema_uniquetest" ALTER COLUMN "year" TYPE bigint USING "year"::bigint;
ALTER TABLE "schema_smallintegerpk" ALTER COLUMN "i" TYPE smallint USING "i"::smallint;

@RichardJCai
Copy link
Contributor Author

@timgraham actually this isn't necessarily a regression - previously the logic did not take into account the USING expression at all.
ALTER TABLE "schema_author" ALTER COLUMN "name" TYPE text USING "name"::text; was equivalent to just
ALTER TABLE "schema_author" ALTER COLUMN "name" TYPE text

Now if any expression is provided, we force a change to happen. The examples you gave, the expression is ignored and the ALTER TABLE is a no-op.

How important is this?

timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 1, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 1, 2020
@timgraham
Copy link
Contributor

Maybe Django doesn't need to add a USING clause (that code was copied from the PostgreSQL backend). Removing that resolves the crashes.

diff --git a/django_cockroachdb/schema.py b/django_cockroachdb/schema.py
index 11d90dc..ca2a9da 100644
--- a/django_cockroachdb/schema.py
+++ b/django_cockroachdb/schema.py
@@ -44,9 +44,6 @@ class DatabaseSchemaEditor(PostgresDatabaseSchemaEditor):

     def _alter_column_type_sql(self, model, old_field, new_field, new_type):
         self.sql_alter_column_type = 'ALTER COLUMN %(column)s TYPE %(type)s'
-        # Cast when data type changed.
-        if self._field_data_type(old_field) != self._field_data_type(new_field):
-            self.sql_alter_column_type += ' USING %(column)s::%(type)s'
         # Make ALTER TYPE with SERIAL make sense.
         # table = strip_quotes(model._meta.db_table)
         serial_fields_map = {'bigserial': 'bigint', 'serial': 'integer', 'smallserial': 'smallint'}

Incidentally, I added "SET enable_experimental_alter_column_type_general = true" and enabled some type change tests without issue.

The remaining type conversion test failures are covered by #47636.

@timgraham
Copy link
Contributor

For what it's worth, here are the failures on PostgreSQL when I remove the USING clause. I guess CockroachDB does these casts implicitly.

======================================================================
ERROR: test_alter_text_field_to_date_field (schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.DatatypeMismatch: column "info" cannot be cast automatically to type date
HINT:  You might need to specify "USING info::date".


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tim/code/django/tests/schema/tests.py", line 778, in test_alter_text_field_to_date_field
    editor.alter_field(Note, old_field, new_field, strict=True)
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 567, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/tim/code/django/django/db/backends/postgresql/schema.py", line 154, in _alter_field
    new_db_params, strict,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 717, in _alter_field
    params,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/tim/code/django/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "info" cannot be cast automatically to type date
HINT:  You might need to specify "USING info::date".


======================================================================
ERROR: test_alter_text_field_to_datetime_field (schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.DatatypeMismatch: column "info" cannot be cast automatically to type timestamp with time zone
HINT:  You might need to specify "USING info::timestamp with time zone".


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tim/code/django/tests/schema/tests.py", line 794, in test_alter_text_field_to_datetime_field
    editor.alter_field(Note, old_field, new_field, strict=True)
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 567, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/tim/code/django/django/db/backends/postgresql/schema.py", line 154, in _alter_field
    new_db_params, strict,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 717, in _alter_field
    params,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/tim/code/django/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "info" cannot be cast automatically to type timestamp with time zone
HINT:  You might need to specify "USING info::timestamp with time zone".


======================================================================
ERROR: test_alter_text_field_to_time_field (schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.DatatypeMismatch: column "info" cannot be cast automatically to type time without time zone
HINT:  You might need to specify "USING info::time without time zone".


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tim/code/django/tests/schema/tests.py", line 810, in test_alter_text_field_to_time_field
    editor.alter_field(Note, old_field, new_field, strict=True)
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 567, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/tim/code/django/django/db/backends/postgresql/schema.py", line 154, in _alter_field
    new_db_params, strict,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 717, in _alter_field
    params,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/tim/code/django/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "info" cannot be cast automatically to type time without time zone
HINT:  You might need to specify "USING info::time without time zone".


======================================================================
ERROR: test_char_field_with_db_index_to_fk (schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.DatatypeMismatch: column "char_field_id" cannot be cast automatically to type integer
HINT:  You might need to specify "USING char_field_id::integer".


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tim/code/django/django/test/testcases.py", line 1229, in skip_wrapper
    return test_func(*args, **kwargs)
  File "/home/tim/code/django/tests/schema/tests.py", line 330, in test_char_field_with_db_index_to_fk
    editor.alter_field(AuthorCharFieldWithIndex, old_field, new_field, strict=True)
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 567, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/tim/code/django/django/db/backends/postgresql/schema.py", line 154, in _alter_field
    new_db_params, strict,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 717, in _alter_field
    params,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/tim/code/django/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "char_field_id" cannot be cast automatically to type integer
HINT:  You might need to specify "USING char_field_id::integer".


======================================================================
ERROR: test_text_field_with_db_index_to_fk (schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.DatatypeMismatch: column "text_field_id" cannot be cast automatically to type integer
HINT:  You might need to specify "USING text_field_id::integer".


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tim/code/django/django/test/testcases.py", line 1229, in skip_wrapper
    return test_func(*args, **kwargs)
  File "/home/tim/code/django/django/test/testcases.py", line 1229, in skip_wrapper
    return test_func(*args, **kwargs)
  File "/home/tim/code/django/tests/schema/tests.py", line 345, in test_text_field_with_db_index_to_fk
    editor.alter_field(AuthorTextFieldWithIndex, old_field, new_field, strict=True)
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 567, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/tim/code/django/django/db/backends/postgresql/schema.py", line 154, in _alter_field
    new_db_params, strict,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 717, in _alter_field
    params,
  File "/home/tim/code/django/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/tim/code/django/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/tim/code/django/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/tim/code/django/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "text_field_id" cannot be cast automatically to type integer
HINT:  You might need to specify "USING text_field_id::integer".

timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 6, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 6, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 19, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 19, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 25, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 25, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 26, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 26, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 28, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 28, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 29, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Aug 29, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Sep 1, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Sep 1, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Sep 3, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Sep 3, 2020
timgraham added a commit to timgraham/django-cockroachdb that referenced this issue Sep 12, 2020
@knz
Copy link
Contributor

knz commented Oct 31, 2022

Added the following two items to the bullet list at top, as per request from @dbist 👍

  • Add NOTICE for changes that are data-destructive (e.g reducing field width).
  • Block data-destructive changes unless sql_safe_updates is false.

@exalate-issue-sync exalate-issue-sync bot added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) and removed T-sql-schema-deprecated Use T-sql-foundations instead labels May 10, 2023
@cornfeedhobo
Copy link

Any hope?

spilchen added a commit to spilchen/cockroach that referenced this issue Nov 21, 2024
Prior to this change, in order to alter a column’s type that needed a backfill
the setting enable_experimental_alter_column_type_general had to be set. This
removes that restriction now that we built out ALTER COLUMN TYPE support in the
DSC. We still check the setting in mixed-version workloads since it depends on
25.1 dep rules. And when using the legacy schema changer.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note (general): Altering a column’s type no longer requires enabling
the enable_experimental_alter_column_type_general setting. This change makes
the feature generally available.
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 21, 2024
Previously, altering a column’s type requiring a backfill required the
enable_experimental_alter_column_type_general setting to be enabled.
This restriction has been removed, as full support for ALTER COLUMN TYPE
has been implemented in the Declarative Schema Changer (DSC).

The setting is still checked in mixed-version clusters, as the operation
relies on 25.1 dependency rules, and when using the legacy schema
changer.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note (general): Altering a column’s type no longer requires enabling
the enable_experimental_alter_column_type_general setting. This change makes
the feature generally available.
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 21, 2024
Previously, altering a column’s type requiring a backfill required the
enable_experimental_alter_column_type_general setting to be enabled.
This restriction has been removed, as full support for ALTER COLUMN TYPE
has been implemented in the Declarative Schema Changer (DSC).

The setting is still checked in mixed-version clusters, as the operation
relies on 25.1 dependency rules, and when using the legacy schema
changer.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note (general change): Altering a column’s type no longer requires
enabling the enable_experimental_alter_column_type_general setting. This
change makes the feature generally available.
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 22, 2024
Previously, altering a column’s type requiring a backfill required the
enable_experimental_alter_column_type_general setting to be enabled.
This restriction has been removed, as full support for ALTER COLUMN TYPE
has been implemented in the Declarative Schema Changer (DSC).

The setting is still checked in mixed-version clusters, as the operation
relies on 25.1 dependency rules, and when using the legacy schema
changer.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note (sql change): Altering a column’s type no longer requires
enabling the enable_experimental_alter_column_type_general setting. This
change makes the feature generally available.
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 22, 2024
Previously, altering a column’s type requiring a backfill required the
enable_experimental_alter_column_type_general setting to be enabled.
This restriction has been removed, as full support for ALTER COLUMN TYPE
has been implemented in the Declarative Schema Changer (DSC).

The setting is still checked in mixed-version clusters, as the operation
relies on 25.1 dependency rules, and when using the legacy schema
changer.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note (sql change): Altering a column’s type no longer requires
enabling the enable_experimental_alter_column_type_general setting. This
change makes the feature generally available.
craig bot pushed a commit that referenced this issue Nov 22, 2024
135936: sql/schemachanger: Remove feature gate for ALTER COLUMN TYPE r=spilchen a=spilchen

Previously, altering a column’s type requiring a backfill required the enable_experimental_alter_column_type_general setting to be enabled. This restriction has been removed, as full support for ALTER COLUMN TYPE has been implemented in the Declarative Schema Changer (DSC).

The setting is still checked in mixed-version clusters, as the operation relies on 25.1 dependency rules, and when using the legacy schema changer.

Epic: CRDB-25314
Informs #49329
Release note (sql change): Altering a column’s type no longer requires enabling the enable_experimental_alter_column_type_general setting. This change makes the feature generally available.

Co-authored-by: Matt Spilchen <[email protected]>
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 25, 2024
…schema changer

This change deprecates the legacy schema changer for ALTER COLUMN TYPE
operations that require a column rewrite. While the legacy schema
changer remains available for mixed-version clusters, starting in
version 25.1, these operations must use the declarative schema changer.

Additionally, this update includes the following improvements:
- Updated error messages for blocking conditions to clarify that they
  apply only when the ALTER COLUMN TYPE requires a column rewrite. Each
  error now includes a hint for resolving the issue.
- Enforced that the sql_safe_updates setting must be disabled to perform
  operations requiring a column rewrite. This is necessary to prevent
  potential data loss when converting between DECIMAL or TIMESTAMP data
  types or when using a USING expression.

Epic: CRDB-25314
Informs: cockroachdb#49329
Release note (sql change): The sql_safe_updates setting must be disabled
to perform ALTER COLUMN TYPE operations that require a column rewrite.
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 25, 2024
…schema changer

This change deprecates the legacy schema changer for ALTER COLUMN TYPE
operations that require a column rewrite. While the legacy schema
changer remains available for mixed-version clusters, starting in
version 25.1, these operations must use the declarative schema changer.

Additionally, this update includes the following improvements:
- Updated error messages for blocking conditions to clarify that they
  apply only when the ALTER COLUMN TYPE requires a column rewrite. Each
  error now includes a hint for resolving the issue.
- Enforced that the sql_safe_updates setting must be disabled to perform
  operations requiring a column rewrite. This is necessary to prevent
  potential data loss when converting between DECIMAL or TIMESTAMP data
  types or when using a USING expression.

Epic: CRDB-25314
Informs: cockroachdb#49329
Release note (sql change): The sql_safe_updates setting must be disabled
to perform ALTER COLUMN TYPE operations that require a column rewrite.
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 25, 2024
This introduces a block that prevents running an ALTER COLUMN TYPE
operation requiring a backfill within a transaction. To support the
schemachanger end-to-end tests, which need to execute ALTERs in a
transaction, I added a session variable to override this default
behavior.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note: none
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 25, 2024
…schema changer

This change deprecates the legacy schema changer for ALTER COLUMN TYPE
operations that require a column rewrite. While the legacy schema
changer remains available for mixed-version clusters, starting in
version 25.1, these operations must use the declarative schema changer.

Additionally, this update includes the following improvements:
- Updated error messages for blocking conditions to clarify that they
  apply only when the ALTER COLUMN TYPE requires a column rewrite. Each
  error now includes a hint for resolving the issue.
- Enforced that the sql_safe_updates setting must be disabled to perform
  operations requiring a column rewrite. This is necessary to prevent
  potential data loss when converting between DECIMAL or TIMESTAMP data
  types or when using a USING expression.

Epic: CRDB-25314
Informs: cockroachdb#49329
Release note (sql change): The sql_safe_updates setting must be disabled
to perform ALTER COLUMN TYPE operations that require a column rewrite.
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 26, 2024
This introduces a block that prevents running an ALTER COLUMN TYPE
operation requiring a backfill within a transaction. To support the
schemachanger end-to-end tests, which need to execute ALTERs in a
transaction, I added a session variable to override this default
behavior.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note: none
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 26, 2024
This introduces a block that prevents running an ALTER COLUMN TYPE
operation requiring a backfill within a transaction. To support the
schemachanger end-to-end tests, which need to execute ALTERs in a
transaction, I added a session variable to override this default
behavior.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note: none
spilchen added a commit to spilchen/cockroach that referenced this issue Nov 26, 2024
This introduces a block that prevents running an ALTER COLUMN TYPE
operation requiring a backfill within a transaction. To support the
schemachanger end-to-end tests, which need to execute ALTERs in a
transaction, I added a session variable to override this default
behavior.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note: none
craig bot pushed a commit that referenced this issue Nov 26, 2024
136178: kvserver: run TestReplicateRestartAfterTruncation with leader leases r=arulajmani a=arulajmani

This test was setting an extremely high RaftElectionTimeoutTicks value, but this doesn't work with raft fortification. That's because we won't campaign until StoreLiveness support is established, and the first time a replica is ticked we won't have this. The high
RaftElectionTimeoutTicks in this test wasn't useful in practice, so let's just remove it.

Note that this change also applies to the ReAdd version of the test.

References #133763

Release note: None

136207: sql/schemachanger: Block explicit transactions for ALTER COLUMN TYPE r=spilchen a=spilchen

This introduces a block that prevents running an ALTER COLUMN TYPE operation requiring a backfill within a transaction. To support the schemachanger end-to-end tests, which need to execute ALTERs in a transaction, I added a session variable to override this default behavior.

Epic: CRDB-25314
Informs #49329
Release note: none

Co-authored-by: Arul Ajmani <[email protected]>
Co-authored-by: Matt Spilchen <[email protected]>
craig bot pushed a commit that referenced this issue Nov 28, 2024
136110: sql/schemachanger: Deprecate ALTER COLUMN TYPE rewrite in the legacy schema changer r=spilchen a=spilchen

This change deprecates the legacy schema changer for ALTER COLUMN TYPE operations that require a column rewrite. While the legacy schema changer remains available for mixed-version clusters, starting in version 25.1, these operations must use the declarative schema changer.

Additionally, this update includes the following improvements:
- Updated error messages for blocking conditions to clarify that they apply only when the ALTER COLUMN TYPE requires a column rewrite. Each error now includes a hint for resolving the issue.
- Enforce that the sql_safe_updates setting must be disabled to perform operations requiring a column rewrite. This is necessary to prevent potential data loss when converting between DECIMAL or TIMESTAMP data types or when applying a USING expression.

Epic: CRDB-25314
Informs: #49329
Release note (sql change): The sql_safe_updates setting must be disabled to perform ALTER COLUMN TYPE operations that require a column rewrite.

136177: kvserver: bring TestRaftPreVote to a leader leases world r=arulajmani a=arulajmani

See individual commits. 

136179: kvserver: take advantage of fortification in TestQuotaPool r=iskettaneh a=arulajmani

This test was using an extremely high number for
RaftElectionTimeoutTicks to keep leadership sticky. This doesn't work with leader leases, as they require store liveness support to establish leadership, and requests for support are only kicked off on the first tick. Conveniently, fortification is yet another way to make leadership sticky -- so let's use that here instead.

References #133763

Release note: None

Co-authored-by: Matt Spilchen <[email protected]>
Co-authored-by: Arul Ajmani <[email protected]>
craig bot pushed a commit that referenced this issue Nov 28, 2024
136110: sql/schemachanger: Deprecate ALTER COLUMN TYPE rewrite in the legacy schema changer r=spilchen a=spilchen

This change deprecates the legacy schema changer for ALTER COLUMN TYPE operations that require a column rewrite. While the legacy schema changer remains available for mixed-version clusters, starting in version 25.1, these operations must use the declarative schema changer.

Additionally, this update includes the following improvements:
- Updated error messages for blocking conditions to clarify that they apply only when the ALTER COLUMN TYPE requires a column rewrite. Each error now includes a hint for resolving the issue.
- Enforce that the sql_safe_updates setting must be disabled to perform operations requiring a column rewrite. This is necessary to prevent potential data loss when converting between DECIMAL or TIMESTAMP data types or when applying a USING expression.

Epic: CRDB-25314
Informs: #49329
Release note (sql change): The sql_safe_updates setting must be disabled to perform ALTER COLUMN TYPE operations that require a column rewrite.

136156: kvserver: move RaftTruncatedState from ReplicaState r=tbg a=pav-kv

The `RaftTruncatedState` is in the unreplicated rangeID-local space. It logically belongs to the raft log storage, and is separate from the replicated state machine state. Before this PR, `RaftTruncatedState` was mixed into the `ReplicaState` struct which contains replicated state such as the range descriptor.

After this PR, `Replica` tracks the `RaftTruncatedState` separately from `ReplicaState`:

- `StateLoader.{Save,Load}` methods ignore this field. It is now saved and loaded using the `RaftTruncatedState` accessors.
- `ReplicaState.TruncatedState` is always nil in memory.
- The only place where the `ReplicaState.TruncatedState` remains used is the `ReplicatedEvalResult.State`. This is needed for compatibility with older versions, because the log may still contain historical proposals.
- However, all new proposals evaluate to a newly introduced `ReplicatedEvalResult.RaftTruncatedState` field. This change is version-gated.

The last remaining use of `ReplicaState.TruncatedState` needs to be phased out with a migration, before the field can be fully removed. All historical entries need to be applied/removed, before it is safe.

Part of #97613

136179: kvserver: take advantage of fortification in TestQuotaPool r=iskettaneh a=arulajmani

This test was using an extremely high number for
RaftElectionTimeoutTicks to keep leadership sticky. This doesn't work with leader leases, as they require store liveness support to establish leadership, and requests for support are only kicked off on the first tick. Conveniently, fortification is yet another way to make leadership sticky -- so let's use that here instead.

References #133763

Release note: None

Co-authored-by: Matt Spilchen <[email protected]>
Co-authored-by: Pavel Kalinnikov <[email protected]>
Co-authored-by: Arul Ajmani <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) meta-issue Contains a list of several other issues. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

No branches or pull requests

9 participants