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

importccl: fail imports on concurrent type changes less aggressively #69706

Open
5 tasks
adityamaru opened this issue Sep 1, 2021 · 5 comments
Open
5 tasks
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@adityamaru
Copy link
Contributor

adityamaru commented Sep 1, 2021

Following #69674, an import into job will store the set of type descriptors referenced by the table being imported into during planning. On completion, the import job will check that the modification time on the saved type descriptors is equal to that on the type descriptors that are looked up. If there is a mismatch, it means that there was a concurrent type change during the import, and so we fail the import job. The method performing this check is called checkForUDTModification.

This check is probably too aggressive and risks failing an import at the last stage unnecessarily. The semantics of which concurrent type changes are safe during an import is still to be ironed out. Once that is done, this method can be refined to only check for the occurrence of the unsafe type changes and fail the import job. Some of the discussions around classes of type changes are listed below:

  • DROP TYPE: We forbid a type from being dropped if there is a table referencing it. This does not change the modification time on the descriptor and so the import job will succeed today.

  • ALTER TYPE DROP VALUE: We forbid an enum value from being dropped if a table referencing it is being imported into. The method canRemoveEnumValue validates all tables referencing the type and fails with could not validate enum value removal for "hi": relation "t" is offline: importing. This type change however changes the modification time prior to hitting the above error, and thus fails the import job today.

  • ALTER TYPE ADD VALUE: Adding a value to an enum being imported into should probably be safe. Today it will fail the import job since the modification time changes.

  • ALTER TYPE RENAME VALUE: Semantics to be thought through.

  • ALTER TYPE RENAME TO: Semantics to be thought through.

Jira issue: CRDB-9734

@adityamaru adityamaru added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-schema-deprecated Use T-sql-foundations instead labels Sep 1, 2021
@ajwerner
Copy link
Contributor

ajwerner commented Sep 1, 2021

Following #69674, an import into job will store the set of type descriptors referenced by the table being imported into during planning.

Do we need to store the set of type descriptors explicitly? The table descriptors know which type descriptors they reference.

DROP TYPE: We forbid a type from being dropped if there is a table referencing it. This does not change the modification time on the descriptor and so the import job will succeed today.

What do you mean that the modification time does not change? Generally, I don't get this one. Don't we end up forbidding the type from being dropped because the importing descriptor references the type?

@adityamaru
Copy link
Contributor Author

Do we need to store the set of type descriptors explicitly? The table descriptors know which type descriptors they reference.

For IMPORT INTO to support default + computed columns referencing UDTs we will be adding a custom type resolver that will be used during import execution. This type resolver will be backed by this set of cached type descriptors, and so I thought it necessary to store the descriptors instead of just the ModificationTime or a subset of the fields.

Don't we end up forbidding the type from being dropped because the importing descriptor references the type?

Yes, we do, so the import job is unaffected. What I was trying to get at was that while DROP TYPE is forbidden and does not change the descriptors modification time, ALTER TYPE DROP VALUE is forbidden, but does update the modification time. Thus, in the latter case, we do fail the import job rather unnecessarily. I am still to look into where ALTER TYPE DROP VALUE changes the modification time before it errors out in canRemoveEnumValue.

@ajwerner
Copy link
Contributor

ajwerner commented Sep 2, 2021

This type resolver will be backed by this set of cached type descriptors, and so I thought it necessary to store the descriptors instead of just the ModificationTime or a subset of the fields.

It's not a bad idea. Otherwise you'd need to go read the historical descriptors. Makes sense.

Yes, we do, so the import job is unaffected. What I was trying to get at was that while DROP TYPE is forbidden and does not change the descriptors modification time, ALTER TYPE DROP VALUE is forbidden, but does update the modification time.

Got it, so can we check off the first box?

I am still to look into where ALTER TYPE DROP VALUE changes the modification time before it errors out in canRemoveEnumValue.

This seems tricky.

@adityamaru
Copy link
Contributor Author

Adding @arulajmani's comment about why ALTER TYPE DROP VALUE updates the modification time even though it is forbidden.

I think it's because the OFFLINE error that you're expecting comes from the async portion of the schema change. The user transaction moves the enum member from PUBLIC to READ ONLY which results in an update to the modification time. The error you're expecting happens when we validate the enum member usages -- we can't for this table because it is offline. Validation fails and the enum member is transitioned back to PUBLIC from READ ONLY, resulting in another update to the modification time.

@ajwerner
Copy link
Contributor

We have decided that this is very low priority. There is quite a bit of work to unify import and sql #67076. There's also quite a bit of work to fix up types. This is an edge case for import.

ajwerner added a commit to ajwerner/cockroach that referenced this issue Oct 1, 2021
In cockroachdb#69674 we enabled importing of tables which used UDTs. We added the caveat
that these types must not change during the import. In cockroachdb#70987, @ajstorm
uncovered that adding new usages of the type cause an illegal change. This is
a particularly painful limitation as all regional by row tables will use the
enum type of the database. That makes the limitation of import much more
extreme than just precluding renames or modifications of enums or their
members.

To fix this limitation, we permit changes to the referencing set which
occur during the import. We also permit changes to privileges as they
won't impact the correctness of the import.

Relates to cockroachdb#69706
Fixes cockroachdb#70987

Release note (enterprise change): Fixed a limitation of IMPORT for tables
using user-defined types whereby any change to the set of tables or views
which reference the type or any changes to privileges on the type during
the IMPORT would lead to failure. Now new references to the type or GRANT
or REVOKE operations performed while the IMPORT is ongoing will not cause
failure.
ajwerner added a commit to ajwerner/cockroach that referenced this issue Oct 1, 2021
In cockroachdb#69674 we enabled importing of tables which used UDTs. We added the caveat
that these types must not change during the import. In cockroachdb#70987, @ajstorm
uncovered that adding new usages of the type cause an illegal change. This is
a particularly painful limitation as all regional by row tables will use the
enum type of the database. That makes the limitation of import much more
extreme than just precluding renames or modifications of enums or their
members.

To fix this limitation, we permit changes to the referencing set which
occur during the import. We also permit changes to privileges as they
won't impact the correctness of the import.

Relates to cockroachdb#69706
Fixes cockroachdb#70987

Release note (enterprise change): Fixed a limitation of IMPORT for tables
using user-defined types whereby any change to the set of tables or views
which reference the type or any changes to privileges on the type during
the IMPORT would lead to failure. Now new references to the type or GRANT
or REVOKE operations performed while the IMPORT is ongoing will not cause
failure.
ajwerner added a commit to ajwerner/cockroach that referenced this issue Oct 1, 2021
In cockroachdb#69674 we enabled importing of tables which used UDTs. We added the caveat
that these types must not change during the import. In cockroachdb#70987, @ajstorm
uncovered that adding new usages of the type cause an illegal change. This is
a particularly painful limitation as all regional by row tables will use the
enum type of the database. That makes the limitation of import much more
extreme than just precluding renames or modifications of enums or their
members.

To fix this limitation, we permit changes to the referencing set which
occur during the import. We also permit changes to privileges as they
won't impact the correctness of the import.

Relates to cockroachdb#69706
Fixes cockroachdb#70987

Release note (enterprise change): Fixed a limitation of IMPORT for tables
using user-defined types whereby any change to the set of tables or views
which reference the type or any changes to privileges on the type during
the IMPORT would lead to failure. Now new references to the type or GRANT
or REVOKE operations performed while the IMPORT is ongoing will not cause
failure.
ajwerner added a commit to ajwerner/cockroach that referenced this issue Oct 11, 2021
In cockroachdb#69674 we enabled importing of tables which used UDTs. We added the caveat
that these types must not change during the import. In cockroachdb#70987, @ajstorm
uncovered that adding new usages of the type cause an illegal change. This is
a particularly painful limitation as all regional by row tables will use the
enum type of the database. That makes the limitation of import much more
extreme than just precluding renames or modifications of enums or their
members.

To fix this limitation, we permit changes to the referencing set which
occur during the import. We also permit changes to privileges as they
won't impact the correctness of the import.

Relates to cockroachdb#69706
Fixes cockroachdb#70987

Release note (enterprise change): Fixed a limitation of IMPORT for tables
using user-defined types whereby any change to the set of tables or views
which reference the type or any changes to privileges on the type during
the IMPORT would lead to failure. Now new references to the type or GRANT
or REVOKE operations performed while the IMPORT is ongoing will not cause
failure.
craig bot pushed a commit that referenced this issue Oct 12, 2021
71016: importccl: allow changes to referencing set or privileges on UDT r=ajwerner a=ajwerner

In #69674 we enabled importing of tables which used UDTs. We added the caveat
that these types must not change during the import. In #70987, @ajstorm
uncovered that adding new usages of the type cause an illegal change. This is
a particularly painful limitation as all regional by row tables will use the
enum type of the database. That makes the limitation of import much more
extreme than just precluding renames or modifications of enums or their
members.

To fix this limitation, we permit changes to the referencing set which
occur during the import. We also permit changes to privileges as they
won't impact the correctness of the import.

Relates to #69706
Fixes #70987

Release note (enterprise change): Fixed a limitation of IMPORT for tables
using user-defined types whereby any change to the set of tables or views
which reference the type or any changes to privileges on the type during
the IMPORT would lead to failure. Now new references to the type or GRANT
or REVOKE operations performed while the IMPORT is ongoing will not cause
failure.

71121: colexec: take advantage of partial ordering in the hash aggregator r=rharding6373 a=rharding6373

This change consists of two commits. The first adds test coverage for 
aggregation with partial ordering of group columns, including adding a new
microbenchmark. The second adds support for partial ordering in the hash 
aggregator.

Results from both the new benchmark, HashAggregatorPartialOrder, and existing
hash aggregator benchmarks show improved performance for the partial order 
case for lower limit values, and no performance degradation for the unordered 
case: 
https://gist.github.com/rharding6373/09eface5ed49a00aac540a8ea8304662

This change is fairly large, so I will follow this PR with an update to the optimizer 
cost model to take advantage of partial ordering.

71420: roachtest/hibernate: fix failing test r=rafiss a=otan

Resolves #71312

Release note: None

Co-authored-by: Andrew Werner <[email protected]>
Co-authored-by: rharding6373 <[email protected]>
Co-authored-by: Oliver Tan <[email protected]>
blathers-crl bot pushed a commit that referenced this issue Oct 12, 2021
In #69674 we enabled importing of tables which used UDTs. We added the caveat
that these types must not change during the import. In #70987, @ajstorm
uncovered that adding new usages of the type cause an illegal change. This is
a particularly painful limitation as all regional by row tables will use the
enum type of the database. That makes the limitation of import much more
extreme than just precluding renames or modifications of enums or their
members.

To fix this limitation, we permit changes to the referencing set which
occur during the import. We also permit changes to privileges as they
won't impact the correctness of the import.

Relates to #69706
Fixes #70987

Release note (enterprise change): Fixed a limitation of IMPORT for tables
using user-defined types whereby any change to the set of tables or views
which reference the type or any changes to privileges on the type during
the IMPORT would lead to failure. Now new references to the type or GRANT
or REVOKE operations performed while the IMPORT is ongoing will not cause
failure.
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

No branches or pull requests

2 participants