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

planner: don't prune sleep function in LogicalProjection (#11927) #11953

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,8 @@ Projection_7 10000.00 root 6_aux_0
│ └─TableScan_9 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_12 10000.00 root data:TableScan_11
└─TableScan_11 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
explain select 1 from (select sleep(1)) t;
id count task operator info
Projection_4 1.00 root 1
└─Projection_5 1.00 root sleep(1)
└─TableDual_6 1.00 root rows:1
3 changes: 3 additions & 0 deletions cmd/explaintest/t/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,6 @@ explain select a in (select a+b from t t2 where t2.b = t1.b) from t t1;
drop table t;
create table t(a int not null, b int);
explain select a in (select a from t t2 where t2.b = t1.b) from t t1;

# test sleep in subquery
explain select 1 from (select sleep(1)) t;
12 changes: 6 additions & 6 deletions planner/core/rule_column_pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ func getUsedList(usedCols []*expression.Column, schema *expression.Schema) ([]bo
return used, nil
}

// exprHasSetVar checks if the expression has SetVar function.
func exprHasSetVar(expr expression.Expression) bool {
// exprHasSetVarOrSleep checks if the expression has SetVar function or Sleep function.
func exprHasSetVarOrSleep(expr expression.Expression) bool {
scalaFunc, isScalaFunc := expr.(*expression.ScalarFunction)
if !isScalaFunc {
return false
}
if scalaFunc.FuncName.L == ast.SetVar {
if scalaFunc.FuncName.L == ast.SetVar || scalaFunc.FuncName.L == ast.Sleep {
return true
}
for _, arg := range scalaFunc.GetArgs() {
if exprHasSetVar(arg) {
if exprHasSetVarOrSleep(arg) {
return true
}
}
return false
}

// PruneColumns implements LogicalPlan interface.
// If any expression has SetVar functions, we do not prune it.
// If any expression has SetVar function or Sleep function, we do not prune it.
func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column) error {
child := p.children[0]
used, err := getUsedList(parentUsedCols, p.schema)
Expand All @@ -80,7 +80,7 @@ func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column) er
}

for i := len(used) - 1; i >= 0; i-- {
if !used[i] && !exprHasSetVar(p.Exprs[i]) {
if !used[i] && !exprHasSetVarOrSleep(p.Exprs[i]) {
p.schema.Columns = append(p.schema.Columns[:i], p.schema.Columns[i+1:]...)
p.Exprs = append(p.Exprs[:i], p.Exprs[i+1:]...)
}
Expand Down