Repository: vitessio/vitess
Pull request #9161 (2021-11-08 17:52:43)

Gen4: Fail cross-shard join query with aggregation and grouping
<!--
  Thank you for your contribution to the Vitess project.
  How to contribute: https://vitess.io/docs/contributing/
  Please first make sure there is an open Issue to discuss the feature/fix suggested in this PR.
  If this is a new feature, please mark the Issue as "RFC".
 -->

<!-- if this PR is Work in Progress please create it as a Draft Pull Request -->

## Description
<!-- A few sentences describing the overall goals of the pull request's commits. -->
<!-- If this is a bug fix and you think the fix should be backported, please write so. -->

Gen4 produces a plan for join queries having aggregation on grouping where the join is handled at VTGate. This was producing the wrong query plan. 
v3 fails for these types of queries already.

## Related Issue(s)
<!-- List related issues and pull requests. If this PR fixes an issue, please add it using Fixes #????  -->

- Fixes https://github.com/vitessio/vitess/issues/9053

## Checklist
- [X] Should this PR be backported? 12.0
- [X] Tests were added or are not required
- [X] Documentation was added or is not required

## Deployment Notes
<!-- Notes regarding deployment of the contained body of work. These should note any db migrations, etc. -->


Patch:
diff --git a/doc/internal/ReleaseInstructions.md b/doc/internal/ReleaseInstructions.md
index 649eb8d411..a2afbcdc93 100644
--- a/doc/internal/ReleaseInstructions.md
+++ b/doc/internal/ReleaseInstructions.md
@@ -117,7 +117,7 @@ The release cutover section is divided in 4 steps:
 
 * Build a Release Notes document using the Makefile: 
     ```shell
-    make VERSION="v12.0.0" FROM="<ref/SHA of the latest tag for v11>" TO="<ref/SHA of main>" SUMMARY="./doc/releasenotes/12_0_0_summary.md" release-notes
+    make VERSION="v12.0.0" FROM="<ref/SHA of the latest tag for v11>" TO="<ref/SHA of main>" release-notes
     ```
 
 * Check to make sure all labels and categories set for each PR.
@@ -165,7 +165,7 @@ The release cutover section is divided in 4 steps:
 
 * Build a Release Notes document using the Makefile:
     ```shell
-    make VERSION="v12.0.0" FROM="<ref/SHA of the latest tag for v11>" TO="<ref/SHA of main>" SUMMARY="./doc/releasenotes/12_0_0_summary.md" release-notes
+    make VERSION="v12.0.0" FROM="<ref/SHA of the latest tag for v11>" TO="<ref/SHA of main>" release-notes
     ```
 
 * Check to make sure all labels and categories set for each PR.
diff --git a/doc/releasenotes/12_0_0_summary.md b/doc/releasenotes/12_0_0_summary.md
index 54c1d5e1ce..8a01147da2 100644
--- a/doc/releasenotes/12_0_0_summary.md
+++ b/doc/releasenotes/12_0_0_summary.md
@@ -27,14 +27,6 @@ zone1-0000000101 sourcekeyspace 0 rdonly 192.168.0.134:15101 192.168.0.134:17101
 zone1-0000000102 sourcekeyspace 0 replica 192.168.0.134:15102 192.168.0.134:17102 [] <null>
 zone1-0000000103 sourcekeyspace 0 rdonly 192.168.0.134:15103 192.168.0.134:17103 [] <null>
 ```
-## Default Behaviour Changes
-
-### Enabling reserved connections
-Use of reserved connections are controlled by the vtgate flag `-enable_system_settings`. This flag has traditionally defaulted to false (or off) in release versions (i.e. x.0 and x.0.y) of Vitess, and to true (or on) in development versions.
-
-From Vitess 12.0 onwards, it defaults to ***true*** in all release and development versions. You can read more [here](https://github.com/vitessio/vitess/issues/9125). Thus you should specify this flag explicitly, so you are sure whether it is enabled or not, independent of which Vitess release/build/version you are running.
-
-If you have reserved connections disabled, you will get the `old` Vitess behavior: where most setting most system settings (e.g. sql_mode) are just silently ignored by Vitess. In situations where you know your backend MySQL defaults are acceptable, this may be the correct tradeoff to ensure the best possible performance of the vttablet <-> MySQL connection pools. As noted above, this comes down to a trade-off between compatibility and performance/scalability. You should also review [this section](https://vitess.io/docs/reference/query-serving/reserved-conn/#number-of-vttablet---mysql-connections) when deciding on whether or not to enable reserved connections.
 
 ## Deprecations
 
diff --git a/go.mod b/go.mod
index 55dc168f4d..2365e006c1 100644
--- a/go.mod
+++ b/go.mod
@@ -111,6 +111,7 @@ require (
 	gopkg.in/gcfg.v1 v1.2.3
 	gopkg.in/ldap.v2 v2.5.0
 	gopkg.in/warnings.v0 v0.1.2 // indirect
+	gopkg.in/yaml.v2 v2.4.0
 	gotest.tools v2.2.0+incompatible
 	honnef.co/go/tools v0.0.1-2020.1.4
 	k8s.io/apiextensions-apiserver v0.18.19
@@ -197,7 +198,6 @@ require (
 	google.golang.org/appengine v1.6.7 // indirect
 	gopkg.in/inf.v0 v0.9.1 // indirect
 	gopkg.in/ini.v1 v1.62.0 // indirect
-	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
 	k8s.io/api v0.20.6 // indirect
 	k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac // indirect
diff --git a/go/vt/vtadmin/cluster/config.go b/go/vt/vtadmin/cluster/config.go
index e662a0af84..7c9c1a068f 100644
--- a/go/vt/vtadmin/cluster/config.go
+++ b/go/vt/vtadmin/cluster/config.go
@@ -87,7 +87,14 @@ func (cfg *Config) Set(value string) error {
 	return parseFlag(cfg, value)
 }
 
-func (cfg *Config) unmarshalMap(attributes map[string]string) error {
+// UnmarshalYAML implements the yaml.Unmarshaler interface.
+func (cfg *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
+	attributes := map[string]string{}
+
+	if err := unmarshal(attributes); err != nil {
+		return err
+	}
+
 	for k, v := range attributes {
 		if err := parseOne(cfg, k, v); err != nil {
 			return err
diff --git a/go/vt/vtadmin/cluster/file_config.go b/go/vt/vtadmin/cluster/file_config.go
index 71fbdeb915..cf4326b95c 100644
--- a/go/vt/vtadmin/cluster/file_config.go
+++ b/go/vt/vtadmin/cluster/file_config.go
@@ -17,17 +17,17 @@ limitations under the License.
 package cluster
 
 import (
+	"os"
 	"strings"
 
-	"github.com/spf13/viper"
+	"gopkg.in/yaml.v2"
 )
 
 // FileConfig represents the structure of a set of cluster configs on disk. It
-// contains both a default config, and cluster-specific overrides. Viper is used
-// internally to load the config file, so any file format supported by viper is
-// permitted.
+// contains both a default config, and cluster-specific overrides. Currently
+// only YAML config files are supported.
 //
-// A valid YAML config looks like:
+// A valid config looks like:
 //		defaults:
 //			discovery: k8s
 //		clusters:
@@ -42,6 +42,30 @@ type FileConfig struct {
 	Clusters map[string]Config
 }
 
+// UnmarshalYAML is part of the yaml.Unmarshaler interface.
+func (fc *FileConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
+	tmp := struct {
+		Defaults Config
+		Clusters map[string]Config
+	}{
+		Defaults: fc.Defaults,
+		Clusters: fc.Clusters,
+	}
+
+	if err := unmarshal(&tmp); err != nil {
+		return err
+	}
+
+	fc.Defaults = tmp.Defaults
+	fc.Clusters = make(map[string]Config, len(tmp.Clusters))
+
+	for id, cfg := range tmp.Clusters {
+		fc.Clusters[id] = cfg.Merge(Config{ID: id})
+	}
+
+	return nil
+}
+
 // String is part of the flag.Value interface.
 func (fc *FileConfig) String() string {
 	buf := strings.Builder{}
@@ -64,57 +88,14 @@ func (fc *FileConfig) Type() string {
 }
 
 // Set is part of the flag.Value interface. It loads the file configuration
-// found at the path passed to the flag. Any config file format supported by
-// viper is supported by FileConfig.
+// found at the path passed to the flag.
 func (fc *FileConfig) Set(value string) error {
-	v := viper.New()
-	v.SetConfigFile(value)
-	if err := v.ReadInConfig(); err != nil {
-		return err
-	}
-
-	return fc.unmarshalViper(v)
-}
-
-func (fc *FileConfig) unmarshalViper(v *viper.Viper) error {
-	tmp := struct { // work around mapstructure's interface; see https://github.com/spf13/viper/issues/338#issuecomment-382376136
-		Defaults map[string]string
-		Clusters map[string]map[string]string
-	}{
-		Defaults: map[string]string{},
-		Clusters: map[string]map[string]string{},
-	}
-
-	if err := v.Unmarshal(&tmp); err != nil {
+	data, err := os.ReadFile(value)
+	if err != nil {
 		return err
 	}
 
-	if err := fc.Defaults.unmarshalMap(tmp.Defaults); err != nil {
-		return err
-	}
-
-	if fc.Clusters == nil {
-		fc.Clusters = map[string]Config{}
-	}
-	for id, clusterMap := range tmp.Clusters {
-		c, ok := fc.Clusters[id]
-		if !ok {
-			c = Config{
-				ID:                   id,
-				DiscoveryFlagsByImpl: map[string]map[string]string{},
-				VtSQLFlags:           map[string]string{},
-				VtctldFlags:          map[string]string{},
-			}
-		}
-
-		if err := c.unmarshalMap(clusterMap); err != nil {
-			return err
-		}
-
-		fc.Clusters[id] = c
-	}
-
-	return nil
+	return yaml.Unmarshal(data, fc)
 }
 
 // Combine combines a FileConfig with a default Config and a ClustersFlag (each
diff --git a/go/vt/vtgate/engine/fuzz.go b/go/vt/vtgate/engine/fuzz.go
deleted file mode 100644
index a71b355ccd..0000000000
--- a/go/vt/vtgate/engine/fuzz.go
+++ /dev/null
@@ -1,107 +0,0 @@
-//go:build gofuzz
-// +build gofuzz
-
-/*
-Copyright 2021 The Vitess Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-/*
-	DEPENDENCIES:
-	This fuzzer relies heavily on
-	$VTROOT/go/vt/vtgate/engine/fake_vcursor_test.go,
-	and in order to run it, it is required to rename:
-	$VTROOT/go/vt/vtgate/engine/fake_vcursor_test.go
-	to
-	$VTROOT/go/vt/vtgate/engine/fake_vcursor.go
-
-	This is handled by the OSS-fuzz build script and
-	is only important to make note of if the fuzzer
-	is run locally.
-
-	STATUS:
-	The fuzzer does not currently implement executions
-	for all possible API's in the engine package, and
-	it can be considered experimental, as I (@AdamKorcz)
-	am interested in its performance when being run
-	continuously by OSS-fuzz. Needless to say, more
-	APIs can be added with ease.
-*/
-
-package engine
-
-import (
-	fuzz "github.com/AdaLogics/go-fuzz-headers"
-
-	querypb "vitess.io/vitess/go/vt/proto/query"
-	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
-)
-
-// FuzzEngine implements the fuzzer
-func FuzzEngine(data []byte) int {
-	c := fuzz.NewConsumer(data)
-
-	index, err := c.GetInt()
-	if err != nil {
-		return 0
-	}
-	switch i := index % 3; i {
-	case 0:
-		execUpdate(c)
-	case 1:
-		execInsert(c)
-	case 2:
-		execRoute(c)
-	default:
-		return 0
-	}
-	return 1
-}
-
-// execUpdate implements a wrapper to fuzz Update.Tryexecute()
-func execUpdate(f *fuzz.ConsumeFuzzer) {
-	upd := &Update{}
-	err := f.GenerateStruct(upd)
-	if err != nil {
-		return
-	}
-	vc := &loggingVCursor{}
-	_, _ = upd.TryExecute(vc, map[string]*querypb.BindVariable{}, false)
-}
-
-// execUpdate implements a wrapper to fuzz Insert.Tryexecute()
-func execInsert(f *fuzz.ConsumeFuzzer) {
-	ins := &Insert{}
-	err := f.GenerateStruct(ins)
-	if err != nil {
-		return
-	}
-	vc := &loggingVCursor{}
-	_, _ = ins.TryExecute(vc, map[string]*querypb.BindVariable{}, false)
-}
-
-// execUpdate implements a wrapper to fuzz Route.Tryexecute()
-func execRoute(f *fuzz.ConsumeFuzzer) {
-	sel := &Route{}
-	err := f.GenerateStruct(sel)
-	if err != nil {
-		return
-	}
-	vc := newFuzzDMLTestVCursor("0")
-	_, _ = sel.TryExecute(vc, map[string]*querypb.BindVariable{}, false)
-}
-
-func newFuzzDMLTestVCursor(shards ...string) *loggingVCursor {
-	return &loggingVCursor{shards: shards, resolvedTargetTabletType: topodatapb.TabletType_PRIMARY}
-}
diff --git a/go/vt/vtgate/planbuilder/abstract/fuzz.go b/go/vt/vtgate/planbuilder/abstract/fuzz.go
index 536c304e85..9315a0cfe9 100644
--- a/go/vt/vtgate/planbuilder/abstract/fuzz.go
+++ b/go/vt/vtgate/planbuilder/abstract/fuzz.go
@@ -3,10 +3,13 @@
 
 /*
 Copyright 2021 The Vitess Authors.
+
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
+
     http://www.apache.org/licenses/LICENSE-2.0
+
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,7 +52,7 @@ func FuzzAnalyse(data []byte) int {
 	}
 	switch stmt := tree.(type) {
 	case *sqlparser.Select:
-		semTable, err := semantics.Analyze(stmt, "", &fakeFuzzSI{})
+		semTable, err := semantics.Analyze(stmt, "", &fakeFuzzSI{}, semantics.NoRewrite)
 		if err != nil {
 			return 0
 		}
diff --git a/go/vt/vtgate/planbuilder/fuzz.go b/go/vt/vtgate/planbuilder/fuzz.go
deleted file mode 100644
index 284516de5e..0000000000
--- a/go/vt/vtgate/planbuilder/fuzz.go
+++ /dev/null
@@ -1,105 +0,0 @@
-//go:build gofuzz
-// +build gofuzz
-
-/*
-Copyright 2021 The Vitess Authors.
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-    http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package planbuilder
-
-import (
-	"sync"
-	"testing"
-
-	"vitess.io/vitess/go/json2"
-	"vitess.io/vitess/go/sqltypes"
-	vschemapb "vitess.io/vitess/go/vt/proto/vschema"
-	"vitess.io/vitess/go/vt/vtgate/vindexes"
-
-	fuzz "github.com/AdaLogics/go-fuzz-headers"
-)
-
-var initter sync.Once
-
-func onceInit() {
-	testing.Init()
-}
-
-// loadSchemaForFuzzing is a helper to load *vindexes.VSchema
-// for fuzzing.
-func loadSchemaForFuzzing(f *fuzz.ConsumeFuzzer) (*vindexes.VSchema, error) {
-	//formal, err := vindexes.LoadFormal(filename)
-	formal, err := loadFormalForFuzzing(f)
-	if err != nil {
-		return nil, err
-	}
-	vschema := vindexes.BuildVSchema(formal)
-	if err != nil {
-		return nil, err
-	}
-	for _, ks := range vschema.Keyspaces {
-		if ks.Error != nil {
-			return nil, err
-		}
-
-		for _, table := range ks.Tables {
-			for i, col := range table.Columns {
-				if sqltypes.IsText(col.Type) {
-					table.Columns[i].CollationName = "latin1_swedish_ci"
-				}
-			}
-		}
-	}
-	return vschema, nil
-}
-
-// loadFormalForFuzzing is a helper to create *vschemapb.SrvVSchema
-func loadFormalForFuzzing(f *fuzz.ConsumeFuzzer) (*vschemapb.SrvVSchema, error) {
-	formal := &vschemapb.SrvVSchema{}
-	data, err := f.GetBytes()
-	if err != nil {
-		return nil, err
-	}
-	err = json2.Unmarshal(data, formal)
-	if err != nil {
-		return nil, err
-	}
-	return formal, nil
-}
-
-// FuzzTestBuilder implements the fuzzer
-func FuzzTestBuilder(data []byte) int {
-	initter.Do(onceInit)
-	f := fuzz.NewConsumer(data)
-	query, err := f.GetString()
-	if err != nil {
-		return 0
-	}
-	keyspace, err := f.GetString()
-	if err != nil {
-		return 0
-	}
-	s, err := loadSchemaForFuzzing(f)
-	if err != nil {
-		return 0
-	}
-	vschemaWrapper := &vschemaWrapper{
-		v:             s,
-		sysVarEnabled: true,
-	}
-
-	_, err = TestBuilder(query, vschemaWrapper, keyspace)
-	if err != nil {
-		return 0
-	}
-	return 1
-}
diff --git a/go/vt/vtgate/planbuilder/horizon_planning.go b/go/vt/vtgate/planbuilder/horizon_planning.go
index 368a241dd3..bc9809ca50 100644
--- a/go/vt/vtgate/planbuilder/horizon_planning.go
+++ b/go/vt/vtgate/planbuilder/horizon_planning.go
@@ -410,6 +410,10 @@ func (hp *horizonPlanning) planAggregations(ctx *planningContext, plan logicalPl
 		hp.vtgateGrouping = true
 	}
 
+	if joinPlan && hp.qp.HasAggr && len(hp.qp.GroupByExprs) > 0 {
+		return nil, vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "unsupported: cross-shard query with aggregates")
+	}
+
 	for _, e := range hp.qp.SelectExprs {
 		aliasExpr, err := e.GetAliasedExpr()
 		if err != nil {
diff --git a/go/vt/vtgate/vindexes/fuzz.go b/go/vt/vtgate/vindexes/fuzz.go
deleted file mode 100644
index b8f7f29358..0000000000
--- a/go/vt/vtgate/vindexes/fuzz.go
+++ /dev/null
@@ -1,244 +0,0 @@
-//go:build gofuzz
-// +build gofuzz
-
-/*
-Copyright 2021 The Vitess Authors.
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-    http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package vindexes
-
-import (
-	"encoding/json"
-	"fmt"
-	"os"
-	"reflect"
-	"sync"
-	"testing"
-
-	fuzz "github.com/AdaLogics/go-fuzz-headers"
-
-	"vitess.io/vitess/go/sqltypes"
-	querypb "vitess.io/vitess/go/vt/proto/query"
-)
-
-var initter sync.Once
-
-func onceInit() {
-	testing.Init()
-}
-
-// All querypbTypes
-var querypbTypes = []querypb.Type{querypb.Type_NULL_TYPE,
-	querypb.Type_INT8,
-	querypb.Type_UINT8,
-	querypb.Type_INT16,
-	querypb.Type_UINT16,
-	querypb.Type_INT24,
-	querypb.Type_UINT24,
-	querypb.Type_INT32,
-	querypb.Type_UINT32,
-	querypb.Type_INT64,
-	querypb.Type_UINT64,
-	querypb.Type_FLOAT32,
-	querypb.Type_FLOAT64,
-	querypb.Type_TIMESTAMP,
-	querypb.Type_DATE,
-	querypb.Type_TIME,
-	querypb.Type_DATETIME,
-	querypb.Type_YEAR,
-	querypb.Type_DECIMAL,
-	querypb.Type_TEXT,
-	querypb.Type_BLOB,
-	querypb.Type_VARCHAR,
-	querypb.Type_VARBINARY,
-	querypb.Type_CHAR,
-	querypb.Type_BINARY,
-	querypb.Type_BIT,
-	querypb.Type_ENUM,
-	querypb.Type_SET,
-	querypb.Type_GEOMETRY,
-	querypb.Type_JSON,
-	querypb.Type_EXPRESSION}
-
-// All valid vindexes
-var availableVindexes = []string{"binary",
-	"unicode_loose_md5",
-	"binary_md5",
-	"lookup_hash",
-	"lookup_hash_unique",
-	"lookup",
-	"lookup_unique",
-	"lookup_unicodeloosemd5_hash",
-	"lookup_unicodeloosemd5_hash_unique",
-	"hash",
-	"region_experimental",
-	"consistent_lookup",
-	"consistent_lookup_unique",
-	"cfc",
-	"numeric",
-	"numeric_static_map",
-	"xxhash",
-	"unicode_loose_xxhash",
-	"reverse_bits",
-	"region_json",
-	"null"}
-
-// FuzzVindex implements the vindexes fuzzer
-func FuzzVindex(data []byte) int {
-	initter.Do(onceInit)
-	f := fuzz.NewConsumer(data)
-
-	// Write region map file
-	createdFile, err := writeRegionMapFile(f)
-	if err != nil {
-		return 0
-	}
-	defer os.Remove(createdFile)
-
-	// Choose type of vindex
-	index, err := f.GetInt()
-	if err != nil {
-		return 0
-	}
-	targetVindex := availableVindexes[index%len(availableVindexes)]
-
-	// Create params map
-	params := make(map[string]string)
-	err = f.FuzzMap(&params)
-	if err != nil {
-		return 0
-	}
-	params["region_map"] = createdFile
-
-	// Create the vindex
-	l, err := CreateVindex(targetVindex, targetVindex, params)
-	if err != nil {
-		return 0
-	}
-
-	// Create values to be passed to our targets
-	allValues, err := createValues(f)
-	if err != nil {
-		return 0
-	}
-
-	vc := &loggingVCursor{}
-
-	// Time to call the actual targets. THere are two:
-	// 1) Map()
-	// 2) Create()
-
-	// Target 1:
-	_, _ = Map(l, vc, allValues)
-
-	// Target 2:
-	s1 := reflect.TypeOf(l).String()
-	switch s1 {
-	case "*vindexes.ConsistentLookup", "*vindexes.LookupHash",
-		"*vindexes.LookupHashUnique", "*vindexes.LookupNonUnique",
-		"*vindexes.LookupUnique", "*vindexes.LookupUnicodeLooseMD5Hash",
-		"*vindexes.LookupUnicodeLooseMD5HashUnique", "*vindexes.clCommon",
-		"*vindexes.lookupInternal":
-		ksids, err := createKsids(f)
-		if err != nil {
-			return 0
-		}
-		_ = l.(Lookup).Create(vc, allValues, ksids, false)
-	}
-	return 1
-}
-
-// Creates a slice of byte slices to use as ksids
-func createKsids(f *fuzz.ConsumeFuzzer) ([][]byte, error) {
-	// create ksids
-	noOfTotalKsids, err := f.GetInt()
-	if err != nil {
-		return nil, err
-	}
-	ksids := make([][]byte, noOfTotalKsids%100)
-	for i := 0; i < noOfTotalKsids%100; i++ {
-		newBytes, err := f.GetBytes()
-		if err != nil {
-			return nil, err
-		}
-		ksids = append(ksids, newBytes)
-	}
-	return ksids, nil
-}
-
-// Checks if a byte slice is valid json
-func IsJSON(data []byte) bool {
-	var js json.RawMessage
-	return json.Unmarshal(data, &js) == nil
-}
-
-// Create and write the RegionMap file
-func writeRegionMapFile(f *fuzz.ConsumeFuzzer) (string, error) {
-	fileBytes, err := f.GetBytes()
-	if err != nil || !IsJSON(fileBytes) {
-		return "", fmt.Errorf("Could not get valid bytes")
-	}
-
-	createdFile, err := os.CreateTemp("", "tmpfile-")
-	if err != nil {
-		return "", err
-	}
-	defer createdFile.Close()
-
-	_, err = createdFile.Write(fileBytes)
-	if err != nil {
-		return "", err
-	}
-	return createdFile.Name(), nil
-
-}
-
-// Creates a slice of slices of sqltypes.Value
-func createValues(f *fuzz.ConsumeFuzzer) ([][]sqltypes.Value, error) {
-	noOfTotalValues, err := f.GetInt()
-	if err != nil {
-		return nil, err
-	}
-	allValues := make([][]sqltypes.Value, 0)
-	for i := 0; i < noOfTotalValues%100; i++ {
-		noOfValues, err := f.GetInt()
-		if err != nil {
-			return nil, err
-		}
-		values := make([]sqltypes.Value, 0)
-		for i2 := 0; i2 < noOfValues%100; i2++ {
-			v, err := createValue(f)
-			if err != nil {
-				return nil, err
-			}
-			values = append(values, v)
-		}
-		allValues = append(allValues, values)
-	}
-	return allValues, nil
-}
-
-// Creates a single sqltypes.Value
-func createValue(f *fuzz.ConsumeFuzzer) (sqltypes.Value, error) {
-	typeIndex, err := f.GetInt()
-	if err != nil {
-		return sqltypes.Value{}, err
-	}
-
-	inputBytes, err := f.GetBytes()
-	if err != nil {
-		return sqltypes.Value{}, err
-	}
-
-	v := querypbTypes[typeIndex%len(querypbTypes)]
-	return sqltypes.NewValue(v, inputBytes)
-}
diff --git a/go/vt/vttablet/onlineddl/executor.go b/go/vt/vttablet/onlineddl/executor.go
index 98fd10acdb..b7c46089d0 100644
--- a/go/vt/vttablet/onlineddl/executor.go
+++ b/go/vt/vttablet/onlineddl/executor.go
@@ -2894,8 +2894,6 @@ func (e *Executor) SubmitMigration(
 		return nil, err
 	}
 
-	retainArtifactsSeconds := int64((*retainOnlineDDLTables).Seconds())
-
 	query, err := sqlparser.ParseAndBind(sqlInsertMigration,
 		sqltypes.StringBindVariable(onlineDDL.UUID),
 		sqltypes.StringBindVariable(e.keyspace),
@@ -2909,7 +2907,6 @@ func (e *Executor) SubmitMigration(
 		sqltypes.StringBindVariable(onlineDDL.RequestContext),
 		sqltypes.StringBindVariable(string(schema.OnlineDDLStatusQueued)),
 		sqltypes.StringBindVariable(e.TabletAliasString()),
-		sqltypes.Int64BindVariable(retainArtifactsSeconds),
 	)
 	if err != nil {
 		return nil, err
diff --git a/go/vt/vttablet/onlineddl/schema.go b/go/vt/vttablet/onlineddl/schema.go
index 09473f132e..dfeb836eab 100644
--- a/go/vt/vttablet/onlineddl/schema.go
+++ b/go/vt/vttablet/onlineddl/schema.go
@@ -61,7 +61,6 @@ const (
 	alterSchemaMigrationsTableAddedUniqueKeys    = "ALTER TABLE _vt.schema_migrations add column added_unique_keys int unsigned NOT NULL DEFAULT 0"
 	alterSchemaMigrationsTableRemovedUniqueKeys  = "ALTER TABLE _vt.schema_migrations add column removed_unique_keys int unsigned NOT NULL DEFAULT 0"
 	alterSchemaMigrationsTableLogFile            = "ALTER TABLE _vt.schema_migrations add column log_file varchar(1024) NOT NULL DEFAULT ''"
-	alterSchemaMigrationsTableRetainArtifacts    = "ALTER TABLE _vt.schema_migrations add column retain_artifacts_seconds bigint NOT NULL DEFAULT 0"
 
 	sqlInsertMigration = `INSERT IGNORE INTO _vt.schema_migrations (
 		migration_uuid,
@@ -76,10 +75,9 @@ const (
 		requested_timestamp,
 		migration_context,
 		migration_status,
-		tablet,
-		retain_artifacts_seconds
+		tablet
 	) VALUES (
-		%a, %a, %a, %a, %a, %a, %a, %a, %a, FROM_UNIXTIME(NOW()), %a, %a, %a, %a
+		%a, %a, %a, %a, %a, %a, %a, %a, %a, FROM_UNIXTIME(NOW()), %a, %a, %a
 	)`
 
 	sqlScheduleSingleMigration = `UPDATE _vt.schema_migrations
@@ -278,10 +276,7 @@ const (
 		WHERE
 			migration_status IN ('complete', 'failed')
 			AND cleanup_timestamp IS NULL
-			AND completed_timestamp <= IF(retain_artifacts_seconds=0,
-				NOW() - INTERVAL %a SECOND,
-				NOW() - INTERVAL retain_artifacts_seconds SECOND
-			)
+			AND completed_timestamp <= NOW() - INTERVAL %a SECOND
 	`
 	sqlFixCompletedTimestamp = `UPDATE _vt.schema_migrations
 		SET
@@ -528,5 +523,4 @@ var ApplyDDL = []string{
 	alterSchemaMigrationsTableAddedUniqueKeys,
 	alterSchemaMigrationsTableRemovedUniqueKeys,
 	alterSchemaMigrationsTableLogFile,
-	alterSchemaMigrationsTableRetainArtifacts,
 }


Test patch:
diff --git a/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go b/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go
index 253a5510b5..3173ff1c20 100644
--- a/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go
+++ b/go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go
@@ -259,13 +259,6 @@ func TestSchemaChange(t *testing.T) {
 		testMigrationRowCount(t, uuid)
 		onlineddl.CheckCancelMigration(t, &vtParams, shards, uuid, false)
 		onlineddl.CheckRetryMigration(t, &vtParams, shards, uuid, false)
-
-		rs := onlineddl.ReadMigrations(t, &vtParams, uuid)
-		require.NotNil(t, rs)
-		for _, row := range rs.Named().Rows {
-			retainArtifactSeconds := row.AsInt64("retain_artifacts_seconds", 0)
-			assert.Equal(t, int64(86400), retainArtifactSeconds)
-		}
 	})
 	t.Run("successful online alter, vtctl", func(t *testing.T) {
 		insertRows(t, 2)
diff --git a/go/test/fuzzing/ast_fuzzer.go b/go/test/fuzzing/ast_fuzzer.go
deleted file mode 100644
index bcb106bb39..0000000000
--- a/go/test/fuzzing/ast_fuzzer.go
+++ /dev/null
@@ -1,59 +0,0 @@
-//go:build gofuzz
-// +build gofuzz
-
-/*
-Copyright 2021 The Vitess Authors.
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-    http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package fuzzing
-
-import (
-	"vitess.io/vitess/go/vt/sqlparser"
-)
-
-// FuzzEqualsSQLNode implements the fuzzer
-func FuzzEqualsSQLNode(data []byte) int {
-	if len(data) < 10 {
-		return 0
-	}
-	if (len(data) % 2) != 0 {
-		return 0
-	}
-	firstHalf := string(data[:len(data)/2])
-	secondHalf := string(data[(len(data)/2)+1:])
-	inA, err := sqlparser.Parse(firstHalf)
-	if err != nil {
-		return 0
-	}
-	inB, err := sqlparser.Parse(secondHalf)
-	if err != nil {
-		return 0
-	}
-
-	// There are 3 targets in this fuzzer:
-	// 1) sqlparser.EqualsSQLNode
-	// 2) sqlparser.CloneSQLNode
-	// 3) sqlparser.VisitSQLNode
-
-	// Target 1:
-	_ = sqlparser.EqualsSQLNode(inA, inB)
-
-	// Target 2:
-	newSQLNode := sqlparser.CloneSQLNode(inA)
-	if !sqlparser.EqualsSQLNode(inA, newSQLNode) {
-		panic("These two nodes should be identical")
-	}
-
-	// Target 3:
-	_ = sqlparser.VisitSQLNode(inA, func(node sqlparser.SQLNode) (bool, error) { return false, nil })
-	return 1
-}
diff --git a/go/test/fuzzing/oss_fuzz_build.sh b/go/test/fuzzing/oss_fuzz_build.sh
index 9a3ad57f2a..c8c7b74ea0 100644
--- a/go/test/fuzzing/oss_fuzz_build.sh
+++ b/go/test/fuzzing/oss_fuzz_build.sh
@@ -14,54 +14,23 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set -o nounset
-set -o pipefail
-set -o errexit
-set -x
-
-go get github.com/AdaLogics/go-fuzz-headers
-go mod vendor
-
-#consistent_lookup_test.go is needed for loggingVCursor
-mv ./go/vt/vtgate/vindexes/consistent_lookup_test.go \
-   ./go/vt/vtgate/vindexes/consistent_lookup_test_fuzz.go
-compile_go_fuzzer vitess.io/vitess/go/vt/vtgate/vindexes FuzzVindex fuzz_vindex
-
-# fake_vcursor_test.go is needed for loggingVCursor
-mv ./go/vt/vtgate/engine/fake_vcursor_test.go \
-    ./go/vt/vtgate/engine/fake_vcursor.go
-compile_go_fuzzer vitess.io/vitess/go/vt/vtgate/engine FuzzEngine engine_fuzzer
-
-# plan_test.go is needed for vschemaWrapper
-mv ./go/vt/vtgate/planbuilder/plan_test.go \
-    ./go/vt/vtgate/planbuilder/plan_test_fuzz.go
-compile_go_fuzzer vitess.io/vitess/go/vt/vtgate/planbuilder FuzzTestBuilder fuzz_test_builder gofuzz
-
-
 compile_go_fuzzer vitess.io/vitess/go/test/fuzzing Fuzz vtctl_fuzzer
 compile_go_fuzzer vitess.io/vitess/go/test/fuzzing FuzzIsDML is_dml_fuzzer
 compile_go_fuzzer vitess.io/vitess/go/test/fuzzing FuzzNormalizer normalizer_fuzzer
 compile_go_fuzzer vitess.io/vitess/go/test/fuzzing FuzzParser parser_fuzzer
-compile_go_fuzzer vitess.io/vitess/go/test/fuzzing FuzzGRPCTMServer fuzz_grpc_tm_server
-compile_go_fuzzer vitess.io/vitess/go/test/fuzzing FuzzOnlineDDLFromCommentedStatement fuzz_online_ddl_from_commented_statement
-compile_go_fuzzer vitess.io/vitess/go/test/fuzzing FuzzNewOnlineDDLs fuzz_new_online_ddls
-compile_go_fuzzer vitess.io/vitess/go/test/fuzzing FuzzEqualsSQLNode fuzz_equals_sql_node
 
 compile_go_fuzzer vitess.io/vitess/go/mysql FuzzWritePacket write_packet_fuzzer
 compile_go_fuzzer vitess.io/vitess/go/mysql FuzzHandleNextCommand handle_next_command_fuzzer
 compile_go_fuzzer vitess.io/vitess/go/mysql FuzzReadQueryResults read_query_results_fuzzer
 compile_go_fuzzer vitess.io/vitess/go/mysql FuzzTLSServer fuzz_tls
-
-# Several test utils are needed from suite_test.go:
-mv ./go/vt/vtgate/grpcvtgateconn/suite_test.go \
-   ./go/vt/vtgate/grpcvtgateconn/suite_test_fuzz.go
-mv ./go/vt/vtgate/grpcvtgateconn/fuzz_flaky_test.go \
-   ./go/vt/vtgate/grpcvtgateconn/fuzz.go
 compile_go_fuzzer vitess.io/vitess/go/vt/vtgate/grpcvtgateconn Fuzz grpc_vtgate_fuzzer
+compile_go_fuzzer vitess.io/vitess/go/vt/vtgate/planbuilder/abstract FuzzAnalyse planbuilder_fuzzer gofuzz
 
-compile_go_fuzzer vitess.io/vitess/go/vt/vtgate/planbuilder/abstract FuzzAnalyse fuzz_analyse gofuzz
-
-
+mv ./go/vt/vtgate/engine/fake_vcursor_test.go \
+    ./go/vt/vtgate/engine/fake_vcursor.go
+mv ./go/vt/vtgate/engine/fuzz_flaky_test.go ./go/vt/vtgate/engine/engine_fuzz.go
+compile_go_fuzzer vitess.io/vitess/go/vt/vtgate/engine FuzzEngine engine_fuzzer
 
 # Build dictionaries
 cp $SRC/vitess/go/test/fuzzing/vtctl_fuzzer.dict $OUT/
+
diff --git a/go/test/fuzzing/vt_schema_fuzzer.go b/go/test/fuzzing/vt_schema_fuzzer.go
deleted file mode 100644
index 2092eac866..0000000000
--- a/go/test/fuzzing/vt_schema_fuzzer.go
+++ /dev/null
@@ -1,88 +0,0 @@
-//go:build gofuzz
-// +build gofuzz
-
-/*
-Copyright 2021 The Vitess Authors.
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-    http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package fuzzing
-
-import (
-	fuzz "github.com/AdaLogics/go-fuzz-headers"
-
-	"vitess.io/vitess/go/vt/schema"
-	"vitess.io/vitess/go/vt/sqlparser"
-)
-
-// FuzzOnlineDDLFromCommentedStatement implements a fuzzer
-// that targets schema.OnlineDDLFromCommentedStatement
-func FuzzOnlineDDLFromCommentedStatement(data []byte) int {
-	stmt, err := sqlparser.Parse(string(data))
-	if err != nil {
-		return 0
-	}
-	onlineDDL, err := schema.OnlineDDLFromCommentedStatement(stmt)
-	if err != nil {
-		return 0
-	}
-	_, _ = onlineDDL.GetAction()
-	_, _, _ = onlineDDL.GetActionStr()
-	_ = onlineDDL.GetGCUUID()
-	return 1
-}
-
-// FuzzNewOnlineDDLs implements a fuzzer that
-// targets schema.NewOnlineDDLs
-func FuzzNewOnlineDDLs(data []byte) int {
-	f := fuzz.NewConsumer(data)
-
-	keyspace, err := f.GetString()
-	if err != nil {
-		return 0
-	}
-
-	ddlstmtString, err := f.GetString()
-	if err != nil {
-		return 0
-	}
-	ddlStmt, _, err := schema.ParseOnlineDDLStatement(ddlstmtString)
-	if err != nil {
-		return 0
-	}
-
-	sql, err := f.GetString()
-	if err != nil {
-		return 0
-	}
-
-	ddlStrategySetting := &schema.DDLStrategySetting{}
-	err = f.GenerateStruct(ddlStrategySetting)
-	if err != nil {
-		return 0
-	}
-
-	requestContext, err := f.GetString()
-	if err != nil {
-		return 0
-	}
-
-	onlineDDLs, err := schema.NewOnlineDDLs(keyspace, sql, ddlStmt, ddlStrategySetting, requestContext)
-	if err != nil {
-		return 0
-	}
-	for _, onlineDDL := range onlineDDLs {
-		_, _ = onlineDDL.GetAction()
-		_, _, _ = onlineDDL.GetActionStr()
-		_ = onlineDDL.GetGCUUID()
-	}
-	return 1
-}
diff --git a/go/test/fuzzing/vttablet_fuzzer.go b/go/test/fuzzing/vttablet_fuzzer.go
deleted file mode 100644
index 3a5fac0764..0000000000
--- a/go/test/fuzzing/vttablet_fuzzer.go
+++ /dev/null
@@ -1,728 +0,0 @@
-//go:build gofuzz
-// +build gofuzz
-
-/*
-Copyright 2021 The Vitess Authors.
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-    http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package fuzzing
-
-import (
-	"context"
-	"fmt"
-	"net"
-	"sync"
-	"testing"
-
-	"google.golang.org/grpc"
-
-	"vitess.io/vitess/go/vt/vttablet/grpctmclient"
-	"vitess.io/vitess/go/vt/vttablet/grpctmserver"
-	"vitess.io/vitess/go/vt/vttablet/tmrpctest"
-
-	fuzz "github.com/AdaLogics/go-fuzz-headers"
-
-	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
-)
-
-var initter sync.Once
-
-func onceInit() {
-	testing.Init()
-}
-
-// createTablets creates a slice of Tablets that can
-// be used by the fuzz targets.
-func (fs *fuzzStore) createTablets(f *fuzz.ConsumeFuzzer) error {
-	tabletCount, err := f.GetInt()
-	if err != nil {
-		return err
-	}
-	tabletCount = tabletCount % 40
-	if tabletCount == 0 {
-		return fmt.Errorf("We don't need a nil-len list")
-	}
-	tablets := make([]*topodatapb.Tablet, 0)
-	for i := 0; i < tabletCount; i++ {
-		tablet := &topodatapb.Tablet{}
-		err = f.GenerateStruct(tablet)
-		if err != nil {
-			return err
-		}
-		tablets = append(tablets, tablet)
-	}
-	fs.tablets = tablets
-	return nil
-}
-
-// createTabletAliases creates a slice of TabletAliases that can
-// be used by the fuzz targets.
-func (fs *fuzzStore) createTabletAliases(f *fuzz.ConsumeFuzzer) error {
-	tabletAliasCount, err := f.GetInt()
-	if err != nil {
-		return err
-	}
-	tabletAliasCount = tabletAliasCount % 40
-	if tabletAliasCount == 0 {
-		return fmt.Errorf("We don't need a nil-len list")
-	}
-	tabletAliases := make([]*topodatapb.TabletAlias, 0)
-	for i := 0; i < tabletAliasCount; i++ {
-		tabletAlias := &topodatapb.TabletAlias{}
-		err = f.GenerateStruct(tabletAlias)
-		if err != nil {
-			return err
-		}
-		tabletAliases = append(tabletAliases, tabletAlias)
-	}
-	fs.tabletAliases = tabletAliases
-	return nil
-}
-
-// createStrings creates a slice of strings that can be used
-// by the fuzz tagets.
-func (fs *fuzzStore) createStrings(f *fuzz.ConsumeFuzzer) error {
-	stringCount, err := f.GetInt()
-	if err != nil {
-		return err
-	}
-	stringCount = stringCount % 100
-	if stringCount == 0 {
-		return fmt.Errorf("We don't need a nil-len list")
-	}
-	stringSlice := make([]string, 0)
-	for i := 0; i < stringCount; i++ {
-		newString, err := f.GetString()
-		if err != nil {
-			return err
-		}
-		stringSlice = append(stringSlice, newString)
-	}
-	fs.miscStrings = stringSlice
-	return nil
-}
-
-// createBytes creates a slice of byte slices that can be used
-// by the fuzz targets.
-func (fs *fuzzStore) createBytes(f *fuzz.ConsumeFuzzer) error {
-	bytesCount, err := f.GetInt()
-	if err != nil {
-		return err
-	}
-	bytesCount = bytesCount % 40
-	if bytesCount == 0 {
-		return fmt.Errorf("We don't need a nil-len list")
-	}
-	byteSlice := make([][]byte, 0)
-	for i := 0; i < bytesCount; i++ {
-		newBytes, err := f.GetBytes()
-		if err != nil {
-			return err
-		}
-		byteSlice = append(byteSlice, newBytes)
-	}
-	fs.miscBytes = byteSlice
-	return nil
-}
-
-// createInts creates a list of ints that can be used
-// by the fuzz targets.
-func (fs *fuzzStore) createInts(f *fuzz.ConsumeFuzzer) error {
-	intCount, err := f.GetInt()
-	if err != nil {
-		return err
-	}
-	intCount = intCount % 40
-	if intCount == 0 {
-		return fmt.Errorf("We don't need a nil-len list")
-	}
-	intSlice := make([]int, 0)
-	for i := 0; i < intCount; i++ {
-		newInt, err := f.GetInt()
-		if err != nil {
-			return err
-		}
-		intSlice = append(intSlice, newInt)
-	}
-	fs.miscInts = intSlice
-	return nil
-}
-
-// createExecutionOrder creates an array of ints that will later
-// be used to determine the order in which we call our fuzz targets.
-func (fs *fuzzStore) createExecutionOrder(f *fuzz.ConsumeFuzzer) error {
-	intCount, err := f.GetInt()
-	if err != nil {
-		return err
-	}
-	intCount = intCount % 60
-	if intCount == 0 {
-		return fmt.Errorf("We don't need a nil-len list")
-	}
-	executionOrder := make([]int, 0)
-	for i := 0; i < intCount; i++ {
-		newInt, err := f.GetInt()
-		if err != nil {
-			return err
-		}
-		executionOrder = append(executionOrder, newInt)
-	}
-	fs.executionOrder = executionOrder
-	return nil
-}
-
-type fuzzStore struct {
-	tablets        []*topodatapb.Tablet
-	tabletAliases  []*topodatapb.TabletAlias
-	miscStrings    []string
-	miscBytes      [][]byte
-	miscInts       []int
-	client         *grpctmclient.Client
-	executionOrder []int
-}
-
-// newFuzzStore creates a store of the data that is needed
-// for the fuzz targets in FuzzGRPCTMServer. The reason
-// a store is created is because the set up of the server
-// comes with a big expense, and having data ready to pass
-// to the targets improves efficiency.
-func newFuzzStore(f *fuzz.ConsumeFuzzer) (*fuzzStore, error) {
-	fs := &fuzzStore{}
-
-	err := fs.createTablets(f)
-	if err != nil {
-		return nil, err
-	}
-
-	err = fs.createTabletAliases(f)
-	if err != nil {
-		return nil, err
-	}
-
-	err = fs.createStrings(f)
-	if err != nil {
-		return nil, err
-	}
-
-	err = fs.createBytes(f)
-	if err != nil {
-		return nil, err
-	}
-
-	err = fs.createInts(f)
-	if err != nil {
-		return nil, err
-	}
-
-	err = fs.createExecutionOrder(f)
-	if err != nil {
-		return nil, err
-	}
-	return fs, nil
-}
-
-func (fs *fuzzStore) getTablet() (*topodatapb.Tablet, error) {
-	if len(fs.tablets) == 0 {
-		return nil, fmt.Errorf("Not enough tablets")
-	}
-	tablet := fs.tablets[0]
-	fs.tablets = fs.tablets[1:]
-	return tablet, nil
-}
-
-func (fs *fuzzStore) getString() (string, error) {
-	if len(fs.miscStrings) == 0 {
-		return "", fmt.Errorf("Not enough tablets")
-	}
-	returnString := fs.miscStrings[0]
-	fs.miscStrings = fs.miscStrings[1:]
-	return returnString, nil
-}
-
-func (fs *fuzzStore) getInt() (int, error) {
-	if len(fs.miscInts) == 0 {
-		return 0, fmt.Errorf("Not enough tablets")
-	}
-	returnInt := fs.miscInts[0]
-	fs.miscInts = fs.miscInts[1:]
-	return returnInt, nil
-}
-
-func (fs *fuzzStore) getBytes() ([]byte, error) {
-	if len(fs.miscBytes) == 0 {
-		return nil, fmt.Errorf("Not enough tablets")
-	}
-	returnBytes := fs.miscBytes[0]
-	fs.miscBytes = fs.miscBytes[1:]
-	return returnBytes, nil
-}
-
-func (fs *fuzzStore) getTabletAlias() (*topodatapb.TabletAlias, error) {
-	if len(fs.tabletAliases) == 0 {
-		return nil, fmt.Errorf("Not enough tablets")
-	}
-	tabletAlias := fs.tabletAliases[0]
-	fs.tabletAliases = fs.tabletAliases[1:]
-	return tabletAlias, nil
-}
-
-// callExecuteFetchAsApp implements a wrapper
-// for fuzzing ExecuteFetchAsApp
-func (fs *fuzzStore) callExecuteFetchAsApp() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	byteQuery, err := fs.getBytes()
-	if err != nil {
-		return err
-	}
-	maxRows, err := fs.getInt()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.ExecuteFetchAsApp(context.Background(), tablet, false, byteQuery, maxRows)
-	return nil
-}
-
-// callInitMaster implements a wrapper
-// for fuzzing InitMaster
-func (fs *fuzzStore) callInitMaster() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.InitMaster(context.Background(), tablet)
-	return nil
-}
-
-// callResetReplication implements a wrapper
-// for fuzzing ResetReplication
-func (fs *fuzzStore) callResetReplication() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.ResetReplication(context.Background(), tablet)
-	return nil
-}
-
-// callGetReplicas implements a wrapper
-// for fuzzing GetReplicas
-func (fs *fuzzStore) callGetReplicas() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.GetReplicas(context.Background(), tablet)
-	return nil
-}
-
-// callStartReplication implements a wrapper
-// for fuzzing StartReplication
-func (fs *fuzzStore) callStartReplication() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.StartReplication(context.Background(), tablet)
-	return nil
-}
-
-// callStopReplication implements a wrapper
-// for fuzzing StopReplication
-func (fs *fuzzStore) callStopReplication() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.StopReplication(context.Background(), tablet)
-	return nil
-}
-
-// callMasterPosition implements a wrapper
-// for fuzzing MasterPosition
-func (fs *fuzzStore) callMasterPosition() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.MasterPosition(context.Background(), tablet)
-	return nil
-}
-
-// callDemoteMaster implements a wrapper
-// for fuzzing DemoteMaster
-func (fs *fuzzStore) callDemoteMaster() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.DemoteMaster(context.Background(), tablet)
-	return nil
-}
-
-// callReplicationStatus implements a wrapper
-// for fuzzing ReplicationStatus
-func (fs *fuzzStore) callReplicationStatus() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.ReplicationStatus(context.Background(), tablet)
-	return nil
-}
-
-// callMasterStatus implements a wrapper
-// for fuzzing MasterStatus
-func (fs *fuzzStore) callMasterStatus() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.MasterStatus(context.Background(), tablet)
-	return nil
-}
-
-// callDemotePrimary implements a wrapper
-// for fuzzing DemotePrimary
-func (fs *fuzzStore) callDemotePrimary() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.DemotePrimary(context.Background(), tablet)
-	return nil
-}
-
-// callUndoDemoteMaster implements a wrapper
-// for fuzzing UndoDemoteMaster
-func (fs *fuzzStore) callUndoDemoteMaster() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.UndoDemoteMaster(context.Background(), tablet)
-	return nil
-}
-
-// callUndoDemotePrimary implements a wrapper
-// for fuzzing UndoDemotePrimary
-func (fs *fuzzStore) callUndoDemotePrimary() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.UndoDemotePrimary(context.Background(), tablet)
-	return nil
-}
-
-// callReplicaWasPromoted implements a wrapper
-// for fuzzing ReplicaWasPromoted
-func (fs *fuzzStore) callReplicaWasPromoted() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.ReplicaWasPromoted(context.Background(), tablet)
-	return nil
-}
-
-// callPromoteReplica implements a wrapper
-// for fuzzing PromoteReplica
-func (fs *fuzzStore) callPromoteReplica() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.PromoteReplica(context.Background(), tablet)
-	return nil
-}
-
-// callStopReplicationAndGetStatus implements a wrapper
-// for fuzzing StopReplicationAndGetStatus
-func (fs *fuzzStore) callStopReplicationAndGetStatus() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	_, _, _ = fs.client.StopReplicationAndGetStatus(context.Background(), tablet, 0)
-	return nil
-}
-
-// callReplicaWasRestarted implements a wrapper
-// for fuzzing ReplicaWasRestarted
-func (fs *fuzzStore) callReplicaWasRestarted() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	parent, err := fs.getTabletAlias()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.ReplicaWasRestarted(context.Background(), tablet, parent)
-	return nil
-}
-
-// callWaitForPosition implements a wrapper
-// for fuzzing WaitForPosition
-func (fs *fuzzStore) callWaitForPosition() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	pos, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.WaitForPosition(context.Background(), tablet, pos)
-	return nil
-}
-
-// callVReplicationExec implements a wrapper
-// for fuzzing VReplicationExec
-func (fs *fuzzStore) callVReplicationExec() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	query, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.VReplicationExec(context.Background(), tablet, query)
-	return nil
-}
-
-// callVExec implements a wrapper
-// for fuzzing VExec
-func (fs *fuzzStore) callVExec() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	query, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	workflow, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	keyspace, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	_, _ = fs.client.VExec(context.Background(), tablet, query, workflow, keyspace)
-	return nil
-}
-
-// callVReplicationWaitForPos implements a wrapper
-// for fuzzing VReplicationWaitForPos
-func (fs *fuzzStore) callVReplicationWaitForPos() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	pos, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	timeCreatedNS, err := fs.getInt()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.VReplicationWaitForPos(context.Background(), tablet, timeCreatedNS, pos)
-	return nil
-}
-
-// callSetMaster implements a wrapper
-// for fuzzing SetMaster
-func (fs *fuzzStore) callSetMaster() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	pos, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	timeCreatedNS, err := fs.getInt()
-	if err != nil {
-		return err
-	}
-	parent, err := fs.getTabletAlias()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.SetMaster(context.Background(), tablet, parent, int64(timeCreatedNS), pos, false)
-	return nil
-}
-
-// callInitReplica implements a wrapper
-// for fuzzing InitReplica
-func (fs *fuzzStore) callInitReplica() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	timeCreatedNS, err := fs.getInt()
-	if err != nil {
-		return err
-	}
-	parent, err := fs.getTabletAlias()
-	if err != nil {
-		return err
-	}
-	replicationPosition, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.InitReplica(context.Background(), tablet, parent, replicationPosition, int64(timeCreatedNS))
-	return nil
-}
-
-// callPopulateReparentJournal implements a wrapper
-// for fuzzing PopulateReparentJournal
-func (fs *fuzzStore) callPopulateReparentJournal() error {
-	tablet, err := fs.getTablet()
-	if err != nil {
-		return err
-	}
-	timeCreatedNS, err := fs.getInt()
-	if err != nil {
-		return err
-	}
-	tabletAlias, err := fs.getTabletAlias()
-	if err != nil {
-		return err
-	}
-	actionName, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	pos, err := fs.getString()
-	if err != nil {
-		return err
-	}
-	_ = fs.client.PopulateReparentJournal(context.Background(), tablet, int64(timeCreatedNS), actionName, tabletAlias, pos)
-	return nil
-}
-
-// executeInRandomOrder calls the fuzz targets in
-// the order specified by f.executionOrder
-func (fs *fuzzStore) executeInRandomOrder() {
-	maxTargets := 24
-	for _, execInt := range fs.executionOrder {
-		var err error
-		switch execInt % maxTargets {
-		case 0:
-			err = fs.callInitMaster()
-		case 1:
-			err = fs.callResetReplication()
-		case 2:
-			err = fs.callGetReplicas()
-		case 3:
-			err = fs.callStartReplication()
-		case 4:
-			err = fs.callStopReplication()
-		case 5:
-			err = fs.callMasterPosition()
-		case 6:
-			err = fs.callDemoteMaster()
-		case 7:
-			err = fs.callReplicationStatus()
-		case 8:
-			err = fs.callMasterStatus()
-		case 9:
-			err = fs.callDemotePrimary()
-		case 10:
-			err = fs.callUndoDemoteMaster()
-		case 11:
-			err = fs.callUndoDemotePrimary()
-		case 12:
-			err = fs.callReplicaWasPromoted()
-		case 13:
-			err = fs.callPromoteReplica()
-		case 14:
-			err = fs.callReplicaWasRestarted()
-		case 15:
-			err = fs.callWaitForPosition()
-		case 16:
-			err = fs.callVReplicationExec()
-		case 17:
-			err = fs.callVExec()
-		case 18:
-			err = fs.callStopReplicationAndGetStatus()
-		case 19:
-			err = fs.callExecuteFetchAsApp()
-		case 20:
-			err = fs.callVReplicationWaitForPos()
-		case 21:
-			err = fs.callSetMaster()
-		case 22:
-			err = fs.callInitReplica()
-		case 23:
-			err = fs.callPopulateReparentJournal()
-		}
-
-		// err means that fuzzStore doesn't have any data
-		// to pass to the target so we return here
-		if err != nil {
-			return
-		}
-	}
-}
-
-// FuzzGRPCTMServer implements the fuzzer.
-func FuzzGRPCTMServer(data []byte) int {
-	initter.Do(onceInit)
-	f := fuzz.NewConsumer(data)
-	fs, err := newFuzzStore(f)
-	if err != nil {
-		return 0
-	}
-	t := &testing.T{}
-
-	// Listen on a random port
-	listener, err := net.Listen("tcp", ":0")
-	if err != nil {
-		return 0
-	}
-	defer listener.Close()
-
-	host := listener.Addr().(*net.TCPAddr).IP.String()
-	port := int32(listener.Addr().(*net.TCPAddr).Port)
-	_, _ = host, port
-	for _, tablet := range fs.tablets {
-		tablet.Hostname = host
-		tablet.PortMap = map[string]int32{
-			"grpc": port,
-		}
-	}
-	s := grpc.NewServer()
-	fakeTM := tmrpctest.NewFakeRPCTM(t)
-	grpctmserver.RegisterForTest(s, fakeTM)
-	go s.Serve(listener)
-	defer s.Stop()
-
-	// Create a gRPC client to talk to the fake tablet.
-	client := grpctmclient.NewClient()
-	defer client.Close()
-	fs.client = client
-
-	// Call the targets in random order.
-	fs.executeInRandomOrder()
-
-	return 1
-}
diff --git a/go/vt/vtadmin/cluster/config_test.go b/go/vt/vtadmin/cluster/config_test.go
index a624642958..5bdfaf49b6 100644
--- a/go/vt/vtadmin/cluster/config_test.go
+++ b/go/vt/vtadmin/cluster/config_test.go
@@ -20,6 +20,8 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"gopkg.in/yaml.v2"
 )
 
 func TestMergeConfig(t *testing.T) {
@@ -141,3 +143,75 @@ func TestMergeConfig(t *testing.T) {
 		})
 	}
 }
+
+func TestConfigUnmarshalYAML(t *testing.T) {
+	t.Parallel()
+
+	tests := []struct {
+		name   string
+		yaml   string
+		config Config
+		err    error
+	}{
+		{
+			name: "simple",
+			yaml: `name: cluster1
+id: c1`,
+			config: Config{
+				ID:                   "c1",
+				Name:                 "cluster1",
+				DiscoveryFlagsByImpl: map[string]map[string]string{},
+			},
+			err: nil,
+		},
+		{
+			name: "discovery flags",
+			yaml: `name: cluster1
+id: c1
+discovery: consul
+discovery-consul-vtgate-datacenter-tmpl: "dev-{{ .Cluster }}"
+discovery-zk-whatever: 5
+`,
+			config: Config{
+				ID:            "c1",
+				Name:          "cluster1",
+				DiscoveryImpl: "consul",
+				DiscoveryFlagsByImpl: map[string]map[string]string{
+					"consul": {
+						"vtgate-datacenter-tmpl": "dev-{{ .Cluster }}",
+					},
+					"zk": {
+						"whatever": "5",
+					},
+				},
+			},
+		},
+		{
+			name:   "errors",
+			yaml:   `name: "cluster1`,
+			config: Config{},
+			err:    assert.AnError,
+		},
+	}
+
+	for _, tt := range tests {
+		tt := tt
+
+		t.Run(tt.name, func(t *testing.T) {
+			t.Parallel()
+
+			cfg := Config{
+				DiscoveryFlagsByImpl: map[string]map[string]string{},
+			}
+
+			err := yaml.Unmarshal([]byte(tt.yaml), &cfg)
+			if tt.err != nil {
+				assert.Error(t, err)
+				return
+			}
+
+			require.NoError(t, err)
+			assert.Equal(t, tt.config, cfg)
+		})
+	}
+}
diff --git a/go/vt/vtadmin/cluster/file_config_test.go b/go/vt/vtadmin/cluster/file_config_test.go
index a472c91820..07bf6dbddb 100644
--- a/go/vt/vtadmin/cluster/file_config_test.go
+++ b/go/vt/vtadmin/cluster/file_config_test.go
@@ -17,26 +17,25 @@ limitations under the License.
 package cluster
 
 import (
-	"io/ioutil"
-	"os"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+	"gopkg.in/yaml.v2"
 )
 
-func TestFileConfigFromViper(t *testing.T) {
+func TestFileConfigUnmarshalYAML(t *testing.T) {
 	t.Parallel()
 
 	tests := []struct {
 		name   string
-		data   string
+		yaml   string
 		config FileConfig
 		err    error
 	}{
 		{
-			name: "clusters.yaml",
-			data: `defaults:
+			name: "simple",
+			yaml: `defaults:
     discovery: consul
     discovery-consul-vtctld-datacenter-tmpl: "dev-{{ .Cluster.Name }}"
     discovery-consul-vtctld-service-name: vtctld-svc
@@ -92,147 +91,29 @@ clusters:
 			},
 			err: nil,
 		},
-		{
-			name: "clusters.json",
-			data: `{
-	"defaults": {
-		"discovery": "consul",
-		"discovery-consul-vtctld-datacenter-tmpl": "dev-{{ .Cluster.Name }}",
-		"discovery-consul-vtctld-service-name": "vtctld-svc",
-		"discovery-consul-vtctld-addr-tmpl": "{{ .Hostname }}.example.com:15000",
-		"discovery-consul-vtgate-datacenter-tmpl": "dev-{{ .Cluster.Name }}",
-		"discovery-consul-vtgate-service-name": "vtgate-svc",
-		"discovery-consul-vtgate-pool-tag": "type",
-		"discovery-consul-vtgate-cell-tag": "zone",
-		"discovery-consul-vtgate-addr-tmpl": "{{ .Hostname }}.example.com:15999"
-	},
-	"clusters": {
-		"c1": {
-			"name": "testcluster1",
-			"discovery-consul-vtgate-datacenter-tmpl": "dev-{{ .Cluster.Name }}-test"
-		},
-		"c2": {
-			"name": "devcluster"
-		}
-	}
-}`,
-			config: FileConfig{
-				Defaults: Config{
-					DiscoveryImpl: "consul",
-					DiscoveryFlagsByImpl: map[string]map[string]string{
-						"consul": {
-							"vtctld-datacenter-tmpl": "dev-{{ .Cluster.Name }}",
-							"vtctld-service-name":    "vtctld-svc",
-							"vtctld-addr-tmpl":       "{{ .Hostname }}.example.com:15000",
-							"vtgate-datacenter-tmpl": "dev-{{ .Cluster.Name }}",
-							"vtgate-service-name":    "vtgate-svc",
-							"vtgate-pool-tag":        "type",
-							"vtgate-cell-tag":        "zone",
-							"vtgate-addr-tmpl":       "{{ .Hostname }}.example.com:15999",
-						},
-					},
-				},
-				Clusters: map[string]Config{
-					"c1": {
-						ID:   "c1",
-						Name: "testcluster1",
-						DiscoveryFlagsByImpl: map[string]map[string]string{
-							"consul": {
-								"vtgate-datacenter-tmpl": "dev-{{ .Cluster.Name }}-test",
-							},
-						},
-						VtSQLFlags:  map[string]string{},
-						VtctldFlags: map[string]string{},
-					},
-					"c2": {
-						ID:                   "c2",
-						Name:                 "devcluster",
-						DiscoveryFlagsByImpl: map[string]map[string]string{},
-						VtSQLFlags:           map[string]string{},
-						VtctldFlags:          map[string]string{},
-					},
-				},
-			},
-			err: nil,
-		},
-		{
-			name: "clusters.toml",
-			data: `[defaults]
-discovery="consul"
-discovery-consul-vtctld-datacenter-tmpl="dev-{{ .Cluster.Name }}"
-discovery-consul-vtctld-service-name="vtctld-svc"
-discovery-consul-vtctld-addr-tmpl="{{ .Hostname }}.example.com:15000"
-discovery-consul-vtgate-datacenter-tmpl="dev-{{ .Cluster.Name }}"
-discovery-consul-vtgate-service-name="vtgate-svc"
-discovery-consul-vtgate-pool-tag="type"
-discovery-consul-vtgate-cell-tag="zone"
-discovery-consul-vtgate-addr-tmpl="{{ .Hostname }}.example.com:15999"
-
-[clusters]
-[clusters.c1]
-name="testcluster1"
-discovery-consul-vtgate-datacenter-tmpl="dev-{{ .Cluster.Name }}-test"
-[clusters.c2]
-name="devcluster"`,
-			config: FileConfig{
-				Defaults: Config{
-					DiscoveryImpl: "consul",
-					DiscoveryFlagsByImpl: map[string]map[string]string{
-						"consul": {
-							"vtctld-datacenter-tmpl": "dev-{{ .Cluster.Name }}",
-							"vtctld-service-name":    "vtctld-svc",
-							"vtctld-addr-tmpl":       "{{ .Hostname }}.example.com:15000",
-							"vtgate-datacenter-tmpl": "dev-{{ .Cluster.Name }}",
-							"vtgate-service-name":    "vtgate-svc",
-							"vtgate-pool-tag":        "type",
-							"vtgate-cell-tag":        "zone",
-							"vtgate-addr-tmpl":       "{{ .Hostname }}.example.com:15999",
-						},
-					},
-				},
-				Clusters: map[string]Config{
-					"c1": {
-						ID:   "c1",
-						Name: "testcluster1",
-						DiscoveryFlagsByImpl: map[string]map[string]string{
-							"consul": {
-								"vtgate-datacenter-tmpl": "dev-{{ .Cluster.Name }}-test",
-							},
-						},
-						VtSQLFlags:  map[string]string{},
-						VtctldFlags: map[string]string{},
-					},
-					"c2": {
-						ID:                   "c2",
-						Name:                 "devcluster",
-						DiscoveryFlagsByImpl: map[string]map[string]string{},
-						VtSQLFlags:           map[string]string{},
-						VtctldFlags:          map[string]string{},
-					},
-				},
-			},
-			err: nil,
-		},
 	}
 
 	for _, tt := range tests {
 		tt := tt
+
 		t.Run(tt.name, func(t *testing.T) {
 			t.Parallel()
 
-			f, err := os.CreateTemp(t.TempDir(), "*"+tt.name)
-			require.NoError(t, err)
+			cfg := FileConfig{
+				Defaults: Config{
+					DiscoveryFlagsByImpl: map[string]map[string]string{},
+				},
+				Clusters: map[string]Config{},
+			}
 
-			t.Cleanup(func() { os.Remove(f.Name()) })
+			err := yaml.Unmarshal([]byte(tt.yaml), &cfg)
+			if tt.err != nil {
+				assert.Error(t, err)
+				return
+			}
 
-			err = ioutil.WriteFile(f.Name(), []byte(tt.data), 0777)
 			require.NoError(t, err)
-
-			fc := FileConfig{}
-			err = fc.Set(f.Name())
-			require.NoError(t, err)
-
-			assert.Equal(t, tt.config, fc)
+			assert.Equal(t, tt.config, cfg)
 		})
 	}
 }
diff --git a/go/vt/vtgate/engine/fuzz_flaky_test.go b/go/vt/vtgate/engine/fuzz_flaky_test.go
new file mode 100644
index 0000000000..cade8cac60
--- /dev/null
+++ b/go/vt/vtgate/engine/fuzz_flaky_test.go
@@ -0,0 +1,330 @@
+//go:build gofuzz
+// +build gofuzz
+
+/*
+Copyright 2021 The Vitess Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+	DEPENDENCIES:
+	This fuzzer relies heavily on
+	$VTROOT/go/vt/vtgate/engine/fake_vcursor_test.go,
+	and in order to run it, it is required to rename:
+	$VTROOT/go/vt/vtgate/engine/fake_vcursor_test.go
+	to
+	$VTROOT/go/vt/vtgate/engine/fake_vcursor.go
+
+	This is handled by the OSS-fuzz build script and
+	is only important to make note of if the fuzzer
+	is run locally.
+
+	STATUS:
+	The fuzzer does not currently implement executions
+	for all possible API's in the engine package, and
+	it can be considered experimental, as I (@AdamKorcz)
+	am interested in its performance when being run
+	continuously by OSS-fuzz. Needless to say, more
+	APIs can be added with ease.
+*/
+
+package engine
+
+import (
+	"errors"
+
+	"vitess.io/vitess/go/vt/sqlparser"
+	"vitess.io/vitess/go/vt/vtgate/vindexes"
+
+	"vitess.io/vitess/go/sqltypes"
+	querypb "vitess.io/vitess/go/vt/proto/query"
+	vschemapb "vitess.io/vitess/go/vt/proto/vschema"
+
+	fuzz "github.com/AdaLogics/go-fuzz-headers"
+
+	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
+	"vitess.io/vitess/go/vt/vtgate/evalengine"
+)
+
+func createVSchema() (vschema *vindexes.VSchema, err error) {
+	invschema := &vschemapb.SrvVSchema{
+		Keyspaces: map[string]*vschemapb.Keyspace{
+			"sharded": {
+				Sharded: true,
+				Vindexes: map[string]*vschemapb.Vindex{
+					"primary": {
+						Type: "lookup_unique",
+						Params: map[string]string{
+							"table": "prim",
+							"from":  "from1",
+							"to":    "toc",
+						},
+					},
+				},
+				Tables: map[string]*vschemapb.Table{
+					"t1": {
+						ColumnVindexes: []*vschemapb.ColumnVindex{{
+							Name:    "primary",
+							Columns: []string{"id"},
+						}},
+					},
+				},
+			},
+		},
+	}
+	vs := vindexes.BuildVSchema(invschema)
+	if err != nil {
+		return nil, err
+	}
+	return vs, nil
+}
+
+// FuzzEngine implements the fuzzer
+func FuzzEngine(data []byte) int {
+	c := fuzz.NewConsumer(data)
+	vc := newFuzzDMLTestVCursor("0")
+	vs, err := createVSchema()
+	if err != nil {
+		return -1
+	}
+	for i := 0; i < 20; i++ {
+		newInt, err := c.GetInt()
+		if err != nil {
+			return -1
+		}
+		execCommand(newInt%7, c, vc, vs)
+	}
+	return 1
+}
+
+func execUnshardedUpdate(query string, vc *loggingVCursor) {
+	upd := &Update{
+		DML: DML{
+			Opcode: Unsharded,
+			Keyspace: &vindexes.Keyspace{
+				Name:    "ks",
+				Sharded: false,
+			},
+			Query: query,
+		},
+	}
+	_, _ = upd.Execute(vc, map[string]*querypb.BindVariable{}, false)
+}
+
+func execUnshardedInsert(query string, vc *loggingVCursor) {
+	ins := &Insert{
+		Opcode: InsertUnsharded,
+		Keyspace: &vindexes.Keyspace{
+			Name:    "ks",
+			Sharded: false,
+		},
+		Query: query,
+	}
+	_, _ = ins.Execute(vc, map[string]*querypb.BindVariable{}, false)
+}
+
+func execShardedInsert(query string, vc *loggingVCursor, vs *vindexes.VSchema) {
+	ks := vs.Keyspaces["sharded"]
+	ins := NewInsert(
+		InsertSharded,
+		ks.Keyspace,
+		[]sqltypes.PlanValue{{
+			Values: []sqltypes.PlanValue{{
+				Values: []sqltypes.PlanValue{{
+					Value: sqltypes.NewVarChar(query),
+				}},
+			}},
+		}},
+		ks.Tables["t1"],
+		"prefix",
+		[]string{" mid1", " mid2", " mid3"},
+		" suffix",
+	)
+	_, _ = ins.Execute(vc, map[string]*querypb.BindVariable{}, false)
+}
+
+func execUnshardedRoute(query, field string, vc *loggingVCursor) {
+	sel := NewRoute(
+		SelectUnsharded,
+		&vindexes.Keyspace{
+			Name:    "ks",
+			Sharded: false,
+		},
+		query,
+		field,
+	)
+	_, _ = sel.Execute(vc, map[string]*querypb.BindVariable{}, false)
+}
+
+func execShardedRoute(query, field string, vc *loggingVCursor) {
+	sel := NewRoute(
+		SelectScatter,
+		&vindexes.Keyspace{
+			Name:    "ks",
+			Sharded: true,
+		},
+		query,
+		field,
+	)
+	_, _ = sel.Execute(vc, map[string]*querypb.BindVariable{}, false)
+}
+
+func execEqualUniqueRoute(query, field, hash, value string, vc *loggingVCursor) {
+	vindex, _ := vindexes.NewHash(hash, nil)
+	sel := NewRoute(
+		SelectEqualUnique,
+		&vindexes.Keyspace{
+			Name:    "ks",
+			Sharded: true,
+		},
+		query,
+		field,
+	)
+	sel.Vindex = vindex.(vindexes.SingleColumn)
+	sel.Values = []sqltypes.PlanValue{{Value: sqltypes.NewVarChar(value)}}
+	_, _ = sel.Execute(vc, map[string]*querypb.BindVariable{}, false)
+}
+
+var defaultFuzzSelectResult = sqltypes.MakeTestResult(
+	sqltypes.MakeTestFields(
+		"id",
+		"int64",
+	),
+	"1",
+)
+
+func execRouteSelectDBA(query, field, tablename, schema, shards string) {
+	stringToExpr := func(in string) []evalengine.Expr {
+		var schema []evalengine.Expr
+		if in != "" {
+			schema = []evalengine.Expr{evalengine.NewLiteralString([]byte(in))}
+		}
+		return schema
+	}
+
+	sel := &Route{
+		Opcode: SelectDBA,
+		Keyspace: &vindexes.Keyspace{
+			Name:    "ks",
+			Sharded: false,
+		},
+		Query:               query,
+		FieldQuery:          field,
+		SysTableTableSchema: stringToExpr(schema),
+		SysTableTableName:   map[string]evalengine.Expr{"table_name": evalengine.NewLiteralString([]byte(tablename))},
+	}
+	vc := &loggingVCursor{
+		shards:  []string{shards},
+		results: []*sqltypes.Result{defaultFuzzSelectResult},
+	}
+
+	vc.tableRoutes = tableRoutes{
+		tbl: &vindexes.Table{
+			Name:     sqlparser.NewTableIdent("routedTable"),
+			Keyspace: &vindexes.Keyspace{Name: "routedKeyspace"},
+		}}
+	_, _ = sel.Execute(vc, map[string]*querypb.BindVariable{}, false)
+}
+
+func queryAndField(c *fuzz.ConsumeFuzzer) (string, string, error) {
+	query, err := c.GetString()
+	if err != nil {
+		return "nil", "nil", err
+	}
+	field, err := c.GetString()
+	if err != nil {
+		return "nil", "nil", err
+	}
+	return query, field, nil
+}
+
+func execCommand(index int, c *fuzz.ConsumeFuzzer, vc *loggingVCursor, vs *vindexes.VSchema) error {
+	switch i := index; i {
+	case 0:
+		query, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		execUnshardedUpdate(query, vc)
+		return nil
+	case 1:
+		query, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		execUnshardedInsert(query, vc)
+		return nil
+	case 2:
+		query, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		execShardedInsert(query, vc, vs)
+		return nil
+	case 3:
+		query, field, err := queryAndField(c)
+		if err != nil {
+			return err
+		}
+		execUnshardedRoute(query, field, vc)
+		return nil
+	case 4:
+		query, field, err := queryAndField(c)
+		if err != nil {
+			return err
+		}
+		execShardedRoute(query, field, vc)
+		return nil
+	case 5:
+		query, field, err := queryAndField(c)
+		if err != nil {
+			return err
+		}
+		hash, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		value, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		execEqualUniqueRoute(query, field, hash, value, vc)
+		return nil
+	case 6:
+		query, field, err := queryAndField(c)
+		if err != nil {
+			return err
+		}
+		tablename, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		schema, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		shards, err := c.GetString()
+		if err != nil {
+			return err
+		}
+		execRouteSelectDBA(query, field, tablename, schema, shards)
+		return nil
+	default:
+		return errors.New("Could not exec")
+	}
+}
+
+func newFuzzDMLTestVCursor(shards ...string) *loggingVCursor {
+	return &loggingVCursor{shards: shards, resolvedTargetTabletType: topodatapb.TabletType_PRIMARY}
+}
diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
index 777d769801..7b96aadf50 100644
--- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
@@ -1696,11 +1696,6 @@ Gen4 plan same as above
   }
 }
 
-# scatter aggregate with complex select list (can't build order by)
-"select distinct a+1 from user"
-"generating order by clause: cannot reference a complex expression"
-Gen4 error: unsupported: in scatter query: complex order by expression: a + 1
-
 # scatter aggregate with numbered order by columns
 "select a, b, c, d, count(*) from user group by 1, 2, 3 order by 1, 2, 3"
 {
@@ -2341,59 +2336,6 @@ Gen4 plan same as above
   }
 }
 
-# Aggregate on join
-"select user.a, count(*) from user join user_extra group by user.a"
-"unsupported: cross-shard query with aggregates"
-Gen4 plan same as above
-
-# Aggregate on other table in join
-"select user.a, count(user_extra.a) from user join user_extra group by user.a"
-"unsupported: cross-shard query with aggregates"
-{
-  "QueryType": "SELECT",
-  "Original": "select user.a, count(user_extra.a) from user join user_extra group by user.a",
-  "Instructions": {
-    "OperatorType": "Aggregate",
-    "Variant": "Ordered",
-    "Aggregates": "count(1) AS count(user_extra.a)",
-    "GroupBy": "(0|2)",
-    "ResultColumns": 2,
-    "Inputs": [
-      {
-        "OperatorType": "Join",
-        "Variant": "Join",
-        "JoinColumnIndexes": "-1,1,-2",
-        "TableName": "`user`_user_extra",
-        "Inputs": [
-          {
-            "OperatorType": "Route",
-            "Variant": "SelectScatter",
-            "Keyspace": {
-              "Name": "user",
-              "Sharded": true
-            },
-            "FieldQuery": "select `user`.a, weight_string(`user`.a) from `user` where 1 != 1",
-            "OrderBy": "(0|1) ASC",
-            "Query": "select `user`.a, weight_string(`user`.a) from `user` order by `user`.a asc",
-            "Table": "`user`"
-          },
-          {
-            "OperatorType": "Route",
-            "Variant": "SelectScatter",
-            "Keyspace": {
-              "Name": "user",
-              "Sharded": true
-            },
-            "FieldQuery": "select count(user_extra.a) from user_extra where 1 != 1",
-            "Query": "select count(user_extra.a) from user_extra",
-            "Table": "user_extra"
-          }
-        ]
-      }
-    ]
-  }
-}
-
 # Cannot have more than one aggr(distinct...
 "select count(distinct a), count(distinct b) from user"
 "unsupported: only one distinct aggregation allowed in a select: count(distinct b)"
@@ -3080,8 +3022,3 @@ Gen4 plan same as above
     ]
   }
 }
-
-# Equal filter with hexadecimal value
-"select count(*) a from user having a = 0x01"
-"unsupported: filtering on results of aggregates"
-Gen4 error: expr cannot be converted, not supported: hexadecimal value: 0x01
diff --git a/go/vt/vtgate/planbuilder/testdata/tpch_cases.txt b/go/vt/vtgate/planbuilder/testdata/tpch_cases.txt
index 37ee941d14..64d3aa702b 100644
--- a/go/vt/vtgate/planbuilder/testdata/tpch_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/tpch_cases.txt
@@ -11,102 +11,7 @@ Gen4 error: unsupported: cross-shard correlated subquery
 # TPC-H query 3
 "select l_orderkey, sum(l_extendedprice * (1 - l_discount)) as revenue, o_orderdate, o_shippriority from customer, orders, lineitem where c_mktsegment = 'BUILDING' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < date('1995-03-15') and l_shipdate > date('1995-03-15') group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate limit 10"
 "unsupported: cross-shard query with aggregates"
-{
-  "QueryType": "SELECT",
-  "Original": "select l_orderkey, sum(l_extendedprice * (1 - l_discount)) as revenue, o_orderdate, o_shippriority from customer, orders, lineitem where c_mktsegment = 'BUILDING' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate \u003c date('1995-03-15') and l_shipdate \u003e date('1995-03-15') group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate limit 10",
-  "Instructions": {
-    "OperatorType": "Limit",
-    "Count": 10,
-    "Inputs": [
-      {
-        "OperatorType": "Sort",
-        "Variant": "Memory",
-        "OrderBy": "1 DESC, (2|5) ASC",
-        "ResultColumns": 4,
-        "Inputs": [
-          {
-            "OperatorType": "Aggregate",
-            "Variant": "Ordered",
-            "Aggregates": "sum(1) AS revenue",
-            "GroupBy": "(0|4), (2|5), (3|6)",
-            "Inputs": [
-              {
-                "OperatorType": "Sort",
-                "Variant": "Memory",
-                "OrderBy": "(0|4) ASC, (2|5) ASC, (3|6) ASC",
-                "Inputs": [
-                  {
-                    "OperatorType": "Join",
-                    "Variant": "Join",
-                    "JoinColumnIndexes": "-1,-2,1,2,-3,3,4",
-                    "JoinVars": {
-                      "l_orderkey": 0
-                    },
-                    "TableName": "lineitem_orders_customer",
-                    "Inputs": [
-                      {
-                        "OperatorType": "Route",
-                        "Variant": "SelectScatter",
-                        "Keyspace": {
-                          "Name": "main",
-                          "Sharded": true
-                        },
-                        "FieldQuery": "select l_orderkey, sum(l_extendedprice * (1 - l_discount)) as revenue, weight_string(l_orderkey) from lineitem where 1 != 1",
-                        "Query": "select l_orderkey, sum(l_extendedprice * (1 - l_discount)) as revenue, weight_string(l_orderkey) from lineitem where l_shipdate \u003e date('1995-03-15')",
-                        "Table": "lineitem"
-                      },
-                      {
-                        "OperatorType": "Join",
-                        "Variant": "Join",
-                        "JoinColumnIndexes": "-2,-3,-4,-5",
-                        "JoinVars": {
-                          "o_custkey": 0
-                        },
-                        "TableName": "orders_customer",
-                        "Inputs": [
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select o_custkey, o_orderdate, o_shippriority, weight_string(o_orderdate), weight_string(o_shippriority) from orders where 1 != 1",
-                            "Query": "select o_custkey, o_orderdate, o_shippriority, weight_string(o_orderdate), weight_string(o_shippriority) from orders where o_orderdate \u003c date('1995-03-15') and o_orderkey = :l_orderkey",
-                            "Table": "orders",
-                            "Values": [
-                              ":l_orderkey"
-                            ],
-                            "Vindex": "hash"
-                          },
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select 1 from customer where 1 != 1",
-                            "Query": "select 1 from customer where c_mktsegment = 'BUILDING' and c_custkey = :o_custkey",
-                            "Table": "customer",
-                            "Values": [
-                              ":o_custkey"
-                            ],
-                            "Vindex": "hash"
-                          }
-                        ]
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ]
-      }
-    ]
-  }
-}
+Gen4 plan same as above
 
 # TPC-H query 4
 "select o_orderpriority, count(*) as order_count from orders where o_orderdate >= date('1993-07-01') and o_orderdate < date('1993-07-01') + interval '3' month and exists ( select * from lineitem where l_orderkey = o_orderkey and l_commitdate < l_receiptdate ) group by o_orderpriority order by o_orderpriority"
@@ -116,174 +21,7 @@ Gen4 error: unsupported: group by in a query having a correlated subquery
 # TPC-H query 5 - Gen4 produces plan but the plan output is flaky
 "select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue from customer, orders, lineitem, supplier, nation, region where c_custkey = o_custkey and l_orderkey = o_orderkey and l_suppkey = s_suppkey and c_nationkey = s_nationkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'ASIA' and o_orderdate >= date('1994-01-01') and o_orderdate < date('1994-01-01') + interval '1' year group by n_name order by revenue desc"
 "unsupported: cross-shard query with aggregates"
-{
-  "QueryType": "SELECT",
-  "Original": "select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue from customer, orders, lineitem, supplier, nation, region where c_custkey = o_custkey and l_orderkey = o_orderkey and l_suppkey = s_suppkey and c_nationkey = s_nationkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'ASIA' and o_orderdate \u003e= date('1994-01-01') and o_orderdate \u003c date('1994-01-01') + interval '1' year group by n_name order by revenue desc",
-  "Instructions": {
-    "OperatorType": "Sort",
-    "Variant": "Memory",
-    "OrderBy": "1 DESC",
-    "ResultColumns": 2,
-    "Inputs": [
-      {
-        "OperatorType": "Aggregate",
-        "Variant": "Ordered",
-        "Aggregates": "sum(1) AS revenue",
-        "GroupBy": "(0|2)",
-        "Inputs": [
-          {
-            "OperatorType": "Sort",
-            "Variant": "Memory",
-            "OrderBy": "(0|2) ASC",
-            "Inputs": [
-              {
-                "OperatorType": "Join",
-                "Variant": "Join",
-                "JoinColumnIndexes": "1,-2,2",
-                "JoinVars": {
-                  "s_nationkey": 0
-                },
-                "TableName": "orders_customer_lineitem_supplier_nation_region",
-                "Inputs": [
-                  {
-                    "OperatorType": "Join",
-                    "Variant": "Join",
-                    "JoinColumnIndexes": "1,2",
-                    "JoinVars": {
-                      "c_nationkey": 1,
-                      "o_orderkey": 0
-                    },
-                    "TableName": "orders_customer_lineitem_supplier",
-                    "Inputs": [
-                      {
-                        "OperatorType": "Join",
-                        "Variant": "Join",
-                        "JoinVars": {
-                          "o_custkey": 0
-                        },
-                        "TableName": "orders_customer",
-                        "Inputs": [
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectScatter",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select o_custkey, o_orderkey from orders where 1 != 1",
-                            "Query": "select o_custkey, o_orderkey from orders where o_orderdate \u003e= date('1994-01-01') and o_orderdate \u003c date('1994-01-01') + interval '1' year",
-                            "Table": "orders"
-                          },
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select c_nationkey from customer where 1 != 1",
-                            "Query": "select c_nationkey from customer where c_custkey = :o_custkey",
-                            "Table": "customer",
-                            "Values": [
-                              ":o_custkey"
-                            ],
-                            "Vindex": "hash"
-                          }
-                        ]
-                      },
-                      {
-                        "OperatorType": "Join",
-                        "Variant": "Join",
-                        "JoinColumnIndexes": "1,-2",
-                        "JoinVars": {
-                          "l_suppkey": 0
-                        },
-                        "TableName": "lineitem_supplier",
-                        "Inputs": [
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select l_suppkey, sum(l_extendedprice * (1 - l_discount)) as revenue from lineitem where 1 != 1",
-                            "Query": "select l_suppkey, sum(l_extendedprice * (1 - l_discount)) as revenue from lineitem where l_orderkey = :o_orderkey",
-                            "Table": "lineitem",
-                            "Values": [
-                              ":o_orderkey"
-                            ],
-                            "Vindex": "lineitem_map"
-                          },
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select s_nationkey from supplier where 1 != 1",
-                            "Query": "select s_nationkey from supplier where s_suppkey = :l_suppkey and s_nationkey = :c_nationkey",
-                            "Table": "supplier",
-                            "Values": [
-                              ":l_suppkey"
-                            ],
-                            "Vindex": "hash"
-                          }
-                        ]
-                      }
-                    ]
-                  },
-                  {
-                    "OperatorType": "Join",
-                    "Variant": "Join",
-                    "JoinColumnIndexes": "-2,-3",
-                    "JoinVars": {
-                      "n_regionkey": 0
-                    },
-                    "TableName": "nation_region",
-                    "Inputs": [
-                      {
-                        "OperatorType": "Route",
-                        "Variant": "SelectEqualUnique",
-                        "Keyspace": {
-                          "Name": "main",
-                          "Sharded": true
-                        },
-                        "FieldQuery": "select n_regionkey, n_name, weight_string(n_name) from nation where 1 != 1",
-                        "Query": "select n_regionkey, n_name, weight_string(n_name) from nation where n_nationkey = :s_nationkey",
-                        "Table": "nation",
-                        "Values": [
-                          ":s_nationkey"
-                        ],
-                        "Vindex": "hash"
-                      },
-                      {
-                        "OperatorType": "Route",
-                        "Variant": "SelectEqualUnique",
-                        "Keyspace": {
-                          "Name": "main",
-                          "Sharded": true
-                        },
-                        "FieldQuery": "select 1 from region where 1 != 1",
-                        "Query": "select 1 from region where r_name = 'ASIA' and r_regionkey = :n_regionkey",
-                        "Table": "region",
-                        "Values": [
-                          ":n_regionkey"
-                        ],
-                        "Vindex": "hash"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ]
-      }
-    ]
-  }
-}
+Gen4 plan same as above
 
 # TPC-H query 6
 "select sum(l_extendedprice * l_discount) as revenue from lineitem where l_shipdate >= date('1994-01-01') and l_shipdate < date('1994-01-01') + interval '1' year and l_discount between 0.06 - 0.01 and 0.06 + 0.01 and l_quantity < 24"
@@ -350,128 +88,7 @@ Gen4 plan same as above
 # TPC-H query 10
 "select c_custkey, c_name, sum(l_extendedprice * (1 - l_discount)) as revenue, c_acctbal, n_name, c_address, c_phone, c_comment from customer, orders, lineitem, nation where c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate >= date('1993-10-01') and o_orderdate < date('1993-10-01') + interval '3' month and l_returnflag = 'R' and c_nationkey = n_nationkey group by c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment order by revenue desc limit 20"
 "unsupported: cross-shard query with aggregates"
-{
-  "QueryType": "SELECT",
-  "Original": "select c_custkey, c_name, sum(l_extendedprice * (1 - l_discount)) as revenue, c_acctbal, n_name, c_address, c_phone, c_comment from customer, orders, lineitem, nation where c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate \u003e= date('1993-10-01') and o_orderdate \u003c date('1993-10-01') + interval '3' month and l_returnflag = 'R' and c_nationkey = n_nationkey group by c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment order by revenue desc limit 20",
-  "Instructions": {
-    "OperatorType": "Limit",
-    "Count": 20,
-    "Inputs": [
-      {
-        "OperatorType": "Sort",
-        "Variant": "Memory",
-        "OrderBy": "2 DESC",
-        "ResultColumns": 8,
-        "Inputs": [
-          {
-            "OperatorType": "Aggregate",
-            "Variant": "Ordered",
-            "Aggregates": "sum(2) AS revenue",
-            "GroupBy": "(0|8), (1|9), (3|10), (6|11), (4|12), (5|13), (7|14)",
-            "Inputs": [
-              {
-                "OperatorType": "Sort",
-                "Variant": "Memory",
-                "OrderBy": "(0|8) ASC, (1|9) ASC, (3|10) ASC, (6|11) ASC, (4|12) ASC, (5|13) ASC, (7|14) ASC",
-                "Inputs": [
-                  {
-                    "OperatorType": "Join",
-                    "Variant": "Join",
-                    "JoinColumnIndexes": "1,2,-2,3,4,5,6,7,8,9,10,11,12,13,14",
-                    "JoinVars": {
-                      "o_custkey": 0
-                    },
-                    "TableName": "orders_lineitem_customer_nation",
-                    "Inputs": [
-                      {
-                        "OperatorType": "Join",
-                        "Variant": "Join",
-                        "JoinColumnIndexes": "-2,1",
-                        "JoinVars": {
-                          "o_orderkey": 0
-                        },
-                        "TableName": "orders_lineitem",
-                        "Inputs": [
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectScatter",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select o_orderkey, o_custkey from orders where 1 != 1",
-                            "Query": "select o_orderkey, o_custkey from orders where o_orderdate \u003e= date('1993-10-01') and o_orderdate \u003c date('1993-10-01') + interval '3' month",
-                            "Table": "orders"
-                          },
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select sum(l_extendedprice * (1 - l_discount)) as revenue from lineitem where 1 != 1",
-                            "Query": "select sum(l_extendedprice * (1 - l_discount)) as revenue from lineitem where l_returnflag = 'R' and l_orderkey = :o_orderkey",
-                            "Table": "lineitem",
-                            "Values": [
-                              ":o_orderkey"
-                            ],
-                            "Vindex": "lineitem_map"
-                          }
-                        ]
-                      },
-                      {
-                        "OperatorType": "Join",
-                        "Variant": "Join",
-                        "JoinColumnIndexes": "-2,-3,-4,1,-5,-6,-7,-8,-9,-10,-11,2,-12,-13",
-                        "JoinVars": {
-                          "c_nationkey": 0
-                        },
-                        "TableName": "customer_nation",
-                        "Inputs": [
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select c_nationkey, c_custkey, c_name, c_acctbal, c_address, c_phone, c_comment, weight_string(c_custkey), weight_string(c_name), weight_string(c_acctbal), weight_string(c_phone), weight_string(c_address), weight_string(c_comment) from customer where 1 != 1",
-                            "Query": "select c_nationkey, c_custkey, c_name, c_acctbal, c_address, c_phone, c_comment, weight_string(c_custkey), weight_string(c_name), weight_string(c_acctbal), weight_string(c_phone), weight_string(c_address), weight_string(c_comment) from customer where c_custkey = :o_custkey",
-                            "Table": "customer",
-                            "Values": [
-                              ":o_custkey"
-                            ],
-                            "Vindex": "hash"
-                          },
-                          {
-                            "OperatorType": "Route",
-                            "Variant": "SelectEqualUnique",
-                            "Keyspace": {
-                              "Name": "main",
-                              "Sharded": true
-                            },
-                            "FieldQuery": "select n_name, weight_string(n_name) from nation where 1 != 1",
-                            "Query": "select n_name, weight_string(n_name) from nation where n_nationkey = :c_nationkey",
-                            "Table": "nation",
-                            "Values": [
-                              ":c_nationkey"
-                            ],
-                            "Vindex": "hash"
-                          }
-                        ]
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ]
-      }
-    ]
-  }
-}
+Gen4 plan same as above
 
 # TPC-H query 11
 "select ps_partkey, sum(ps_supplycost * ps_availqty) as value from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'GERMANY' group by ps_partkey  having sum(ps_supplycost * ps_availqty) > ( select sum(ps_supplycost * ps_availqty) * 0.00001000000 from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'GERMANY' ) order by value desc"
@@ -481,68 +98,12 @@ Gen4 error: unsupported: in scatter query: complex aggregate expression
 # TPC-H query 12
 "select l_shipmode, sum(case when o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority <> '1-URGENT' and o_orderpriority <> '2-HIGH' then 1 else 0 end) as low_line_count from orders, lineitem where o_orderkey = l_orderkey and l_shipmode in ('MAIL', 'SHIP') and l_commitdate < l_receiptdate and l_shipdate < l_commitdate and l_receiptdate >= date('1994-01-01') and l_receiptdate < date('1994-01-01') + interval '1' year group by l_shipmode order by l_shipmode"
 "unsupported: cross-shard query with aggregates"
-{
-  "QueryType": "SELECT",
-  "Original": "select l_shipmode, sum(case when o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority \u003c\u003e '1-URGENT' and o_orderpriority \u003c\u003e '2-HIGH' then 1 else 0 end) as low_line_count from orders, lineitem where o_orderkey = l_orderkey and l_shipmode in ('MAIL', 'SHIP') and l_commitdate \u003c l_receiptdate and l_shipdate \u003c l_commitdate and l_receiptdate \u003e= date('1994-01-01') and l_receiptdate \u003c date('1994-01-01') + interval '1' year group by l_shipmode order by l_shipmode",
-  "Instructions": {
-    "OperatorType": "Aggregate",
-    "Variant": "Ordered",
-    "Aggregates": "sum(1) AS high_line_count, sum(2) AS low_line_count",
-    "GroupBy": "(0|3)",
-    "ResultColumns": 3,
-    "Inputs": [
-      {
-        "OperatorType": "Sort",
-        "Variant": "Memory",
-        "OrderBy": "(0|3) ASC",
-        "Inputs": [
-          {
-            "OperatorType": "Join",
-            "Variant": "Join",
-            "JoinColumnIndexes": "1,-2,-3,2",
-            "JoinVars": {
-              "o_orderkey": 0
-            },
-            "TableName": "orders_lineitem",
-            "Inputs": [
-              {
-                "OperatorType": "Route",
-                "Variant": "SelectScatter",
-                "Keyspace": {
-                  "Name": "main",
-                  "Sharded": true
-                },
-                "FieldQuery": "select o_orderkey, sum(case when o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority != '1-URGENT' and o_orderpriority != '2-HIGH' then 1 else 0 end) as low_line_count from orders where 1 != 1",
-                "Query": "select o_orderkey, sum(case when o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority != '1-URGENT' and o_orderpriority != '2-HIGH' then 1 else 0 end) as low_line_count from orders",
-                "Table": "orders"
-              },
-              {
-                "OperatorType": "Route",
-                "Variant": "SelectEqualUnique",
-                "Keyspace": {
-                  "Name": "main",
-                  "Sharded": true
-                },
-                "FieldQuery": "select l_shipmode, weight_string(l_shipmode) from lineitem where 1 != 1",
-                "Query": "select l_shipmode, weight_string(l_shipmode) from lineitem where l_shipmode in ('MAIL', 'SHIP') and l_commitdate \u003c l_receiptdate and l_shipdate \u003c l_commitdate and l_receiptdate \u003e= date('1994-01-01') and l_receiptdate \u003c date('1994-01-01') + interval '1' year and l_orderkey = :o_orderkey",
-                "Table": "lineitem",
-                "Values": [
-                  ":o_orderkey"
-                ],
-                "Vindex": "lineitem_map"
-              }
-            ]
-          }
-        ]
-      }
-    ]
-  }
-}
+Gen4 plan same as above
 
 # TPC-H query 13
 "select c_count, count(*) as custdist from ( select c_custkey, count(o_orderkey) from customer left outer join orders on c_custkey = o_custkey and o_comment not like '%special%requests%' group by c_custkey ) as c_orders(c_custkey, c_count) group by c_count order by custdist desc, c_count desc"
 "unsupported: column aliases in derived table"
-Gen4 error: unsupported: cross-shard left join and column expressions
+Gen4 error: unsupported: cross-shard query with aggregates
 
 # TPC-H query 14
 "select 100.00 * sum(case when p_type like 'PROMO%' then l_extendedprice * (1 - l_discount) else 0 end) /  sum(l_extendedprice * (1 - l_discount)) as promo_revenue from lineitem, part where l_partkey = p_partkey and l_shipdate >= date('1995-09-01') and l_shipdate < date('1995-09-01') + interval '1' month"
diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
index d67579258e..8a558850ac 100644
--- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
+++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
@@ -612,3 +612,23 @@ Gen4 plan same as above
 "with x as (select * from user) select * from x union select * from x"
 "unsupported: with expression in union statement"
 Gen4 plan same as above
+
+# Aggregate on join
+"select user.a, count(*) from user join user_extra group by user.a"
+"unsupported: cross-shard query with aggregates"
+Gen4 plan same as above
+
+# Aggregate on other table in join
+"select user.a, count(user_extra.a) from user join user_extra group by user.a"
+"unsupported: cross-shard query with aggregates"
+Gen4 plan same as above
+
+# Equal filter with hexadecimal value
+"select count(*) a from user having a = 0x01"
+"unsupported: filtering on results of aggregates"
+Gen4 error: expr cannot be converted, not supported: hexadecimal value: 0x01
+
+# scatter aggregate with complex select list (can't build order by)
+"select distinct a+1 from user"
+"generating order by clause: cannot reference a complex expression"
+Gen4 error: unsupported: in scatter query: complex order by expression: a + 1