Skip to content

assertion HashCode should not change after ReHashCode is called #64156

@hawkingrei

Description

@hawkingrei

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

run TestInstancePlanCacheConcurrencyComp

2. What did you expect to see? (Required)

3. What did you see instead (Required)

panic: assert failed, HashCode should not change after ReHashCode is called [recovered]
	panic: assert failed, HashCode should not change after ReHashCode is called
goroutine 2120 [running]:
github.com/pingcap/tidb/pkg/executor.(*Compiler).Compile.func1()
	pkg/executor/compiler.go:64 +0x4e8
panic({0x7d11480?, 0xc00f36cbb0?})
	GOROOT/src/runtime/panic.go:791 +0x132
github.com/pingcap/tidb/pkg/util/intest.doPanic(...)
	pkg/util/intest/assert_common.go:58
github.com/pingcap/tidb/pkg/util/intest.doAssert(...)
	pkg/util/intest/assert_common.go:30
github.com/pingcap/tidb/pkg/util/intest.Assert(...)
	pkg/util/intest/assert.go:25
github.com/pingcap/tidb/pkg/expression.assertCheckHashCode(0xc006485650)
	pkg/expression/scalar_function.go:408 +0x2d4
github.com/pingcap/tidb/pkg/expression.(*ScalarFunction).Equal(0xc006485650, {0x931a940, 0xc00120f540}, {0x936f5e0?, 0xc0064856c0})
	pkg/expression/scalar_function.go:395 +0x225
github.com/pingcap/tidb/pkg/util/ranger.removeConditions.Contains.func1({0x936f5e0?, 0xc006485650?})
	pkg/expression/util.go:1144 +0xbc
slices.IndexFunc[...](...)
	GOROOT/src/slices/slices.go:109
slices.ContainsFunc[...]({0xc00f376420?, 0x2, 0x10}, 0xc00f367cb0?)
	GOROOT/src/slices/slices.go:124 +0x5f
github.com/pingcap/tidb/pkg/expression.Contains(...)
	pkg/expression/util.go:1140
github.com/pingcap/tidb/pkg/util/ranger.removeConditions({0x931a940, 0xc00120f540}, {0xc00f376440, 0x2, 0x2?}, {0xc00f376420, 0x2, 0x2})
	pkg/util/ranger/detacher.go:1136 +0x1d4
github.com/pingcap/tidb/pkg/util/ranger.ExtractEqAndInCondition(0xc00f362e00, {0xc002e329e0, 0x2, 0x2}, {0xc00723e620, 0x2, 0x2}, {0xc00f354fc0, 0x2, 0x2})
	pkg/util/ranger/detacher.go:840 +0x17c5
github.com/pingcap/tidb/pkg/util/ranger.(*rangeDetacher).detachCNFCondAndBuildRangeForIndex(0xc0015b0cd0, {0xc002e329e0, 0x2, 0x2}, {0xc00f36cb50, 0x2, 0x2}, 0x1)
	pkg/util/ranger/detacher.go:405 +0x105
github.com/pingcap/tidb/pkg/util/ranger.(*rangeDetacher).detachCondAndBuildRangeForCols(0xc0015b0cd0)
	pkg/util/ranger/detacher.go:1107 +0x3d5
github.com/pingcap/tidb/pkg/util/ranger.DetachCondAndBuildRangeForIndex(0xc0015b0f50?, {0xc002e329e0?, 0x4?, 0xc00f351e91?}, {0xc00723e620?, 0xc009734fea?, 0x2?}, {0xc00f354fc0, 0x2, 0x2}, ...)
	pkg/util/ranger/detacher.go:1042 +0xf0
github.com/pingcap/tidb/pkg/planner/core.buildRangeForIndexScan({0x932b970?, 0xc0016c0a10?}, 0xc00f3566c8)
	pkg/planner/core/plan_cache_rebuild.go:421 +0x167
github.com/pingcap/tidb/pkg/planner/core.rebuildRange({0x92fcb40, 0xc00f3566c8})
	pkg/planner/core/plan_cache_rebuild.go:105 +0x5b8
github.com/pingcap/tidb/pkg/planner/core.rebuildRange({0x92fddc0, 0xc00f37a900})
	pkg/planner/core/plan_cache_rebuild.go:115 +0x8e7
github.com/pingcap/tidb/pkg/planner/core.RebuildPlan4CachedPlan({0x92fddc0, 0xc00f37a900})
	pkg/planner/core/plan_cache_rebuild.go:38 +0xb7
github.com/pingcap/tidb/pkg/planner/core.adjustCachedPlan({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6fb88}, {0x92fddc0, 0xc00f37a900}, 0xc006485ce0, 0x0, 0x0, {0x0, ...}, ...)
	pkg/planner/core/plan_cache.go:318 +0x13f
github.com/pingcap/tidb/pkg/planner/core.GetPlanFromPlanCache({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6fb88}, 0x0, {0x932e8b0, 0xc0101f5b00}, 0xc00f37c600, {0xc00f376380, 0x2, ...})
	pkg/planner/core/plan_cache.go:241 +0x5e5
github.com/pingcap/tidb/pkg/planner.OptimizeExecStmt({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6fb88}, 0xc0015b16c0, {0x932e8b0, 0xc0101f5b00})
	pkg/planner/optimize.go:536 +0x545
github.com/pingcap/tidb/pkg/planner.Optimize({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6fb88}, 0xc0015b16c0, {0x932e8b0, 0xc0101f5b00})
	pkg/planner/optimize.go:184 +0x2bf
github.com/pingcap/tidb/pkg/executor.(*Compiler).Compile(0xc0015b19f8, {0x92c9390?, 0xdb1e160?}, {0x92ed9e0, 0xc010a863c0})
	pkg/executor/compiler.go:107 +0x6e5
github.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt(0xc008d6fb88, {0x92c9390?, 0xdb1e160?}, {0x92ed9e0, 0xc010a863c0})
	pkg/session/session.go:2205 +0xe1d
github.com/pingcap/tidb/pkg/testkit.(*TestKit).ExecWithContext(0xc002d16700, {0x92c9390, 0xdb1e160}, {0x888ea6e, 0x19}, {0x0, 0x0, 0x0})
	pkg/testkit/testkit.go:421 +0x1086
github.com/pingcap/tidb/pkg/testkit.(*TestKit).MustQueryWithContext(0xc002d16700, {0x92c9390, 0xdb1e160}, {0x888ea6e, 0x19}, {0x0, 0x0, 0x0})
	pkg/testkit/testkit.go:251 +0x26a
github.com/pingcap/tidb/pkg/testkit.(*TestKit).MustQuery(0xc002d16700, {0x888ea6e, 0x19}, {0x0, 0x0, 0x0})
	pkg/testkit/testkit.go:186 +0x106
pkg/planner/core/casetest/instanceplancache/instanceplancache_test.(*worker).run(0xc00664a360)
	pkg/planner/core/casetest/instanceplancache/concurrency_test.go:82 +0x60c
created by pkg/planner/core/casetest/instanceplancache/instanceplancache_test.testWithWorkers in goroutine 84
	pkg/planner/core/casetest/instanceplancache/concurrency_test.go:110 +0x365
panic: assert failed, HashCode should not change after ReHashCode is called [recovered]
	panic: assert failed, HashCode should not change after ReHashCode is called
goroutine 2119 [running]:
github.com/pingcap/tidb/pkg/executor.(*Compiler).Compile.func1()
	pkg/executor/compiler.go:64 +0x4e8
panic({0x7d11480?, 0xc00f4ffa20?})
	GOROOT/src/runtime/panic.go:791 +0x132
github.com/pingcap/tidb/pkg/util/intest.doPanic(...)
	pkg/util/intest/assert_common.go:58
github.com/pingcap/tidb/pkg/util/intest.doAssert(...)
	pkg/util/intest/assert_common.go:30
github.com/pingcap/tidb/pkg/util/intest.Assert(...)
	pkg/util/intest/assert.go:25
github.com/pingcap/tidb/pkg/expression.assertCheckHashCode(0xc006485650)
	pkg/expression/scalar_function.go:408 +0x2d4
github.com/pingcap/tidb/pkg/expression.(*ScalarFunction).Equal(0xc006485650, {0x931a940, 0xc00120f040}, {0x936f5e0?, 0xc0064856c0})
	pkg/expression/scalar_function.go:395 +0x225
github.com/pingcap/tidb/pkg/util/ranger.removeConditions.Contains.func1({0x936f5e0?, 0xc006485650?})
	pkg/expression/util.go:1144 +0xbc
slices.IndexFunc[...](...)
	GOROOT/src/slices/slices.go:109
slices.ContainsFunc[...]({0xc00ff3a2c0?, 0x2, 0x10}, 0xc00ff32d50?)
	GOROOT/src/slices/slices.go:124 +0x5f
github.com/pingcap/tidb/pkg/expression.Contains(...)
	pkg/expression/util.go:1140
github.com/pingcap/tidb/pkg/util/ranger.removeConditions({0x931a940, 0xc00120f040}, {0xc00ff3a2e0, 0x2, 0x2?}, {0xc00ff3a2c0, 0x2, 0x2})
	pkg/util/ranger/detacher.go:1136 +0x1d4
github.com/pingcap/tidb/pkg/util/ranger.ExtractEqAndInCondition(0xc00ff29180, {0xc002e329e0, 0x2, 0x2}, {0xc00723e620, 0x2, 0x2}, {0xc00ff1c760, 0x2, 0x2})
	pkg/util/ranger/detacher.go:840 +0x17c5
github.com/pingcap/tidb/pkg/util/ranger.(*rangeDetacher).detachCNFCondAndBuildRangeForIndex(0xc001e6ecd0, {0xc002e329e0, 0x2, 0x2}, {0xc00f4ff9c0, 0x2, 0x2}, 0x1)
	pkg/util/ranger/detacher.go:405 +0x105
github.com/pingcap/tidb/pkg/util/ranger.(*rangeDetacher).detachCondAndBuildRangeForCols(0xc001e6ecd0)
	pkg/util/ranger/detacher.go:1107 +0x3d5
github.com/pingcap/tidb/pkg/util/ranger.DetachCondAndBuildRangeForIndex(0xc001e6ef50?, {0xc002e329e0?, 0x4?, 0xc00ff26d11?}, {0xc00723e620?, 0xc009734fea?, 0x2?}, {0xc00ff1c760, 0x2, 0x2}, ...)
	pkg/util/ranger/detacher.go:1042 +0xf0
github.com/pingcap/tidb/pkg/planner/core.buildRangeForIndexScan({0x932b970?, 0xc001c1bc90?}, 0xc00f06f208)
	pkg/planner/core/plan_cache_rebuild.go:421 +0x167
github.com/pingcap/tidb/pkg/planner/core.rebuildRange({0x92fcb40, 0xc00f06f208})
	pkg/planner/core/plan_cache_rebuild.go:105 +0x5b8
github.com/pingcap/tidb/pkg/planner/core.rebuildRange({0x92fddc0, 0xc00ff366c0})
	pkg/planner/core/plan_cache_rebuild.go:115 +0x8e7
github.com/pingcap/tidb/pkg/planner/core.RebuildPlan4CachedPlan({0x92fddc0, 0xc00ff366c0})
	pkg/planner/core/plan_cache_rebuild.go:38 +0xb7
github.com/pingcap/tidb/pkg/planner/core.adjustCachedPlan({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6f8c8}, {0x92fddc0, 0xc00ff366c0}, 0xc006485ce0, 0x0, 0x0, {0x0, ...}, ...)
	pkg/planner/core/plan_cache.go:318 +0x13f
github.com/pingcap/tidb/pkg/planner/core.GetPlanFromPlanCache({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6f8c8}, 0x0, {0x932e8b0, 0xc010798c60}, 0xc00ff1ad80, {0xc00ff3a220, 0x2, ...})
	pkg/planner/core/plan_cache.go:241 +0x5e5
github.com/pingcap/tidb/pkg/planner.OptimizeExecStmt({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6f8c8}, 0xc001e6f6c0, {0x932e8b0, 0xc010798c60})
	pkg/planner/optimize.go:536 +0x545
github.com/pingcap/tidb/pkg/planner.Optimize({0x92c9390, 0xdb1e160}, {0x937ce00, 0xc008d6f8c8}, 0xc001e6f6c0, {0x932e8b0, 0xc010798c60})
	pkg/planner/optimize.go:184 +0x2bf
github.com/pingcap/tidb/pkg/executor.(*Compiler).Compile(0xc001e6f9f8, {0x92c9390?, 0xdb1e160?}, {0x92ed9e0, 0xc00f4efea0})
	pkg/executor/compiler.go:107 +0x6e5
github.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt(0xc008d6f8c8, {0x92c9390?, 0xdb1e160?}, {0x92ed9e0, 0xc00f4efea0})
	pkg/session/session.go:2205 +0xe1d
github.com/pingcap/tidb/pkg/testkit.(*TestKit).ExecWithContext(0xc00116ff10, {0x92c9390, 0xdb1e160}, {0x888ea6e, 0x19}, {0x0, 0x0, 0x0})
	pkg/testkit/testkit.go:421 +0x1086
github.com/pingcap/tidb/pkg/testkit.(*TestKit).MustQueryWithContext(0xc00116ff10, {0x92c9390, 0xdb1e160}, {0x888ea6e, 0x19}, {0x0, 0x0, 0x0})
	pkg/testkit/testkit.go:251 +0x26a
github.com/pingcap/tidb/pkg/testkit.(*TestKit).MustQuery(0xc00116ff10, {0x888ea6e, 0x19}, {0x0, 0x0, 0x0})
	pkg/testkit/testkit.go:186 +0x106
pkg/planner/core/casetest/instanceplancache/instanceplancache_test.(*worker).run(0xc00664a330)
	pkg/planner/core/casetest/instanceplancache/concurrency_test.go:82 +0x60c
created by pkg/planner/core/casetest/instanceplancache/instanceplancache_test.testWithWorkers in goroutine 84
	pkg/planner/core/casetest/instanceplancache/concurrency_test.go:110 +0x365

4. What is your TiDB version? (Required)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions