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

fix a bug that nullable unique index can not find null values using index. #7163

Merged
merged 6 commits into from
Jul 27, 2018
Merged

fix a bug that nullable unique index can not find null values using index. #7163

merged 6 commits into from
Jul 27, 2018

Conversation

winkyao
Copy link
Contributor

@winkyao winkyao commented Jul 26, 2018

What have you changed? (mandatory)

Append 0 to the EndKey of the 'Is Null' index range. To make unique-key range [null, null] to be a scan rather than point-get in tikv.

See https://github.com/pingcap/tidb/blob/master/store/mockstore/mocktikv/executor.go#L289, and it will judge the range as point-get by:

// IsPoint checks if the key range represents a point.
func (r *KeyRange) IsPoint() bool {
	return bytes.Equal(r.StartKey.PrefixNext(), r.EndKey)
}

What is the type of the changes? (mandatory)

  • Bug fix (non-breaking change which fixes an issue)

How has this PR been tested? (mandatory)

UT

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

no

Does this PR affect tidb-ansible update? (mandatory)

no

Does this PR need to be added to the release notes? (mandatory)

no

Refer to a related PR or issue link (optional)

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

@winkyao winkyao added the type/bugfix This PR fixes a bug. label Jul 26, 2018
@winkyao
Copy link
Contributor Author

winkyao commented Jul 26, 2018

@coocood @winoros PTAL

var hasNull bool
for _, highVal := range ran.HighVal {
if highVal.IsNull() {
hasNull = true
Copy link
Member

Choose a reason for hiding this comment

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

We could break at once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -67,6 +67,10 @@ func (ran *Range) IsPoint(sc *stmtctx.StatementContext) bool {
if cmp != 0 {
return false
}

if a.IsNull() && b.IsNull() {
Copy link
Member

Choose a reason for hiding this comment

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

Since cmp is 0. Compare once is enough?

}

if hasNull {
// append 0 to make unique-key range [null, null] to be a scan rather than point-get.
Copy link
Member

Choose a reason for hiding this comment

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

Capitalize first character.

@winoros winoros added the sig/execution SIG execution label Jul 26, 2018
@winkyao
Copy link
Contributor Author

winkyao commented Jul 26, 2018

@winoros PTAL

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm

@winoros winoros added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 26, 2018
@winkyao
Copy link
Contributor Author

winkyao commented Jul 27, 2018

@coocood PTAL

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala
Copy link
Contributor

/run-all-tests

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 27, 2018
@coocood
Copy link
Member

coocood commented Jul 27, 2018

LGTM

@winkyao
Copy link
Contributor Author

winkyao commented Jul 27, 2018

/run-all-tests

@winkyao
Copy link
Contributor Author

winkyao commented Jul 27, 2018

/run-unit-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants