Skip to content

Commit

Permalink
Merge pull request vitessio#9863 from planetscale/join-cols-pretty
Browse files Browse the repository at this point in the history
feat: make the join columns output easier to read
  • Loading branch information
systay authored Mar 11, 2022
2 parents 63a4f00 + 2ea7ac9 commit d282dc5
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 232 deletions.
15 changes: 14 additions & 1 deletion go/vt/vtgate/engine/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func combineVars(bv1, bv2 map[string]*querypb.BindVariable) map[string]*querypb.
func (jn *Join) description() PrimitiveDescription {
other := map[string]interface{}{
"TableName": jn.GetTableName(),
"JoinColumnIndexes": strings.Trim(strings.Join(strings.Fields(fmt.Sprint(jn.Cols)), ","), "[]"),
"JoinColumnIndexes": jn.joinColsDescription(),
}
if len(jn.Vars) > 0 {
other["JoinVars"] = orderedStringIntMap(jn.Vars)
Expand All @@ -271,3 +271,16 @@ func (jn *Join) description() PrimitiveDescription {
Other: other,
}
}

func (jn *Join) joinColsDescription() string {
var joinCols []string
for _, col := range jn.Cols {
if col < 0 {
joinCols = append(joinCols, fmt.Sprintf("L:%d", -col-1))
} else {
joinCols = append(joinCols, fmt.Sprintf("R:%d", col-1))
}
}
joinColTxt := strings.Join(joinCols, ",")
return joinColTxt
}
20 changes: 10 additions & 10 deletions go/vt/vtgate/planbuilder/testdata/aggr_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1,1",
"JoinColumnIndexes": "L:0,R:0",
"TableName": "`user`_unsharded",
"Inputs": [
{
Expand Down Expand Up @@ -2307,7 +2307,7 @@ Gen4 plan same as above
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1,-2",
"JoinColumnIndexes": "L:0,L:1",
"TableName": "`user`_user_extra",
"Inputs": [
{
Expand Down Expand Up @@ -3174,7 +3174,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1,1",
"JoinColumnIndexes": "L:0,R:0",
"TableName": "`user`_user_extra",
"Inputs": [
{
Expand Down Expand Up @@ -3250,7 +3250,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-2,-3,-1,1",
"JoinColumnIndexes": "L:1,L:2,L:0,R:0",
"TableName": "`user`_user_extra",
"Inputs": [
{
Expand Down Expand Up @@ -3308,7 +3308,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-2,-3,-1,1",
"JoinColumnIndexes": "L:1,L:2,L:0,R:0",
"TableName": "`user`_user_extra",
"Inputs": [
{
Expand Down Expand Up @@ -3372,7 +3372,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1,2,-2,3,4,-3,5,6",
"JoinColumnIndexes": "R:0,R:1,L:1,R:2,R:3,L:2,R:4,R:5",
"JoinVars": {
"u_foo": 0
},
Expand All @@ -3392,7 +3392,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "2,3,-2,1,-3,1",
"JoinColumnIndexes": "R:1,R:2,L:1,R:0,L:2,R:0",
"JoinVars": {
"ue_bar": 0
},
Expand Down Expand Up @@ -3727,7 +3727,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-3,-4,-6",
"JoinColumnIndexes": "L:2,L:3,L:5",
"JoinVars": {
"u2_val2": 0
},
Expand All @@ -3736,7 +3736,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1,1,-3,-1,2,-2",
"JoinColumnIndexes": "R:0,R:0,L:2,L:0,R:1,L:1",
"JoinVars": {
"u_val2": 0
},
Expand Down Expand Up @@ -3820,7 +3820,7 @@ Gen4 error: cannot push projections in ordered aggregates
{
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1,-2,-3,1,2",
"JoinColumnIndexes": "L:0,L:1,L:2,R:0,R:1",
"JoinVars": {
"user_col": 0
},
Expand Down
40 changes: 20 additions & 20 deletions go/vt/vtgate/planbuilder/testdata/filter_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_col": 0
},
Expand Down Expand Up @@ -735,7 +735,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_col": 0
},
Expand Down Expand Up @@ -802,7 +802,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_col": 0
},
Expand Down Expand Up @@ -847,7 +847,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_col": 0
},
Expand Down Expand Up @@ -884,7 +884,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_col": 0
},
Expand Down Expand Up @@ -1081,7 +1081,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_id": 0
},
Expand Down Expand Up @@ -1118,7 +1118,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1",
"JoinColumnIndexes": "L:0",
"JoinVars": {
"unsharded_id": 0
},
Expand Down Expand Up @@ -1185,7 +1185,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_extra_col": 0
},
Expand Down Expand Up @@ -1226,7 +1226,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_extra_col": 0
},
Expand Down Expand Up @@ -1270,7 +1270,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_extra_col": 0
},
Expand Down Expand Up @@ -1311,7 +1311,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_extra_col": 0
},
Expand Down Expand Up @@ -1355,7 +1355,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"TableName": "user_extra_`user`",
"Inputs": [
{
Expand Down Expand Up @@ -1393,7 +1393,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"TableName": "user_extra_`user`",
"Inputs": [
{
Expand Down Expand Up @@ -1434,7 +1434,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_extra_col": 0
},
Expand Down Expand Up @@ -1475,7 +1475,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_extra_col": 0
},
Expand Down Expand Up @@ -2989,7 +2989,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1",
"JoinColumnIndexes": "L:0",
"JoinVars": {
"user_id": 0
},
Expand Down Expand Up @@ -3044,7 +3044,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-1",
"JoinColumnIndexes": "L:0",
"JoinVars": {
"user_id": 0
},
Expand Down Expand Up @@ -3081,7 +3081,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "1",
"JoinColumnIndexes": "R:0",
"JoinVars": {
"user_extra_col": 0
},
Expand Down Expand Up @@ -3144,7 +3144,7 @@ Gen4 plan same as above
"Instructions": {
"OperatorType": "Join",
"Variant": "Join",
"JoinColumnIndexes": "-2",
"JoinColumnIndexes": "L:1",
"JoinVars": {
"user_col": 0
},
Expand Down Expand Up @@ -3200,7 +3200,7 @@ Gen4 plan same as above
{
"OperatorType": "Join",
"Variant": "LeftJoin",
"JoinColumnIndexes": "1,-2",
"JoinColumnIndexes": "R:0,L:1",
"JoinVars": {
"user_col": 0
},
Expand Down
Loading

0 comments on commit d282dc5

Please sign in to comment.