diff --git a/expression/scalar_function.go b/expression/scalar_function.go index 9767d3b3866f0..3b4f380a4a265 100644 --- a/expression/scalar_function.go +++ b/expression/scalar_function.go @@ -440,7 +440,7 @@ func (sf *ScalarFunction) EvalJSON(ctx sessionctx.Context, row chunk.Row) (types // HashCode implements Expression interface. func (sf *ScalarFunction) HashCode(sc *stmtctx.StatementContext) []byte { - if sc.CanonicalHashCode { + if sc != nil && sc.CanonicalHashCode { if len(sf.canonicalhashcode) > 0 { return sf.canonicalhashcode }