Skip to content

Commit 5a18241

Browse files
authored
Merge branch 'master' into zeronull-int-scanner
2 parents 562761a + cc34da5 commit 5a18241

82 files changed

Lines changed: 609 additions & 263 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See for configurations: https://golangci-lint.run/usage/configuration/
2+
version: 2
3+
4+
# See: https://golangci-lint.run/usage/formatters/
5+
formatters:
6+
default: none
7+
enable:
8+
- gofmt # https://pkg.go.dev/cmd/gofmt
9+
- gofumpt # https://github.com/mvdan/gofumpt
10+
11+
settings:
12+
gofmt:
13+
simplify: true # Simplify code: gofmt with `-s` option.
14+
15+
gofumpt:
16+
# Module path which contains the source code being formatted.
17+
# Default: ""
18+
module-path: github.com/jackc/pgx/v5 # Should match with module in go.mod
19+
# Choose whether to use the extra rules.
20+
# Default: false
21+
extra-rules: true

batch.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ func (br *batchResults) Query() (Rows, error) {
207207
func (br *batchResults) QueryRow() Row {
208208
rows, _ := br.Query()
209209
return (*connRow)(rows.(*baseRows))
210-
211210
}
212211

213212
// Close closes the batch operation. Any error that occurred during a batch operation may have made it impossible to
@@ -220,6 +219,8 @@ func (br *batchResults) Close() error {
220219
}
221220
br.endTraced = true
222221
}
222+
223+
invalidateCachesOnBatchResultsError(br.conn, br.b, br.err)
223224
}()
224225

225226
if br.err != nil {
@@ -378,7 +379,6 @@ func (br *pipelineBatchResults) Query() (Rows, error) {
378379
func (br *pipelineBatchResults) QueryRow() Row {
379380
rows, _ := br.Query()
380381
return (*connRow)(rows.(*baseRows))
381-
382382
}
383383

384384
// Close closes the batch operation. Any error that occurred during a batch operation may have made it impossible to
@@ -391,6 +391,8 @@ func (br *pipelineBatchResults) Close() error {
391391
}
392392
br.endTraced = true
393393
}
394+
395+
invalidateCachesOnBatchResultsError(br.conn, br.b, br.err)
394396
}()
395397

396398
if br.err == nil && br.lastRows != nil && br.lastRows.err != nil {
@@ -441,3 +443,20 @@ func (br *pipelineBatchResults) nextQueryAndArgs() (query string, args []any, er
441443
br.qqIdx++
442444
return bi.SQL, bi.Arguments, nil
443445
}
446+
447+
// invalidates statement and description caches on batch results error
448+
func invalidateCachesOnBatchResultsError(conn *Conn, b *Batch, err error) {
449+
if err != nil && conn != nil && b != nil {
450+
if sc := conn.statementCache; sc != nil {
451+
for _, bi := range b.QueuedQueries {
452+
sc.Invalidate(bi.SQL)
453+
}
454+
}
455+
456+
if sc := conn.descriptionCache; sc != nil {
457+
for _, bi := range b.QueuedQueries {
458+
sc.Invalidate(bi.SQL)
459+
}
460+
}
461+
}
462+
}

batch_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
488488
defer cancel()
489489

490490
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
491-
492491
batch := &pgx.Batch{}
493492
batch.Queue("select n from generate_series(0,5) n")
494493
batch.Queue("select n from generate_series(0,5) n")
@@ -539,7 +538,6 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
539538
if err != nil {
540539
t.Fatal(err)
541540
}
542-
543541
})
544542
}
545543

@@ -550,7 +548,6 @@ func TestConnSendBatchQueryError(t *testing.T) {
550548
defer cancel()
551549

552550
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
553-
554551
batch := &pgx.Batch{}
555552
batch.Queue("select n from generate_series(0,5) n where 100/(5-n) > 0")
556553
batch.Queue("select n from generate_series(0,5) n")
@@ -580,7 +577,6 @@ func TestConnSendBatchQueryError(t *testing.T) {
580577
if pgErr, ok := err.(*pgconn.PgError); !(ok && pgErr.Code == "22012") {
581578
t.Errorf("br.Close() => %v, want error code %v", err, 22012)
582579
}
583-
584580
})
585581
}
586582

@@ -591,7 +587,6 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) {
591587
defer cancel()
592588

593589
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
594-
595590
batch := &pgx.Batch{}
596591
batch.Queue("select 1 1")
597592

@@ -607,7 +602,6 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) {
607602
if err == nil {
608603
t.Error("Expected error")
609604
}
610-
611605
})
612606
}
613607

@@ -618,7 +612,6 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) {
618612
defer cancel()
619613

620614
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
621-
622615
sql := `create temporary table ledger(
623616
id serial primary key,
624617
description varchar not null,
@@ -647,7 +640,6 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) {
647640
}
648641

649642
br.Close()
650-
651643
})
652644
}
653645

@@ -658,7 +650,6 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
658650
defer cancel()
659651

660652
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
661-
662653
sql := `create temporary table ledger(
663654
id serial primary key,
664655
description varchar not null,
@@ -687,7 +678,6 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
687678
}
688679

689680
br.Close()
690-
691681
})
692682
}
693683

@@ -698,7 +688,6 @@ func TestTxSendBatch(t *testing.T) {
698688
defer cancel()
699689

700690
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
701-
702691
sql := `create temporary table ledger1(
703692
id serial primary key,
704693
description varchar not null
@@ -757,7 +746,6 @@ func TestTxSendBatch(t *testing.T) {
757746
if err != nil {
758747
t.Fatal(err)
759748
}
760-
761749
})
762750
}
763751

@@ -768,7 +756,6 @@ func TestTxSendBatchRollback(t *testing.T) {
768756
defer cancel()
769757

770758
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
771-
772759
sql := `create temporary table ledger1(
773760
id serial primary key,
774761
description varchar not null
@@ -795,7 +782,6 @@ func TestTxSendBatchRollback(t *testing.T) {
795782
if count != 0 {
796783
t.Errorf("count => %v, want %v", count, 0)
797784
}
798-
799785
})
800786
}
801787

@@ -855,7 +841,6 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
855841
defer cancel()
856842

857843
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
858-
859844
pgxtest.SkipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
860845

861846
mustExec(t, conn, `create temporary table t (
@@ -894,7 +879,6 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
894879
if err, ok := err.(*pgconn.PgError); !ok || err.Code != "23505" {
895880
t.Fatalf("expected error 23505, got %v", err)
896881
}
897-
898882
})
899883
}
900884

bench_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ func multiInsert(conn *pgx.Conn, tableName string, columnNames []string, rowSrc
516516
}
517517

518518
return rowCount, nil
519-
520519
}
521520

522521
func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
@@ -535,7 +534,8 @@ func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
535534
src := newBenchmarkWriteTableCopyFromSrc(n)
536535

537536
_, err := multiInsert(conn, "t",
538-
[]string{"varchar_1",
537+
[]string{
538+
"varchar_1",
539539
"varchar_2",
540540
"varchar_null_1",
541541
"date_1",
@@ -547,7 +547,8 @@ func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
547547
"tstz_2",
548548
"bool_1",
549549
"bool_2",
550-
"bool_3"},
550+
"bool_3",
551+
},
551552
src)
552553
if err != nil {
553554
b.Fatal(err)
@@ -568,7 +569,8 @@ func benchmarkWriteNRowsViaCopy(b *testing.B, n int) {
568569

569570
_, err := conn.CopyFrom(context.Background(),
570571
pgx.Identifier{"t"},
571-
[]string{"varchar_1",
572+
[]string{
573+
"varchar_1",
572574
"varchar_2",
573575
"varchar_null_1",
574576
"date_1",
@@ -580,7 +582,8 @@ func benchmarkWriteNRowsViaCopy(b *testing.B, n int) {
580582
"tstz_2",
581583
"bool_1",
582584
"bool_2",
583-
"bool_3"},
585+
"bool_3",
586+
},
584587
src)
585588
if err != nil {
586589
b.Fatal(err)
@@ -611,6 +614,7 @@ func BenchmarkWrite5RowsViaInsert(b *testing.B) {
611614
func BenchmarkWrite5RowsViaMultiInsert(b *testing.B) {
612615
benchmarkWriteNRowsViaMultiInsert(b, 5)
613616
}
617+
614618
func BenchmarkWrite5RowsViaBatchInsert(b *testing.B) {
615619
benchmarkWriteNRowsViaBatchInsert(b, 5)
616620
}
@@ -626,6 +630,7 @@ func BenchmarkWrite10RowsViaInsert(b *testing.B) {
626630
func BenchmarkWrite10RowsViaMultiInsert(b *testing.B) {
627631
benchmarkWriteNRowsViaMultiInsert(b, 10)
628632
}
633+
629634
func BenchmarkWrite10RowsViaBatchInsert(b *testing.B) {
630635
benchmarkWriteNRowsViaBatchInsert(b, 10)
631636
}
@@ -641,6 +646,7 @@ func BenchmarkWrite100RowsViaInsert(b *testing.B) {
641646
func BenchmarkWrite100RowsViaMultiInsert(b *testing.B) {
642647
benchmarkWriteNRowsViaMultiInsert(b, 100)
643648
}
649+
644650
func BenchmarkWrite100RowsViaBatchInsert(b *testing.B) {
645651
benchmarkWriteNRowsViaBatchInsert(b, 100)
646652
}
@@ -672,6 +678,7 @@ func BenchmarkWrite10000RowsViaInsert(b *testing.B) {
672678
func BenchmarkWrite10000RowsViaMultiInsert(b *testing.B) {
673679
benchmarkWriteNRowsViaMultiInsert(b, 10000)
674680
}
681+
675682
func BenchmarkWrite10000RowsViaBatchInsert(b *testing.B) {
676683
benchmarkWriteNRowsViaBatchInsert(b, 10000)
677684
}
@@ -1043,7 +1050,6 @@ func BenchmarkSelectRowsScanDecoder(b *testing.B) {
10431050
}
10441051
for _, format := range formats {
10451052
b.Run(format.name, func(b *testing.B) {
1046-
10471053
br := &BenchRowDecoder{}
10481054
for i := 0; i < b.N; i++ {
10491055
rows, err := conn.Query(

0 commit comments

Comments
 (0)