Skip to content

key type conversion during foreign key checks#10935

Merged
zachmu merged 1 commit into
mainfrom
zachmu/fk-type-conversion
Apr 24, 2026
Merged

key type conversion during foreign key checks#10935
zachmu merged 1 commit into
mainfrom
zachmu/fk-type-conversion

Conversation

@zachmu
Copy link
Copy Markdown
Member

@zachmu zachmu commented Apr 24, 2026

This PR adds key type conversion for native encodings (encodings that don't have a TupleTypeHandler) for foreign key enforcement during merge. Postgres, but not MySQL, allows different but compatible types for the columns in foreign key constraints, e.g TEXT and VARCHAR. This means that Doltgres, but not Dolt, needs to sometimes convert the bytes of a tuple value from one encoding to another before an index lookup to determine if a constraint violation exists. Previously all such logic happened with TupleTypeHandler (DoltgresType was the main implementor). But with dolthub/doltgresql#2559, Doltgres is now using Dolt's native encodings where possible, e.g. StringEnc, StringAdaptiveEnc. This means this same logic must now work for these native encodings.

Dolt continues to prevent foreign key constraints from being created between different types, following the MySQL behavior, but with this change we could choose to relax this limitation in the future.

@zachmu zachmu requested a review from fulghum April 24, 2026 17:24
@coffeegoddd
Copy link
Copy Markdown
Contributor

@zachmu DOLT

read_tests from_latency to_latency percent_change
covering_index_scan 0.74 0.75 1.35
groupby_scan 10.84 10.84 0.0
index_join 1.79 1.82 1.68
index_join_scan 1.32 1.32 0.0
index_scan 21.5 21.5 0.0
oltp_point_select 0.25 0.25 0.0
oltp_read_only 5.28 5.28 0.0
select_random_points 0.5 0.5 0.0
select_random_ranges 0.77 0.77 0.0
table_scan 21.5 21.5 0.0
types_table_scan 66.84 65.65 -1.78
write_tests from_latency to_latency percent_change
oltp_delete_insert 6.32 6.32 0.0
oltp_insert 3.07 3.07 0.0
oltp_read_write 11.24 11.24 0.0
oltp_update_index 3.19 3.19 0.0
oltp_update_non_index 3.02 3.02 0.0
oltp_write_only 5.99 5.99 0.0
types_delete_insert 6.79 6.79 0.0

@coffeegoddd
Copy link
Copy Markdown
Contributor

@zachmu DOLT

test_name from_latency_p95 to_latency_p95 percent_change
tpcc-scale-factor-1 56.84 57.87 1.81
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 02c4b4e 42.56 dolt f06e4f1 41.44 -2.63

@coffeegoddd
Copy link
Copy Markdown
Contributor

@zachmu DOLT

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

Copy link
Copy Markdown
Contributor

@fulghum fulghum left a comment

Choose a reason for hiding this comment

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

Looks good!

@zachmu zachmu merged commit de49a75 into main Apr 24, 2026
45 of 48 checks passed
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