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

unsupported aggregate function caused a "nil pointer dereference" panic #5339

Closed
XuHuaiyu opened this issue Dec 7, 2017 · 3 comments
Closed
Assignees
Labels
type/bug The issue is confirmed as a bug.

Comments

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Dec 7, 2017

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
./gentest.pl --dsn dbi:mysql:host=127.0.0.1:port=4000:user=root:database=test --grammar=conf/subquery_semijoin.yy --gendata --thread=1
SELECT DISTINCT BIT_OR( OUTR . `col_varchar_key` ) AS X FROM C AS OUTR WHERE ( OUTR . `col_int_key` , OUTR . `col_int_nokey` ) IN ( SELECT DISTINCT INNR . `col_int_nokey` AS X , INNR . `col_int_key` AS Y FROM CC AS INNR2 LEFT JOIN BB AS INNR ON ( INNR2 . `col_varchar_key` < INNR . `col_varchar_nokey` ) WHERE OUTR . `col_time_nokey` >= '2003-04-22' ORDER BY INNR . `col_int_nokey` ) AND OUTR . `col_varchar_nokey` IS NULL  ORDER BY OUTR . `col_varchar_nokey` , OUTR . `pk`;

aggissue.txt
2. What did you expect to see?

no error

  1. What did you see instead?
runtime error: invalid memory address or nil pointer dereference, goroutine 30848 [running]:
github.com/pingcap/tidb/server.(*clientConn).Run.func1(0xc420b04b00)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/server/conn.go:389 +0xfd
panic(0x1c4fa20, 0x274d2f0)
	/Users/xuhuaiyu/.gvm/gos/go1.9/src/runtime/panic.go:491 +0x283
github.com/pingcap/tidb/plan.(*planBuilder).buildAggregation(0xc4211ac1e0, 0x2561980, 0xc420c46780, 0xc421646290, 0x1, 0x1, 0x0, 0x0, 0x0, 0xc420cbae01, ...)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/plan/logical_plan_builder.go:100 +0x837
github.com/pingcap/tidb/plan.(*planBuilder).buildSelect(0xc4211ac1e0, 0xc4211ac140, 0x0, 0x0)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/plan/logical_plan_builder.go:1503 +0x992
github.com/pingcap/tidb/plan.(*planBuilder).build(0xc4211ac1e0, 0x253d900, 0xc4211ac140, 0x0, 0xc420c46660)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/plan/planbuilder.go:189 +0x55b
github.com/pingcap/tidb/plan.Optimize(0x254b7a0, 0xc4213b7a70, 0x253d900, 0xc4211ac140, 0x25497c0, 0xc4211e3950, 0x27be900, 0x0, 0x0, 0xc4205b3870)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/plan/optimizer.go:66 +0x12c
github.com/pingcap/tidb/executor.(*Compiler).Compile(0xc4205b3aa0, 0x2b571c8, 0xc420cbadc0, 0x2541740, 0xc4211ac140, 0x0, 0x0, 0x0)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/executor/compiler.go:44 +0x1eb
github.com/pingcap/tidb.(*session).Execute(0xc4213b7a70, 0x2b57208, 0xc420c46120, 0xc4201505a1, 0x1d9, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/session.go:761 +0xb8c
github.com/pingcap/tidb/server.(*TiDBContext).Execute(0xc421057650, 0x2b57208, 0xc420c46120, 0xc4201505a1, 0x1d9, 0xc4205b3c60, 0x1029ee9, 0xc4209b07b0, 0xc4205b3c80, 0x20)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/server/driver_tidb.go:196 +0x7c
github.com/pingcap/tidb/server.(*clientConn).handleQuery(0xc420b04b00, 0x2b57208, 0xc420c46120, 0xc4201505a1, 0x1d9, 0x0, 0x0)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/server/conn.go:741 +0x8d
github.com/pingcap/tidb/server.(*clientConn).dispatch(0xc420b04b00, 0xc4201505a1, 0x1da, 0x1da, 0x0, 0x0)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/server/conn.go:530 +0x511
github.com/pingcap/tidb/server.(*clientConn).Run(0xc420b04b00)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/server/conn.go:412 +0x18a
github.com/pingcap/tidb/server.(*Server).onConn(0xc4203fce40, 0x2547620, 0xc4202dbb60)
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/server/server.go:315 +0x144
created by github.com/pingcap/tidb/server.(*Server).Run
	/Users/xuhuaiyu/Development/GOPATH/src/github.com/pingcap/tidb/server/server.go:261 +0x496
  1. What version of TiDB are you using (tidb-server -V)?

648e51d19e51120e9158f6333c060f17260b7ea6

@XuHuaiyu XuHuaiyu added the type/bug The issue is confirmed as a bug. label Dec 7, 2017
@zz-jason
Copy link
Member

zz-jason commented Dec 7, 2017

in expression/aggregation/aggregation.go:

 82 // NewAggFunction creates a new Aggregation.
 83 func NewAggFunction(funcType string, funcArgs []expression.Expression, distinct bool) Aggregation {
 84     switch tp := strings.ToLower(funcType); tp {
 85     case ast.AggFuncSum:
 86         return &sumFunction{aggFunction: newAggFunc(tp, funcArgs, distinct)}
 87     case ast.AggFuncCount:
 88         return &countFunction{aggFunction: newAggFunc(tp, funcArgs, distinct)}
 89     case ast.AggFuncAvg:
 90         return &avgFunction{aggFunction: newAggFunc(tp, funcArgs, distinct)}
 91     case ast.AggFuncGroupConcat:
 92         return &concatFunction{aggFunction: newAggFunc(tp, funcArgs, distinct)}
 93     case ast.AggFuncMax:
 94         return &maxMinFunction{aggFunction: newAggFunc(tp, funcArgs, distinct), isMax: true}
 95     case ast.AggFuncMin:
 96         return &maxMinFunction{aggFunction: newAggFunc(tp, funcArgs, distinct), isMax: false}
 97     case ast.AggFuncFirstRow:
 98         return &firstRowFunction{aggFunction: newAggFunc(tp, funcArgs, distinct)}
 99     case ast.AggFuncBitXor:
100         return &bitXorFunction{aggFunction: newAggFunc(tp, funcArgs, distinct)}
101     case ast.AggFuncBitAnd:
102         return &bitAndFunction{aggFunction: newAggFunc(tp, funcArgs, distinct)}
103     }
104     return nil
105 }

BIT_OR is not supported yet, so we got a nil pointer after NewAggFunction and paniced during the following procession.

@zz-jason
Copy link
Member

zz-jason commented Dec 7, 2017

#5145 should fix this.

By the way, we should throw an error in NewAggFunction or just panic here in case there is an unsupported aggregation function.

@zz-jason zz-jason self-assigned this Dec 7, 2017
@zz-jason zz-jason changed the title unexpected runtime error occured unsupported aggregate function caused a "nil pointer dereference" panic Dec 8, 2017
@zz-jason
Copy link
Member

  1. bit_xor is supported now.
  2. we will not panic when a aggregation function is not supported now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

2 participants