Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new index to postgres datastore for GC #1550

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package migrations

import (
"context"
"fmt"

"github.com/jackc/pgx/v5"
)

const createTunedGCIndex = `CREATE INDEX CONCURRENTLY
IF NOT EXISTS ix_gc_index
ON relation_tuple (deleted_xid DESC)
WHERE deleted_xid < '9223372036854775807'::xid8;`

const deleteSuboptimalGCIndex = `DROP INDEX CONCURRENTLY IF EXISTS ix_relation_tuple_by_deleted_xid`

func init() {
if err := DatabaseMigrations.Register("add-tuned-gc-index", "add-gc-covering-index",
func(ctx context.Context, conn *pgx.Conn) error {
if _, err := conn.Exec(ctx, createTunedGCIndex); err != nil {
return fmt.Errorf("failed to create new tuned GC Index: %w", err)
}
if _, err := conn.Exec(ctx, deleteSuboptimalGCIndex); err != nil {
return fmt.Errorf("failed to remove old GC Index: %w", err)
}
if _, err := conn.Exec(ctx, "ANALYZE relation_tuple"); err != nil {
return fmt.Errorf("failed to update relation_tuple table statistics after new index: %w", err)
}
return nil
},
noTxMigration); err != nil {
panic("failed to register migration: " + err.Error())
}
}
Loading