Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions db_test/20261001064316_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- +goose Up
CREATE TABLE vulnerabilities (
id TEXT PRIMARY KEY, -- NB: This should have COLLATE "C"
Comment thread
michaelkedar marked this conversation as resolved.
data JSONB NOT NULL,
proto BYTEA NOT NULL
);
-- vuln_id does not reference vulnerabilities(id) because there is no index on (vuln_id)
-- (to save space/writes), which would cause a full table scan on vulnerability deletes.
-- Use vuln_commits to look up commits and delete by (commit_sha, vuln_id).
CREATE TABLE affected_commits (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need references for vulnerabilities here as well? just like vuln_commits and affected_versions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't for a bit of an optimisation reason:
If we were to add REFERENCES vulnerabilities(id) here, we'd either have to do a full table scan or create a new vuln_id index on the table (which we already have vuln_commits for to do the ID -> commits lookup more efficiently, which we can use for deletes as well)

I've added a comment here to explain also

commit_sha BYTEA NOT NULL,
vuln_id TEXT NOT NULL,
PRIMARY KEY (commit_sha, vuln_id)
);
CREATE TABLE vuln_commits (
vuln_id TEXT PRIMARY KEY REFERENCES vulnerabilities(id) ON DELETE CASCADE,
commits BYTEA[]
);

CREATE TABLE affected_versions (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
vuln_id TEXT NOT NULL REFERENCES vulnerabilities(id) ON DELETE CASCADE,
name TEXT NOT NULL,
base_ecosystem TEXT NOT NULL,
ecosystems TEXT[] NOT NULL,
coarse_min TEXT COLLATE "C" NOT NULL,
coarse_max TEXT COLLATE "C" NOT NULL,
versions TEXT[],
events JSONB
);

-- Primary index for typical queries (with ecosystem provided)
CREATE INDEX idx_affected_versions_match
ON affected_versions (name, base_ecosystem, vuln_id, id, coarse_min, coarse_max)
INCLUDE (ecosystems);

-- Secondary index for queries without ecosystems
CREATE INDEX idx_affected_versions_name_only
ON affected_versions (name, vuln_id, id);

-- Index for worker updates/deletes by vuln_id
CREATE INDEX idx_affected_versions_vuln_id ON affected_versions (vuln_id);


-- +goose Down
DROP TABLE affected_versions;
DROP TABLE vuln_commits;
DROP TABLE affected_commits;
DROP TABLE vulnerabilities;
21 changes: 21 additions & 0 deletions deployment/terraform/environments/temp/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions deployment/terraform/environments/temp/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
variable "project_id" {
description = "The GCP project ID to deploy the experimental Cloud SQL database to."
type = string
default = "oss-vdb-test"
}

resource "google_sql_database_instance" "experiment" {
project = var.project_id
name = "experiment-db"
database_version = "POSTGRES_18"
region = "us-west2"

settings {
tier = "db-perf-optimized-N-4"
availability_type = "ZONAL"

connection_pool_config {
connection_pooling_enabled = true
}

ip_configuration {
ipv4_enabled = true
private_network = data.google_compute_network.default.id
enable_private_path_for_google_cloud_services = true
ssl_mode = "ENCRYPTED_ONLY"
}

database_flags {
name = "cloudsql.iam_authentication"
value = "on"
}
database_flags {
name = "temp_file_limit"
value = "2147483647" # maximum allowed (2TiB, measured in KiB)
}
}

deletion_protection = false
depends_on = [google_service_networking_connection.private_vpc_connection]
}

resource "google_sql_database" "osv" {
name = "osv"
instance = google_sql_database_instance.experiment.name
project = var.project_id
}


resource "google_project_service" "service_networking" {
project = var.project_id
service = "servicenetworking.googleapis.com"
disable_on_destroy = false
}

resource "google_compute_global_address" "private_ip_address" {
project = var.project_id
name = "google-managed-services-default"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = data.google_compute_network.default.id
}

resource "google_service_networking_connection" "private_vpc_connection" {
network = data.google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_address.name]

depends_on = [google_project_service.service_networking]
}

data "google_compute_network" "default" {
project = var.project_id
name = "default"
}
3 changes: 3 additions & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/google/go-cmp v0.7.0
github.com/google/osv-scalibr v0.5.3
github.com/hashicorp/go-retryablehttp v0.7.8
github.com/jackc/pgx/v5 v5.11.0
github.com/klauspost/compress v1.20.1
github.com/microcosm-cc/bluemonday v1.0.27
github.com/nikolalohinski/gonja/v2 v2.9.1
Expand Down Expand Up @@ -95,6 +96,8 @@ require (
github.com/gorilla/css v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.6.0 // indirect
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB1
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg=
github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY=
Expand Down Expand Up @@ -272,6 +280,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
Expand Down
Loading
Loading