From f6aa990842ec00d98273acacc816c3028bad3294 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 7 Nov 2025 14:03:25 +0800 Subject: [PATCH] expression: Clone scalar function when to check the equivalence of the expression (#64298) close pingcap/tidb#64156 --- pkg/expression/scalar_function.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/expression/scalar_function.go b/pkg/expression/scalar_function.go index 1f80b3cae0..fb415064fa 100644 --- a/pkg/expression/scalar_function.go +++ b/pkg/expression/scalar_function.go @@ -404,8 +404,10 @@ func assertCheckHashCode(sf *ScalarFunction) { intest.Assert(intest.InTest) copyhashcode := make([]byte, len(sf.hashcode)) copy(copyhashcode, sf.hashcode) - ReHashCode(sf) - intest.Assert(bytes.Equal(sf.hashcode, copyhashcode), "HashCode should not change after ReHashCode is called") + // avoid data race in the plan cache + s := sf.Clone().(*ScalarFunction) + ReHashCode(s) + intest.Assert(bytes.Equal(s.hashcode, copyhashcode), "HashCode should not change after ReHashCode is called") } // IsCorrelated implements Expression interface.