oxidecomputer / oxidecomputer/omicron
The query used to filter out overlapping IP Pool ranges could be simpler
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 572
- Forks
- 97
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 96
Description
I ran into this while testing IPv6 address allocations. We use the following type:
to filter out overlapping IP Ranges when we add them to a pool. This generates four subqueries, and uses them inside WHERE NOT EXISTS(subq) in the main INSERT query. If any one of those returns TRUE, we try to insert NULL and fail the whole query.
Those four conditions check:
- The candidate first address is between any existing first / last address
- The candidate last address is between any existing first / last address
- Any existing first address is between the candidate first / last address
- Any existing last address is between the candidate first / last address
That's all fine, but it's overly complicated. We could simplify this whole thing to:
INSERT INTO
ip_pool_range
SELECT
<candidate_data>
WHERE NOT EXISTS (
SELECT 1
FROM ip_pool_range
WHERE time_deleted IS NULL
AND first_address <= $candidate_last_address
AND last_address >= $candidate_first_address
)
That's logically equivalent, but probably faster and certainly simpler.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in nexus/db-queries/src/db/queries/ip_pool.rs around line 113 and inspect how the current overlap checks are used in the insert query. Replace the four-condition overlap check with the simpler equivalent predicate described in the issue, then verify IPv6 range allocation and overlap rejection using the relevant existing tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- backend, databases
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100