Skip to content

schema: preserve table metadata when updating column tags#11152

Open
elianddb wants to merge 6 commits into
mainfrom
elian/11007-1-schema
Open

schema: preserve table metadata when updating column tags#11152
elianddb wants to merge 6 commits into
mainfrom
elian/11007-1-schema

Conversation

@elianddb

@elianddb elianddb commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

updateColumnTag was duplicated as a private helper in schcmds/update-tag.go and dprocedures/dolt_update_column_tag.go, and rebuilt the schema without preserving a schema's secondary indexes, CHECK constraints, table comment, and target row size.

@coffeegoddd

coffeegoddd commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@elianddb DOLT

read_tests from_latency to_latency percent_change
covering_index_scan 2.3 2.3 0.0
groupby_scan 142.39 139.85 -1.78
index_join 2.03 2.0 -1.48
index_join_scan 1.37 1.34 -2.19
index_scan 248.83 215.44 -13.42
oltp_point_select 0.26 0.26 0.0
oltp_read_only 5.18 5.18 0.0
select_random_points 0.55 0.56 1.82
select_random_ranges 0.65 0.65 0.0
table_scan 196.89 196.89 0.0
types_table_scan 467.3 450.77 -3.54
write_tests from_latency to_latency percent_change
oltp_delete_insert 6.21 6.21 0.0
oltp_insert 3.19 3.19 0.0
oltp_read_write 11.45 11.45 0.0
oltp_update_index 3.3 3.3 0.0
oltp_update_non_index 3.02 3.02 0.0
oltp_write_only 6.43 6.32 -1.71
types_delete_insert 6.91 6.91 0.0

@coffeegoddd

coffeegoddd commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@elianddb DOLT

test_name from_latency_p95 to_latency_p95 percent_change
tpcc-scale-factor-1 45.79 45.79 0.0
test_name from_server_name from_server_version from_tps to_server_name to_server_version to_tps percent_change
tpcc-scale-factor-1 dolt 2109ee0 52.91 dolt b93db02 52.85 -0.11

@coffeegoddd

Copy link
Copy Markdown
Contributor

@elianddb DOLT

comparing_percentages
100.000000 to 100.000000
version result total
db26747 ok 5937471
version total_tests
db26747 5937471
correctness_percentage
100.0

@elianddb elianddb changed the title schema: add tag remap helpers and dedup column-tag updates schema: preserve table metadata when updating column tags Jun 3, 2026
@coffeegoddd

Copy link
Copy Markdown
Contributor

@elianddb DOLT

comparing_percentages
100.000000 to 100.000000
version result total
16a9945 ok 5937471
version total_tests
16a9945 5937471
correctness_percentage
100.0

@elianddb elianddb force-pushed the elian/11007-1-schema branch from 16a9945 to b11391a Compare June 5, 2026 19:34
@coffeegoddd

Copy link
Copy Markdown
Contributor

@elianddb DOLT

comparing_percentages
100.000000 to 100.000000
version result total
b11391a ok 5937471
version total_tests
b11391a 5937471
correctness_percentage
100.0

@coffeegoddd

Copy link
Copy Markdown
Contributor

@elianddb DOLT

comparing_percentages
100.000000 to 100.000000
version result total
b93db02 ok 5937471
version total_tests
b93db02 5937471
correctness_percentage
100.0

@fulghum fulghum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a couple small things to check out.

}

@test "sql-update-column-tag: preserves indexes, check constraints, comment, and multi-column primary key" {
# See https://github.com/dolthub/dolt/issues/11007

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue doesn't seem related, right? It's about dolt reset not losing unstaged tables, but we don't seem to use reset at all here. Seems like we can just delete this comment if that's the case.

}

@test "column_tags: update-tag preserves indexes, check constraints, comment, and multi-column primary key" {
# See https://github.com/dolthub/dolt/issues/11007

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this was in all three BATS tests, but doesn't seem to be the issue we're actually testing for, so seems like we either fix this link to the related issue or take it out. Let me know if I'm just missing something.

Comment on lines +147 to +153
pkOrdinals := slices.Clone(sch.GetPkOrdinals())
newSch, err := NewSchema(NewColCollection(cols...), pkOrdinals, sch.GetCollation(), nil, sch.Checks().Copy())
if err != nil {
return nil, err
}
newSch.SetTargetRowSize(sch.GetTargetRowSize())
newSch.SetComment(sch.GetComment())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to use Schema.Copy() to get a copy and save some code here, as well as not having to update this code in the future if new properties are added to schema that would then need to be set on the new instance. I see you're updating the indexes, too, so would need to account for that, but it may still end up being simpler.


err = sch.Indexes().Iter(func(idx Index) (stop bool, err error) {
tags := RemapTags(idx.IndexedColumnTags(), tagRemap)
_, err = newSch.Indexes().AddIndexByColTags(idx.Name(), tags, idx.PrefixLengths(), idx.Properties())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe foreign keys also need some help, since they encode a column tag, if I'm remembering correctly. Would be good to test that case, but I suspect it needs to be updated, too.

}

func TestWithRemappedColumnTags(t *testing.T) {
// See https://github.com/dolthub/dolt/issues/11007

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple comments about this below, but I think I see now that this issue kinda turned into multiple PRs. The issue is a bit confusing though, because the repro doesn't use update-tag or show that the tags are conflicting. Something to think about, just wasn't immediately clear how that issue is related to these tests when the repro in the issue doesn't modify column tags.

require.Equal(t, uint64(200), pkCols[1].Tag, "PK column must carry the remapped id tag")
})

t.Run("PreservesIndexes", func(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good coverage of different schema features. I think foreign keys are also worth looking at, since I believe they work off of column tags, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants