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: validate against array type usages when dropping enum values #61406

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

arulajmani
Copy link
Collaborator

Previously, when dropping an enum value, we weren't validating if the
enum value was used in a column of array type. This patch fixes the bug.

Fixes #60004

Release justification: bug fix to new functionality
Release note: None

@arulajmani arulajmani requested review from ajwerner, otan and a team March 3, 2021 16:06
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator Author

@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.

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


pkg/sql/type_change.go, line 849 at r1 (raw file):

		// Construct a query of the form:
		// SELECT * FROM [

I couldn't find an easier/less expensive way of doing this validation.

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @otan)


pkg/sql/type_change.go, line 849 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I couldn't find an easier/less expensive way of doing this validation.

why square brackets on the outer one? can't this just be subqueries? Also, can we just do a UNION and put the where on the outside?

@arulajmani arulajmani force-pushed the validate-array-types-fr branch from 78099d5 to 011e5ae Compare March 7, 2021 00:57
Copy link
Collaborator Author

@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.

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


pkg/sql/type_change.go, line 849 at r1 (raw file):

Previously, ajwerner wrote…

why square brackets on the outer one? can't this just be subqueries? Also, can we just do a UNION and put the where on the outside?

Something like this?

@arulajmani arulajmani requested a review from ajwerner March 7, 2021 00:58
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @otan)


pkg/sql/type_change.go, line 849 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Something like this?

indeed


pkg/sql/type_change.go, line 733 at r2 (raw file):

Quoted 8 lines of code…
	var byteRep strings.Builder
	byteRep.WriteString("b'")
	for _, b := range bytes {
		byteRep.WriteByte(b)
	}
	byteRep.WriteString("'")
	return byteRep.String()
}

How tested is this? I'm scared that this is extremely wrong. https://play.golang.org/p/vG5lTcG3O4o

0, I believe, is absolutely a valid member for these things. FWIW that string is not empty but it does contain invisible 0-byte charcters. I'm way out of my element here, I have no idea what a b'' string is in cockroach and how exactly we treat it but I am scared about some bad behavior trying to round-trip this. Can we get a domain area expert to wave me off?


pkg/sql/type_change.go, line 851 at r2 (raw file):

		//  		SELECT unnest(c1) FROM [SELECT %d AS t]
		// 		UNION
		//			SELECT unnest(c2) FROM [SELECT %d AS t]

nit: spacing


pkg/sql/type_change.go, line 895 at r2 (raw file):

		}
		if len(rows) > 0 {
			return errors.Newf("could not remove enum value %q as it is being used by table %q",

nit: grab a fully qualified name.

Should we put a condition failure pgcode in here?

Copy link
Collaborator Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @otan)


pkg/sql/type_change.go, line 733 at r2 (raw file):

Previously, ajwerner wrote…
	var byteRep strings.Builder
	byteRep.WriteString("b'")
	for _, b := range bytes {
		byteRep.WriteByte(b)
	}
	byteRep.WriteString("'")
	return byteRep.String()
}

How tested is this? I'm scared that this is extremely wrong. https://play.golang.org/p/vG5lTcG3O4o

0, I believe, is absolutely a valid member for these things. FWIW that string is not empty but it does contain invisible 0-byte charcters. I'm way out of my element here, I have no idea what a b'' string is in cockroach and how exactly we treat it but I am scared about some bad behavior trying to round-trip this. Can we get a domain area expert to wave me off?

I think we may be fine because the way we generate these physical representations, specifically

if mid == p {
, ensures that we never end up with a bunch of zeros as the bytes representation.

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @otan)


pkg/sql/type_change.go, line 733 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I think we may be fine because the way we generate these physical representations, specifically

if mid == p {
, ensures that we never end up with a bunch of zeros as the bytes representation.

But wait, if I keep saying BEFORE won't it decrement to 1? I guess what I'm saying is less that 0 is itself specifically the problem but rather that these strings don't seem obviously to carry a valid encoding. What is b and can somebody confirm it works correctly in binary strings? What about across the wire

Previously, when dropping an enum value, we weren't validating if the
enum value was used in a column of array type. This patch fixes the bug.

Fixes cockroachdb#60004

Release justification: bug fix to new functionality
Release note: None
@arulajmani arulajmani force-pushed the validate-array-types-fr branch from 8f8526c to fe888db Compare March 15, 2021 17:55
Copy link
Collaborator Author

@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.

Fixed the byte string stuff as per what we discussed on Slack. TFTR!

bors r=ajwerner

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

@craig craig bot merged commit ae3a358 into cockroachdb:master Mar 15, 2021
@craig
Copy link
Contributor

craig bot commented Mar 15, 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: ALTER TYPE ... DROP VALUE doesn't account for array type usages
3 participants