-
Notifications
You must be signed in to change notification settings - Fork 31
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
fix: add composite index for summing payments #140
Conversation
Will this update the current DB, too? is this a migration? |
@bumi it's an automatic migration. So we create an index for all 4 fields, should we still add indexes for the individual columns too? |
@bumi updated |
Preimage string | ||
CreatedAt time.Time | ||
Preimage string `gorm:"index:idx_payment_sum"` | ||
CreatedAt time.Time `gorm:"index:idx_payment_sum"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is idx_
a convention we follow here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first gorm composite index. I am happy to change it, do you have a suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have special migration files actually. some migration that can be run on the existing DBs then.
this feels a bit more stable to me. what do you think.
App App `gorm:"constraint:OnDelete:CASCADE"` | ||
NostrEventId uint `gorm:"index" validate:"required"` | ||
NostrEvent NostrEvent | ||
Amount uint | ||
Amount uint `gorm:"index:idx_payment_sum"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the amount in the index does not make sense to have the amount part of the index we do not query for that.
we do WHERE app_id = ? AND preimage IS NOT ? AND created_at > ?
so maybe we do the 3 in the index and include the amount that then can be used to sum things up.
https://atlasgo.io/guides/postgres/included-columns
Replaced by #148 |
fixes #140
improves performance of query to sum payments in current budget period