Merge pull request #3848 from tinyspeck/on-dup-shard-key

Insert on duplicate key query support enhancement
This commit is contained in:
Sugu Sougoumarane 2018-05-09 07:35:36 -07:00 коммит произвёл GitHub
Родитель d6d7d226cc 32848b5022
Коммит a14b21cb33
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 81 добавлений и 3 удалений

Просмотреть файл

@ -464,6 +464,73 @@
}
}
# sharded upsert with sharding key set to vindex column
"insert into music(user_id, id) values(1, 2) on duplicate key update user_id = values(user_id)"
{
"Original": "insert into music(user_id, id) values(1, 2) on duplicate key update user_id = values(user_id)",
"Instructions": {
"Opcode": "InsertShardedIgnore",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "insert into music(user_id, id) values (:_user_id0, :_id0) on duplicate key update user_id = values(user_id)",
"Values": [
[
[
1
]
],
[
[
2
]
]
],
"Table": "music",
"Prefix": "insert into music(user_id, id) values ",
"Mid": [
"(:_user_id0, :_id0)"
],
"Suffix": " on duplicate key update user_id = values(user_id)"
}
}
# sharded bulk upsert with sharding key set to vindex column
"insert into music(user_id, id) values (1, 2), (3,4) on duplicate key update user_id = values(user_id)"
{
"Original": "insert into music(user_id, id) values (1, 2), (3,4) on duplicate key update user_id = values(user_id)",
"Instructions": {
"Opcode": "InsertShardedIgnore",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "insert into music(user_id, id) values (:_user_id0, :_id0), (:_user_id1, :_id1) on duplicate key update user_id = values(user_id)",
"Values": [
[
[
1,
3
]
],
[
[
2,
4
]
]
],
"Table": "music",
"Prefix": "insert into music(user_id, id) values ",
"Mid": [
"(:_user_id0, :_id0)",
"(:_user_id1, :_id1)"
],
"Suffix": " on duplicate key update user_id = values(user_id)"
}
}
# insert unsharded with select
"insert into unsharded select id from unsharded_auto"
{

Просмотреть файл

@ -395,6 +395,10 @@
"insert into user(id) values(1) on duplicate key update id = 3"
"unsupported: DML cannot change vindex column"
# sharded upsert can't change vindex using values function
"insert into music(user_id, id) values(1, 2) on duplicate key update user_id = values(id)"
"unsupported: DML cannot change vindex column"
# sharded insert from select
"insert into user(id) select 1 from dual"
"unsupported: insert into select"

Просмотреть файл

@ -235,7 +235,14 @@ func isVindexChanging(setClauses sqlparser.UpdateExprs, colVindexes []*vindexes.
for _, vcol := range colVindexes {
for _, col := range vcol.Columns {
if col.Equal(assignment.Name.Name) {
return true
valueExpr, isValuesFuncExpr := assignment.Expr.(*sqlparser.ValuesFuncExpr)
if !isValuesFuncExpr {
return true
}
// update on duplicate key is changing the vindex column, not supported.
if !valueExpr.Name.Equal(assignment.Name.Name) {
return true
}
}
}
}

Просмотреть файл

@ -103,7 +103,7 @@ func buildChangedVindexesValues(eupd *engine.Update, update *sqlparser.Update, c
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "column has duplicate set values: '%v'", assignment.Name.Name)
}
found = true
pv, err := extractValueFromUpdate(assignment, vcol)
pv, err := extractValueFromUpdate(assignment)
if err != nil {
return nil, err
}
@ -155,7 +155,7 @@ func generateUpdateSubquery(upd *sqlparser.Update, table *vindexes.Table) string
// extractValueFromUpdate given an UpdateExpr attempts to extracts the Value
// it's holding. At the moment it only supports: StrVal, HexVal, IntVal, ValArg.
// If a complex expression is provided (e.g set name = name + 1), the update will be rejected.
func extractValueFromUpdate(upd *sqlparser.UpdateExpr, col sqlparser.ColIdent) (pv sqltypes.PlanValue, err error) {
func extractValueFromUpdate(upd *sqlparser.UpdateExpr) (pv sqltypes.PlanValue, err error) {
if !sqlparser.IsValue(upd.Expr) {
err := vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "unsupported: Only values are supported. Invalid update on column: %v", upd.Name.Name)
return sqltypes.PlanValue{}, err