-
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: support more types to use IndexMerge to access MVIndex #40343
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e82fb9b
fixup
qw4990 5786961
Merge branch 'master' into mvindex-types
qw4990 65ee8ad
Merge remote-tracking branch 'upstream/master' into mvindex-types
qw4990 14d727d
fixup
qw4990 3f37257
fixup
qw4990 effe6e5
fixup
qw4990 9a64cc9
Merge branch 'master' into mvindex-types
qw4990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,7 +567,8 @@ func (ds *DataSource) generateIndexMergeJSONMVIndexPath(normalPathCnt int, filte | |
indexMergeIsIntersection = true | ||
jsonPath = sf.GetArgs()[0] | ||
var ok bool | ||
vals, ok = jsonArrayExpr2Exprs(ds.ctx, sf.GetArgs()[1]) | ||
//virCol.RetType | ||
vals, ok = jsonArrayExpr2Exprs(ds.ctx, sf.GetArgs()[1], virCol.GetType()) | ||
if !ok { | ||
continue | ||
} | ||
|
@@ -582,7 +583,7 @@ func (ds *DataSource) generateIndexMergeJSONMVIndexPath(normalPathCnt int, filte | |
} | ||
jsonPath = sf.GetArgs()[jsonPathIdx] | ||
var ok bool | ||
vals, ok = jsonArrayExpr2Exprs(ds.ctx, sf.GetArgs()[1-jsonPathIdx]) | ||
vals, ok = jsonArrayExpr2Exprs(ds.ctx, sf.GetArgs()[1-jsonPathIdx], virCol.GetType()) | ||
if !ok { | ||
continue | ||
} | ||
|
@@ -597,21 +598,6 @@ func (ds *DataSource) generateIndexMergeJSONMVIndexPath(normalPathCnt int, filte | |
if !jsonPath.Equal(ds.ctx, targetJSONPath) { | ||
continue // not on the same JSON col | ||
} | ||
// only support INT now | ||
// TODO: support more types | ||
if jsonPath.GetType().EvalType() == types.ETInt { | ||
continue | ||
} | ||
allInt := true | ||
// TODO: support using IndexLookUp to handle single-value cases. | ||
for _, v := range vals { | ||
if v.GetType().EvalType() != types.ETInt { | ||
allInt = false | ||
} | ||
} | ||
if !allInt { | ||
continue | ||
} | ||
|
||
// Step 2.3. Generate a IndexMerge Path of this filter on the current MVIndex. | ||
var partialPaths []*util.AccessPath | ||
|
@@ -642,16 +628,8 @@ func (ds *DataSource) generateIndexMergeJSONMVIndexPath(normalPathCnt int, filte | |
} | ||
|
||
// jsonArrayExpr2Exprs converts a JsonArray expression to expression list: cast('[1, 2, 3]' as JSON) --> []expr{1, 2, 3} | ||
func jsonArrayExpr2Exprs(sctx sessionctx.Context, jsonArrayExpr expression.Expression) ([]expression.Expression, bool) { | ||
// only support cast(const as JSON) | ||
arrayExpr, wrappedByJSONCast := unwrapJSONCast(jsonArrayExpr) | ||
if !wrappedByJSONCast { | ||
return nil, false | ||
} | ||
if _, isConst := arrayExpr.(*expression.Constant); !isConst { | ||
return nil, false | ||
} | ||
if expression.IsMutableEffectsExpr(arrayExpr) { | ||
func jsonArrayExpr2Exprs(sctx sessionctx.Context, jsonArrayExpr expression.Expression, targetType *types.FieldType) ([]expression.Expression, bool) { | ||
if !expression.IsInmutableExpr(jsonArrayExpr) || jsonArrayExpr.GetType().EvalType() != types.ETJson { | ||
return nil, false | ||
} | ||
|
||
|
@@ -660,15 +638,15 @@ func jsonArrayExpr2Exprs(sctx sessionctx.Context, jsonArrayExpr expression.Expre | |
return nil, false | ||
} | ||
if jsonArray.TypeCode != types.JSONTypeCodeArray { | ||
single, ok := jsonValue2Expr(jsonArray) // '1' -> []expr{1} | ||
single, ok := jsonValue2Expr(sctx, jsonArray, targetType) // '1' -> []expr{1} | ||
if ok { | ||
return []expression.Expression{single}, true | ||
} | ||
return nil, false | ||
} | ||
var exprs []expression.Expression | ||
for i := 0; i < jsonArray.GetElemCount(); i++ { // '[1, 2, 3]' -> []expr{1, 2, 3} | ||
expr, ok := jsonValue2Expr(jsonArray.ArrayGetElem(i)) | ||
expr, ok := jsonValue2Expr(sctx, jsonArray.ArrayGetElem(i), targetType) | ||
if !ok { | ||
return nil, false | ||
} | ||
|
@@ -677,16 +655,18 @@ func jsonArrayExpr2Exprs(sctx sessionctx.Context, jsonArrayExpr expression.Expre | |
return exprs, true | ||
} | ||
|
||
func jsonValue2Expr(v types.BinaryJSON) (expression.Expression, bool) { | ||
if v.TypeCode != types.JSONTypeCodeInt64 { | ||
// only support INT now | ||
// TODO: support more types | ||
func jsonValue2Expr(sctx sessionctx.Context, v types.BinaryJSON, targetType *types.FieldType) (expression.Expression, bool) { | ||
convertFunc := expression.ConvertJSON2Tp(targetType.EvalType()) | ||
if convertFunc == nil { | ||
return nil, false | ||
} | ||
datum, err := convertFunc(sctx.GetSessionVars().StmtCtx, v, targetType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please ref the usage in expression package |
||
if err != nil { | ||
return nil, false | ||
} | ||
val := v.GetInt64() | ||
return &expression.Constant{ | ||
Value: types.NewDatum(val), | ||
RetType: types.NewFieldType(mysql.TypeLonglong), | ||
Value: types.NewDatum(datum), | ||
RetType: targetType, | ||
}, true | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
how about use
FoldConst
?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.
No, I've tried this and found that
FoldConst
cannot handle expressions with nested Scalar-Functions likeadd(1, add(1, 1))
.