Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/test/vtexplain/multi-output/options-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ select * from user where id in (1,2,3,4,5,6,7,8)
1 ks_sharded/c0-: select * from user where id in (4, 6, 7, 8) limit 10001

----------------------------------------------------------------------
insert into user (id, name) values(2, 'bob')
insert into user (id, name) values (2, 'bob')

1 ks_sharded/c0-: begin
1 ks_sharded/c0-: insert into name_user_map(name, user_id) values ('bob', 2) /* _stream name_user_map (name user_id ) ('Ym9i' 2 ); */ /* vtgate:: keyspace_id:da8a82595aa28154c17717955ffeed8b */
Expand Down
18 changes: 18 additions & 0 deletions data/test/vtexplain/multi-output/target-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
----------------------------------------------------------------------
select * from user where email='null@void.com'

1 ks_sharded/40-80: select * from user where email = 'null@void.com' limit 10001

----------------------------------------------------------------------
select * from user where id in (1,2,3,4,5,6,7,8)

1 ks_sharded/40-80: select * from user where id in (1, 2, 3, 4, 5, 6, 7, 8) limit 10001

----------------------------------------------------------------------
insert into user (id, name) values (2, 'bob')

1 ks_sharded/40-80: begin
1 ks_sharded/40-80: insert into user(id, name) values (2, 'bob')/* vtgate:: filtered_replication_unfriendly */
2 ks_sharded/40-80: commit

----------------------------------------------------------------------
2 changes: 1 addition & 1 deletion data/test/vtexplain/options-queries.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
select * from user where email='null@void.com';
select * from user where id in (1,2,3,4,5,6,7,8);
insert into user (id, name) values(2, 'bob');
insert into user (id, name) values (2, 'bob');
8 changes: 8 additions & 0 deletions data/test/vtexplain/target-queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* These are the same set of queries from "options-queries.sql" but
* are run with an explicit shard target of ks_sharded/40-80 which
* bypasses the normal v3 routing.
*/
select * from user where email='null@void.com';
select * from user where id in (1,2,3,4,5,6,7,8);
insert into user (id, name) values (2, 'bob');
3 changes: 3 additions & 0 deletions go/cmd/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
replicationMode = flag.String("replication-mode", "ROW", "The replication mode to simulate -- must be set to either ROW or STATEMENT")
normalize = flag.Bool("normalize", false, "Whether to enable vtgate normalization")
outputMode = flag.String("output-mode", "text", "Output in human-friendly text or json")
dbName = flag.String("dbname", "", "Optional database target to override normal routing")

// vtexplainFlags lists all the flags that should show in usage
vtexplainFlags = []string{
Expand All @@ -53,6 +54,7 @@ var (
"sql-file",
"vschema",
"vschema-file",
"dbname",
}
)

Expand Down Expand Up @@ -153,6 +155,7 @@ func parseAndRun() error {
ReplicationMode: *replicationMode,
NumShards: *numShards,
Normalize: *normalize,
Target: *dbName,
}

log.V(100).Infof("sql %s\n", sql)
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type Options struct {
// StrictDDL is used in unit tests only to verify that the schema
// is parsed properly.
StrictDDL bool

// Target is used to override the "database" target in the
// vtgate session to simulate `USE <target>`
Target string
}

// TabletQuery defines a query that was sent to a given tablet and how it was
Expand Down
10 changes: 10 additions & 0 deletions go/vt/vtexplain/vtexplain_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ func TestOptions(t *testing.T) {

testExplain("options", opts, t)
}
func TestTarget(t *testing.T) {
opts := &Options{
ReplicationMode: "ROW",
NumShards: 4,
Normalize: false,
Target: "ks_sharded/40-80",
}

testExplain("target", opts, t)
}

func TestComments(t *testing.T) {
testExplain("comments", defaultTestOpts(), t)
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vtexplain/vtexplain_vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
healthCheck *discovery.FakeHealthCheck

vtgateSession = &vtgatepb.Session{
TargetString: "@master",
TargetString: "",
Autocommit: true,
}
)
Expand All @@ -62,6 +62,8 @@ func initVtgateExecutor(vSchemaStr string, opts *Options) error {
return err
}

vtgateSession.TargetString = opts.Target

streamSize := 10
queryPlanCacheSize := int64(10)
vtgateExecutor = vtgate.NewExecutor(context.Background(), explainTopo, vtexplainCell, "", resolver, opts.Normalize, streamSize, queryPlanCacheSize, false /* legacyAutocommit */)
Expand Down