Skip to content

Commit

Permalink
introduces a faster query to tuple GC
Browse files Browse the repository at this point in the history
we've noticed that even after #1550
was introduced and made the nested GC SELECT query faster,
deletions are still causing spikes in postgres
and Aurora instances.

The proposed query seemed 1 order of magnitude less cost
that the current query on a test PG 15.6 with 5M dead
tuples and 5M alive tuples.
  • Loading branch information
vroldanbet committed Apr 8, 2024
1 parent d3150c2 commit c167656
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions internal/datastore/postgres/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ import (
var (
_ common.GarbageCollector = (*pgDatastore)(nil)

relationTuplePKCols = []string{
colNamespace,
colObjectID,
colRelation,
colUsersetNamespace,
colUsersetObjectID,
colUsersetRelation,
colCreatedXid,
colDeletedXid,
}
gcPKCols = []string{"ctid"}

namespacePKCols = []string{colNamespace, colCreatedXid, colDeletedXid}

Expand Down Expand Up @@ -88,7 +79,7 @@ func (pgd *pgDatastore) DeleteBeforeTx(ctx context.Context, txID datastore.Revis
removed.Relationships, err = pgd.batchDelete(
ctx,
tableTuple,
relationTuplePKCols,
gcPKCols,
sq.Lt{colDeletedXid: minTxAlive},
)
if err != nil {
Expand Down Expand Up @@ -135,7 +126,6 @@ func (pgd *pgDatastore) batchDelete(
}

pkColsExpression := strings.Join(pkCols, ", ")

query := fmt.Sprintf(`WITH rows AS (%[1]s)
DELETE FROM %[2]s
WHERE (%[3]s) IN (SELECT %[3]s FROM rows);
Expand Down

0 comments on commit c167656

Please sign in to comment.