Skip to content

sql: CREATE TABLE/VIEW works on non-serializable transactions, but shouldnt #17404

@knz

Description

@knz

Both CREATE TABLE and CREATE VIEW can modify descriptors of other tables/views than the one being created, to update either their depended-on list (for CREATE VIEW) or their index list (for CREATE TABLE with FKs).

This is done by using planner.avoidCachedDescriptor to disable use of the descriptor cache, so that the descriptor is read from KV in the same transaction. Then the descriptor is modified in-place, UpVersion is set, and written back in the same txn.

However, if the isolation level is SNAPSHOT, we run the risk of working with an outdated descriptor when committing!

It is important that DDL statements are rejected when the txn level is not at least SERIALIZABLE.

cc @cockroachdb/sql-async

Found by @andreimatei in #17310.

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions