Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/cmd/generate-logictest/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func runExecBuildLogicTest(t *testing.T, file string) {
ForceProductionValues: true,{{end}}
// Disable the direct scans in order to keep the output of EXPLAIN (VEC)
// deterministic.
DisableDirectColumnarScans: true,
DisableDirectColumnarScans: true,{{ if not .ForceProductionValues }}
// ForceProductionValues is not set for this config, so we must
// explicitly disable optimizer perturbations to keep EXPLAIN output
// deterministic when COCKROACH_LOGIC_TEST_OPTIMIZER_METAMORPHIC is set.
DisableOptimizerPerturbations: true,{{end}}
}
logictest.RunLogicTest(t, serverArgs, configIdx, filepath.Join(execBuildLogicTestDir, file))
}
Expand All @@ -65,7 +69,8 @@ func runSqliteLogicTest(t *testing.T, file string) {
DisableUseMVCCRangeTombstonesForPointDeletes: true,
// Some sqlite tests with very low bytes limit value are too slow, so
// ensure 3 KiB lower bound.
BatchBytesLimitLowerBound: 3 << 10, // 3 KiB
BatchBytesLimitLowerBound: 3 << 10, // 3 KiB
DisableOptimizerPerturbations: true,
}
logictest.RunLogicTest(t, serverArgs, configIdx, filepath.Join(sqliteLogicTestDir, file))
}
Expand Down Expand Up @@ -188,7 +193,8 @@ func TestLogic_tmp(t *testing.T) {
{{- if .ExecBuildLogicTest }}
glob = filepath.Join(execBuildLogicTestDir, "_*")
serverArgs := logictest.TestServerArgs{
DisableWorkmemRandomization: true,
DisableWorkmemRandomization: true,
DisableOptimizerPerturbations: true,
}
logictest.RunLogicTests(t, serverArgs, configIdx, glob)
{{- end }}
Expand Down
54 changes: 52 additions & 2 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,24 @@ var (
)
sqlfmtLen = flag.Int("line-length", tree.DefaultPrettyCfg().LineWidth,
"target line length when using -rewrite-sql")

// metamorphicDisableOptRuleProbability and metamorphicOptimizerCostPerturbation
// mirror the testing_optimizer_cost_perturbation and
// testing_optimizer_disable_rule_probability session settings used by costfuzz and
// unoptimized-query-oracle. They are only applied when
// COCKROACH_LOGIC_TEST_OPTIMIZER_METAMORPHIC=true so that logictest files with
// fixed query plans are not perturbed during normal CI runs.
metamorphicDisableOptRuleProbability = metamorphic.ConstantWithTestChoice(
"logictest-disable-opt-rule-probability", float64(0), float64(0.5), float64(1.0))
// metamorphicOptimizerCostPerturbation mirrors the range used by costfuzz
// (see testing_optimizer_cost_perturbation). 0.1 exercises mild plan
// variation while 1.0 stress-tests extreme perturbations.
metamorphicOptimizerCostPerturbation = metamorphic.ConstantWithTestChoice(
"logictest-optimizer-cost-perturbation", float64(0), float64(0.1), float64(1.0))

logicTestOptimizerMetamorphicEnabled = envutil.EnvOrDefaultBool(
"COCKROACH_LOGIC_TEST_OPTIMIZER_METAMORPHIC", false)

disableOptRuleProbability = flag.Float64(
"disable-opt-rule-probability", 0,
"disable transformation rules in the cost-based optimizer with the given probability.")
Expand Down Expand Up @@ -1638,12 +1656,15 @@ func (t *logicTest) newCluster(
return st
}
setSQLTestingKnobs := func(knobs *base.TestingKnobs) {
disableProb, costPerturb := optimizerTestingKnobValues(
serverArgs, *disableOptRuleProbability, *optimizerCostPerturbation,
)
knobs.SQLEvalContext = &eval.TestingKnobs{
AssertBinaryExprReturnTypes: true,
AssertUnaryExprReturnTypes: true,
AssertFuncExprReturnTypes: true,
DisableOptimizerRuleProbability: *disableOptRuleProbability,
OptimizerCostPerturbation: *optimizerCostPerturbation,
DisableOptimizerRuleProbability: disableProb,
OptimizerCostPerturbation: costPerturb,
ForceProductionValues: serverArgs.ForceProductionValues,
UnsafeOverride: func() *bool {
v := t.allowUnsafe.Load()
Expand Down Expand Up @@ -4850,6 +4871,35 @@ type TestServerArgs struct {
BatchBytesLimitLowerBound int64
// If set, sql.distsql.direct_columnar_scans.enabled is set to false.
DisableDirectColumnarScans bool
// If set, testing optimizer perturbation knobs are forced to 0. This is
// needed for tests with fixed query plans in expected output (e.g. EXPLAIN
// tests and SQLite logic tests).
DisableOptimizerPerturbations bool
}

func optimizerTestingKnobValues(
serverArgs TestServerArgs, disableFlag, costFlag float64,
) (disableProb, costPerturb float64) {
disableProb = disableFlag
costPerturb = costFlag
if serverArgs.ForceProductionValues || serverArgs.DisableOptimizerPerturbations {
return 0, 0
}
if logicTestOptimizerMetamorphicEnabled {
// Only apply the metamorphic constant when no explicit non-zero value
// was passed via the command-line flag. This lets callers override the
// metamorphic behaviour (e.g. -disable-opt-rule-probability=0.3) while
// still getting metamorphic defaults in unattended runs. Note: the
// metamorphic constant itself may be 0 (one of its valid choices), in
// which case the assignment is a no-op.
if disableProb == 0 {
disableProb = metamorphicDisableOptRuleProbability
}
if costPerturb == 0 {
costPerturb = metamorphicOptimizerCostPerturbation
}
}
return disableProb, costPerturb
}

// RunLogicTests runs logic tests for all files matching the given glob.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/sql/sqlitelogictest/tests/3node-tenant/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/sql/sqlitelogictest/tests/fakedist/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/sql/sqlitelogictest/tests/local/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading