Skip to content
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e
github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
github.com/dolthub/vitess v0.0.0-20231024164600-7606aaf59e2e
github.com/dolthub/vitess v0.0.0-20231024170615-f475795064f6
github.com/go-kit/kit v0.10.0
github.com/go-sql-driver/mysql v1.7.1
github.com/gocraft/dbr/v2 v2.7.2
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72 h1:NfWmngMi1CYU
github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72/go.mod h1:ZWUdY4iszqRQ8OcoXClkxiAVAoWoK3cq0Hvv4ddGRuM=
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/vitess v0.0.0-20231024164600-7606aaf59e2e h1:l65gk7CyrwNWs2CD5WmFBSouyhP4yJDDzdrvntrfoMs=
github.com/dolthub/vitess v0.0.0-20231024164600-7606aaf59e2e/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20231018211336-45c2d7dce528 h1:DUHzyi+/Wn9/59zPkz7ghXktRQlB9j486jUEjg5fMs8=
github.com/dolthub/vitess v0.0.0-20231018211336-45c2d7dce528/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20231020183313-ef26be7c2600 h1:y28nGSuLzR48fSNSpohG/t763dvowdBfeNdE4NfCrYY=
github.com/dolthub/vitess v0.0.0-20231020183313-ef26be7c2600/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20231024170615-f475795064f6 h1:2fGQYxszmACz2xtuyRVblnwvusIefQK9AloUKGIdcCI=
github.com/dolthub/vitess v0.0.0-20231024170615-f475795064f6/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
Expand Down
2 changes: 1 addition & 1 deletion server/golden/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (h MySqlProxy) ComInitDB(c *mysql.Conn, schemaName string) error {
}

// ComPrepare implements mysql.Handler.
func (h MySqlProxy) ComPrepare(c *mysql.Conn, query string) ([]*querypb.Field, error) {
func (h MySqlProxy) ComPrepare(_ *mysql.Conn, _ string, _ *mysql.PrepareData) ([]*querypb.Field, error) {
return nil, fmt.Errorf("ComPrepare unsupported")
}

Expand Down
2 changes: 1 addition & 1 deletion server/golden/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (v Validator) ComInitDB(c *mysql.Conn, schemaName string) error {

// ComPrepare parses, partially analyzes, and caches a prepared statement's plan
// with the given [c.ConnectionID].
func (v Validator) ComPrepare(c *mysql.Conn, query string) ([]*query.Field, error) {
func (v Validator) ComPrepare(_ *mysql.Conn, _ string, _ *mysql.PrepareData) ([]*query.Field, error) {
return nil, fmt.Errorf("ComPrepare unsupported")
}

Expand Down
16 changes: 5 additions & 11 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/dolthub/vitess/go/mysql"
"github.com/dolthub/vitess/go/netutil"
"github.com/dolthub/vitess/go/sqltypes"
"github.com/dolthub/vitess/go/vt/log"
"github.com/dolthub/vitess/go/vt/proto/query"
"github.com/dolthub/vitess/go/vt/sqlparser"
"github.com/go-kit/kit/metrics/discard"
Expand Down Expand Up @@ -62,15 +61,6 @@ const (
MultiStmtModeOn MultiStmtMode = 1
)

func init() {
// Set the log.Error and log.Errorf functions in Vitess so that any errors
// logged by Vitess will appear in our logs. Without this, errors from Vitess
// can be swallowed (e.g. any parse error for a ComPrepare event is silently
// swallowed without this wired up), which makes debugging failures harder.
log.Error = logrus.StandardLogger().Error
log.Errorf = logrus.StandardLogger().Errorf
}

// Handler is a connection handler for a SQLe engine, implementing the Vitess mysql.Handler interface.
type Handler struct {
e *sqle.Engine
Expand Down Expand Up @@ -102,7 +92,11 @@ func (h *Handler) ComInitDB(c *mysql.Conn, schemaName string) error {

// ComPrepare parses, partially analyzes, and caches a prepared statement's plan
// with the given [c.ConnectionID].
func (h *Handler) ComPrepare(c *mysql.Conn, query string) ([]*query.Field, error) {
func (h *Handler) ComPrepare(c *mysql.Conn, query string, prepare *mysql.PrepareData) ([]*query.Field, error) {
logrus.WithField("query", query).
WithField("paramsCount", prepare.ParamsCount).
WithField("statementId", prepare.StatementID).Debugf("preparing query")

ctx, err := h.sm.NewContextWithQuery(c, query)
if err != nil {
return nil, err
Expand Down
13 changes: 9 additions & 4 deletions server/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import (
"github.com/dolthub/go-mysql-server/sql/variables"
)

var samplePrepareData = &mysql.PrepareData{
StatementID: 42,
ParamsCount: 1,
}

func TestHandlerOutput(t *testing.T) {
e, pro := setupMemDB(require.New(t))
dbFunc := pro.Database
Expand Down Expand Up @@ -263,7 +268,7 @@ func TestHandlerComPrepare(t *testing.T) {
} {
t.Run(test.name, func(t *testing.T) {
handler.ComInitDB(dummyConn, "test")
schema, err := handler.ComPrepare(dummyConn, test.statement)
schema, err := handler.ComPrepare(dummyConn, test.statement, samplePrepareData)
if test.expectedErr == nil {
require.NoError(t, err)
require.Equal(t, test.expected, schema)
Expand Down Expand Up @@ -328,7 +333,7 @@ func TestHandlerComPrepareExecute(t *testing.T) {
} {
t.Run(test.name, func(t *testing.T) {
handler.ComInitDB(dummyConn, "test")
schema, err := handler.ComPrepare(dummyConn, test.prepare.PrepareStmt)
schema, err := handler.ComPrepare(dummyConn, test.prepare.PrepareStmt, samplePrepareData)
require.NoError(t, err)
require.Equal(t, test.schema, schema)

Expand Down Expand Up @@ -406,7 +411,7 @@ func TestHandlerComPrepareExecuteWithPreparedDisabled(t *testing.T) {
} {
t.Run(test.name, func(t *testing.T) {
handler.ComInitDB(dummyConn, "test")
schema, err := handler.ComPrepare(dummyConn, test.prepare.PrepareStmt)
schema, err := handler.ComPrepare(dummyConn, test.prepare.PrepareStmt, samplePrepareData)
require.NoError(t, err)
require.Equal(t, test.schema, schema)

Expand Down Expand Up @@ -533,7 +538,7 @@ func TestServerEventListener(t *testing.T) {

conn3 := newConn(3)
query := "SELECT ?"
_, err = handler.ComPrepare(conn3, query)
_, err = handler.ComPrepare(conn3, query, samplePrepareData)
require.NoError(err)
require.Equal(1, len(e.PreparedDataCache.GetSessionData(conn3.ConnectionID)))
require.NotNil(e.PreparedDataCache.GetCachedStmt(conn3.ConnectionID, query))
Expand Down