@@ -12,6 +12,7 @@ import (
1212 "strings"
1313 "sync"
1414 "time"
15+ "unicode"
1516
1617 "connectrpc.com/connect"
1718 gonanoid "github.com/matoous/go-nanoid/v2"
@@ -23,6 +24,7 @@ import (
2324 "golang.org/x/net/http2/h2c"
2425 "vitess.io/vitess/go/mysql"
2526 "vitess.io/vitess/go/sqlescape"
27+ "vitess.io/vitess/go/sqltypes"
2628
2729 "github.com/mattrobenolt/ps-http-sim/internal/session"
2830 "github.com/mattrobenolt/ps-http-sim/internal/vitess"
@@ -218,6 +220,31 @@ func runTCPProxy() error {
218220 return nil
219221}
220222
223+ func isQueryFiltered (query string ) bool {
224+ const minLength = 4
225+ if len (query ) < minLength {
226+ return false
227+ }
228+ query = strings .TrimSpace (query )
229+ if len (query ) < minLength {
230+ return false
231+ }
232+
233+ // we want to explicitly filter out `SET @@boost_cached_queries = true` for now
234+ if strings .EqualFold (query [:minLength ], "set " ) {
235+ query = strings .TrimLeftFunc (query [minLength :], unicode .IsSpace )
236+ return strings .HasPrefix (query , "@@boost_cached_queries" )
237+ }
238+
239+ // prevent any special `USE @replica` since that isn't going to work locally
240+ if strings .EqualFold (query [:minLength ], "use " ) {
241+ query = strings .TrimLeftFunc (query [minLength :], unicode .IsSpace )
242+ return strings .ContainsRune (query , '@' )
243+ }
244+
245+ return false
246+ }
247+
221248func init () {
222249 // Vitess doesn't play nicely, so replace the entire default flagset
223250 flag .CommandLine = commandLine
@@ -362,11 +389,19 @@ func (server) Execute(
362389 }
363390 defer returnConn (conn )
364391
365- ll .Info ("ok" )
366-
367392 start := time .Now ()
368- // This is a gross simplificiation, but is likely sufficient
369- qr , err := conn .ExecuteFetch (query , int (* flagMySQLMaxRows ), true )
393+
394+ var qr * sqltypes.Result
395+ if isQueryFiltered (query ) {
396+ qr = & sqltypes.Result {}
397+ err = nil
398+ ll .Info ("ignored" )
399+ } else {
400+ // This is a gross simplificiation, but is likely sufficient
401+ qr , err = conn .ExecuteFetch (query , int (* flagMySQLMaxRows ), true )
402+ ll .Info ("ok" )
403+ }
404+
370405 timing := time .Since (start )
371406 session .Update (qr , sess )
372407
0 commit comments