|
9 | 9 | "context" |
10 | 10 | gosql "database/sql" |
11 | 11 | "fmt" |
| 12 | + "math/rand" |
12 | 13 | "os" |
13 | 14 | "path/filepath" |
14 | 15 | "strings" |
@@ -172,7 +173,7 @@ func runOneTLP( |
172 | 173 | continue |
173 | 174 | } |
174 | 175 |
|
175 | | - if err := runTLPQuery(t, conn, tlpSmither, logStmt); err != nil { |
| 176 | + if err := runTLPQuery(t, conn, rnd, tlpSmither, logStmt); err != nil { |
176 | 177 | t.Fatal(err) |
177 | 178 | } |
178 | 179 | } |
@@ -209,15 +210,29 @@ func runMutationStatement( |
209 | 210 | // partitioned query. See GenerateTLP for more information on TLP and the |
210 | 211 | // generated queries. |
211 | 212 | func runTLPQuery( |
212 | | - t task.Tasker, conn *gosql.DB, smither *sqlsmith.Smither, logStmt func(string), |
213 | | -) error { |
| 213 | + t task.Tasker, conn *gosql.DB, rnd *rand.Rand, smither *sqlsmith.Smither, logStmt func(string), |
| 214 | +) (err error) { |
214 | 215 | // Ignore panics from GenerateTLP. |
215 | 216 | defer func() { |
216 | 217 | if r := recover(); r != nil { |
217 | 218 | return |
218 | 219 | } |
219 | 220 | }() |
220 | 221 |
|
| 222 | + // Force generic query plans for 25% of queries. |
| 223 | + generic := false |
| 224 | + const forceGeneric = "SET plan_cache_mode = force_generic_plan" |
| 225 | + if rnd.Intn(4) == 0 { |
| 226 | + generic = true |
| 227 | + _, err = conn.Exec(forceGeneric) |
| 228 | + if err != nil { |
| 229 | + return err |
| 230 | + } |
| 231 | + defer func() { |
| 232 | + _, err = conn.Exec("RESET plan_cache_mode") |
| 233 | + }() |
| 234 | + } |
| 235 | + |
221 | 236 | unpartitioned, partitioned, args := smither.GenerateTLP() |
222 | 237 | combined := sqlsmith.CombinedTLP(unpartitioned, partitioned) |
223 | 238 |
|
@@ -263,6 +278,9 @@ func runTLPQuery( |
263 | 278 | } |
264 | 279 |
|
265 | 280 | diff := unsortedMatricesDiff(unpartitionedRows, partitionedRows) |
| 281 | + if generic { |
| 282 | + logStmt(forceGeneric) |
| 283 | + } |
266 | 284 | logStmt(unpartitioned) |
267 | 285 | logStmt(partitioned) |
268 | 286 | return errors.Newf( |
|
0 commit comments