@@ -835,8 +835,8 @@ func TestDDLTargeted(t *testing.T) {
835835 utils .AssertMatches (t , conn , `select id from ddl_targeted` , `[[INT64(1)]]` )
836836}
837837
838- // TestTabletTargeting tests tablet-specific routing with USE keyspace@tablet-alias syntax.
839- // In a sharded keyspace, this validates that tablet-specific routing overrides normal hash -based routing .
838+ // TestTabletTargeting tests tablet-specific routing with USE keyspace:shard @tablet-alias syntax.
839+ // When shard is specified, tablet-specific routing bypasses vindex -based shard resolution .
840840func TestTabletTargeting (t * testing.T ) {
841841 ctx := context .Background ()
842842 conn , err := mysql .Connect (ctx , & vtParams )
@@ -865,41 +865,46 @@ func TestTabletTargeting(t *testing.T) {
865865 require .NotEmpty (t , primaryShard80Minus , "no PRIMARY tablet found for -80 shard" )
866866 require .NotEmpty (t , primaryShard80Plus , "no PRIMARY tablet found for 80- shard" )
867867
868- // Test: Target the -80 shard's PRIMARY and insert rows that normally hash to -80
869- // id1=1 and id1=2 both hash to -80 shard based on the hash vindex
870- utils .Exec (t , conn , fmt .Sprintf ("USE ks@%s" , primaryShard80Minus ))
868+ // Test: Target a specific tablet in -80 shard and insert rows
869+ // id1=1 and id1=2 both hash to -80 shard - this validates normal behavior
870+ utils .Exec (t , conn , fmt .Sprintf ("USE ks:-80 @%s" , primaryShard80Minus ))
871871 utils .Exec (t , conn , "insert into t1(id1, id2) values(1, 100), (2, 200)" )
872872 utils .AssertMatches (t , conn , "select id1 from t1 where id1 in (1, 2) order by id1" , "[[INT64(1)] [INT64(2)]]" )
873873
874- // Test: Verify the other shard (80-) did not receive these writes
875- utils .Exec (t , conn , fmt .Sprintf ("USE ks@%s" , primaryShard80Plus ))
876- utils .AssertIsEmpty (t , conn , "select id1 from t1 where id1 in (1, 2)" )
874+ // Test: Insert data that would normally hash to 80- shard, but goes to -80 because of shard targeting
875+ // id1=4 hashes to 80-, but we're targeting -80 shard explicitly
876+ utils .Exec (t , conn , fmt .Sprintf ("USE ks:-80@%s" , primaryShard80Minus ))
877+ utils .Exec (t , conn , "insert into t1(id1, id2) values(4, 400)" )
878+
879+ // Verify the data went to -80 shard (not where vindex would have put it)
880+ utils .Exec (t , conn , "USE ks:-80" )
881+ utils .AssertMatches (t , conn , "select id1 from t1 where id1=4" , "[[INT64(4)]]" )
882+
883+ // Verify the data did NOT go to 80- shard (where vindex says it should be)
884+ utils .Exec (t , conn , "USE ks:80-" )
885+ utils .AssertIsEmpty (t , conn , "select id1 from t1 where id1=4" )
877886
878887 // Test: Transaction with tablet-specific routing
879- utils .Exec (t , conn , fmt .Sprintf ("USE ks@%s" , primaryShard80Minus ))
888+ utils .Exec (t , conn , fmt .Sprintf ("USE ks:-80 @%s" , primaryShard80Minus ))
880889 utils .Exec (t , conn , "begin" )
881890 utils .Exec (t , conn , "insert into t1(id1, id2) values(10, 300)" )
882891 utils .Exec (t , conn , "commit" )
883892 utils .AssertMatches (t , conn , "select id1 from t1 where id1=10" , "[[INT64(10)]]" )
884893
885- // Test: Verify the other shard still has no data for our test rows
886- utils .Exec (t , conn , fmt .Sprintf ("USE ks@%s" , primaryShard80Plus ))
887- utils .AssertIsEmpty (t , conn , "select id1 from t1 where id1 in (1, 2, 10)" )
888-
889894 // Test: Rollback with tablet-specific routing
890- utils .Exec (t , conn , fmt .Sprintf ("USE ks@%s" , primaryShard80Minus ))
895+ utils .Exec (t , conn , fmt .Sprintf ("USE ks:-80 @%s" , primaryShard80Minus ))
891896 utils .Exec (t , conn , "begin" )
892- utils .Exec (t , conn , "insert into t1(id1, id2) values(20, 400 )" )
897+ utils .Exec (t , conn , "insert into t1(id1, id2) values(20, 500 )" )
893898 utils .Exec (t , conn , "rollback" )
894899 // 20 should not exist
895900 utils .AssertIsEmpty (t , conn , "select id1 from t1 where id1=20" )
896901
897902 // Test: Clear tablet targeting returns to normal routing
898903 utils .Exec (t , conn , "USE ks" )
899- utils .AssertMatches (t , conn , "select id1 from t1 where id1 in (1, 2, 10) order by id1" , "[[INT64(1)] [INT64(2)] [INT64(10)]]" )
904+ utils .AssertMatches (t , conn , "select id1 from t1 where id1 in (1, 2, 4, 10) order by id1" , "[[INT64(1)] [INT64(2)] [INT64(4 )] [INT64(10)]]" )
900905
901906 // Cleanup
902- utils .Exec (t , conn , "delete from t1 where id1 in (1, 2, 10)" )
907+ utils .Exec (t , conn , "delete from t1 where id1 in (1, 2, 4, 10)" )
903908}
904909
905910// TestDynamicConfig tests the dynamic configurations.
0 commit comments