Skip to content

sql: alter column type can corrupt tables with secondary indexes storing the column #72771

@ajwerner

Description

@ajwerner

Describe the problem

The experimental ALTER COLUMN TYPE has an egregious bug. We seemingly don't do anything about indexes which store the column. This leads to these indexes persisting with the old column even after it is not in the table. For various reasons, this sort of worked out surprisingly well because the implementation of the various column ordinal maps wouldn't find the column and stored columns end up, mostly, being an optimization.

To Reproduce

The repro from #72718 (comment) demonstrates it.

Expected behavior
We should have rewritten the index.

Additional context

This leaves us in a sticky situation. These indexes might exist in the wild. Ideally we'd properly validate that all the columns in an index exist in the table descriptor. I'm inclined to add such validation now. In the meantime, existing descriptors will be broken and we'll need to drop the index.


#72718 is caused by this and #72676 reveals it. The way that it gets revealed, which is rather horrific, is that there's a different behavior in the small and large FastIntMap. If the value does not exist in small, you'll get -1, false, but if it does not exist in large, you'll get 0, false. See

return int(val), (val != -1)
}
value, ok = m.large[key]
return value, ok

Metadata

Metadata

Assignees

Labels

A-schema-descriptorsRelating to SQL table/db descriptor handling.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions