зеркало из https://github.com/github/vitess-gh.git
Changing mysql.ComQuery parameter to []byte.
So we minimize copies.
This commit is contained in:
Родитель
49029120da
Коммит
d1783bbbeb
|
@ -241,7 +241,8 @@ func (db *DB) ConnectionClosed(c *mysql.Conn) {
|
|||
}
|
||||
|
||||
// ComQuery is part of the mysql.Handler interface.
|
||||
func (db *DB) ComQuery(c *mysql.Conn, query string) (*sqltypes.Result, error) {
|
||||
func (db *DB) ComQuery(c *mysql.Conn, q []byte) (*sqltypes.Result, error) {
|
||||
query := string(q)
|
||||
db.t.Logf("ComQuery(%v): client %v: %v", db.name, c.ConnectionID, query)
|
||||
|
||||
key := strings.ToLower(query)
|
||||
|
|
|
@ -454,8 +454,8 @@ func (c *Conn) readComQueryResponse() (uint64, uint64, int, error) {
|
|||
// Server side methods.
|
||||
//
|
||||
|
||||
func (c *Conn) parseComQuery(data []byte) string {
|
||||
return string(data[1:])
|
||||
func (c *Conn) parseComQuery(data []byte) []byte {
|
||||
return data[1:]
|
||||
}
|
||||
|
||||
func (c *Conn) parseComInitDB(data []byte) string {
|
||||
|
|
|
@ -404,7 +404,7 @@ func checkQueryInternal(t *testing.T, query string, sConn, cConn *Conn, result *
|
|||
if comQuery[0] != ComQuery {
|
||||
t.Fatalf("server got bad packet: %v", comQuery)
|
||||
}
|
||||
got := sConn.parseComQuery(comQuery)
|
||||
got := string(sConn.parseComQuery(comQuery))
|
||||
if got != query {
|
||||
t.Errorf("server got query '%v' but expected '%v'", got, query)
|
||||
}
|
||||
|
|
|
@ -54,7 +54,9 @@ type Handler interface {
|
|||
ConnectionClosed(c *Conn)
|
||||
|
||||
// ComQuery is called when a connection receives a query.
|
||||
ComQuery(c *Conn, query string) (*sqltypes.Result, error)
|
||||
// Note the contents of the query slice may change after this method
|
||||
// returns, so the Handler should not hang on to the byte slice.
|
||||
ComQuery(c *Conn, query []byte) (*sqltypes.Result, error)
|
||||
}
|
||||
|
||||
// Listener is the MySQL server protocol listener.
|
||||
|
|
|
@ -71,7 +71,8 @@ func (th *testHandler) NewConnection(c *Conn) {
|
|||
func (th *testHandler) ConnectionClosed(c *Conn) {
|
||||
}
|
||||
|
||||
func (th *testHandler) ComQuery(c *Conn, query string) (*sqltypes.Result, error) {
|
||||
func (th *testHandler) ComQuery(c *Conn, q []byte) (*sqltypes.Result, error) {
|
||||
query := string(q)
|
||||
if query == "error" {
|
||||
return nil, NewSQLError(ERUnknownComError, SSUnknownComError, "forced query handling error for: %v", query)
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func (vh *vtgateHandler) ConnectionClosed(c *mysql.Conn) {
|
|||
}
|
||||
}
|
||||
|
||||
func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string) (*sqltypes.Result, error) {
|
||||
func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query []byte) (*sqltypes.Result, error) {
|
||||
// FIXME(alainjobart): Add some kind of timeout to the context.
|
||||
ctx := context.Background()
|
||||
|
||||
|
@ -99,7 +99,7 @@ func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string) (*sqltypes.Result
|
|||
if c.SchemaName != "" {
|
||||
session.TargetString = c.SchemaName
|
||||
}
|
||||
session, result, err := vh.vtg.Execute(ctx, session, query, make(map[string]interface{}))
|
||||
session, result, err := vh.vtg.Execute(ctx, session, string(query), make(map[string]interface{}))
|
||||
c.ClientData = session
|
||||
return result, mysql.NewSQLErrorFromError(err)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче