From dfb71022c29253b16d6778d61af83dbeb581f0bd Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 4 Jun 2020 19:33:19 +0200 Subject: [PATCH] Fixes #6266 Signed-off-by: Andres Taylor --- .../vtgate/vindex_bindvars/main_test.go | 225 ++++++++++++++++++ go/vt/vtgate/autocommit_test.go | 42 ++-- go/vt/vtgate/engine/insert.go | 16 +- go/vt/vtgate/engine/insert_test.go | 98 ++++---- go/vt/vtgate/executor_dml_test.go | 222 ++++++++--------- go/vt/vtgate/plan_executor_dml_test.go | 222 ++++++++--------- go/vt/vtgate/planbuilder/insert.go | 5 +- .../vtgate/planbuilder/testdata/dml_cases.txt | 40 ++-- 8 files changed, 549 insertions(+), 321 deletions(-) create mode 100644 go/test/endtoend/vtgate/vindex_bindvars/main_test.go diff --git a/go/test/endtoend/vtgate/vindex_bindvars/main_test.go b/go/test/endtoend/vtgate/vindex_bindvars/main_test.go new file mode 100644 index 00000000000..a40ae633bcc --- /dev/null +++ b/go/test/endtoend/vtgate/vindex_bindvars/main_test.go @@ -0,0 +1,225 @@ +/* +Copyright 2019 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package vtgate + +import ( + "context" + "flag" + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/require" + "gotest.tools/assert" + "vitess.io/vitess/go/sqltypes" + + "vitess.io/vitess/go/mysql" + "vitess.io/vitess/go/test/endtoend/cluster" +) + +var ( + clusterInstance *cluster.LocalProcessCluster + vtParams mysql.ConnParams + KeyspaceName = "ks" + Cell = "test" + SchemaSQL = `CREATE TABLE t1 ( + id BIGINT NOT NULL, + field BIGINT NOT NULL, + field2 BIGINT, + PRIMARY KEY (id) +) ENGINE=Innodb; + + +CREATE TABLE lookup1 ( + field BIGINT NOT NULL, + keyspace_id binary(8), + UNIQUE KEY (field) +) ENGINE=Innodb; + +CREATE TABLE lookup2 ( + field2 BIGINT NOT NULL, + keyspace_id binary(8), + UNIQUE KEY (field2) +) ENGINE=Innodb; +` + + VSchema = ` +{ + "sharded": true, + "vindexes": { + "hash": { + "type": "hash" + }, + "lookup1": { + "type": "consistent_lookup", + "params": { + "table": "lookup1", + "from": "field", + "to": "keyspace_id", + "ignore_nulls": "true" + }, + "owner": "t1" + }, + "lookup2": { + "type": "consistent_lookup", + "params": { + "table": "lookup2", + "from": "field2", + "to": "keyspace_id", + "ignore_nulls": "true" + }, + "owner": "t1" + } + }, + "tables": { + "t1": { + "column_vindexes": [ + { + "column": "id", + "name": "hash" + }, + { + "column": "field", + "name": "lookup1" + }, + { + "column": "field2", + "name": "lookup2" + } + ] + }, + "lookup1": { + "column_vindexes": [ + { + "column": "field", + "name": "hash" + } + ] + }, + "lookup2": { + "column_vindexes": [ + { + "column": "field2", + "name": "hash" + } + ] + } + } +}` +) + +func TestMain(m *testing.M) { + defer cluster.PanicHandler(nil) + flag.Parse() + + exitCode := func() int { + clusterInstance = cluster.NewCluster(Cell, "localhost") + defer clusterInstance.Teardown() + + // Start topo server + err := clusterInstance.StartTopo() + if err != nil { + return 1 + } + + // Start keyspace + keyspace := &cluster.Keyspace{ + Name: KeyspaceName, + SchemaSQL: SchemaSQL, + VSchema: VSchema, + } + err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true) + if err != nil { + return 1 + } + + // Start vtgate + err = clusterInstance.StartVtgate() + if err != nil { + return 1 + } + vtParams = mysql.ConnParams{ + Host: clusterInstance.Hostname, + Port: clusterInstance.VtgateMySQLPort, + } + return m.Run() + }() + os.Exit(exitCode) +} + +func TestVindexBindVarOverlap(t *testing.T) { + defer cluster.PanicHandler(t) + ctx := context.Background() + conn, err := mysql.Connect(ctx, &vtParams) + require.Nil(t, err) + defer conn.Close() + + exec(t, conn, "INSERT INTO t1 (id, field, field2) VALUES "+ + "(0,1,2), "+ + "(1,2,3), "+ + "(2,3,4), "+ + "(3,4,5), "+ + "(4,5,6), "+ + "(5,6,7), "+ + "(6,7,8), "+ + "(7,8,9), "+ + "(8,9,10), "+ + "(9,10,11), "+ + "(10,11,12), "+ + "(11,12,13), "+ + "(12,13,14), "+ + "(13,14,15), "+ + "(14,15,16), "+ + "(15,16,17), "+ + "(16,17,18), "+ + "(17,18,19), "+ + "(18,19,20), "+ + "(19,20,21), "+ + "(20,21,22)") + result := exec(t, conn, "select id, field, field2 from t1 order by id") + + expected := + "[[INT64(0) INT64(1) INT64(2)] " + + "[INT64(1) INT64(2) INT64(3)] " + + "[INT64(2) INT64(3) INT64(4)] " + + "[INT64(3) INT64(4) INT64(5)] " + + "[INT64(4) INT64(5) INT64(6)] " + + "[INT64(5) INT64(6) INT64(7)] " + + "[INT64(6) INT64(7) INT64(8)] " + + "[INT64(7) INT64(8) INT64(9)] " + + "[INT64(8) INT64(9) INT64(10)] " + + "[INT64(9) INT64(10) INT64(11)] " + + "[INT64(10) INT64(11) INT64(12)] " + + "[INT64(11) INT64(12) INT64(13)] " + + "[INT64(12) INT64(13) INT64(14)] " + + "[INT64(13) INT64(14) INT64(15)] " + + "[INT64(14) INT64(15) INT64(16)] " + + "[INT64(15) INT64(16) INT64(17)] " + + "[INT64(16) INT64(17) INT64(18)] " + + "[INT64(17) INT64(18) INT64(19)] " + + "[INT64(18) INT64(19) INT64(20)] " + + "[INT64(19) INT64(20) INT64(21)] " + + "[INT64(20) INT64(21) INT64(22)]]" + assert.Equal(t, expected, fmt.Sprintf("%v", result.Rows)) +} + +func exec(t *testing.T, conn *mysql.Conn, query string) *sqltypes.Result { + t.Helper() + qr, err := conn.ExecuteFetch(query, 1000, true) + require.NoError(t, err) + return qr +} diff --git a/go/vt/vtgate/autocommit_test.go b/go/vt/vtgate/autocommit_test.go index 2c37d7b0665..ce829ed3a94 100644 --- a/go/vt/vtgate/autocommit_test.go +++ b/go/vt/vtgate/autocommit_test.go @@ -248,9 +248,9 @@ func TestAutocommitInsertSharded(t *testing.T) { require.NoError(t, err) testBatchQuery(t, "sbc1", sbc1, &querypb.BoundQuery{ - Sql: "insert into user_extra(user_id, v) values (:_user_id0, 2)", + Sql: "insert into user_extra(user_id, v) values (:_user_id_0, 2)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(1), + "_user_id_0": sqltypes.Int64BindVariable(1), }, }) testAsTransactionCount(t, "sbc1", sbc1, 1) @@ -279,11 +279,11 @@ func TestAutocommitInsertLookup(t *testing.T) { testCommitCount(t, "sbclookup", sbclookup, 1) testQueries(t, "sbc1", sbc1, []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "__seq0": sqltypes.Int64BindVariable(1), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "__seq0": sqltypes.Int64BindVariable(1), }, }}) testAsTransactionCount(t, "sbc1", sbc1, 0) @@ -298,20 +298,20 @@ func TestAutocommitInsertMultishardAutoCommit(t *testing.T) { require.NoError(t, err) testBatchQuery(t, "sbc1", sbc1, &querypb.BoundQuery{ - Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id0, 2)", + Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id_0, 2)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(1), - "_user_id1": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(1), + "_user_id_1": sqltypes.Int64BindVariable(3), }, }) testAsTransactionCount(t, "sbc1", sbc1, 1) testCommitCount(t, "sbc1", sbc1, 0) testBatchQuery(t, "sbc2", sbc2, &querypb.BoundQuery{ - Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id1, 4)", + Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id_1, 4)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(1), - "_user_id1": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(1), + "_user_id_1": sqltypes.Int64BindVariable(3), }, }) testAsTransactionCount(t, "sbc2", sbc2, 1) @@ -330,10 +330,10 @@ func TestAutocommitInsertMultishardAutoCommit(t *testing.T) { testCommitCount(t, "sbc1", sbc1, 0) testBatchQuery(t, "sbc2", sbc2, &querypb.BoundQuery{ - Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id1, 4)", + Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id_1, 4)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(1), - "_user_id1": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(1), + "_user_id_1": sqltypes.Int64BindVariable(3), }, }) testAsTransactionCount(t, "sbc2", sbc2, 1) @@ -348,20 +348,20 @@ func TestAutocommitInsertMultishard(t *testing.T) { require.NoError(t, err) testQueries(t, "sbc1", sbc1, []*querypb.BoundQuery{{ - Sql: "insert into user_extra(user_id, v) values (:_user_id0, 2)", + Sql: "insert into user_extra(user_id, v) values (:_user_id_0, 2)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(1), - "_user_id1": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(1), + "_user_id_1": sqltypes.Int64BindVariable(3), }, }}) testAsTransactionCount(t, "sbc1", sbc1, 0) testCommitCount(t, "sbc1", sbc1, 1) testQueries(t, "sbc2", sbc2, []*querypb.BoundQuery{{ - Sql: "insert into user_extra(user_id, v) values (:_user_id1, 4)", + Sql: "insert into user_extra(user_id, v) values (:_user_id_1, 4)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(1), - "_user_id1": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(1), + "_user_id_1": sqltypes.Int64BindVariable(3), }, }}) testAsTransactionCount(t, "sbc2", sbc2, 0) diff --git a/go/vt/vtgate/engine/insert.go b/go/vt/vtgate/engine/insert.go index 7e9d7af07e5..5e17a95b589 100644 --- a/go/vt/vtgate/engine/insert.go +++ b/go/vt/vtgate/engine/insert.go @@ -23,13 +23,14 @@ import ( "strings" "time" + "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/vtgate/evalengine" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/key" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/srvtopo" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vtgate/vindexes" @@ -397,7 +398,8 @@ func (ins *Insert) getInsertShardedRoute(vcursor VCursor, bindVars map[string]*q } for colIdx, vindexKey := range rowColumnKeys { col := colVindex.Columns[colIdx] - bindVars[insertVarName(col, rowNum)] = sqltypes.ValueBindVariable(vindexKey) + name := InsertVarName(col, rowNum) + bindVars[name] = sqltypes.ValueBindVariable(vindexKey) } } } @@ -514,9 +516,9 @@ func (ins *Insert) processOwned(vcursor VCursor, vindexColumnsKeys [][]sqltypes. // processUnowned either reverse maps or validates the values for an unowned column. func (ins *Insert) processUnowned(vcursor VCursor, vindexColumnsKeys [][]sqltypes.Value, colVindex *vindexes.ColumnVindex, ksids [][]byte) error { - var reverseIndexes []int + reverseIndexes := []int{} var reverseKsids [][]byte - var verifyIndexes []int + verifyIndexes := []int{} var verifyKeys [][]sqltypes.Value var verifyKsids [][]byte @@ -580,8 +582,10 @@ func (ins *Insert) processUnowned(vcursor VCursor, vindexColumnsKeys [][]sqltype return nil } -func insertVarName(col sqlparser.ColIdent, rowNum int) string { - return "_" + col.CompliantName() + strconv.Itoa(rowNum) +//InsertVarName returns a name for the bind var for this column. This method is used by the planner and engine, +//to make sure they both produce the same names +func InsertVarName(col sqlparser.ColIdent, rowNum int) string { + return fmt.Sprintf("_%s_%d", col.CompliantName(), rowNum) } func (ins *Insert) description() PrimitiveDescription { diff --git a/go/vt/vtgate/engine/insert_test.go b/go/vt/vtgate/engine/insert_test.go index 3c46e5510af..479508eba23 100644 --- a/go/vt/vtgate/engine/insert_test.go +++ b/go/vt/vtgate/engine/insert_test.go @@ -177,7 +177,7 @@ func TestInsertShardedSimple(t *testing.T) { `ResolveDestinations sharded [value:"0" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6)`, // Row 2 will go to -20, rows 1 & 3 will go to 20- `ExecuteMultiShard ` + - `sharded.20-: prefix mid1 suffix {_id0: type:INT64 value:"1" } ` + + `sharded.20-: prefix mid1 suffix {_id_0: type:INT64 value:"1" } ` + `true true`, }) @@ -216,8 +216,8 @@ func TestInsertShardedSimple(t *testing.T) { `ResolveDestinations sharded [value:"0" value:"1" value:"2" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6),DestinationKeyspaceID(06e7ea22ce92708f),DestinationKeyspaceID(4eb190c9a2fa169c)`, // Row 2 will go to -20, rows 1 & 3 will go to 20- `ExecuteMultiShard ` + - `sharded.20-: prefix mid1, mid3 suffix {_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + - `sharded.-20: prefix mid2 suffix {_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `sharded.20-: prefix mid1, mid3 suffix {_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + + `sharded.-20: prefix mid2 suffix {_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `true false`, }) @@ -258,8 +258,8 @@ func TestInsertShardedSimple(t *testing.T) { `ResolveDestinations sharded [value:"0" value:"1" value:"2" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6),DestinationKeyspaceID(06e7ea22ce92708f),DestinationKeyspaceID(4eb190c9a2fa169c)`, // Row 2 will go to -20, rows 1 & 3 will go to 20- `ExecuteMultiShard ` + - `sharded.20-: prefix mid1, mid3 suffix {_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + - `sharded.-20: prefix mid2 suffix {_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `sharded.20-: prefix mid1, mid3 suffix {_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + + `sharded.-20: prefix mid2 suffix {_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `true true`, }) } @@ -412,10 +412,10 @@ func TestInsertShardedGenerate(t *testing.T) { `ExecuteMultiShard ` + `sharded.20-: prefix mid1, mid3 suffix ` + `{__seq0: type:INT64 value:"1" __seq1: type:INT64 value:"2" __seq2: type:INT64 value:"2" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `sharded.-20: prefix mid2 suffix ` + `{__seq0: type:INT64 value:"1" __seq1: type:INT64 value:"2" __seq2: type:INT64 value:"2" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `true false`, }) @@ -549,15 +549,15 @@ func TestInsertShardedOwned(t *testing.T) { `ResolveDestinations sharded [value:"0" value:"1" value:"2" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6),DestinationKeyspaceID(06e7ea22ce92708f),DestinationKeyspaceID(4eb190c9a2fa169c)`, `ExecuteMultiShard ` + `sharded.20-: prefix mid1, mid3 suffix ` + - `{_c10: type:INT64 value:"4" _c11: type:INT64 value:"5" _c12: type:INT64 value:"6" ` + - `_c20: type:INT64 value:"7" _c21: type:INT64 value:"8" _c22: type:INT64 value:"9" ` + - `_c30: type:INT64 value:"10" _c31: type:INT64 value:"11" _c32: type:INT64 value:"12" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `{_c1_0: type:INT64 value:"4" _c1_1: type:INT64 value:"5" _c1_2: type:INT64 value:"6" ` + + `_c2_0: type:INT64 value:"7" _c2_1: type:INT64 value:"8" _c2_2: type:INT64 value:"9" ` + + `_c3_0: type:INT64 value:"10" _c3_1: type:INT64 value:"11" _c3_2: type:INT64 value:"12" ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `sharded.-20: prefix mid2 suffix ` + - `{_c10: type:INT64 value:"4" _c11: type:INT64 value:"5" _c12: type:INT64 value:"6" ` + - `_c20: type:INT64 value:"7" _c21: type:INT64 value:"8" _c22: type:INT64 value:"9" ` + - `_c30: type:INT64 value:"10" _c31: type:INT64 value:"11" _c32: type:INT64 value:"12" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `{_c1_0: type:INT64 value:"4" _c1_1: type:INT64 value:"5" _c1_2: type:INT64 value:"6" ` + + `_c2_0: type:INT64 value:"7" _c2_1: type:INT64 value:"8" _c2_2: type:INT64 value:"9" ` + + `_c3_0: type:INT64 value:"10" _c3_1: type:INT64 value:"11" _c3_2: type:INT64 value:"12" ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `true false`, }) } @@ -640,7 +640,7 @@ func TestInsertShardedOwnedWithNull(t *testing.T) { `value:"\026k@\264J\272K\326" true`, `ResolveDestinations sharded [value:"0" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6)`, `ExecuteMultiShard sharded.20-: prefix mid1 suffix ` + - `{_c30: _id0: type:INT64 value:"1" } true true`, + `{_c3_0: _id_0: type:INT64 value:"1" } true true`, }) } @@ -737,11 +737,11 @@ func TestInsertShardedGeo(t *testing.T) { `keyspace_id0: type:VARBINARY value:"\001\026k@\264J\272K\326" keyspace_id1: type:VARBINARY value:"\377\026k@\264J\272K\326" true`, `ResolveDestinations sharded [value:"0" value:"1" ] Destinations:DestinationKeyspaceID(01166b40b44aba4bd6),DestinationKeyspaceID(ff166b40b44aba4bd6)`, `ExecuteMultiShard sharded.20-: prefix mid1 suffix ` + - `{_id0: type:INT64 value:"1" _id1: type:INT64 value:"1" ` + - `_region0: type:INT64 value:"1" _region1: type:INT64 value:"255" } ` + + `{_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"1" ` + + `_region_0: type:INT64 value:"1" _region_1: type:INT64 value:"255" } ` + `sharded.-20: prefix mid2 suffix ` + - `{_id0: type:INT64 value:"1" _id1: type:INT64 value:"1" ` + - `_region0: type:INT64 value:"1" _region1: type:INT64 value:"255" } ` + + `{_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"1" ` + + `_region_0: type:INT64 value:"1" _region_1: type:INT64 value:"255" } ` + `true false`, }) } @@ -924,15 +924,15 @@ func TestInsertShardedIgnoreOwned(t *testing.T) { // Bind vars for rows 2 & 3 may be missing because they were not sent. `ExecuteMultiShard ` + `sharded.20-: prefix mid1 suffix ` + - `{_c10: type:INT64 value:"5" _c13: type:INT64 value:"8" ` + - `_c20: type:INT64 value:"9" _c23: type:INT64 value:"12" ` + - `_c30: type:INT64 value:"13" _c33: type:INT64 value:"16" ` + - `_id0: type:INT64 value:"1" _id3: type:INT64 value:"4" } ` + + `{_c1_0: type:INT64 value:"5" _c1_3: type:INT64 value:"8" ` + + `_c2_0: type:INT64 value:"9" _c2_3: type:INT64 value:"12" ` + + `_c3_0: type:INT64 value:"13" _c3_3: type:INT64 value:"16" ` + + `_id_0: type:INT64 value:"1" _id_3: type:INT64 value:"4" } ` + `sharded.-20: prefix mid4 suffix ` + - `{_c10: type:INT64 value:"5" _c13: type:INT64 value:"8" ` + - `_c20: type:INT64 value:"9" _c23: type:INT64 value:"12" ` + - `_c30: type:INT64 value:"13" _c33: type:INT64 value:"16" ` + - `_id0: type:INT64 value:"1" _id3: type:INT64 value:"4" } ` + + `{_c1_0: type:INT64 value:"5" _c1_3: type:INT64 value:"8" ` + + `_c2_0: type:INT64 value:"9" _c2_3: type:INT64 value:"12" ` + + `_c3_0: type:INT64 value:"13" _c3_3: type:INT64 value:"16" ` + + `_id_0: type:INT64 value:"1" _id_3: type:INT64 value:"4" } ` + `true false`, }) } @@ -1028,7 +1028,7 @@ func TestInsertShardedIgnoreOwnedWithNull(t *testing.T) { `Execute select from from lkp1 where from = :from and toc = :toc from: toc: type:VARBINARY value:"\026k@\264J\272K\326" false`, `ResolveDestinations sharded [value:"0" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6)`, `ExecuteMultiShard sharded.-20: prefix mid1 suffix ` + - `{_c30: _id0: type:INT64 value:"1" } true true`, + `{_c3_0: _id_0: type:INT64 value:"1" } true true`, }) } @@ -1174,15 +1174,15 @@ func TestInsertShardedUnownedVerify(t *testing.T) { `ResolveDestinations sharded [value:"0" value:"1" value:"2" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6),DestinationKeyspaceID(06e7ea22ce92708f),DestinationKeyspaceID(4eb190c9a2fa169c)`, `ExecuteMultiShard ` + `sharded.20-: prefix mid1, mid3 suffix ` + - `{_c10: type:INT64 value:"4" _c11: type:INT64 value:"5" _c12: type:INT64 value:"6" ` + - `_c20: type:INT64 value:"7" _c21: type:INT64 value:"8" _c22: type:INT64 value:"9" ` + - `_c30: type:INT64 value:"10" _c31: type:INT64 value:"11" _c32: type:INT64 value:"12" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `{_c1_0: type:INT64 value:"4" _c1_1: type:INT64 value:"5" _c1_2: type:INT64 value:"6" ` + + `_c2_0: type:INT64 value:"7" _c2_1: type:INT64 value:"8" _c2_2: type:INT64 value:"9" ` + + `_c3_0: type:INT64 value:"10" _c3_1: type:INT64 value:"11" _c3_2: type:INT64 value:"12" ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `sharded.-20: prefix mid2 suffix ` + - `{_c10: type:INT64 value:"4" _c11: type:INT64 value:"5" _c12: type:INT64 value:"6" ` + - `_c20: type:INT64 value:"7" _c21: type:INT64 value:"8" _c22: type:INT64 value:"9" ` + - `_c30: type:INT64 value:"10" _c31: type:INT64 value:"11" _c32: type:INT64 value:"12" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `{_c1_0: type:INT64 value:"4" _c1_1: type:INT64 value:"5" _c1_2: type:INT64 value:"6" ` + + `_c2_0: type:INT64 value:"7" _c2_1: type:INT64 value:"8" _c2_2: type:INT64 value:"9" ` + + `_c3_0: type:INT64 value:"10" _c3_1: type:INT64 value:"11" _c3_2: type:INT64 value:"12" ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `true false`, }) } @@ -1292,11 +1292,11 @@ func TestInsertShardedIgnoreUnownedVerify(t *testing.T) { `ResolveDestinations sharded [value:"0" value:"2" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6),DestinationKeyspaceID(4eb190c9a2fa169c)`, `ExecuteMultiShard ` + `sharded.20-: prefix mid1 suffix ` + - `{_c30: type:INT64 value:"10" _c32: type:INT64 value:"12" ` + - `_id0: type:INT64 value:"1" _id2: type:INT64 value:"3" } ` + + `{_c3_0: type:INT64 value:"10" _c3_2: type:INT64 value:"12" ` + + `_id_0: type:INT64 value:"1" _id_2: type:INT64 value:"3" } ` + `sharded.-20: prefix mid3 suffix ` + - `{_c30: type:INT64 value:"10" _c32: type:INT64 value:"12" ` + - `_id0: type:INT64 value:"1" _id2: type:INT64 value:"3" } ` + + `{_c3_0: type:INT64 value:"10" _c3_2: type:INT64 value:"12" ` + + `_id_0: type:INT64 value:"1" _id_2: type:INT64 value:"3" } ` + `true false`, }) } @@ -1500,15 +1500,15 @@ func TestInsertShardedUnownedReverseMap(t *testing.T) { `ResolveDestinations sharded [value:"0" value:"1" value:"2" ] Destinations:DestinationKeyspaceID(166b40b44aba4bd6),DestinationKeyspaceID(06e7ea22ce92708f),DestinationKeyspaceID(4eb190c9a2fa169c)`, `ExecuteMultiShard ` + `sharded.20-: prefix mid1, mid3 suffix ` + - `{_c10: type:UINT64 value:"1" _c11: type:UINT64 value:"2" _c12: type:UINT64 value:"3" ` + - `_c20: _c21: _c22: ` + - `_c30: type:UINT64 value:"1" _c31: type:UINT64 value:"2" _c32: type:UINT64 value:"3" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `{_c1_0: type:UINT64 value:"1" _c1_1: type:UINT64 value:"2" _c1_2: type:UINT64 value:"3" ` + + `_c2_0: _c2_1: _c2_2: ` + + `_c3_0: type:UINT64 value:"1" _c3_1: type:UINT64 value:"2" _c3_2: type:UINT64 value:"3" ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `sharded.-20: prefix mid2 suffix ` + - `{_c10: type:UINT64 value:"1" _c11: type:UINT64 value:"2" _c12: type:UINT64 value:"3" ` + - `_c20: _c21: _c22: ` + - `_c30: type:UINT64 value:"1" _c31: type:UINT64 value:"2" _c32: type:UINT64 value:"3" ` + - `_id0: type:INT64 value:"1" _id1: type:INT64 value:"2" _id2: type:INT64 value:"3" } ` + + `{_c1_0: type:UINT64 value:"1" _c1_1: type:UINT64 value:"2" _c1_2: type:UINT64 value:"3" ` + + `_c2_0: _c2_1: _c2_2: ` + + `_c3_0: type:UINT64 value:"1" _c3_1: type:UINT64 value:"2" _c3_2: type:UINT64 value:"3" ` + + `_id_0: type:INT64 value:"1" _id_1: type:INT64 value:"2" _id_2: type:INT64 value:"3" } ` + `true false`, }) } diff --git a/go/vt/vtgate/executor_dml_test.go b/go/vt/vtgate/executor_dml_test.go index 23915311361..8f35107e237 100644 --- a/go/vt/vtgate/executor_dml_test.go +++ b/go/vt/vtgate/executor_dml_test.go @@ -555,11 +555,11 @@ func TestInsertSharded(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 2, 'myname')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "__seq0": sqltypes.Int64BindVariable(1), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "__seq0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -587,11 +587,11 @@ func TestInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user(id, v, name) values (3, 2, 'myname2')", nil) require.NoError(t, err) wantQueries = []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(3), - "__seq0": sqltypes.Int64BindVariable(3), - "_name0": sqltypes.BytesBindVariable([]byte("myname2")), + "_Id_0": sqltypes.Int64BindVariable(3), + "__seq0": sqltypes.Int64BindVariable(3), + "_name_0": sqltypes.BytesBindVariable([]byte("myname2")), }, }} if !reflect.DeepEqual(sbc2.Queries, wantQueries) { @@ -615,11 +615,11 @@ func TestInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user2(id, name, lastname) values (2, 'myname', 'mylastname')", nil) require.NoError(t, err) wantQueries = []*querypb.BoundQuery{{ - Sql: "insert into user2(id, name, lastname) values (:_id0, :_name0, :_lastname0)", + Sql: "insert into user2(id, name, lastname) values (:_id_0, :_name_0, :_lastname_0)", BindVariables: map[string]*querypb.BindVariable{ - "_id0": sqltypes.Int64BindVariable(2), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "_lastname0": sqltypes.BytesBindVariable([]byte("mylastname")), + "_id_0": sqltypes.Int64BindVariable(2), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "_lastname_0": sqltypes.BytesBindVariable([]byte("mylastname")), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -689,11 +689,11 @@ func TestInsertShardedAutocommitLookup(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 2, 'myname')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "__seq0": sqltypes.Int64BindVariable(1), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "__seq0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -757,34 +757,34 @@ func TestInsertShardedIgnore(t *testing.T) { _, err := executorExec(executor, query, nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv0, :_owned0, :_verify0),(:_pv4, :_owned4, :_verify4)", + Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv_0, :_owned_0, :_verify_0),(:_pv_4, :_owned_4, :_verify_4)", BindVariables: map[string]*querypb.BindVariable{ - "_pv0": sqltypes.Int64BindVariable(1), - "_pv4": sqltypes.Int64BindVariable(5), - "_pv5": sqltypes.Int64BindVariable(6), - "_owned0": sqltypes.Int64BindVariable(1), - "_owned4": sqltypes.Int64BindVariable(5), - "_owned5": sqltypes.Int64BindVariable(6), - "_verify0": sqltypes.Int64BindVariable(1), - "_verify4": sqltypes.Int64BindVariable(1), - "_verify5": sqltypes.Int64BindVariable(3), + "_pv_0": sqltypes.Int64BindVariable(1), + "_pv_4": sqltypes.Int64BindVariable(5), + "_pv_5": sqltypes.Int64BindVariable(6), + "_owned_0": sqltypes.Int64BindVariable(1), + "_owned_4": sqltypes.Int64BindVariable(5), + "_owned_5": sqltypes.Int64BindVariable(6), + "_verify_0": sqltypes.Int64BindVariable(1), + "_verify_4": sqltypes.Int64BindVariable(1), + "_verify_5": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { t.Errorf("sbc1.Queries:\n%+v, want\n%+v\n", sbc1.Queries, wantQueries) } wantQueries = []*querypb.BoundQuery{{ - Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv5, :_owned5, :_verify5)", + Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv_5, :_owned_5, :_verify_5)", BindVariables: map[string]*querypb.BindVariable{ - "_pv0": sqltypes.Int64BindVariable(1), - "_pv4": sqltypes.Int64BindVariable(5), - "_pv5": sqltypes.Int64BindVariable(6), - "_owned0": sqltypes.Int64BindVariable(1), - "_owned4": sqltypes.Int64BindVariable(5), - "_owned5": sqltypes.Int64BindVariable(6), - "_verify0": sqltypes.Int64BindVariable(1), - "_verify4": sqltypes.Int64BindVariable(1), - "_verify5": sqltypes.Int64BindVariable(3), + "_pv_0": sqltypes.Int64BindVariable(1), + "_pv_4": sqltypes.Int64BindVariable(5), + "_pv_5": sqltypes.Int64BindVariable(6), + "_owned_0": sqltypes.Int64BindVariable(1), + "_owned_4": sqltypes.Int64BindVariable(5), + "_owned_5": sqltypes.Int64BindVariable(6), + "_verify_0": sqltypes.Int64BindVariable(1), + "_verify_4": sqltypes.Int64BindVariable(1), + "_verify_5": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc2.Queries, wantQueries) { @@ -907,11 +907,11 @@ func TestInsertOnDupKey(t *testing.T) { _, err := executorExec(executor, query, nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into insert_ignore_test(pv, owned, verify) values (:_pv0, :_owned0, :_verify0) on duplicate key update col = 2", + Sql: "insert into insert_ignore_test(pv, owned, verify) values (:_pv_0, :_owned_0, :_verify_0) on duplicate key update col = 2", BindVariables: map[string]*querypb.BindVariable{ - "_pv0": sqltypes.Int64BindVariable(1), - "_owned0": sqltypes.Int64BindVariable(1), - "_verify0": sqltypes.Int64BindVariable(1), + "_pv_0": sqltypes.Int64BindVariable(1), + "_owned_0": sqltypes.Int64BindVariable(1), + "_verify_0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -949,11 +949,11 @@ func TestInsertComments(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 2, 'myname') /* trailing */", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0) /* trailing */", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0) /* trailing */", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "__seq0": sqltypes.Int64BindVariable(1), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "__seq0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -987,11 +987,11 @@ func TestInsertGeneratorSharded(t *testing.T) { result, err := executorExec(executor, "insert into user(v, name) values (2, 'myname')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(v, name, id) values (2, :_name0, :_Id0)", + Sql: "insert into user(v, name, id) values (2, :_name_0, :_Id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), + "_Id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1032,9 +1032,9 @@ func TestInsertAutoincSharded(t *testing.T) { result, err := executorExec(router, "insert into user_extra(user_id) values (2)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user_extra(user_id) values (:_user_id0)", + Sql: "insert into user_extra(user_id) values (:_user_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), + "_user_id_0": sqltypes.Int64BindVariable(2), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1103,11 +1103,11 @@ func TestInsertLookupOwned(t *testing.T) { _, err := executorExec(executor, "insert into music(user_id, id) values (2, 3)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(user_id, id) values (:_user_id0, :_id0)", + Sql: "insert into music(user_id, id) values (:_user_id_0, :_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(3), - "__seq0": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(3), + "__seq0": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1138,11 +1138,11 @@ func TestInsertLookupOwnedGenerator(t *testing.T) { result, err := executorExec(executor, "insert into music(user_id) values (2)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(user_id, id) values (:_user_id0, :_id0)", + Sql: "insert into music(user_id, id) values (:_user_id_0, :_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(4), - "__seq0": sqltypes.Int64BindVariable(4), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(4), + "__seq0": sqltypes.Int64BindVariable(4), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1174,10 +1174,10 @@ func TestInsertLookupUnowned(t *testing.T) { _, err := executorExec(executor, "insert into music_extra(user_id, music_id) values (2, 3)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music_extra(user_id, music_id) values (:_user_id0, :_music_id0)", + Sql: "insert into music_extra(user_id, music_id) values (:_user_id_0, :_music_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), - "_music_id0": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_music_id_0": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1201,10 +1201,10 @@ func TestInsertLookupUnownedUnsupplied(t *testing.T) { _, err := executorExec(executor, "insert into music_extra_reversed(music_id) values (3)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music_extra_reversed(music_id, user_id) values (:_music_id0, :_user_id0)", + Sql: "insert into music_extra_reversed(music_id, user_id) values (:_music_id_0, :_user_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Uint64BindVariable(1), - "_music_id0": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Uint64BindVariable(1), + "_music_id_0": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1270,26 +1270,26 @@ func TestMultiInsertSharded(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 1, 'myname1'),(3, 3, 'myname3')", nil) require.NoError(t, err) wantQueries1 := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 1, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 1, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname1")), - "__seq0": sqltypes.Int64BindVariable(1), - "_Id1": sqltypes.Int64BindVariable(3), - "_name1": sqltypes.BytesBindVariable([]byte("myname3")), - "__seq1": sqltypes.Int64BindVariable(3), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname1")), + "__seq0": sqltypes.Int64BindVariable(1), + "_Id_1": sqltypes.Int64BindVariable(3), + "_name_1": sqltypes.BytesBindVariable([]byte("myname3")), + "__seq1": sqltypes.Int64BindVariable(3), }, }} wantQueries2 := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id1, 3, :_name1)", + Sql: "insert into user(id, v, name) values (:_Id_1, 3, :_name_1)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname1")), - "__seq0": sqltypes.Int64BindVariable(1), - "_Id1": sqltypes.Int64BindVariable(3), - "_name1": sqltypes.BytesBindVariable([]byte("myname3")), - "__seq1": sqltypes.Int64BindVariable(3), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname1")), + "__seq0": sqltypes.Int64BindVariable(1), + "_Id_1": sqltypes.Int64BindVariable(3), + "_name_1": sqltypes.BytesBindVariable([]byte("myname3")), + "__seq1": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries1) { @@ -1319,14 +1319,14 @@ func TestMultiInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user(id, v, name) values (1, 1, 'myname1'),(2, 2, 'myname2')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 1, :_name0),(:_Id1, 2, :_name1)", + Sql: "insert into user(id, v, name) values (:_Id_0, 1, :_name_0),(:_Id_1, 2, :_name_1)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname1")), - "_Id1": sqltypes.Int64BindVariable(2), - "__seq1": sqltypes.Int64BindVariable(2), - "_name1": sqltypes.BytesBindVariable([]byte("myname2")), + "_Id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname1")), + "_Id_1": sqltypes.Int64BindVariable(2), + "__seq1": sqltypes.Int64BindVariable(2), + "_name_1": sqltypes.BytesBindVariable([]byte("myname2")), }, }} @@ -1356,14 +1356,14 @@ func TestMultiInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user2(id, name, lastname) values (2, 'myname', 'mylastname'), (3, 'myname2', 'mylastname2')", nil) require.NoError(t, err) wantQueries = []*querypb.BoundQuery{{ - Sql: "insert into user2(id, name, lastname) values (:_id0, :_name0, :_lastname0)", + Sql: "insert into user2(id, name, lastname) values (:_id_0, :_name_0, :_lastname_0)", BindVariables: map[string]*querypb.BindVariable{ - "_id0": sqltypes.Int64BindVariable(2), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "_lastname0": sqltypes.BytesBindVariable([]byte("mylastname")), - "_id1": sqltypes.Int64BindVariable(3), - "_name1": sqltypes.BytesBindVariable([]byte("myname2")), - "_lastname1": sqltypes.BytesBindVariable([]byte("mylastname2")), + "_id_0": sqltypes.Int64BindVariable(2), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "_lastname_0": sqltypes.BytesBindVariable([]byte("mylastname")), + "_id_1": sqltypes.Int64BindVariable(3), + "_name_1": sqltypes.BytesBindVariable([]byte("myname2")), + "_lastname_1": sqltypes.BytesBindVariable([]byte("mylastname2")), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -1398,15 +1398,15 @@ func TestMultiInsertGenerator(t *testing.T) { result, err := executorExec(executor, "insert into music(user_id, name) values (:u, 'myname1'),(:u, 'myname2')", map[string]*querypb.BindVariable{"u": sqltypes.Int64BindVariable(2)}) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(user_id, name, id) values (:_user_id0, 'myname1', :_id0),(:_user_id1, 'myname2', :_id1)", + Sql: "insert into music(user_id, name, id) values (:_user_id_0, 'myname1', :_id_0),(:_user_id_1, 'myname2', :_id_1)", BindVariables: map[string]*querypb.BindVariable{ - "u": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_user_id0": sqltypes.Int64BindVariable(2), - "_id1": sqltypes.Int64BindVariable(2), - "__seq1": sqltypes.Int64BindVariable(2), - "_user_id1": sqltypes.Int64BindVariable(2), + "u": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_1": sqltypes.Int64BindVariable(2), + "__seq1": sqltypes.Int64BindVariable(2), + "_user_id_1": sqltypes.Int64BindVariable(2), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1447,18 +1447,18 @@ func TestMultiInsertGeneratorSparse(t *testing.T) { result, err := executorExec(executor, "insert into music(id, user_id, name) values (NULL, :u, 'myname1'),(2, :u, 'myname2'), (NULL, :u, 'myname3')", map[string]*querypb.BindVariable{"u": sqltypes.Int64BindVariable(2)}) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(id, user_id, name) values (:_id0, :_user_id0, 'myname1'),(:_id1, :_user_id1, 'myname2'),(:_id2, :_user_id2, 'myname3')", + Sql: "insert into music(id, user_id, name) values (:_id_0, :_user_id_0, 'myname1'),(:_id_1, :_user_id_1, 'myname2'),(:_id_2, :_user_id_2, 'myname3')", BindVariables: map[string]*querypb.BindVariable{ - "u": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_user_id0": sqltypes.Int64BindVariable(2), - "_id1": sqltypes.Int64BindVariable(2), - "__seq1": sqltypes.Int64BindVariable(2), - "_user_id1": sqltypes.Int64BindVariable(2), - "_id2": sqltypes.Int64BindVariable(2), - "__seq2": sqltypes.Int64BindVariable(2), - "_user_id2": sqltypes.Int64BindVariable(2), + "u": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_1": sqltypes.Int64BindVariable(2), + "__seq1": sqltypes.Int64BindVariable(2), + "_user_id_1": sqltypes.Int64BindVariable(2), + "_id_2": sqltypes.Int64BindVariable(2), + "__seq2": sqltypes.Int64BindVariable(2), + "_user_id_2": sqltypes.Int64BindVariable(2), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { diff --git a/go/vt/vtgate/plan_executor_dml_test.go b/go/vt/vtgate/plan_executor_dml_test.go index 744eec16ba0..d0f71f32d0a 100644 --- a/go/vt/vtgate/plan_executor_dml_test.go +++ b/go/vt/vtgate/plan_executor_dml_test.go @@ -555,11 +555,11 @@ func TestPlanInsertSharded(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 2, 'myname')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "__seq0": sqltypes.Int64BindVariable(1), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "__seq0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -587,11 +587,11 @@ func TestPlanInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user(id, v, name) values (3, 2, 'myname2')", nil) require.NoError(t, err) wantQueries = []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(3), - "__seq0": sqltypes.Int64BindVariable(3), - "_name0": sqltypes.BytesBindVariable([]byte("myname2")), + "_Id_0": sqltypes.Int64BindVariable(3), + "__seq0": sqltypes.Int64BindVariable(3), + "_name_0": sqltypes.BytesBindVariable([]byte("myname2")), }, }} if !reflect.DeepEqual(sbc2.Queries, wantQueries) { @@ -615,11 +615,11 @@ func TestPlanInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user2(id, name, lastname) values (2, 'myname', 'mylastname')", nil) require.NoError(t, err) wantQueries = []*querypb.BoundQuery{{ - Sql: "insert into user2(id, name, lastname) values (:_id0, :_name0, :_lastname0)", + Sql: "insert into user2(id, name, lastname) values (:_id_0, :_name_0, :_lastname_0)", BindVariables: map[string]*querypb.BindVariable{ - "_id0": sqltypes.Int64BindVariable(2), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "_lastname0": sqltypes.BytesBindVariable([]byte("mylastname")), + "_id_0": sqltypes.Int64BindVariable(2), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "_lastname_0": sqltypes.BytesBindVariable([]byte("mylastname")), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -689,11 +689,11 @@ func TestPlanInsertShardedAutocommitLookup(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 2, 'myname')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "__seq0": sqltypes.Int64BindVariable(1), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "__seq0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -757,34 +757,34 @@ func TestPlanInsertShardedIgnore(t *testing.T) { _, err := executorExec(executor, query, nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv0, :_owned0, :_verify0),(:_pv4, :_owned4, :_verify4)", + Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv_0, :_owned_0, :_verify_0),(:_pv_4, :_owned_4, :_verify_4)", BindVariables: map[string]*querypb.BindVariable{ - "_pv0": sqltypes.Int64BindVariable(1), - "_pv4": sqltypes.Int64BindVariable(5), - "_pv5": sqltypes.Int64BindVariable(6), - "_owned0": sqltypes.Int64BindVariable(1), - "_owned4": sqltypes.Int64BindVariable(5), - "_owned5": sqltypes.Int64BindVariable(6), - "_verify0": sqltypes.Int64BindVariable(1), - "_verify4": sqltypes.Int64BindVariable(1), - "_verify5": sqltypes.Int64BindVariable(3), + "_pv_0": sqltypes.Int64BindVariable(1), + "_pv_4": sqltypes.Int64BindVariable(5), + "_pv_5": sqltypes.Int64BindVariable(6), + "_owned_0": sqltypes.Int64BindVariable(1), + "_owned_4": sqltypes.Int64BindVariable(5), + "_owned_5": sqltypes.Int64BindVariable(6), + "_verify_0": sqltypes.Int64BindVariable(1), + "_verify_4": sqltypes.Int64BindVariable(1), + "_verify_5": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { t.Errorf("sbc1.Queries:\n%+v, want\n%+v\n", sbc1.Queries, wantQueries) } wantQueries = []*querypb.BoundQuery{{ - Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv5, :_owned5, :_verify5)", + Sql: "insert ignore into insert_ignore_test(pv, owned, verify) values (:_pv_5, :_owned_5, :_verify_5)", BindVariables: map[string]*querypb.BindVariable{ - "_pv0": sqltypes.Int64BindVariable(1), - "_pv4": sqltypes.Int64BindVariable(5), - "_pv5": sqltypes.Int64BindVariable(6), - "_owned0": sqltypes.Int64BindVariable(1), - "_owned4": sqltypes.Int64BindVariable(5), - "_owned5": sqltypes.Int64BindVariable(6), - "_verify0": sqltypes.Int64BindVariable(1), - "_verify4": sqltypes.Int64BindVariable(1), - "_verify5": sqltypes.Int64BindVariable(3), + "_pv_0": sqltypes.Int64BindVariable(1), + "_pv_4": sqltypes.Int64BindVariable(5), + "_pv_5": sqltypes.Int64BindVariable(6), + "_owned_0": sqltypes.Int64BindVariable(1), + "_owned_4": sqltypes.Int64BindVariable(5), + "_owned_5": sqltypes.Int64BindVariable(6), + "_verify_0": sqltypes.Int64BindVariable(1), + "_verify_4": sqltypes.Int64BindVariable(1), + "_verify_5": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc2.Queries, wantQueries) { @@ -907,11 +907,11 @@ func TestPlanInsertOnDupKey(t *testing.T) { _, err := executorExec(executor, query, nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into insert_ignore_test(pv, owned, verify) values (:_pv0, :_owned0, :_verify0) on duplicate key update col = 2", + Sql: "insert into insert_ignore_test(pv, owned, verify) values (:_pv_0, :_owned_0, :_verify_0) on duplicate key update col = 2", BindVariables: map[string]*querypb.BindVariable{ - "_pv0": sqltypes.Int64BindVariable(1), - "_owned0": sqltypes.Int64BindVariable(1), - "_verify0": sqltypes.Int64BindVariable(1), + "_pv_0": sqltypes.Int64BindVariable(1), + "_owned_0": sqltypes.Int64BindVariable(1), + "_verify_0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -949,11 +949,11 @@ func TestPlanInsertComments(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 2, 'myname') /* trailing */", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 2, :_name0) /* trailing */", + Sql: "insert into user(id, v, name) values (:_Id_0, 2, :_name_0) /* trailing */", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "__seq0": sqltypes.Int64BindVariable(1), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "__seq0": sqltypes.Int64BindVariable(1), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -987,11 +987,11 @@ func TestPlanInsertGeneratorSharded(t *testing.T) { result, err := executorExec(executor, "insert into user(v, name) values (2, 'myname')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(v, name, id) values (2, :_name0, :_Id0)", + Sql: "insert into user(v, name, id) values (2, :_name_0, :_Id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), + "_Id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1032,9 +1032,9 @@ func TestPlanInsertAutoincSharded(t *testing.T) { result, err := executorExec(router, "insert into user_extra(user_id) values (2)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user_extra(user_id) values (:_user_id0)", + Sql: "insert into user_extra(user_id) values (:_user_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), + "_user_id_0": sqltypes.Int64BindVariable(2), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1103,11 +1103,11 @@ func TestPlanInsertLookupOwned(t *testing.T) { _, err := executorExec(executor, "insert into music(user_id, id) values (2, 3)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(user_id, id) values (:_user_id0, :_id0)", + Sql: "insert into music(user_id, id) values (:_user_id_0, :_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(3), - "__seq0": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(3), + "__seq0": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1138,11 +1138,11 @@ func TestPlanInsertLookupOwnedGenerator(t *testing.T) { result, err := executorExec(executor, "insert into music(user_id) values (2)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(user_id, id) values (:_user_id0, :_id0)", + Sql: "insert into music(user_id, id) values (:_user_id_0, :_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(4), - "__seq0": sqltypes.Int64BindVariable(4), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(4), + "__seq0": sqltypes.Int64BindVariable(4), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1174,10 +1174,10 @@ func TestPlanInsertLookupUnowned(t *testing.T) { _, err := executorExec(executor, "insert into music_extra(user_id, music_id) values (2, 3)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music_extra(user_id, music_id) values (:_user_id0, :_music_id0)", + Sql: "insert into music_extra(user_id, music_id) values (:_user_id_0, :_music_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Int64BindVariable(2), - "_music_id0": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_music_id_0": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1201,10 +1201,10 @@ func TestPlanInsertLookupUnownedUnsupplied(t *testing.T) { _, err := executorExec(executor, "insert into music_extra_reversed(music_id) values (3)", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music_extra_reversed(music_id, user_id) values (:_music_id0, :_user_id0)", + Sql: "insert into music_extra_reversed(music_id, user_id) values (:_music_id_0, :_user_id_0)", BindVariables: map[string]*querypb.BindVariable{ - "_user_id0": sqltypes.Uint64BindVariable(1), - "_music_id0": sqltypes.Int64BindVariable(3), + "_user_id_0": sqltypes.Uint64BindVariable(1), + "_music_id_0": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1270,26 +1270,26 @@ func TestPlanMultiInsertSharded(t *testing.T) { _, err := executorExec(executor, "insert into user(id, v, name) values (1, 1, 'myname1'),(3, 3, 'myname3')", nil) require.NoError(t, err) wantQueries1 := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 1, :_name0)", + Sql: "insert into user(id, v, name) values (:_Id_0, 1, :_name_0)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname1")), - "__seq0": sqltypes.Int64BindVariable(1), - "_Id1": sqltypes.Int64BindVariable(3), - "_name1": sqltypes.BytesBindVariable([]byte("myname3")), - "__seq1": sqltypes.Int64BindVariable(3), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname1")), + "__seq0": sqltypes.Int64BindVariable(1), + "_Id_1": sqltypes.Int64BindVariable(3), + "_name_1": sqltypes.BytesBindVariable([]byte("myname3")), + "__seq1": sqltypes.Int64BindVariable(3), }, }} wantQueries2 := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id1, 3, :_name1)", + Sql: "insert into user(id, v, name) values (:_Id_1, 3, :_name_1)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname1")), - "__seq0": sqltypes.Int64BindVariable(1), - "_Id1": sqltypes.Int64BindVariable(3), - "_name1": sqltypes.BytesBindVariable([]byte("myname3")), - "__seq1": sqltypes.Int64BindVariable(3), + "_Id_0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname1")), + "__seq0": sqltypes.Int64BindVariable(1), + "_Id_1": sqltypes.Int64BindVariable(3), + "_name_1": sqltypes.BytesBindVariable([]byte("myname3")), + "__seq1": sqltypes.Int64BindVariable(3), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries1) { @@ -1319,14 +1319,14 @@ func TestPlanMultiInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user(id, v, name) values (1, 1, 'myname1'),(2, 2, 'myname2')", nil) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into user(id, v, name) values (:_Id0, 1, :_name0),(:_Id1, 2, :_name1)", + Sql: "insert into user(id, v, name) values (:_Id_0, 1, :_name_0),(:_Id_1, 2, :_name_1)", BindVariables: map[string]*querypb.BindVariable{ - "_Id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_name0": sqltypes.BytesBindVariable([]byte("myname1")), - "_Id1": sqltypes.Int64BindVariable(2), - "__seq1": sqltypes.Int64BindVariable(2), - "_name1": sqltypes.BytesBindVariable([]byte("myname2")), + "_Id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_name_0": sqltypes.BytesBindVariable([]byte("myname1")), + "_Id_1": sqltypes.Int64BindVariable(2), + "__seq1": sqltypes.Int64BindVariable(2), + "_name_1": sqltypes.BytesBindVariable([]byte("myname2")), }, }} @@ -1356,14 +1356,14 @@ func TestPlanMultiInsertSharded(t *testing.T) { _, err = executorExec(executor, "insert into user2(id, name, lastname) values (2, 'myname', 'mylastname'), (3, 'myname2', 'mylastname2')", nil) require.NoError(t, err) wantQueries = []*querypb.BoundQuery{{ - Sql: "insert into user2(id, name, lastname) values (:_id0, :_name0, :_lastname0)", + Sql: "insert into user2(id, name, lastname) values (:_id_0, :_name_0, :_lastname_0)", BindVariables: map[string]*querypb.BindVariable{ - "_id0": sqltypes.Int64BindVariable(2), - "_name0": sqltypes.BytesBindVariable([]byte("myname")), - "_lastname0": sqltypes.BytesBindVariable([]byte("mylastname")), - "_id1": sqltypes.Int64BindVariable(3), - "_name1": sqltypes.BytesBindVariable([]byte("myname2")), - "_lastname1": sqltypes.BytesBindVariable([]byte("mylastname2")), + "_id_0": sqltypes.Int64BindVariable(2), + "_name_0": sqltypes.BytesBindVariable([]byte("myname")), + "_lastname_0": sqltypes.BytesBindVariable([]byte("mylastname")), + "_id_1": sqltypes.Int64BindVariable(3), + "_name_1": sqltypes.BytesBindVariable([]byte("myname2")), + "_lastname_1": sqltypes.BytesBindVariable([]byte("mylastname2")), }, }} if !reflect.DeepEqual(sbc1.Queries, wantQueries) { @@ -1398,15 +1398,15 @@ func TestPlanMultiInsertGenerator(t *testing.T) { result, err := executorExec(executor, "insert into music(user_id, name) values (:u, 'myname1'),(:u, 'myname2')", map[string]*querypb.BindVariable{"u": sqltypes.Int64BindVariable(2)}) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(user_id, name, id) values (:_user_id0, 'myname1', :_id0),(:_user_id1, 'myname2', :_id1)", + Sql: "insert into music(user_id, name, id) values (:_user_id_0, 'myname1', :_id_0),(:_user_id_1, 'myname2', :_id_1)", BindVariables: map[string]*querypb.BindVariable{ - "u": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_user_id0": sqltypes.Int64BindVariable(2), - "_id1": sqltypes.Int64BindVariable(2), - "__seq1": sqltypes.Int64BindVariable(2), - "_user_id1": sqltypes.Int64BindVariable(2), + "u": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_1": sqltypes.Int64BindVariable(2), + "__seq1": sqltypes.Int64BindVariable(2), + "_user_id_1": sqltypes.Int64BindVariable(2), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { @@ -1447,18 +1447,18 @@ func TestPlanMultiInsertGeneratorSparse(t *testing.T) { result, err := executorExec(executor, "insert into music(id, user_id, name) values (NULL, :u, 'myname1'),(2, :u, 'myname2'), (NULL, :u, 'myname3')", map[string]*querypb.BindVariable{"u": sqltypes.Int64BindVariable(2)}) require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "insert into music(id, user_id, name) values (:_id0, :_user_id0, 'myname1'),(:_id1, :_user_id1, 'myname2'),(:_id2, :_user_id2, 'myname3')", + Sql: "insert into music(id, user_id, name) values (:_id_0, :_user_id_0, 'myname1'),(:_id_1, :_user_id_1, 'myname2'),(:_id_2, :_user_id_2, 'myname3')", BindVariables: map[string]*querypb.BindVariable{ - "u": sqltypes.Int64BindVariable(2), - "_id0": sqltypes.Int64BindVariable(1), - "__seq0": sqltypes.Int64BindVariable(1), - "_user_id0": sqltypes.Int64BindVariable(2), - "_id1": sqltypes.Int64BindVariable(2), - "__seq1": sqltypes.Int64BindVariable(2), - "_user_id1": sqltypes.Int64BindVariable(2), - "_id2": sqltypes.Int64BindVariable(2), - "__seq2": sqltypes.Int64BindVariable(2), - "_user_id2": sqltypes.Int64BindVariable(2), + "u": sqltypes.Int64BindVariable(2), + "_id_0": sqltypes.Int64BindVariable(1), + "__seq0": sqltypes.Int64BindVariable(1), + "_user_id_0": sqltypes.Int64BindVariable(2), + "_id_1": sqltypes.Int64BindVariable(2), + "__seq1": sqltypes.Int64BindVariable(2), + "_user_id_1": sqltypes.Int64BindVariable(2), + "_id_2": sqltypes.Int64BindVariable(2), + "__seq2": sqltypes.Int64BindVariable(2), + "_user_id_2": sqltypes.Int64BindVariable(2), }, }} if !reflect.DeepEqual(sbc.Queries, wantQueries) { diff --git a/go/vt/vtgate/planbuilder/insert.go b/go/vt/vtgate/planbuilder/insert.go index 8f264294c2d..aa584b19284 100644 --- a/go/vt/vtgate/planbuilder/insert.go +++ b/go/vt/vtgate/planbuilder/insert.go @@ -171,10 +171,9 @@ func buildInsertShardedPlan(ins *sqlparser.Insert, table *vindexes.Table) (engin for _, colVindex := range eins.Table.ColumnVindexes { for _, col := range colVindex.Columns { colNum := findOrAddColumn(ins, col) - // swap bind variables - baseName := ":_" + col.CompliantName() for rowNum, row := range rows { - row[colNum] = sqlparser.NewValArg([]byte(baseName + strconv.Itoa(rowNum))) + name := ":" + engine.InsertVarName(col, rowNum) + row[colNum] = sqlparser.NewValArg([]byte(name)) } } } diff --git a/go/vt/vtgate/planbuilder/testdata/dml_cases.txt b/go/vt/vtgate/planbuilder/testdata/dml_cases.txt index 271b0ecbf98..0f43e3b8611 100644 --- a/go/vt/vtgate/planbuilder/testdata/dml_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/dml_cases.txt @@ -719,7 +719,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into music(user_id, id) values (:_user_id0, :_id0) on duplicate key update user_id = values(user_id)", + "Query": "insert into music(user_id, id) values (:_user_id_0, :_id_0) on duplicate key update user_id = values(user_id)", "TableName": "music" } } @@ -738,7 +738,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into music(user_id, id) values (:_user_id0, :_id0), (:_user_id1, :_id1) on duplicate key update user_id = values(user_id)", + "Query": "insert into music(user_id, id) values (:_user_id_0, :_id_0), (:_user_id_1, :_id_1) on duplicate key update user_id = values(user_id)", "TableName": "music" } } @@ -894,7 +894,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0)", + "Query": "insert into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0)", "TableName": "user" } } @@ -917,7 +917,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into authoritative(user_id, col1, col2) values (:_user_id0, 2, 3)", + "Query": "insert into authoritative(user_id, col1, col2) values (:_user_id_0, 2, 3)", "TableName": "authoritative" } } @@ -940,7 +940,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0)", + "Query": "insert into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0)", "TableName": "user" } } @@ -959,7 +959,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert ignore into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0)", + "Query": "insert ignore into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0)", "TableName": "user" } } @@ -978,7 +978,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0) on duplicate key update col = 2", + "Query": "insert into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0) on duplicate key update col = 2", "TableName": "user" } } @@ -997,7 +997,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0)", + "Query": "insert into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0)", "TableName": "user" } } @@ -1016,7 +1016,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(nonid, id, Name, Costly) values (2, :_Id0, :_Name0, :_Costly0)", + "Query": "insert into user(nonid, id, Name, Costly) values (2, :_Id_0, :_Name_0, :_Costly_0)", "TableName": "user" } } @@ -1035,7 +1035,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(id, nonid, Name, Costly) values (:_Id0, 2, :_Name0, :_Costly0)", + "Query": "insert into user(id, nonid, Name, Costly) values (:_Id_0, 2, :_Name_0, :_Costly_0)", "TableName": "user" } } @@ -1054,7 +1054,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(nonid, id, Name, Costly) values (true, :_Id0, :_Name0, :_Costly0)", + "Query": "insert into user(nonid, id, Name, Costly) values (true, :_Id_0, :_Name_0, :_Costly_0)", "TableName": "user" } } @@ -1073,7 +1073,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(nonid, name, id, Costly) values (2, :_Name0, :_Id0, :_Costly0)", + "Query": "insert into user(nonid, name, id, Costly) values (2, :_Name_0, :_Id_0, :_Costly_0)", "TableName": "user" } } @@ -1092,7 +1092,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user_extra(nonid, extra_id, user_id) values (2, :__seq0, :_user_id0)", + "Query": "insert into user_extra(nonid, extra_id, user_id) values (2, :__seq0, :_user_id_0)", "TableName": "user_extra" } } @@ -1111,7 +1111,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into `weird``name`(`a``b*c`, `b*c`) values (:_a_b_c0, 2)", + "Query": "insert into `weird``name`(`a``b*c`, `b*c`) values (:_a_b_c_0, 2)", "TableName": "weird`name" } } @@ -1165,7 +1165,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0), (:_Id1, :_Name1, :_Costly1)", + "Query": "insert into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0), (:_Id_1, :_Name_1, :_Costly_1)", "TableName": "user" } } @@ -1184,7 +1184,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert /*vt+ QUERY_TIMEOUT_MS=1 */ into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0), (:_Id1, :_Name1, :_Costly1)", + "Query": "insert /*vt+ QUERY_TIMEOUT_MS=1 */ into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0), (:_Id_1, :_Name_1, :_Costly_1)", "QueryTimeout": 1, "TableName": "user" } @@ -1204,7 +1204,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": true, - "Query": "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0), (:_Id1, :_Name1, :_Costly1)", + "Query": "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user(id, Name, Costly) values (:_Id_0, :_Name_0, :_Costly_0), (:_Id_1, :_Name_1, :_Costly_1)", "TableName": "user" } } @@ -1330,7 +1330,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into multicolvin(column_a, column_b, column_c, kid) values (:_column_a0, :_column_b0, :_column_c0, :_kid0)", + "Query": "insert into multicolvin(column_a, column_b, column_c, kid) values (:_column_a_0, :_column_b_0, :_column_c_0, :_kid_0)", "TableName": "multicolvin" } } @@ -1349,7 +1349,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into overlap_vindex(kid, column_a, column_b) values (:_kid0, :_column_a0, 3)", + "Query": "insert into overlap_vindex(kid, column_a, column_b) values (:_kid_0, :_column_a_0, 3)", "TableName": "overlap_vindex" } } @@ -1368,7 +1368,7 @@ }, "TargetTabletType": "MASTER", "MultiShardAutocommit": false, - "Query": "insert into multicolvin(column_a, column_b, column_c, kid) values (:_column_a0, :_column_b0, :_column_c0, :_kid0), (:_column_a1, :_column_b1, :_column_c1, :_kid1)", + "Query": "insert into multicolvin(column_a, column_b, column_c, kid) values (:_column_a_0, :_column_b_0, :_column_c_0, :_kid_0), (:_column_a_1, :_column_b_1, :_column_c_1, :_kid_1)", "TableName": "multicolvin" } }