-
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
executor, expression: support Chunk in ProjectionExec #5178
Conversation
/run-all-tests |
func EvalExprsToChunk(ctx context.Context, exprs []Expression, input, output *chunk.Chunk) error { | ||
sc := ctx.GetSessionVars().StmtCtx | ||
for rowID, length := 0, input.NumRows(); rowID < length; rowID++ { | ||
for colID, expr := range exprs { |
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.
It would be more cache friendly If we move exprs
range to outer for loop.
expression/expression.go
Outdated
} | ||
|
||
func evalOneCell(sc *variable.StatementContext, expr Expression, input, output *chunk.Chunk, rowID, colID int) error { | ||
switch fieldType, evalType := expr.GetType(), expr.GetType().EvalType(); evalType { |
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.
The EvalType
is constant for every row, so we can loop all the rows under a certain eval type case.
LGTM |
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.
LGTM
res, isNull, err := expr.EvalInt(input.GetRow(rowID), sc) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} else if isNull { |
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.
Save this else.
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.
ok, I'll do it in the next pr
} | ||
case types.ETReal: | ||
res, isNull, err := expr.EvalReal(input.GetRow(rowID), sc) | ||
if err != nil { |
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.
ditto
To simplify code, I haven't support vectorized expression evaluation here, to support it, we have to check whether there exists some special expressions, I'll do it in the near future.
Here is an example that we have to evaluate expressions row by row:
Main changes:
ProjectionExec
support chunk and add implement functionNextChunk
.EvalExprsToChunk
in package expression to evaluate a list of expression based on an input Chunk and append all the result to an output Chunk. We can further improve it to evaluate output Chunk column by column, ie. support vectorized expression evaluation.newChunk
to interfaceexecutor