Skip to content

sql: create new indexes rather than a new table in TRUNCATE #52170

@ajwerner

Description

@ajwerner

Is your feature request related to a problem? Please describe.
Today the implementation of TRUNCATE creates a new table with the same structure as an old one. It then drops the old one and renames it to the new one. This has caused a number of problems and bugs. Worse yet, it means that a table ID is not a stable identifier, complicating how we store references to it in other tables.

Describe the solution you'd like

This was probably done because prior to 20.1, we required that every table have a primary index with ID 1. This is no longer the case since we implemented primary key changes. We should just drop all of the existing indexes and create new ones in truncate.

Describe alternatives you've considered
None

Additional context

This will make challenges related to renaming things which are referenced easier. See #10083 and #51090.

One problem here is that the index IDs might get quite high. This could be mitigated with #47981.

Metadata

Metadata

Assignees

Labels

A-schema-changesA-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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions