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

adds postgres index to support efficient querying via Watch API #2143

Merged
merged 1 commit into from
Nov 26, 2024
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,23 @@
package migrations

import (
"context"
"fmt"

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

const addWatchAPIIndexToRelationTupleTable = `CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_watch_index ON relation_tuple (created_xid);`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought for later: since the query also filters on deleted_xid, we might want to try a composite index on (created_xid, deleted_xid) down the line.

CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_watch_index ON relation_tuple (created_xid, deleted_xid);

It could make queries with both columns even faster by improving how rows are filtered. Definitely not a blocker tho.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the composite index and it didn't give any extra value, because we already have an index for deleted_xid that was selected. So it didn't improve the situation, neither made it worse, it was equally performing.


func init() {
if err := DatabaseMigrations.Register("add-watch-api-index-to-relation-tuple-table", "add-metadata-to-transaction-table",
func(ctx context.Context, conn *pgx.Conn) error {
if _, err := conn.Exec(ctx, addWatchAPIIndexToRelationTupleTable); err != nil {
return fmt.Errorf("failed to add watch API index to relation tuple table: %w", err)
}
return nil
},
noTxMigration); err != nil {
panic("failed to register migration: " + err.Error())
}
}
Loading