Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit e99e03d

Browse files
jgpruittcevian
authored andcommitted
Reuse temp table for trace ingest
Reusing the temp table will reduce catalog bloat and logging. No need to recreate it continuously.
1 parent 33a7443 commit e99e03d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/pgmodel/ingestor/trace/writer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,15 @@ func (t *traceWriterImpl) insertRows(ctx context.Context, table string, columns
391391
}
392392
}()
393393

394-
if _, err = tx.Exec(ctx, fmt.Sprintf("CREATE TEMPORARY TABLE temp ON COMMIT DROP AS TABLE _ps_trace.%s WITH NO DATA", table)); err != nil {
394+
if _, err = tx.Exec(ctx, fmt.Sprintf("CREATE TEMPORARY TABLE IF NOT EXISTS trace_writer_temp ON COMMIT DELETE ROWS AS TABLE _ps_trace.%s WITH NO DATA", table)); err != nil {
395395
return err
396396
}
397397

398398
if _, err = tx.CopyFrom(ctx, pgx.Identifier{"temp"}, columns, pgx.CopyFromRows(data)); err != nil {
399399
return err
400400
}
401401

402-
if _, err = tx.Exec(ctx, fmt.Sprintf("INSERT INTO _ps_trace.%s(%[2]s) SELECT %[2]s FROM temp ON CONFLICT DO NOTHING", table, strings.Join(columns, ","))); err != nil {
402+
if _, err = tx.Exec(ctx, fmt.Sprintf("INSERT INTO _ps_trace.%s(%[2]s) SELECT %[2]s FROM trace_writer_temp ON CONFLICT DO NOTHING", table, strings.Join(columns, ","))); err != nil {
403403
return err
404404
}
405405
return tx.Commit(ctx)

0 commit comments

Comments
 (0)