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: Remove unnecessary constraints check in show create #40417

Merged
merged 1 commit into from
Sep 5, 2019

Conversation

rohany
Copy link
Contributor

@rohany rohany commented Sep 3, 2019

The show create table function would not display a zone configuration
if the constraints list was empty. However, this isn't a valid check
because the constraints list could be empty but other fields set.

Release note: None

@rohany rohany requested review from solongordon and a team September 3, 2019 15:13
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@solongordon solongordon 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 @rohany and @solongordon)


pkg/sql/crdb_internal.go, line 1221 at r1 (raw file):

				if zoneConfig.RangeMinBytes != nil || zoneConfig.RangeMaxBytes != nil ||
					zoneConfig.NumReplicas != nil || len(zoneConfig.Constraints) != 0 ||
					len(zoneConfig.LeasePreferences) != 0 {

This looks brittle. If anyone adds a new field to ZoneConfig and doesn't update this logic it'll be broken. Would it work to just compare to an empty config.ZoneConfig{} instead?

@rohany
Copy link
Contributor Author

rohany commented Sep 4, 2019

I just tried, and it doesn't seem like we can. The arrays inside of the zoneConfig can't be compared, so an error is thrown at compile time. A better solution might be to define an equality function on zone configs, and then drop a comment to update that? Or define a function isEmptyZoneConfig and then update that when the zoneConfig struct changes.

@solongordon
Copy link
Contributor

If I'm not mistaken, ZoneConfig should be a protobuf-generated struct which already comes with an Equal method built in.

@rohany
Copy link
Contributor Author

rohany commented Sep 4, 2019

Oh sweet -- i didnt know proto did that for us. Let me change that.

The show create table function would not display a zone configuration
if the constraints list was empty. However, this isn't a valid check
because the constraints list could be empty but other fields set. We
instead need to check that all the fields are default/empty values
before not showing anything in the create statements.

Release note: None
@rohany
Copy link
Contributor Author

rohany commented Sep 4, 2019

Alright, that looks like it worked. PTAL

@rohany rohany requested a review from solongordon September 5, 2019 14:40
Copy link
Contributor

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

Lovely

@rohany
Copy link
Contributor Author

rohany commented Sep 5, 2019

bors r+

craig bot pushed a commit that referenced this pull request Sep 5, 2019
40417: sql: Remove unnecessary constraints check in show create r=rohany a=rohany

The show create table function would not display a zone configuration
if the constraints list was empty. However, this isn't a valid check
because the constraints list could be empty but other fields set.

Release note: None

40441: storage: assert zero HardState.Commit on replica creation r=nvanbenschoten a=nvanbenschoten

An uninitialized replica should never have a commit index in its
HardState. And yet, we observed in #40213 that (likely) due to a
missing Range deletion tombstone, this invariant can be violated
in practice.

This assertion will allow us to catch this kind of violation without
the need for a MsgVote to race with a MsgSnap, hopefully making the
bug implied by #40213 easier to track down.

Release note: None

40472: opt: detect zero-cardinality semi/anti joins r=rytaft a=rytaft

This commit adds two normalization rules to detect zero-cardinality
semi and anti joins, and replace them with an empty `Values`.

It also updates the stats estimate to ensure that the row count of semi
and anti joins is not zero unless the cardinality is zero.

Fixes #40456
Fixes #40440
Fixes #40394

Release note: None

Co-authored-by: Rohan Yadav <[email protected]>
Co-authored-by: Nathan VanBenschoten <[email protected]>
Co-authored-by: Rebecca Taft <[email protected]>
@craig
Copy link
Contributor

craig bot commented Sep 5, 2019

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.

3 participants