From fdab808589ba535ee7034215316d9b4ce6c033c5 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Tue, 19 Sep 2023 18:26:19 +0530 Subject: [PATCH] fix: cost to include subshard opcode Signed-off-by: Harshit Gangal --- .../planbuilder/operators/sharded_routing.go | 2 +- .../planbuilder/testdata/from_cases.json | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/go/vt/vtgate/planbuilder/operators/sharded_routing.go b/go/vt/vtgate/planbuilder/operators/sharded_routing.go index 13f28005ea8..a1babd90e32 100644 --- a/go/vt/vtgate/planbuilder/operators/sharded_routing.go +++ b/go/vt/vtgate/planbuilder/operators/sharded_routing.go @@ -327,7 +327,7 @@ func (tr *ShardedRouting) Cost() int { switch tr.RouteOpCode { case engine.EqualUnique: return 1 - case engine.Equal: + case engine.Equal, engine.SubShard: return 5 case engine.IN: return 10 diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.json b/go/vt/vtgate/planbuilder/testdata/from_cases.json index efa04bfa7ca..805ce85dad9 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.json @@ -4039,5 +4039,53 @@ "main.unsharded_authoritative" ] } + }, + { + "comment": "join query using table with muticolumn vindex", + "query": "select 1 from multicol_tbl m1 join multicol_tbl m2 on m1.cola = m2.cola", + "plan": { + "QueryType": "SELECT", + "Original": "select 1 from multicol_tbl m1 join multicol_tbl m2 on m1.cola = m2.cola", + "Instructions": { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "L:0", + "JoinVars": { + "m1_cola": 1 + }, + "TableName": "multicol_tbl_multicol_tbl", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "Scatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1, m1.cola from multicol_tbl as m1 where 1 != 1", + "Query": "select 1, m1.cola from multicol_tbl as m1", + "Table": "multicol_tbl" + }, + { + "OperatorType": "Route", + "Variant": "SubShard", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select 1 from multicol_tbl as m2 where 1 != 1", + "Query": "select 1 from multicol_tbl as m2 where m2.cola = :m1_cola", + "Table": "multicol_tbl", + "Values": [ + ":m1_cola" + ], + "Vindex": "multicolIdx" + } + ] + }, + "TablesUsed": [ + "user.multicol_tbl" + ] + } } ]