-
Notifications
You must be signed in to change notification settings - Fork 458
add unique_address constraint for peers table #397
add unique_address constraint for peers table #397
Conversation
Referred to postgres docs it is better to have constraints while resolving conflicts during upserts. closes LiskArchive#361 Signed-off-by: Maciej Baj <macie.baj@gmail.com>
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.
However, I don't think that will help solve referenced issue, because UNIQUE CONSTRAINT
rely on UNIQUE INDEX
under the hood.
|
||
ALTER TABLE peers | ||
ADD CONSTRAINT unique_address | ||
UNIQUE (ip, port); |
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.
We already have unique index on those fields, so USING INDEX peers_unique;
Maintaining both unique index and unique constraint is costly and we don't need it.
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.
so do you have any suggestions?
solutions are:
- not add the constraint and leave the potential errors from upsert
- add the constraint and risk with the performance issues.
Guess that none of these solutions is satisfiable for us.
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.
ALTER TABLE peers ADD CONSTRAINT unique_address USING INDEX peers_unique;
- should be fine, there shouldn't be noticeable performance hit if any.
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.
thanks! Changed
Referred to postgres docs it is better to have constraints while resolving conflicts during upserts.
closes #361