Skip to content

Commit

Permalink
Revert "Reduce network pressure on multi row insert (#14064)"
Browse files Browse the repository at this point in the history
This reverts commit b793adf.
  • Loading branch information
frouioui authored Oct 11, 2023
1 parent 8d7b507 commit 5df2ce4
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 445 deletions.
2 changes: 1 addition & 1 deletion go/test/endtoend/cluster/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func VerifyRowsInTablet(t *testing.T, vttablet *Vttablet, ksName string, expecte
}

// PanicHandler handles the panic in the testcase.
func PanicHandler(t testing.TB) {
func PanicHandler(t *testing.T) {
err := recover()
if t == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func ExecCompareMySQL(t *testing.T, vtConn, mysqlConn *mysql.Conn, query string)

// ExecAllowError executes the given query without failing the test if it produces
// an error. The error is returned to the client, along with the result set.
func ExecAllowError(t testing.TB, conn *mysql.Conn, query string) (*sqltypes.Result, error) {
func ExecAllowError(t *testing.T, conn *mysql.Conn, query string) (*sqltypes.Result, error) {
t.Helper()
return conn.ExecuteFetch(query, 1000, true)
}
Expand Down
80 changes: 0 additions & 80 deletions go/test/endtoend/vtgate/queries/benchmark/benchmark_test.go

This file was deleted.

124 changes: 0 additions & 124 deletions go/test/endtoend/vtgate/queries/benchmark/main_test.go

This file was deleted.

16 changes: 0 additions & 16 deletions go/test/endtoend/vtgate/queries/benchmark/sharded_schema.sql

This file was deleted.

18 changes: 0 additions & 18 deletions go/test/endtoend/vtgate/queries/benchmark/vschema.json

This file was deleted.

6 changes: 6 additions & 0 deletions go/vt/vtgate/autocommit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func TestAutocommitInsertLookup(t *testing.T) {
BindVariables: map[string]*querypb.BindVariable{
"_Id_0": sqltypes.Int64BindVariable(1),
"_name_0": sqltypes.StringBindVariable("myname"),
"__seq0": sqltypes.Int64BindVariable(1),
},
}})
testCommitCount(t, "sbc1", sbc1, 1)
Expand All @@ -291,13 +292,15 @@ func TestAutocommitInsertMultishardAutoCommit(t *testing.T) {
Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id_0, 2)",
BindVariables: map[string]*querypb.BindVariable{
"_user_id_0": sqltypes.Int64BindVariable(1),
"_user_id_1": sqltypes.Int64BindVariable(3),
},
}})
testCommitCount(t, "sbc1", sbc1, 0)

assertQueries(t, sbc2, []*querypb.BoundQuery{{
Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id_1, 4)",
BindVariables: map[string]*querypb.BindVariable{
"_user_id_0": sqltypes.Int64BindVariable(1),
"_user_id_1": sqltypes.Int64BindVariable(3),
},
}})
Expand All @@ -318,6 +321,7 @@ func TestAutocommitInsertMultishardAutoCommit(t *testing.T) {
assertQueries(t, sbc2, []*querypb.BoundQuery{{
Sql: "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user_extra(user_id, v) values (:_user_id_1, 4)",
BindVariables: map[string]*querypb.BindVariable{
"_user_id_0": sqltypes.Int64BindVariable(1),
"_user_id_1": sqltypes.Int64BindVariable(3),
},
}})
Expand All @@ -335,13 +339,15 @@ func TestAutocommitInsertMultishard(t *testing.T) {
Sql: "insert into user_extra(user_id, v) values (:_user_id_0, 2)",
BindVariables: map[string]*querypb.BindVariable{
"_user_id_0": sqltypes.Int64BindVariable(1),
"_user_id_1": sqltypes.Int64BindVariable(3),
},
}})
testCommitCount(t, "sbc1", sbc1, 1)

assertQueries(t, sbc2, []*querypb.BoundQuery{{
Sql: "insert into user_extra(user_id, v) values (:_user_id_1, 4)",
BindVariables: map[string]*querypb.BindVariable{
"_user_id_0": sqltypes.Int64BindVariable(1),
"_user_id_1": sqltypes.Int64BindVariable(3),
},
}})
Expand Down
13 changes: 3 additions & 10 deletions go/vt/vtgate/engine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions go/vt/vtgate/engine/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"sync"
"time"

"vitess.io/vitess/go/slice"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/key"
querypb "vitess.io/vitess/go/vt/proto/query"
Expand Down Expand Up @@ -76,7 +75,7 @@ type (

// Prefix, Mid and Suffix are for sharded insert plans.
Prefix string
Mid sqlparser.Values
Mid []string
Suffix string

// Option to override the standard behavior and allow a multi-shard insert
Expand Down Expand Up @@ -133,7 +132,7 @@ func NewInsert(
vindexValues [][][]evalengine.Expr,
table *vindexes.Table,
prefix string,
mid sqlparser.Values,
mid []string,
suffix string,
) *Insert {
ins := &Insert{
Expand Down Expand Up @@ -759,23 +758,17 @@ func (ins *Insert) getInsertShardedRoute(

queries := make([]*querypb.BoundQuery, len(rss))
for i := range rss {
shardBindVars := map[string]*querypb.BindVariable{}
var mids []string
for _, indexValue := range indexesPerRss[i] {
index, _ := strconv.ParseInt(string(indexValue.Value), 0, 64)
if keyspaceIDs[index] != nil {
mids = append(mids, sqlparser.String(ins.Mid[index]))
for _, expr := range ins.Mid[index] {
if arg, ok := expr.(*sqlparser.Argument); ok {
shardBindVars[arg.Name] = bindVars[arg.Name]
}
}
mids = append(mids, ins.Mid[index])
}
}
rewritten := ins.Prefix + strings.Join(mids, ",") + ins.Suffix
queries[i] = &querypb.BoundQuery{
Sql: rewritten,
BindVariables: shardBindVars,
BindVariables: bindVars,
}
}

Expand Down Expand Up @@ -992,10 +985,7 @@ func (ins *Insert) description() PrimitiveDescription {
other["VindexOffsetFromSelect"] = valuesOffsets
}
if len(ins.Mid) > 0 {
mids := slice.Map(ins.Mid, func(from sqlparser.ValTuple) string {
return sqlparser.String(from)
})
shardQuery := fmt.Sprintf("%s%s%s", ins.Prefix, strings.Join(mids, ", "), ins.Suffix)
shardQuery := fmt.Sprintf("%s%s%s", ins.Prefix, strings.Join(ins.Mid, ", "), ins.Suffix)
if shardQuery != ins.Query {
other["ShardedQuery"] = shardQuery
}
Expand Down
Loading

0 comments on commit 5df2ce4

Please sign in to comment.