Skip to content

Commit

Permalink
onDup walk to remove database qualifier
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Dec 11, 2023
1 parent b5ac0ff commit 02bbbdd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion go/vt/vtgate/planbuilder/operator_transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,11 @@ func generateInsertShardedQuery(ins *sqlparser.Insert) (prefix string, mids sqlp
ins.Table, ins.Columns)
prefix = prefixBuf.String()

suffix = ins.OnDup
suffix = sqlparser.CopyOnRewrite(ins.OnDup, nil, func(cursor *sqlparser.CopyOnWriteCursor) {
if tblName, ok := cursor.Node().(sqlparser.TableName); ok {
cursor.Replace(sqlparser.NewTableName(tblName.Name.String()))
}
}, nil).(sqlparser.OnDup)
return
}

Expand Down
27 changes: 27 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/dml_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4899,5 +4899,32 @@
"comment": "insert row values greater than number of columns",
"query": "insert into user(one, two, three) values (1, 2, 3, 4)",
"plan": "VT03006: column count does not match value count at row 1"
},
{
"comment": "insert on duplicate key update with database qualifier",
"query": "insert into user.music(id, user_id, col) values (1, 2, 3) on duplicate key update user.music.col = 5",
"plan": {
"QueryType": "INSERT",
"Original": "insert into user.music(id, user_id, col) values (1, 2, 3) on duplicate key update user.music.col = 5",
"Instructions": {
"OperatorType": "Insert",
"Variant": "Sharded",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"TargetTabletType": "PRIMARY",
"InsertIgnore": true,
"Query": "insert into music(id, user_id, col) values (:_id_0, :_user_id_0, 3) on duplicate key update music.col = 5",
"TableName": "music",
"VindexValues": {
"music_user_map": "1",
"user_index": "2"
}
},
"TablesUsed": [
"user.music"
]
}
}
]

0 comments on commit 02bbbdd

Please sign in to comment.