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

sql/sem/tree: properly serialize physical values of enums #61933

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

ajwerner
Copy link
Contributor

The optimizer generates check constraints for enums. It does so by
writing these constraints as physical values. Unfortunately the way
we serialized these physical values was bogus if the enum's physical
value was more than one byte long. The reason was because of a difference
between string literal and byte string literals and their use of \x.

This fixes that by using hex byte string literals for these enum
values.

Fixes #61814

Release note (bug fix): Fixed a bug whereby enums which have large numbers of
values may cause unexpected errors when attempting to read from tables with
columns using that enum.

@ajwerner ajwerner requested a review from arulajmani March 12, 2021 19:03
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ajwerner ajwerner force-pushed the ajwerner/fix-large-enums branch from 2a1861a to 8187ca0 Compare March 15, 2021 04:33
Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/sql/sem/tree/datum.go, line 1447 at r1 (raw file):

		writeAsHexString(ctx, d)
		ctx.WriteString(`"`)
	} else if f.HasFlags(fmtFormatByteLiterals) {

nit: could you update the comment on fmtFormatByteLiterals to reflect this change


pkg/sql/tests/enum_test.go, line 19 at r1 (raw file):

)

func TestLargeEnums(t *testing.T) {

Nice test! 💯

@ajwerner ajwerner changed the title sql/sem/tree: properly encode serialize physical values of enums sql/sem/tree: properly serialize physical values of enums Mar 16, 2021
@ajwerner ajwerner force-pushed the ajwerner/fix-large-enums branch 3 times, most recently from 8b2b038 to dad7087 Compare March 16, 2021 04:43
The optimizer generates check constraints for enums. It does so by
writing these constraints as physical values. Unfortunately the way
we serialized these physical values was bogus if the enum's physical
value was more than one byte long. The reason was because of a difference
between string literal and byte string literals and their use of `\x`.

This fixes that by using hex byte string literals for these enum
values.

Fixes cockroachdb#61814

Release note (bug fix): Fixed a bug whereby enums which have large numbers of
values may cause unexpected errors when attempting to read from tables with
columns using that enum.
@ajwerner ajwerner force-pushed the ajwerner/fix-large-enums branch from dad7087 to 18bad51 Compare March 16, 2021 05:40
@ajwerner
Copy link
Contributor Author

Updated the comment.

bors r+

@craig
Copy link
Contributor

craig bot commented Mar 16, 2021

Build succeeded:

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.

sql: adding too many enum values may render tables using them inaccessible
3 participants