Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mismatch in column count and value count #14417

Merged
merged 12 commits into from
Nov 21, 2023
3 changes: 3 additions & 0 deletions go/vt/vtgate/planbuilder/operators/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ func modifyForAutoinc(ins *sqlparser.Insert, vTable *vindexes.Table) (*Generate,
case sqlparser.Values:
autoIncValues := make(sqlparser.ValTuple, 0, len(rows))
for rowNum, row := range rows {
if len(ins.Columns) != len(row) {
return nil, vterrors.VT03006()
}
// Support the DEFAULT keyword by treating it as null
if _, ok := row[colNum].(*sqlparser.Default); ok {
row[colNum] = &sqlparser.NullVal{}
Expand Down
44 changes: 44 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/dml_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4889,5 +4889,49 @@
"comment": "Unsupported update statement with a replica target destination",
"query": "update `user[-]@replica`.user_metadata set id=2",
"plan": "VT09002: update statement with a replica target"
},
{
"comment": "insert row values smaller than number of columns",
"query": "insert into unsharded(one, two, three, four) values (1, 2, 3)",
"plan": {
"QueryType": "INSERT",
"Original": "insert into unsharded(one, two, three, four) values (1, 2, 3)",
"Instructions": {
"OperatorType": "Insert",
"Variant": "Unsharded",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetTabletType": "PRIMARY",
"Query": "insert into unsharded(one, two, three, four) values (1, 2, 3)",
"TableName": "unsharded"
},
"TablesUsed": [
"main.unsharded"
]
}
},
{
"comment": "insert row values greater than number of columns",
"query": "insert into unsharded(one, two, three) values (1, 2, 3, 4)",
"plan": {
"QueryType": "INSERT",
"Original": "insert into unsharded(one, two, three) values (1, 2, 3, 4)",
"Instructions": {
"OperatorType": "Insert",
"Variant": "Unsharded",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetTabletType": "PRIMARY",
"Query": "insert into unsharded(one, two, three) values (1, 2, 3, 4)",
"TableName": "unsharded"
},
"TablesUsed": [
"main.unsharded"
]
}
FirePing32 marked this conversation as resolved.
Show resolved Hide resolved
}
]
Loading