indexer
indexer copied to clipboard
writer: deallocate partially prepared statements on error
Summary
Writer does not call Close (and so that DEALLOCATE) if some of statements fail in the middle.
Although go's pg driver's Prepare
is has map of prepared statements to prevent such errors (see the code excerpt below) it looks more correct to clean up in case of an error.
// Prepare creates a prepared statement with name and sql. sql can contain placeholders
// for bound parameters. These placeholders are referenced positional as $1, $2, etc.
//
// Prepare is idempotent; i.e. it is safe to call Prepare multiple times with the same
// name and sql arguments. This allows a code path to Prepare and Query/Exec without
// concern for if the statement has already been prepared.
func (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.StatementDescription, err error) {
if name != "" {
var ok bool
if sd, ok = c.preparedStatements[name]; ok && sd.SQL == sql {
return sd, nil
}
}
...
sd, err = c.pgConn.Prepare(ctx, name, sql, nil)
...
if name != "" {
c.preparedStatements[name] = sd
}
return sd, nil
}
Test Plan
No test, it is hard/impossible to test b/c driver's Prepare
caches statements.
Codecov Report
Attention: 4 lines
in your changes are missing coverage. Please review.
Comparison is base (
4bd144f
) 68.45% compared to head (10f7c28
) 68.43%.
Files | Patch % | Lines |
---|---|---|
idb/postgres/internal/writer/writer.go | 33.33% | 4 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #1592 +/- ##
==========================================
- Coverage 68.45% 68.43% -0.02%
==========================================
Files 37 37
Lines 7434 7439 +5
==========================================
+ Hits 5089 5091 +2
- Misses 1915 1918 +3
Partials 430 430
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@algorandskiy I suggest we ice box/close this for now - the driver for why the work was done may be resolved through configuration