Skip to content

Commit 6c05044

Browse files
committed
sqlsmith: fix potential panic when creating stats on 0-column table
This commit avoids a panic by adding a check for 0 columns before calling rand.Intn(len(columns)). There is no release note since this is a test-only change. Release note: None
1 parent e06b5d1 commit 6c05044

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/internal/sqlsmith/relational.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,9 @@ func makeCreateStats(s *Smither) (tree.Statement, bool) {
19401940
s.rnd.Shuffle(len(columns), func(i, j int) {
19411941
columns[i], columns[j] = columns[j], columns[i]
19421942
})
1943-
columns = columns[0:s.rnd.Intn(len(columns))]
1943+
if len(columns) > 0 {
1944+
columns = columns[0 : s.rnd.Intn(len(columns))+1]
1945+
}
19441946
}
19451947

19461948
var options tree.CreateStatsOptions

0 commit comments

Comments
 (0)