-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Compare DATE column with INT value result in NULL and wrong result #17868
Comments
/pick-up |
Pick up success. |
The root cause of this issue is about two parts: 1. // at scalar_function.go: line 326
func (sf *ScalarFunction) Eval(row chunk.Row) (d types.Datum, err error) {
...
switch tp, evalType := sf.GetType(), sf.GetType().EvalType(); evalType {
...
case types.ETDatetime, types.ETTimestamp:
res, isNull, err = sf.EvalTime(sf.GetCtx(), row)
...
}
// as long as err != nil, the returned Datum will be set to null
if isNull || err != nil {
d.SetNull()
return d, err
}
d.SetValue(res, sf.RetType)
return
} In the expression Therefore, At 2. All Even if we modify Because all // builtin_cast.go: line 571
func (b *builtinCastIntAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNull bool, err error) {
...
res, err = types.ParseTimeFromNum(b.ctx.GetSessionVars().StmtCtx, val, b.tp.Tp, int8(b.tp.Decimal))
if err != nil {
// isNull returned as true, but res is types.ZeroTime
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
}
...
} So cast So far I cannot find a good solution. Any suggestions? @qw4990 @zhangysh1995 |
@LENSHOOD I found a related description in MySQL 8 documentation:
It seems it should do a
Which will further call
At last the value is converted to a number: func (b *builtinCastTimeAsIntSig) evalInt(row chunk.Row) (res int64, isNull bool, err error) {
// extract the value
val, isNull, err := b.args[0].EvalTime(b.ctx, row)
if isNull || err != nil {
return res, isNull, err
}
// not sure what is done here
sc := b.ctx.GetSessionVars().StmtCtx
t, err := val.RoundFrac(sc, types.DefaultFsp)
if err != nil {
return res, false, err
}
// convert to a numer
res, err = t.ToNumber().ToInt()
return res, false, err
} As long as |
@LENSHOOD You did not submit PR within 7 days, so give up automatically. |
In TiDB, the comparison logic is transfer constant (at this case num "1") to the column type ("date"), so when planner generate logic plan from AST, it will choose related transfer function by comparison pair, we can see this logic at 'foldConstant()' function. Therefore, planner will transfer int to date rather than date to int, but the num 1 is not a valid date num... |
Please edit this comment or add a new comment to complete the following informationNot a bug
Duplicate bug
BugNote: Make Sure that 'component', and 'severity' labels are added 1. Root Cause Analysis (RCA) (optional)2. Symptom (optional)3. All Trigger Conditions (optional)4. Workaround (optional)5. Affected versions6. Fixed versions |
Description
Bug Report
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. Affected version (Required)
Reproducible on master branch:
5. Root Cause Analysis
SIG slack channel
#sig-exec
Score
Mentor
The text was updated successfully, but these errors were encountered: