-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Codex/plan cache hint only #67412
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
Codex/plan cache hint only #67412
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1642,6 +1642,9 @@ type SessionVars struct { | |
| // PlanCacheMaxPlanSize controls the maximum size of a plan that can be cached. | ||
| PlanCacheMaxPlanSize uint64 | ||
|
|
||
| // PlanCachePolicy controls how plan cache is enabled. | ||
| PlanCachePolicy string | ||
|
|
||
| // SessionPlanCacheSize controls the size of session plan cache. | ||
| SessionPlanCacheSize uint64 | ||
|
|
||
|
|
@@ -2455,6 +2458,7 @@ func NewSessionVars(hctx HookContext) *SessionVars { | |
| RegardNULLAsPoint: vardef.DefTiDBRegardNULLAsPoint, | ||
| AllowProjectionPushDown: vardef.DefOptEnableProjectionPushDown, | ||
| SkipMissingPartitionStats: vardef.DefTiDBSkipMissingPartitionStats, | ||
| PlanCachePolicy: vardef.DefTiDBPlanCachePolicy, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Read-only verification: find tests and related coverage for tidb_plan_cache_policy.
set -euo pipefail
echo "== References in implementation =="
rg -n -C2 'tidb_plan_cache_policy|PlanCachePolicy|DefTiDBPlanCachePolicy|hint_only|USE_PLAN_CACHE'
echo
echo "== References in Go tests =="
rg -n -C2 'tidb_plan_cache_policy|PlanCachePolicy|hint_only|USE_PLAN_CACHE' --iglob '*_test.go'
echo
echo "== References in SQL/integration test assets =="
rg -n -C2 'tidb_plan_cache_policy|hint_only|USE_PLAN_CACHE' --iglob '*.sql' --iglob '*.result' --iglob '*.test'Repository: pingcap/tidb Length of output: 9835 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Test function containing tidb_plan_cache_policy =="
sed -n '1810,1860p' pkg/planner/core/casetest/plancache/plan_cache_suite_test.go
echo
echo "== Looking for test function name around line 1820 =="
sed -n '1800,1830p' pkg/planner/core/casetest/plancache/plan_cache_suite_test.go | head -40
echo
echo "== Search for other test files that might test plan cache policy =="
fd -e go -e test -e sql -e result -e test | xargs grep -l 'tidb_plan_cache_policy' 2>/dev/null | head -20
echo
echo "== Check for default value test scenarios =="
rg -n 'DefTiDBPlanCachePolicy|PlanCachePolicyAll' --type go pkg/sessionctx/ | grep -i test
echo
echo "== Check if GLOBAL scope is tested for this variable =="
rg -n 'global.*tidb_plan_cache_policy|tidb_plan_cache_policy.*global' --type go -iRepository: pingcap/tidb Length of output: 4191 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== All test functions in plan_cache_suite_test.go =="
rg '^func Test' pkg/planner/core/casetest/plancache/plan_cache_suite_test.go | head -30
echo
echo "== Search for SQL/integration test files in plancache directory =="
fd -e sql -e result -e test . pkg/planner/core/casetest/plancache/ 2>/dev/null | head -20
echo
echo "== Check for any default value behavior test =="
rg -n "PlanCachePolicyAll|DefTiDBPlanCachePolicy" --type go pkg/planner/core/casetest/ -A 2 -B 2
echo
echo "== Check GLOBAL variable scope test in sysvar.go =="
sed -n '1580,1610p' pkg/sessionctx/variable/sysvar.go
echo
echo "== List all test files in plancache directory =="
ls -la pkg/planner/core/casetest/plancache/*.go | head -20Repository: pingcap/tidb Length of output: 1783 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check the sysvar.go definition again for scope =="
sed -n '1585,1600p' pkg/sessionctx/variable/sysvar.go
echo
echo "== Search for tests that set DEFAULT value or test 'all' policy =="
rg -n "PlanCachePolicyAll|tidb_plan_cache_policy.*all" --type go -i pkg/planner/ | head -20
echo
echo "== Search for tests that use GLOBAL scope (@@global. prefix) =="
rg -n "@@global.*tidb_plan_cache_policy|@@global.*PlanCachePolicy" --type go -i
echo
echo "== Check what the default value actually is =="
rg -n "DefTiDBPlanCachePolicy.*=" pkg/sessionctx/vardef/tidb_vars.go
echo
echo "== Look for any test that doesn't set the variable (implicit default test) =="
rg -n "func Test" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go -A 15 | grep -A 15 "TestInitLRUWithSystemVar"
echo
echo "== Search integration tests directory structure =="
find pkg -type d -name "*test*" | grep -i integ | head -10
find pkg -type f -name "*.test" | head -10
find pkg -type f -name "*.sql" | head -10Repository: pingcap/tidb Length of output: 1021 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check for SetGlobal function in sysvar.go for tidb_plan_cache_policy =="
sed -n '1585,1610p' pkg/sessionctx/variable/sysvar.go | cat -n
echo
echo "== Search for how other variables define SetGlobal =="
rg -n "SetGlobal:" pkg/sessionctx/variable/sysvar.go | head -5
echo
echo "== Check if tidb_plan_cache_policy has SetGlobal defined =="
sed -n '1585,1600p' pkg/sessionctx/variable/sysvar.go | grep -i setglobal || echo "No SetGlobal found"
echo
echo "== Search for tests that verify default behavior at session startup =="
rg -n "NewSessionVars|NewSessionWithOpts" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go | head -5
echo
echo "== Look at beginning of plan_cache_suite_test.go to see imports and setup =="
head -60 pkg/planner/core/casetest/plancache/plan_cache_suite_test.go
echo
echo "== Check if there are dedicated integration test suites =="
fd -type f -name '*.test' | head -20Repository: pingcap/tidb Length of output: 2649 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check for default SetGlobal behavior when SetGlobal is not defined =="
rg -n "SetGlobal.*nil\|if.*SetGlobal.*==\|SetGlobal.*==" pkg/sessionctx/variable/sysvar.go | head -10
echo
echo "== Look for how SetGlobal is used/handled in the system =="
rg -n "s.SetGlobal" pkg/sessionctx/variable/ | head -10
echo
echo "== Check if SetSession alone works for both GLOBAL and SESSION =="
rg -n "SetSession:" pkg/sessionctx/variable/sysvar.go | head -5
echo
echo "== Check how other GLOBAL|SESSION scope variables handle this =="
sed -n '1400,1450p' pkg/sessionctx/variable/sysvar.go | grep -A 10 "ScopeGlobal.*ScopeSession"
echo
echo "== Find the actual test of hint_only to understand what behavior is verified =="
sed -n '1800,1900p' pkg/planner/core/casetest/plancache/plan_cache_suite_test.goRepository: pingcap/tidb Length of output: 128 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Search for any test that reads the default value without setting it =="
rg -n "tidb_plan_cache_policy" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go -B 5 | head -40
echo
echo "== Check what TestInitLRUWithSystemVar does =="
sed -n '100,200p' pkg/planner/core/casetest/plancache/plan_cache_suite_test.go | grep -A 100 "func TestInitLRUWithSystemVar"
echo
echo "== Count how many times the variable is explicitly tested =="
rg -c "tidb_plan_cache_policy" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go
echo
echo "== Check if setvar_affect.go (which flags variable for invalidation) has tests =="
fd -name '*setvar*test*' pkg/sessionctx/variable/
echo
echo "== Search for sql test files for session variables =="
fd -path '*/sessionctx/*' -name '*.test' -o -name '*.sql' 2>/dev/null | head -10Repository: pingcap/tidb Length of output: 852 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check if variable supports GLOBAL SET by looking at SetGlobal in sysvar.go for this variable =="
sed -n '1585,1595p' pkg/sessionctx/variable/sysvar.go
echo
echo "== Search for any test that uses @@global.tidb_plan_cache_policy =="
rg '@@global.*tidb_plan_cache_policy' --type go
echo
echo "== Check integration/sql test files that might test plan cache =="
find . -path './tests' -prune -o -name '*.test' -type f -print 2>/dev/null | xargs grep -l 'tidb_plan_cache_policy' 2>/dev/null || echo "No .test files found with the variable"
echo
echo "== Check if there's an integration test suite for sessionctx =="
find . -path '*tests*' -name '*session*.test' -o -name '*variable*.test' 2>/dev/null | head -10
echo
echo "== Look at what the actual default value constant is =="
rg -n "DefTiDBPlanCachePolicy" pkg/sessionctx/vardef/tidb_vars.go -A 1 -B 1
echo
echo "== Check if there's documentation for test coverage patterns =="
cat AGENTS.md 2>/dev/null | grep -A 5 "session.*variable" || echo "No AGENTS.md guidance found"Repository: pingcap/tidb Length of output: 995 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check how GLOBAL scope variables work without explicit SetGlobal =="
rg -n "func.*applySetGlobal\|SetGlobal.*nil\|SetGlobal.*func" pkg/sessionctx/variable/sysvar.go | head -10
echo
echo "== Check if ScopeGlobal without SetGlobal gets default behavior =="
grep -B 5 -A 5 "ScopeGlobal.*SetSession.*func" pkg/sessionctx/variable/sysvar.go | head -30
echo
echo "== Look for how variables with only SetSession handle global scope =="
rg -n "Scope:.*Global.*Session.*SetSession:" pkg/sessionctx/variable/sysvar.go -A 5 | head -50
echo
echo "== Verify the default value constant =="
grep -n "PlanCachePolicyAll\|DefTiDBPlanCachePolicy" pkg/sessionctx/vardef/tidb_vars.go | head -5
echo
echo "== Check if there are any other tests besides the one we found =="
rg -n "\.PlanCachePolicy\|tidb_plan_cache_policy" pkg/planner/core/casetest/plancache/plan_cache_suite_test.goRepository: pingcap/tidb Length of output: 126 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== List all occurrences of tidb_plan_cache_policy in the entire codebase =="
rg 'tidb_plan_cache_policy' --type go --type sql -i
echo
echo "== Check the sysvar definition structure more carefully =="
sed -n '1580,1600p' pkg/sessionctx/variable/sysvar.go | head -30
echo
echo "== Look for how SetGlobal falls back when not defined =="
grep -r "SetGlobal == nil\|SetGlobal.*nil\|if.*SetGlobal" pkg/sessionctx/variable/ | head -10
echo
echo "== Check if variable is mentioned in testing docs or test helpers =="
find . -name "*test*helper*" -o -name "*test*util*" | xargs grep -l "session.*variable" 2>/dev/null | head -5Repository: pingcap/tidb Length of output: 2581 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check how SetGlobal is used in variable.go to understand the behavior =="
grep -B 5 -A 10 "if sv.SetGlobal != nil" pkg/sessionctx/variable/variable.go | head -30
echo
echo "== Check if GLOBAL scope for enum variables requires SetGlobal =="
rg -n "ScopeGlobal.*TypeEnum" pkg/sessionctx/variable/sysvar.go -A 5 | head -50
echo
echo "== Look for any integration test that might test this variable at GLOBAL scope =="
find . -name "*.test" -type f 2>/dev/null | xargs grep -l "set global tidb_plan_cache_policy" 2>/dev/null | head -5 || echo "No .test files found"
echo
echo "== Check documentation or comments about the scope limitation =="
sed -n '1645,1650p' pkg/sessionctx/variable/session.goRepository: pingcap/tidb Length of output: 6005 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check what happens when SetGlobal is nil and variable has ScopeGlobal =="
sed -n '1,100p' pkg/sessionctx/variable/variable.go | grep -A 30 "SetGlobalFromHook"
echo
echo "== Verify the complete SetGlobalFromHook logic =="
sed -n '230,270p' pkg/sessionctx/variable/variable.go
echo
echo "== Check if there's a test that tries to set GLOBAL scope =="
rg -n "set.*global.*tidb_plan_cache_policy" --type go -i
echo
echo "== Check setvar_affect.go to understand why this var is listed there =="
sed -n '110,125p' pkg/sessionctx/variable/setvar_affect.go
echo
echo "== Check if the variable has Aliases =="
rg -n "TiDBPlanCachePolicy.*Aliases\|Aliases.*PlanCachePolicy" pkg/sessionctx/variable/sysvar.goRepository: pingcap/tidb Length of output: 131 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Read variable.go SetGlobalFromHook function =="
sed -n '85,125p' pkg/sessionctx/variable/variable.go
echo
echo "== Check if SetGlobal being nil is handled =="
sed -n '85,150p' pkg/sessionctx/variable/variable.go
echo
echo "== Check the complete definition of SysVar struct =="
sed -n '1,150p' pkg/sessionctx/variable/sysvar_definition.go | head -80Repository: pingcap/tidb Length of output: 4660 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Find SetGlobalFromHook implementation =="
rg -n "func.*SetGlobalFromHook" pkg/sessionctx/variable/ -A 20
echo
echo "== Check if SetGlobal being nil causes issues or is handled =="
rg -n "sv.SetGlobal" pkg/sessionctx/variable/variable.go -B 3 -A 3
echo
echo "== Look at how the variable is initialized in session =="
sed -n '2450,2470p' pkg/sessionctx/variable/session.goRepository: pingcap/tidb Length of output: 3942 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Verify what happens when GLOBAL SET is called on this variable =="
rg -n "SetGlobalSysVarOnly" pkg/sessionctx/variable/ | head -10
echo
echo "== Check if there are any tests that verify default value 'all' =="
rg -n "PlanCachePolicyAll\|'all'" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go
echo
echo "== Check if any test tries to set GLOBAL scope =="
rg -n "@@global" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go
echo
echo "== Verify if DefTiDBPlanCachePolicy equals PlanCachePolicyAll =="
rg -n "DefTiDBPlanCachePolicy\|PlanCachePolicyAll" pkg/sessionctx/vardef/tidb_vars.go | grep -A 1 -B 1 "1675\|2128"Repository: pingcap/tidb Length of output: 1671 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Get line 1675 from tidb_vars.go to confirm default value =="
sed -n '1673,1677p' pkg/sessionctx/vardef/tidb_vars.go
echo
echo "== Get line 2128 from tidb_vars.go to confirm policy values =="
sed -n '2125,2132p' pkg/sessionctx/vardef/tidb_vars.go
echo
echo "== Count test occurrences in plan_cache_suite_test.go =="
wc -l pkg/planner/core/casetest/plancache/plan_cache_suite_test.go
echo
echo "== Verify TestPreparedPlanCacheHintOnlyWithBinding is the ONLY test using the variable =="
rg -n "tidb_plan_cache_policy\|PlanCachePolicy" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go | wc -l
echo
echo "== Check if there's a test that doesn't explicitly set the variable (uses default) =="
rg -n "TestNonPreparedPlanCacheBasically\|TestInitLRUWithSystemVar" pkg/planner/core/casetest/plancache/plan_cache_suite_test.go -A 30 | head -50Repository: pingcap/tidb Length of output: 1120 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Check if there are any .test files specifically for session variables =="
find . -path './tests' -name '*.test' -type f 2>/dev/null | xargs grep -l "tidb_plan_cache_policy" 2>/dev/null | head -5 || echo "No .test files found"
echo
echo "== Look for SQL integration test pattern in the repo =="
fd '.test' --max-depth 3 ./tests 2>/dev/null | head -10
echo
echo "== Confirm that TestPreparedPlanCacheHintOnlyWithBinding exists and what it covers =="
sed -n '1813,1900p' pkg/planner/core/casetest/plancache/plan_cache_suite_test.goRepository: pingcap/tidb Length of output: 5140 Confirm test coverage for Test coverage exists for SESSION scope (
Per guidelines for session variables, add targeted package tests for default value and GLOBAL scope, plus SQL integration tests for user-visible behavior. 🤖 Prompt for AI Agents |
||
| IndexLookUpPushDownPolicy: vardef.DefTiDBIndexLookUpPushDownPolicy, | ||
| OptPartialOrderedIndexForTopN: vardef.DefTiDBOptPartialOrderedIndexForTopN, | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.