Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow varchar columns as primary keys #620

Merged
merged 6 commits into from
Aug 15, 2024
Merged

Allow varchar columns as primary keys #620

merged 6 commits into from
Aug 15, 2024

Conversation

zachmu
Copy link
Member

@zachmu zachmu commented Aug 14, 2024

The problem: the varchar type in pgtypes was declared as Text, not Varchar. This triggered validation checks in both GMS and Dolt when such a column was used in a primary key. I originally tried adding additional index / length info in the CREATE TABLE transformation, but with the varchar type being interpreted as Text, there's no combination of params that can satisfy all the validation checks.

The error before this fix is e.g.

"ERROR: blob/text column 't' used in key specification without a key length"

Given that we have a lot of validation logic with key prefix lengths related to BLOB / TEXT types, it seems like this type really can't be declared as TEXT, but open to other ideas.

Collation / charset support is still fake and will need to be fixed, but no worse than it was before.

Copy link
Collaborator

@Hydrocharged Hydrocharged left a comment

Choose a reason for hiding this comment

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

Looks fine, but I'd prefer if we just removed the validation roadblock in GMS, rather than making changes here. Also seems far simpler to disable the GMS roadblock, but can't confirm that. We also can't have TEXT as a primary key, which that would fix (since this PR only addresses VARCHAR). Could be more types too, not sure.

server/connection_handler.go Outdated Show resolved Hide resolved
server/types/varchar.go Outdated Show resolved Hide resolved
@zachmu
Copy link
Member Author

zachmu commented Aug 15, 2024

Looks fine, but I'd prefer if we just removed the validation roadblock in GMS, rather than making changes here. Also seems far simpler to disable the GMS roadblock, but can't confirm that. We also can't have TEXT as a primary key, which that would fix (since this PR only addresses VARCHAR). Could be more types too, not sure.

Yes, we'll need to loosen the key type restrictions or make them customizable to support text as a primary key. Hard to do without breaking a bunch of stuff in GMS and Dolt. Bigger project.

@zachmu zachmu enabled auto-merge August 15, 2024 18:14
@zachmu zachmu merged commit 2989c86 into main Aug 15, 2024
9 checks passed
@zachmu zachmu deleted the zachmu/schema-fixes branch August 15, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants