Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

add unique_address constraint for peers table #397

Merged
merged 2 commits into from
Jan 26, 2017

Conversation

MaciejBaj
Copy link
Contributor

@MaciejBaj MaciejBaj commented Jan 19, 2017

Referred to postgres docs it is better to have constraints while resolving conflicts during upserts.

closes #361

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>
@karmacoma karmacoma self-assigned this Jan 19, 2017
Copy link
Contributor

@4miners 4miners left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! Changed

@karmacoma karmacoma merged commit 5c98dc0 into LiskArchive:development Jan 26, 2017
@MaciejBaj MaciejBaj deleted the upsert-constraint branch January 27, 2017 13:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to sweep peers
3 participants