oxidecomputer / oxidecomputer/omicron

VPC Subnet insertion query is not efficient

Open
#1,221 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

database enhancement networking
Dominant language
Rust
Stars
572
Forks
97
Avg merge
2d 12h
Merged PRs (30d)
96

Description

In the query for inserting a VPC Subnet, we look for the existence of overlapping IP subnets from other VPC Subnets already in the same VPC. That's done here, with a call to the CockroachDB function inet_contains_or_equals. That is correct, but pretty inefficient if the VPC starts to get a lot of subnets. We're using an index on the vpc_subnet table on the vpc_id column, but we'll still need to do a full scan of that index. That's better than a table scan, but not great.

We could instead store the first and last address of each VPC Subnet's IP subnets (both v4 and v6). A unique index on each of these would be great, and would support fast lookups of overlapping subnets. An existing subnet containing the candidate is one where the first and last addresses are before and after the first address of the candidate, respectively. An existing subnet contained by the candidate is one where the first address is between the candidate's first and last address.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in nexus/src/db/queries/vpc_subnet.rs at the query around line 138, then inspect the vpc_subnet table and its existing vpc_id index. Review how CockroachDB's inet_contains_or_equals check finds overlapping subnets. Done means overlap checks use stored boundary addresses and supporting indexes rather than scanning the full vpc_id index.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.