Skip to content
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

sqlsmith: randomly generate auto partial stats in sqlsmith tests #140057

Merged
merged 1 commit into from
Jan 31, 2025
Merged
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
15 changes: 10 additions & 5 deletions pkg/internal/sqlsmith/relational.go
Original file line number Diff line number Diff line change
Expand Up @@ -1865,21 +1865,24 @@ func makeCreateStats(s *Smither) (tree.Statement, bool) {

// Names slightly change behavior of statistics, so pick randomly between:
// ~50%: __auto__ (simulating auto stats)
// ~33%: random (simulating manual CREATE STATISTICS statements)
// ~17%: __auto_partial__ (simulating auto partial stats)
// ~17%: random (simulating manual CREATE STATISTICS statements)
// ~17%: blank (simulating manual ANALYZE statements)
var name tree.Name
switch s.d6() {
case 1, 2, 3:
name = jobspb.AutoStatsName
case 4, 5:
case 4:
name = jobspb.AutoPartialStatsName
case 5:
name = s.name("stats")
}

// Pick specific columns ~17% of the time. We only do this for simulated
// Pick specific columns ~8% of the time. We only do this for simulated
// manual CREATE STATISTICS statements because neither auto stats nor ANALYZE
// allow column selection.
var columns tree.NameList
if name != jobspb.AutoStatsName && name != "" && s.coin() {
if name != jobspb.AutoStatsName && name != jobspb.AutoPartialStatsName && name != "" && s.coin() {
for _, col := range table.Columns {
if !colinfo.IsSystemColumnName(string(col.Name)) {
columns = append(columns, col.Name)
Expand All @@ -1892,12 +1895,14 @@ func makeCreateStats(s *Smither) (tree.Statement, bool) {
}

var options tree.CreateStatsOptions
if name == jobspb.AutoStatsName {
if name == jobspb.AutoStatsName || name == jobspb.AutoPartialStatsName {
// For auto stats we always set throttling and AOST.
options.Throttling = 0.9
// For auto stats we use AOST -30s by default, but this will make things
// non-deterministic, so we use the smallest legal AOST instead.
options.AsOf = tree.AsOfClause{Expr: tree.NewStrVal("-0.001ms")}
// For auto partial stats we always set UsingExtremes.
options.UsingExtremes = name == jobspb.AutoPartialStatsName
} else if name == "" {
// ANALYZE only sets AOST.
options.AsOf = tree.AsOfClause{Expr: tree.NewStrVal("-0.001ms")}
Expand Down
Loading