Skip to content

Commit ed7d68d

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dolthub/master
2 parents afee073 + a841e81 commit ed7d68d

21 files changed

+234
-123
lines changed

Diff for: .github/workflows/test.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@ jobs:
2323
import os
2424
go = [
2525
# Keep the most recent production release at the top
26-
'1.19',
26+
'1.20',
2727
# Older production releases
28+
'1.19',
2829
'1.18',
29-
'1.17',
30-
'1.16',
31-
'1.15',
32-
'1.14',
33-
'1.13',
3430
]
3531
mysql = [
3632
'8.0',
3733
'5.7',
3834
'5.6',
35+
'mariadb-10.11',
3936
'mariadb-10.6',
4037
'mariadb-10.5',
4138
'mariadb-10.4',
@@ -45,7 +42,7 @@ jobs:
4542
includes = []
4643
# Go versions compatibility check
4744
for v in go[1:]:
48-
includes.append({'os': 'ubuntu-latest', 'go': v, 'mysql': mysql[0]})
45+
includes.append({'os': 'ubuntu-latest', 'go': v, 'mysql': mysql[0]})
4946
5047
matrix = {
5148
# OS vs MySQL versions
@@ -67,10 +64,10 @@ jobs:
6764
matrix: ${{ fromJSON(needs.list.outputs.matrix) }}
6865
steps:
6966
- uses: actions/checkout@v3
70-
- uses: actions/setup-go@v3
67+
- uses: actions/setup-go@v4
7168
with:
7269
go-version: ${{ matrix.go }}
73-
- uses: shogo82148/actions-setup-mysql@v1
70+
- uses: shogo82148/actions-setup-mysql@v1.16.0
7471
with:
7572
mysql-version: ${{ matrix.mysql }}
7673
user: ${{ env.MYSQL_TEST_USER }}

Diff for: AUTHORS

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Dave Protasowski <dprotaso at gmail.com>
3333
DisposaBoy <disposaboy at dby.me>
3434
Egor Smolyakov <egorsmkv at gmail.com>
3535
Erwan Martin <hello at erwan.io>
36+
Evan Elias <evan at skeema.net>
3637
Evan Shaw <evan at vendhq.com>
3738
Frederick Mayle <frederickmayle at gmail.com>
3839
Gustavo Kristic <gkristic at gmail.com>
@@ -47,6 +48,7 @@ INADA Naoki <songofacandy at gmail.com>
4748
Jacek Szwec <szwec.jacek at gmail.com>
4849
James Harr <james.harr at gmail.com>
4950
Janek Vedock <janekvedock at comcast.net>
51+
Jean-Yves Pellé <jy at pelle.link>
5052
Jeff Hodges <jeff at somethingsimilar.com>
5153
Jeffrey Charles <jeffreycharles at gmail.com>
5254
Jerome Meyer <jxmeyer at gmail.com>
@@ -78,6 +80,7 @@ Olivier Mengué <dolmen at cpan.org>
7880
oscarzhao <oscarzhaosl at gmail.com>
7981
Paul Bonser <misterpib at gmail.com>
8082
Peter Schultz <peter.schultz at classmarkets.com>
83+
Phil Porada <philporada at gmail.com>
8184
Rebecca Chin <rchin at pivotal.io>
8285
Reed Allman <rdallman10 at gmail.com>
8386
Richard Wilkes <wilkes at me.com>
@@ -94,6 +97,7 @@ Stan Putrya <root.vagner at gmail.com>
9497
Stanley Gunawan <gunawan.stanley at gmail.com>
9598
Steven Hartland <steven.hartland at multiplay.co.uk>
9699
Tan Jinhua <312841925 at qq.com>
100+
Tetsuro Aoki <t.aoki1130 at gmail.com>
97101
Thomas Wodarek <wodarekwebpage at gmail.com>
98102
Tim Ruffles <timruffles at gmail.com>
99103
Tom Jenkinson <tom at tjenkinson.me>

Diff for: CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## Version 1.7.1 (2023-04-25)
2+
3+
Changes:
4+
5+
- bump actions/checkout@v3 and actions/setup-go@v3 (#1375)
6+
- Add go1.20 and mariadb10.11 to the testing matrix (#1403)
7+
- Increase default maxAllowedPacket size. (#1411)
8+
9+
Bugfixes:
10+
11+
- Use SET syntax as specified in the MySQL documentation (#1402)
12+
13+
114
## Version 1.7 (2022-11-29)
215

316
Changes:

Diff for: README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
4040
* Optional placeholder interpolation
4141

4242
## Requirements
43-
* Go 1.13 or higher. We aim to support the 3 latest versions of Go.
44-
* MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
43+
* Go 1.18 or higher. We aim to support the 3 latest versions of Go.
44+
* MySQL (5.6+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
4545

4646
---------------------------------------
4747

@@ -287,10 +287,10 @@ Please keep in mind, that param values must be [url.QueryEscape](https://golang.
287287
##### `maxAllowedPacket`
288288
```
289289
Type: decimal number
290-
Default: 4194304
290+
Default: 64*1024*1024
291291
```
292292

293-
Max packet size allowed in bytes. The default value is 4 MiB and should be adjusted to match the server settings. `maxAllowedPacket=0` can be used to automatically fetch the `max_allowed_packet` variable from server *on every connection*.
293+
Max packet size allowed in bytes. The default value is 64 MiB and should be adjusted to match the server settings. `maxAllowedPacket=0` can be used to automatically fetch the `max_allowed_packet` variable from server *on every connection*.
294294

295295
##### `multiStatements`
296296

@@ -470,7 +470,7 @@ user:password@/
470470
The connection pool is managed by Go's database/sql package. For details on how to configure the size of the pool and how long connections stay in the pool see `*DB.SetMaxOpenConns`, `*DB.SetMaxIdleConns`, and `*DB.SetConnMaxLifetime` in the [database/sql documentation](https://golang.org/pkg/database/sql/). The read, write, and dial timeouts for each individual connection are configured with the DSN parameters [`readTimeout`](#readtimeout), [`writeTimeout`](#writetimeout), and [`timeout`](#timeout), respectively.
471471

472472
## `ColumnType` Support
473-
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `BIGINT`.
473+
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `MEDIUMINT`, `BIGINT`.
474474

475475
## `context.Context` Support
476476
Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.

Diff for: auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
291291
return enc, err
292292

293293
default:
294-
errLog.Print("unknown auth plugin:", plugin)
294+
mc.cfg.Logger.Print("unknown auth plugin:", plugin)
295295
return nil, ErrUnknownPlugin
296296
}
297297
}

Diff for: benchmark_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,59 @@ func BenchmarkQueryRawBytes(b *testing.B) {
372372
})
373373
}
374374
}
375+
376+
// BenchmarkReceiveMassiveRows measures performance of receiving large number of rows.
377+
func BenchmarkReceiveMassiveRows(b *testing.B) {
378+
// Setup -- prepare 10000 rows.
379+
db := initDB(b,
380+
"DROP TABLE IF EXISTS foo",
381+
"CREATE TABLE foo (id INT PRIMARY KEY, val TEXT)")
382+
defer db.Close()
383+
384+
sval := strings.Repeat("x", 50)
385+
stmt, err := db.Prepare(`INSERT INTO foo (id, val) VALUES (?, ?)` + strings.Repeat(",(?,?)", 99))
386+
if err != nil {
387+
b.Errorf("failed to prepare query: %v", err)
388+
return
389+
}
390+
for i := 0; i < 10000; i += 100 {
391+
args := make([]any, 200)
392+
for j := 0; j < 100; j++ {
393+
args[j*2] = i + j
394+
args[j*2+1] = sval
395+
}
396+
_, err := stmt.Exec(args...)
397+
if err != nil {
398+
b.Error(err)
399+
return
400+
}
401+
}
402+
stmt.Close()
403+
404+
// Use b.Run() to skip expensive setup.
405+
b.Run("query", func(b *testing.B) {
406+
b.ReportAllocs()
407+
408+
for i := 0; i < b.N; i++ {
409+
rows, err := db.Query(`SELECT id, val FROM foo`)
410+
if err != nil {
411+
b.Errorf("failed to select: %v", err)
412+
return
413+
}
414+
for rows.Next() {
415+
var i int
416+
var s sql.RawBytes
417+
err = rows.Scan(&i, &s)
418+
if err != nil {
419+
b.Errorf("failed to scan: %v", err)
420+
_ = rows.Close()
421+
return
422+
}
423+
}
424+
if err = rows.Err(); err != nil {
425+
b.Errorf("failed to read rows: %v", err)
426+
}
427+
_ = rows.Close()
428+
}
429+
})
430+
}

Diff for: connection.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (mc *mysqlConn) handleParams() (err error) {
6868
default:
6969
if cmdSet.Len() == 0 {
7070
// Heuristic: 29 chars for each other key=value to reduce reallocations
71-
cmdSet.Grow(4 + len(param) + 1 + len(val) + 30*(len(mc.cfg.Params)-1))
71+
cmdSet.Grow(4 + len(param) + 3 + len(val) + 30*(len(mc.cfg.Params)-1))
7272
cmdSet.WriteString("SET ")
7373
} else {
7474
cmdSet.WriteString(", ")
@@ -105,7 +105,7 @@ func (mc *mysqlConn) Begin() (driver.Tx, error) {
105105

106106
func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) {
107107
if mc.closed.Load() {
108-
errLog.Print(ErrInvalidConn)
108+
mc.cfg.Logger.Print(ErrInvalidConn)
109109
return nil, driver.ErrBadConn
110110
}
111111
var q string
@@ -147,7 +147,7 @@ func (mc *mysqlConn) cleanup() {
147147
return
148148
}
149149
if err := mc.netConn.Close(); err != nil {
150-
errLog.Print(err)
150+
mc.cfg.Logger.Print(err)
151151
}
152152
}
153153

@@ -163,14 +163,14 @@ func (mc *mysqlConn) error() error {
163163

164164
func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) {
165165
if mc.closed.Load() {
166-
errLog.Print(ErrInvalidConn)
166+
mc.cfg.Logger.Print(ErrInvalidConn)
167167
return nil, driver.ErrBadConn
168168
}
169169
// Send command
170170
err := mc.writeCommandPacketStr(comStmtPrepare, query)
171171
if err != nil {
172172
// STMT_PREPARE is safe to retry. So we can return ErrBadConn here.
173-
errLog.Print(err)
173+
mc.cfg.Logger.Print(err)
174174
return nil, driver.ErrBadConn
175175
}
176176

@@ -204,7 +204,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
204204
buf, err := mc.buf.takeCompleteBuffer()
205205
if err != nil {
206206
// can not take the buffer. Something must be wrong with the connection
207-
errLog.Print(err)
207+
mc.cfg.Logger.Print(err)
208208
return "", ErrInvalidConn
209209
}
210210
buf = buf[:0]
@@ -296,7 +296,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
296296

297297
func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, error) {
298298
if mc.closed.Load() {
299-
errLog.Print(ErrInvalidConn)
299+
mc.cfg.Logger.Print(ErrInvalidConn)
300300
return nil, driver.ErrBadConn
301301
}
302302
if len(args) != 0 {
@@ -357,7 +357,7 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
357357

358358
func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) {
359359
if mc.closed.Load() {
360-
errLog.Print(ErrInvalidConn)
360+
mc.cfg.Logger.Print(ErrInvalidConn)
361361
return nil, driver.ErrBadConn
362362
}
363363
if len(args) != 0 {
@@ -451,7 +451,7 @@ func (mc *mysqlConn) finish() {
451451
// Ping implements driver.Pinger interface
452452
func (mc *mysqlConn) Ping(ctx context.Context) (err error) {
453453
if mc.closed.Load() {
454-
errLog.Print(ErrInvalidConn)
454+
mc.cfg.Logger.Print(ErrInvalidConn)
455455
return driver.ErrBadConn
456456
}
457457

Diff for: connection_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func TestPingErrInvalidConn(t *testing.T) {
179179
buf: newBuffer(nc),
180180
maxAllowedPacket: defaultMaxAllowedPacket,
181181
closech: make(chan struct{}),
182+
cfg: NewConfig(),
182183
}
183184

184185
err := ms.Ping(context.Background())

Diff for: connector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
9292
authResp, err := mc.auth(authData, plugin)
9393
if err != nil {
9494
// try the default auth plugin, if using the requested plugin failed
95-
errLog.Print("could not use requested auth plugin '"+plugin+"': ", err.Error())
95+
c.cfg.Logger.Print("could not use requested auth plugin '"+plugin+"': ", err.Error())
9696
plugin = defaultAuthPlugin
9797
authResp, err = mc.auth(authData, plugin)
9898
if err != nil {

Diff for: const.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package mysql
1010

1111
const (
1212
defaultAuthPlugin = "mysql_native_password"
13-
defaultMaxAllowedPacket = 4 << 20 // 4 MiB
13+
defaultMaxAllowedPacket = 64 << 20 // 64 MiB. See https://github.com/go-sql-driver/mysql/issues/1355
1414
minProtocolVersion = 10
1515
maxPacketSize = 1<<24 - 1
1616
timeFormat = "2006-01-02 15:04:05.999999"

Diff for: driver.go

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func RegisterDialContext(net string, dial DialContextFunc) {
5555
dials[net] = dial
5656
}
5757

58+
// DeregisterDialContext removes the custom dial function registered with the given net.
59+
func DeregisterDialContext(net string) {
60+
dialsLock.Lock()
61+
defer dialsLock.Unlock()
62+
if dials != nil {
63+
if _, ok := dials[net]; ok {
64+
delete(dials, net)
65+
}
66+
}
67+
}
68+
5869
// RegisterDial registers a custom dial function. It can then be used by the
5970
// network address mynet(addr), where mynet is the registered new network.
6071
// addr is passed as a parameter to the dial function.

0 commit comments

Comments
 (0)