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

session, util: update session to use new APIs #22652

Merged
merged 14 commits into from
Feb 19, 2021
104 changes: 52 additions & 52 deletions session/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,35 @@ func prepareBenchSession() (Session, *domain.Domain, kv.Storage) {

func prepareBenchData(se Session, colType string, valueFormat string, valueCount int) {
mustExecute(se, "drop table if exists t")
mustExecute(se, fmt.Sprintf("create table t (pk int primary key auto_increment, col %s, index idx (col))", colType))
mustExecute(se, "create table t (pk int primary key auto_increment, col %n, index idx (col))", colType)
mustExecute(se, "begin")
for i := 0; i < valueCount; i++ {
mustExecute(se, "insert t (col) values ("+fmt.Sprintf(valueFormat, i)+")")
mustExecute(se, "insert t (col) values (%?)", fmt.Sprintf(valueFormat, i))
}
mustExecute(se, "commit")
}

func prepareSortBenchData(se Session, colType string, valueFormat string, valueCount int) {
func prepareSortBenchData(se Session, colType string, valueCount int) {
mustExecute(se, "drop table if exists t")
mustExecute(se, fmt.Sprintf("create table t (pk int primary key auto_increment, col %s)", colType))
mustExecute(se, "create table t (pk int primary key auto_increment, col %n)", colType)
mustExecute(se, "begin")
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < valueCount; i++ {
if i%1000 == 0 {
mustExecute(se, "commit")
mustExecute(se, "begin")
}
mustExecute(se, "insert t (col) values ("+fmt.Sprintf(valueFormat, r.Intn(valueCount))+")")
mustExecute(se, "insert t (col) values (%?)", r.Intn(valueCount))
}
mustExecute(se, "commit")
}

func prepareJoinBenchData(se Session, colType string, valueFormat string, valueCount int) {
mustExecute(se, "drop table if exists t")
mustExecute(se, fmt.Sprintf("create table t (pk int primary key auto_increment, col %s)", colType))
mustExecute(se, "create table t (pk int primary key auto_increment, col %n)", colType)
mustExecute(se, "begin")
for i := 0; i < valueCount; i++ {
mustExecute(se, "insert t (col) values ("+fmt.Sprintf(valueFormat, i)+")")
mustExecute(se, "insert t (col) values (%?)", i)
}
mustExecute(se, "commit")
}
Expand Down Expand Up @@ -113,11 +113,11 @@ func BenchmarkBasic(b *testing.B) {
}()
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select 1")
rs, err := se.ExecuteInternal(ctx, "select 1")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -133,11 +133,11 @@ func BenchmarkTableScan(b *testing.B) {
prepareBenchData(se, "int", "%v", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t")
rs, err := se.ExecuteInternal(ctx, "select * from t")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], smallCount)
readResult(ctx, rs, smallCount)
}
b.StopTimer()
}
Expand All @@ -153,11 +153,11 @@ func BenchmarkExplainTableScan(b *testing.B) {
prepareBenchData(se, "int", "%v", 0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "explain select * from t")
rs, err := se.ExecuteInternal(ctx, "explain select * from t")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -173,11 +173,11 @@ func BenchmarkTableLookup(b *testing.B) {
prepareBenchData(se, "int", "%d", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where pk = 64")
rs, err := se.ExecuteInternal(ctx, "select * from t where pk = 64")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -193,11 +193,11 @@ func BenchmarkExplainTableLookup(b *testing.B) {
prepareBenchData(se, "int", "%d", 0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "explain select * from t where pk = 64")
rs, err := se.ExecuteInternal(ctx, "explain select * from t where pk = 64")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -213,11 +213,11 @@ func BenchmarkStringIndexScan(b *testing.B) {
prepareBenchData(se, "varchar(255)", "'hello %d'", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where col > 'hello'")
rs, err := se.ExecuteInternal(ctx, "select * from t where col > 'hello'")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], smallCount)
readResult(ctx, rs, smallCount)
}
b.StopTimer()
}
Expand All @@ -233,11 +233,11 @@ func BenchmarkExplainStringIndexScan(b *testing.B) {
prepareBenchData(se, "varchar(255)", "'hello %d'", 0)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "explain select * from t where col > 'hello'")
rs, err := se.ExecuteInternal(ctx, "explain select * from t where col > 'hello'")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -253,11 +253,11 @@ func BenchmarkStringIndexLookup(b *testing.B) {
prepareBenchData(se, "varchar(255)", "'hello %d'", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where col = 'hello 64'")
rs, err := se.ExecuteInternal(ctx, "select * from t where col = 'hello 64'")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -273,11 +273,11 @@ func BenchmarkIntegerIndexScan(b *testing.B) {
prepareBenchData(se, "int", "%v", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where col >= 0")
rs, err := se.ExecuteInternal(ctx, "select * from t where col >= 0")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], smallCount)
readResult(ctx, rs, smallCount)
}
b.StopTimer()
}
Expand All @@ -293,11 +293,11 @@ func BenchmarkIntegerIndexLookup(b *testing.B) {
prepareBenchData(se, "int", "%v", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where col = 64")
rs, err := se.ExecuteInternal(ctx, "select * from t where col = 64")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -313,11 +313,11 @@ func BenchmarkDecimalIndexScan(b *testing.B) {
prepareBenchData(se, "decimal(32,6)", "%v.1234", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where col >= 0")
rs, err := se.ExecuteInternal(ctx, "select * from t where col >= 0")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], smallCount)
readResult(ctx, rs, smallCount)
}
b.StopTimer()
}
Expand All @@ -333,11 +333,11 @@ func BenchmarkDecimalIndexLookup(b *testing.B) {
prepareBenchData(se, "decimal(32,6)", "%v.1234", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where col = 64.1234")
rs, err := se.ExecuteInternal(ctx, "select * from t where col = 64.1234")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand All @@ -353,7 +353,7 @@ func BenchmarkInsertWithIndex(b *testing.B) {
mustExecute(se, "create table t (pk int primary key, col int, index idx (col))")
b.ResetTimer()
for i := 0; i < b.N; i++ {
mustExecute(se, fmt.Sprintf("insert t values (%d, %d)", i, i))
mustExecute(se, "insert t values (%d, %d)", i, i)
}
b.StopTimer()
}
Expand All @@ -369,7 +369,7 @@ func BenchmarkInsertNoIndex(b *testing.B) {
mustExecute(se, "create table t (pk int primary key, col int)")
b.ResetTimer()
for i := 0; i < b.N; i++ {
mustExecute(se, fmt.Sprintf("insert t values (%d, %d)", i, i))
mustExecute(se, "insert t values (%d, %d)", i, i)
}
b.StopTimer()
}
Expand All @@ -382,14 +382,14 @@ func BenchmarkSort(b *testing.B) {
st.Close()
do.Close()
}()
prepareSortBenchData(se, "int", "%v", bigCount)
prepareSortBenchData(se, "int", bigCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t order by col limit 50")
rs, err := se.ExecuteInternal(ctx, "select * from t order by col limit 50")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 50)
readResult(ctx, rs, 50)
}
b.StopTimer()
}
Expand All @@ -405,11 +405,11 @@ func BenchmarkJoin(b *testing.B) {
prepareJoinBenchData(se, "int", "%v", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t a join t b on a.col = b.col")
rs, err := se.ExecuteInternal(ctx, "select * from t a join t b on a.col = b.col")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], smallCount)
readResult(ctx, rs, smallCount)
}
b.StopTimer()
}
Expand All @@ -425,11 +425,11 @@ func BenchmarkJoinLimit(b *testing.B) {
prepareJoinBenchData(se, "int", "%v", smallCount)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t a join t b on a.col = b.col limit 1")
rs, err := se.ExecuteInternal(ctx, "select * from t a join t b on a.col = b.col limit 1")
if err != nil {
b.Fatal(err)
}
readResult(ctx, rs[0], 1)
readResult(ctx, rs, 1)
}
b.StopTimer()
}
Expand Down Expand Up @@ -1472,11 +1472,11 @@ partition p1023 values less than (738538)
)`)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where dt > to_days('2019-04-01 21:00:00') and dt < to_days('2019-04-07 23:59:59')")
rs, err := se.ExecuteInternal(ctx, "select * from t where dt > to_days('2019-04-01 21:00:00') and dt < to_days('2019-04-07 23:59:59')")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
_, err = drainRecordSet(ctx, se.(*session), rs)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -1504,11 +1504,11 @@ func BenchmarkRangeColumnPartitionPruning(b *testing.B) {
mustExecute(se, build.String())
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where dt > '2020-05-01' and dt < '2020-06-07'")
rs, err := se.ExecuteInternal(ctx, "select * from t where dt > '2020-05-01' and dt < '2020-06-07'")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
_, err = drainRecordSet(ctx, se.(*session), rs)
if err != nil {
b.Fatal(err)
}
Expand All @@ -1528,11 +1528,11 @@ func BenchmarkHashPartitionPruningPointSelect(b *testing.B) {
mustExecute(se, `create table t (id int, dt datetime) partition by hash(id) partitions 1024;`)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where id = 2330")
rs, err := se.ExecuteInternal(ctx, "select * from t where id = 2330")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
_, err = drainRecordSet(ctx, se.(*session), rs)
if err != nil {
b.Fatal(err)
}
Expand All @@ -1552,27 +1552,27 @@ func BenchmarkHashPartitionPruningMultiSelect(b *testing.B) {
mustExecute(se, `create table t (id int, dt datetime) partition by hash(id) partitions 1024;`)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where id = 2330")
rs, err := se.ExecuteInternal(ctx, "select * from t where id = 2330")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
_, err = drainRecordSet(ctx, se.(*session), rs)
if err != nil {
b.Fatal(err)
}
rs, err = se.Execute(ctx, "select * from t where id = 1233 or id = 1512")
rs, err = se.ExecuteInternal(ctx, "select * from t where id = 1233 or id = 1512")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
_, err = drainRecordSet(ctx, se.(*session), rs)
if err != nil {
b.Fatal(err)
}
rs, err = se.Execute(ctx, "select * from t where id in (117, 1233, 15678)")
rs, err = se.ExecuteInternal(ctx, "select * from t where id in (117, 1233, 15678)")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
_, err = drainRecordSet(ctx, se.(*session), rs)
if err != nil {
b.Fatal(err)
}
Expand Down
Loading