Skip to content

Commit d338105

Browse files
committed
roachtest/tlp: randomly force generic query plans
Generic query plans are now forced for 25% of TLP queries. Note that only one type of TLP query uses placeholders, which are required for "interesting" generic query plans, simple `SELECT .. WHERE ..` queries. Joins and grouping do not yet use placeholders. Fixes #128912 Release note: None
1 parent 650eac4 commit d338105

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pkg/cmd/roachtest/tests/tlp.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
gosql "database/sql"
1111
"fmt"
12+
"math/rand"
1213
"os"
1314
"path/filepath"
1415
"strings"
@@ -172,7 +173,7 @@ func runOneTLP(
172173
continue
173174
}
174175

175-
if err := runTLPQuery(t, conn, tlpSmither, logStmt); err != nil {
176+
if err := runTLPQuery(t, conn, rnd, tlpSmither, logStmt); err != nil {
176177
t.Fatal(err)
177178
}
178179
}
@@ -209,15 +210,29 @@ func runMutationStatement(
209210
// partitioned query. See GenerateTLP for more information on TLP and the
210211
// generated queries.
211212
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) {
214215
// Ignore panics from GenerateTLP.
215216
defer func() {
216217
if r := recover(); r != nil {
217218
return
218219
}
219220
}()
220221

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+
221236
unpartitioned, partitioned, args := smither.GenerateTLP()
222237
combined := sqlsmith.CombinedTLP(unpartitioned, partitioned)
223238

@@ -263,6 +278,9 @@ func runTLPQuery(
263278
}
264279

265280
diff := unsortedMatricesDiff(unpartitionedRows, partitionedRows)
281+
if generic {
282+
logStmt(forceGeneric)
283+
}
266284
logStmt(unpartitioned)
267285
logStmt(partitioned)
268286
return errors.Newf(

0 commit comments

Comments
 (0)