-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner: fix wrong count when is out of range with datetime #58661
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #58661 +/- ##
================================================
+ Coverage 73.0885% 73.7014% +0.6128%
================================================
Files 1676 1706 +30
Lines 463646 471767 +8121
================================================
+ Hits 338872 347699 +8827
+ Misses 103927 102525 -1402
- Partials 20847 21543 +696
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/retest |
/retest |
c1f5638
to
cda41cd
Compare
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@hawkingrei: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
valueTime := value.GetMysqlTime() | ||
var minTime types.Time | ||
switch valueTime.Type() { | ||
case mysql.TypeDate: | ||
minTime = types.NewTime(types.MinDatetime, mysql.TypeDate, types.DefaultFsp) | ||
case mysql.TypeDatetime: | ||
minTime = types.NewTime(types.MinDatetime, mysql.TypeDatetime, types.DefaultFsp) | ||
case mysql.TypeTimestamp: | ||
minTime = types.MinTimestamp | ||
} | ||
return float64(valueTime.Sub(UTCWithAllowInvalidDateCtx, &minTime).Duration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to change this.
We can directly use convertDatumToScalar()
to replace convertMysqlTimeDatumToScalar()
in this PR since the input is definitely of KindMysqlTime
.
@@ -239,6 +239,10 @@ func getIndexRowCountForStatsV2(sctx planctx.PlanContext, idx *statistics.Index, | |||
if debugTrace { | |||
debugTraceStartEstimateRange(sctx, indexRange, lb, rb, totalCount) | |||
} | |||
isMysqlTime := indexRange.LowVal[0].Kind() == types.KindMysqlTime && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this variable put so far from where it's used?
It can be moved to where it's used, and part of it can be merged with isSingleColRange
.
@@ -896,6 +897,22 @@ func (hg *Histogram) OutOfRange(val types.Datum) bool { | |||
chunk.Compare(hg.Bounds.GetRow(hg.Bounds.NumRows()-1), 0, &val) < 0 | |||
} | |||
|
|||
func convertTime(d *types.Datum) (*types.Datum, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some comments to explain why we need the extra conversion.
return nil | ||
} | ||
|
||
func TestIssue50080(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't (1) put the user schema in the public test case and (2) put such a large stats file with the code if unnecessary.
Possible suggestion:
- change the column names and put this case into
tests/integrationtest/
where the stats files are compressed. - put this case into the private repo.
What problem does this PR solve?
Issue Number: close #50080
Problem Summary:
What changed and how does it work?
First, we found that this issue shows a significant difference between datetime with an index and without an index. Therefore, one of the goals of this PR is to reduce the error between them.
The issue actually occurs at this point: we found that datetime is first specially encoded into a uint64, and this uint64 is different from a timestamp — it cannot be directly subtracted.
by
codec.EncodeKey
->encode
->EncodeMySQLTime
->ToPackedUint
,datetime
will become auint64
.If we only use this uint64 to compare values, it can still be manageable. However, directly using it to compare the difference in magnitude will cause issues.
but PR is only for single-column index.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.