Reuse one ResultReader per connection
This commit is contained in:
@@ -98,7 +98,9 @@ type PgConn struct {
|
|||||||
bufferingReceiveMsg pgproto3.BackendMessage
|
bufferingReceiveMsg pgproto3.BackendMessage
|
||||||
bufferingReceiveErr error
|
bufferingReceiveErr error
|
||||||
|
|
||||||
wbuf []byte // Reusable write buffer
|
// Reusable / preallocated resources
|
||||||
|
wbuf []byte // write buffer
|
||||||
|
resultReader ResultReader
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect establishes a connection to a PostgreSQL server using the environment and connString (in URL or DSN format)
|
// Connect establishes a connection to a PostgreSQL server using the environment and connString (in URL or DSN format)
|
||||||
@@ -756,11 +758,12 @@ func (pgConn *PgConn) ExecPrepared(ctx context.Context, stmtName string, paramVa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pgConn *PgConn) execExtendedPrefix(ctx context.Context, paramValues [][]byte) *ResultReader {
|
func (pgConn *PgConn) execExtendedPrefix(ctx context.Context, paramValues [][]byte) *ResultReader {
|
||||||
result := &ResultReader{
|
pgConn.resultReader = ResultReader{
|
||||||
pgConn: pgConn,
|
pgConn: pgConn,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cleanupContextDeadline: func() {},
|
cleanupContextDeadline: func() {},
|
||||||
}
|
}
|
||||||
|
result := &pgConn.resultReader
|
||||||
|
|
||||||
if err := pgConn.lock(); err != nil {
|
if err := pgConn.lock(); err != nil {
|
||||||
result.concludeCommand("", err)
|
result.concludeCommand("", err)
|
||||||
@@ -1035,20 +1038,22 @@ func (mrr *MultiResultReader) NextResult() bool {
|
|||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *pgproto3.RowDescription:
|
case *pgproto3.RowDescription:
|
||||||
mrr.rr = &ResultReader{
|
mrr.pgConn.resultReader = ResultReader{
|
||||||
pgConn: mrr.pgConn,
|
pgConn: mrr.pgConn,
|
||||||
multiResultReader: mrr,
|
multiResultReader: mrr,
|
||||||
ctx: mrr.ctx,
|
ctx: mrr.ctx,
|
||||||
cleanupContextDeadline: func() {},
|
cleanupContextDeadline: func() {},
|
||||||
fieldDescriptions: msg.Fields,
|
fieldDescriptions: msg.Fields,
|
||||||
}
|
}
|
||||||
|
mrr.rr = &mrr.pgConn.resultReader
|
||||||
return true
|
return true
|
||||||
case *pgproto3.CommandComplete:
|
case *pgproto3.CommandComplete:
|
||||||
mrr.rr = &ResultReader{
|
mrr.pgConn.resultReader = ResultReader{
|
||||||
commandTag: CommandTag(msg.CommandTag),
|
commandTag: CommandTag(msg.CommandTag),
|
||||||
commandConcluded: true,
|
commandConcluded: true,
|
||||||
closed: true,
|
closed: true,
|
||||||
}
|
}
|
||||||
|
mrr.rr = &mrr.pgConn.resultReader
|
||||||
return true
|
return true
|
||||||
case *pgproto3.EmptyQueryResponse:
|
case *pgproto3.EmptyQueryResponse:
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user