diff --git a/go/vt/vtgate/planbuilder/operators/insert.go b/go/vt/vtgate/planbuilder/operators/insert.go index e3f0748b78b..fa2f60dcecc 100644 --- a/go/vt/vtgate/planbuilder/operators/insert.go +++ b/go/vt/vtgate/planbuilder/operators/insert.go @@ -641,6 +641,9 @@ func modifyForAutoinc(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, v 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{} diff --git a/go/vt/vtgate/planbuilder/testdata/dml_cases.json b/go/vt/vtgate/planbuilder/testdata/dml_cases.json index eebcf63edf3..5ec8210b12d 100644 --- a/go/vt/vtgate/planbuilder/testdata/dml_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/dml_cases.json @@ -4889,5 +4889,15 @@ "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 user(one, two, three, four) values (1, 2, 3)", + "plan": "VT03006: column count does not match value count at row 1" + }, + { + "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" } ]