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

TEMP COMMIT: Benchmark quick and dirty bytes.Buffer conversion. #8955

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go/cmd/dolt/commands/query_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (q QueryDiff) ArgParser() *argparser.ArgParser {
func (q QueryDiff) compareRows(pkOrds []int, row1, row2 sql.Row) (int, bool) {
var cmp int
for _, pkOrd := range pkOrds {
pk1, _ := gmstypes.ConvertToString(row1[pkOrd], gmstypes.Text, nil)
pk2, _ := gmstypes.ConvertToString(row2[pkOrd], gmstypes.Text, nil)
pk1, _ := gmstypes.ConvertToString(row1[pkOrd], gmstypes.Text)
pk2, _ := gmstypes.ConvertToString(row2[pkOrd], gmstypes.Text)
if pk1 < pk2 {
cmp = -1
} else if pk1 > pk2 {
Expand All @@ -82,8 +82,8 @@ func (q QueryDiff) compareRows(pkOrds []int, row1, row2 sql.Row) (int, bool) {
}
var diff bool
for i := 0; i < len(row1); i++ {
a, _ := gmstypes.ConvertToString(row1[i], gmstypes.Text, nil)
b, _ := gmstypes.ConvertToString(row2[i], gmstypes.Text, nil)
a, _ := gmstypes.ConvertToString(row1[i], gmstypes.Text)
b, _ := gmstypes.ConvertToString(row2[i], gmstypes.Text)
if a != b {
diff = true
break
Expand Down
4 changes: 1 addition & 3 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ require (
github.com/cespare/xxhash/v2 v2.2.0
github.com/creasty/defaults v1.6.0
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-mysql-server v0.19.1-0.20250305230031-14a57e076a0a
github.com/dolthub/go-mysql-server v0.19.1-0.20250307194723-790e7986bdf2
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63
github.com/dolthub/swiss v0.1.0
github.com/esote/minmaxheap v1.0.0
github.com/goccy/go-json v0.10.2
github.com/google/btree v1.1.2
Expand Down Expand Up @@ -111,7 +110,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dolthub/go-icu-regex v0.0.0-20250303123116-549b8d7cad00 // indirect
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 // indirect
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577 // indirect
github.com/go-fonts/liberation v0.2.0 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,20 @@ github.com/dolthub/go-icu-regex v0.0.0-20250303123116-549b8d7cad00 h1:rh2ij2yTYK
github.com/dolthub/go-icu-regex v0.0.0-20250303123116-549b8d7cad00/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA=
github.com/dolthub/go-mysql-server v0.19.1-0.20250305230031-14a57e076a0a h1:lemFIUt0NCKIeX7vnU2yKF8UIgc0DT8zIoEUn7oy+60=
github.com/dolthub/go-mysql-server v0.19.1-0.20250305230031-14a57e076a0a/go.mod h1:yr+Vv47/YLOKMgiEY+QxHTlbIVpTuiVtkEZ5l+xruY4=
github.com/dolthub/go-mysql-server v0.19.1-0.20250306232711-0f5daa0f74ad h1:BwhzrefjW44+c1IY8VbwYkRw46VBUiVijGjmCoKTViQ=
github.com/dolthub/go-mysql-server v0.19.1-0.20250306232711-0f5daa0f74ad/go.mod h1:yr+Vv47/YLOKMgiEY+QxHTlbIVpTuiVtkEZ5l+xruY4=
github.com/dolthub/go-mysql-server v0.19.1-0.20250307180035-896fdb378db1 h1:4tXRljpWgZ+b9JnhOtYz8Ja1S4bzApiO5ChWHCLQK7U=
github.com/dolthub/go-mysql-server v0.19.1-0.20250307180035-896fdb378db1/go.mod h1:yr+Vv47/YLOKMgiEY+QxHTlbIVpTuiVtkEZ5l+xruY4=
github.com/dolthub/go-mysql-server v0.19.1-0.20250307194723-790e7986bdf2 h1:cuH+LJDk8Fvf2x2lPVsDr48r8uCGsy3qe7eWEUkvEM0=
github.com/dolthub/go-mysql-server v0.19.1-0.20250307194723-790e7986bdf2/go.mod h1:yr+Vv47/YLOKMgiEY+QxHTlbIVpTuiVtkEZ5l+xruY4=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto=
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTEtT5tOBsCuCrlYnLRKpbJVJkDbrTRhwQ=
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577 h1:SegEguMxToBn045KRHLIUlF2/jR7Y2qD6fF+3tdOfvI=
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
github.com/dolthub/vitess v0.0.0-20250304211657-920ca9ec2b9a h1:HIH9g4z+yXr4DIFyT6L5qOIEGJ1zVtlj6baPyHAG4Yw=
github.com/dolthub/vitess v0.0.0-20250304211657-920ca9ec2b9a/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -670,8 +672,6 @@ github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
github.com/tetratelabs/wazero v1.8.2 h1:yIgLR/b2bN31bjxwXHD8a3d+BogigR952csSDdLYEv4=
github.com/tetratelabs/wazero v1.8.2/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
github.com/thepudds/swisstable v0.0.0-20221011152303-9c77dc657777 h1:5u+6YWU2faS+Sr/x8j9yalMpSDUkatNOZWXV3wMUCGQ=
github.com/thepudds/swisstable v0.0.0-20221011152303-9c77dc657777/go.mod h1:4af3KxEsswy6aTzsTcwa8QZUSh4V+80oHdp1QX9uJHA=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand Down
12 changes: 9 additions & 3 deletions go/libraries/doltcore/sqle/sqlutil/sql_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package sqlutil

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -228,6 +229,7 @@ var sqlColToStrContext = sql.NewEmptyContext()
// SqlColToStr is a utility function for converting a sql column of type interface{} to a string.
// NULL values are treated as empty strings. Handle nil separately if you require other behavior.
func SqlColToStr(sqlType sql.Type, col interface{}) (string, error) {
var buf bytes.Buffer
if col != nil {
switch typedCol := col.(type) {
case bool:
Expand All @@ -237,17 +239,21 @@ func SqlColToStr(sqlType sql.Type, col interface{}) (string, error) {
return "false", nil
}
case sql.SpatialColumnType:
res, err := sqlType.SQL(sqlColToStrContext, nil, col)
hexRes := fmt.Sprintf("0x%X", res.Raw())
bufres, err := sqlType.SQL(sqlColToStrContext, &buf, col)
if err != nil {
return "", err
}
res := bufres.ToValue(buf.Bytes())
hexRes := fmt.Sprintf("0x%X", res.Raw())
if err != nil {
}
return hexRes, nil
default:
res, err := sqlType.SQL(sqlColToStrContext, nil, col)
bufres, err := sqlType.SQL(sqlColToStrContext, &buf, col)
if err != nil {
return "", err
}
res := bufres.ToValue(buf.Bytes())
return res.ToString(), nil
}
}
Expand Down
19 changes: 15 additions & 4 deletions go/libraries/doltcore/table/typed/json/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package json

import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -133,6 +134,7 @@ func (j *RowWriter) WriteSqlRow(ctx context.Context, row sql.Row) error {
func (j *RowWriter) jsonDataForSchema(row sql.Row) ([]byte, error) {
allCols := j.sch.GetAllCols()
colValMap := make(map[string]interface{}, allCols.Size())
var buf bytes.Buffer
if err := allCols.Iter(func(tag uint64, col schema.Column) (stop bool, err error) {
val := row[allCols.TagToIdx[tag]]
if val == nil {
Expand All @@ -149,17 +151,21 @@ func (j *RowWriter) jsonDataForSchema(row sql.Row) ([]byte, error) {
typeinfo.TupleTypeIdentifier,
typeinfo.UuidTypeIdentifier,
typeinfo.VarBinaryTypeIdentifier:
sqlVal, err := col.TypeInfo.ToSqlType().SQL(sqlContext, nil, val)
bufVal, err := col.TypeInfo.ToSqlType().SQL(sqlContext, &buf, val)
if err != nil {
return true, err
}
sqlVal := bufVal.ToValue(buf.Bytes())
val = sqlVal.ToString()
buf.Reset()
case typeinfo.JSONTypeIdentifier:
sqlVal, err := col.TypeInfo.ToSqlType().SQL(sqlContext, nil, val)
bufVal, err := col.TypeInfo.ToSqlType().SQL(sqlContext, &buf, val)
if err != nil {
return true, err
}
sqlVal := bufVal.ToValue(buf.Bytes())
str := sqlVal.ToString()
buf.Reset()

// This is kind of silly: we are unmarshalling JSON just to marshall it back again
// But it makes marshalling much simpler
Expand Down Expand Up @@ -193,6 +199,7 @@ func (j *RowWriter) jsonDataForSchema(row sql.Row) ([]byte, error) {
// jsonDataForSqlSchema returns a JSON representation of the given row, using the sql schema for serialization hints
func (j *RowWriter) jsonDataForSqlSchema(row sql.Row) ([]byte, error) {
colValMap := make(map[string]interface{}, len(j.sqlSch))
var buf bytes.Buffer
for i, col := range j.sqlSch {
val := row[i]
if val == nil {
Expand All @@ -206,17 +213,21 @@ func (j *RowWriter) jsonDataForSqlSchema(row sql.Row) ([]byte, error) {
sql.StringType,
sql.SetType,
types.TupleType:
sqlVal, err := col.Type.SQL(sqlContext, nil, val)
bufVal, err := col.Type.SQL(sqlContext, &buf, val)
if err != nil {
return nil, err
}
sqlVal := bufVal.ToValue(buf.Bytes())
val = sqlVal.ToString()
buf.Reset()
case types.JsonType:
sqlVal, err := col.Type.SQL(sqlContext, nil, val)
bufVal, err := col.Type.SQL(sqlContext, &buf, val)
if err != nil {
return nil, err
}
sqlVal := bufVal.ToValue(buf.Bytes())
str := sqlVal.ToString()
buf.Reset()

// This is kind of silly: we are unmarshalling JSON just to marshall it back again
// But it makes marshalling much simpler
Expand Down
10 changes: 8 additions & 2 deletions go/performance/microsysbench/sysbench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package microsysbench

import (
"bytes"
"context"
"fmt"
"io"
Expand All @@ -26,6 +27,7 @@ import (

"github.com/dolthub/go-mysql-server/server"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/vitess/go/sqltypes"
"github.com/stretchr/testify/require"

"github.com/dolthub/dolt/go/cmd/dolt/commands"
Expand Down Expand Up @@ -125,14 +127,18 @@ func benchmarkSysbenchQuery(b *testing.B, getQuery func(int) string) {
schema, iter, _, err := eng.Query(ctx, getQuery(i))
require.NoError(b, err)
i := 0
buf := sql.NewByteBuffer(16000)
var buf bytes.Buffer
for {
i++
row, err := iter.Next(ctx)
if err != nil {
break
}
outputRow, err := server.RowToSQL(ctx, schema, row, nil, buf)
bufRow, err := server.RowToSQL(ctx, schema, row, nil, &buf)
outputRow := make([]sqltypes.Value, len(bufRow))
for i := range bufRow {
outputRow[i] = bufRow[i].ToValue(buf.Bytes())
}
_ = outputRow
if i%128 == 0 {
buf.Reset()
Expand Down
Loading