Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENT] add indexes for common queries on ENT #2032

Merged
merged 2 commits into from
Jul 16, 2024
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
6 changes: 0 additions & 6 deletions internal/testing/testdata/exampledata/ingest_predicates.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@
],
"subpath": ""
},
"depPkgMatchFlag" : {
"pkg": "SPECIFIC_VERSION"
},
"isDependency": {
"dependencyType": "UNKNOWN",
"justification": "top level package dependency",
Expand Down Expand Up @@ -127,9 +124,6 @@
],
"subpath": ""
},
"depPkgMatchFlag" : {
"pkg": "SPECIFIC_VERSION"
},
"isDependency": {
"dependencyType": "UNKNOWN",
"justification": "top level package dependency",
Expand Down
36 changes: 12 additions & 24 deletions internal/testing/testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,62 +1126,50 @@ var (

cdxLegalDeps = []assembler.IsDependencyIngest{
{
Pkg: cdxTopQuarkusPack,
DepPkg: cdxResteasyPack,
DepPkgMatchFlag: model.MatchFlags{Pkg: model.PkgMatchTypeSpecificVersion},
Pkg: cdxTopQuarkusPack,
DepPkg: cdxResteasyPack,
IsDependency: &model.IsDependencyInputSpec{
DependencyType: model.DependencyTypeDirect,
VersionRange: "2.13.4.Final",
Justification: isCDXDepJustifyDependsJustification,
},
},
{
Pkg: cdxTopQuarkusPack,
DepPkg: cdxReactiveCommonPack,
DepPkgMatchFlag: model.MatchFlags{Pkg: model.PkgMatchTypeSpecificVersion},
Pkg: cdxTopQuarkusPack,
DepPkg: cdxReactiveCommonPack,
IsDependency: &model.IsDependencyInputSpec{
DependencyType: model.DependencyTypeIndirect,
VersionRange: "2.13.4.Final",
Justification: isCDXDepJustifyDependsJustification,
},
},
{
Pkg: cdxResteasyPack,
DepPkg: cdxReactiveCommonPack,
DepPkgMatchFlag: model.MatchFlags{Pkg: model.PkgMatchTypeSpecificVersion},
Pkg: cdxResteasyPack,
DepPkg: cdxReactiveCommonPack,
IsDependency: &model.IsDependencyInputSpec{
DependencyType: model.DependencyTypeDirect,
VersionRange: "2.13.4.Final",
Justification: isCDXDepJustifyDependsJustification,
},
},
{
Pkg: cdxTopQuarkusPack,
DepPkg: cdxSmallRye,
DepPkgMatchFlag: model.MatchFlags{Pkg: model.PkgMatchTypeSpecificVersion},
Pkg: cdxTopQuarkusPack,
DepPkg: cdxSmallRye,
IsDependency: &model.IsDependencyInputSpec{
DependencyType: model.DependencyTypeUnknown,
VersionRange: "2.27.0",
Justification: isDepJustifyTopPkgJustification,
},
},
{
Pkg: cdxTopQuarkusPack,
DepPkg: cdxNetbasePack,
DepPkgMatchFlag: model.MatchFlags{Pkg: model.PkgMatchTypeSpecificVersion},
Pkg: cdxTopQuarkusPack,
DepPkg: cdxNetbasePack,
IsDependency: &model.IsDependencyInputSpec{
DependencyType: model.DependencyTypeUnknown,
VersionRange: "6.3",
Justification: isDepJustifyTopPkgJustification,
},
},
{
Pkg: cdxTopQuarkusPack,
DepPkg: cdxMicroprofilePack,
DepPkgMatchFlag: model.MatchFlags{Pkg: model.PkgMatchTypeSpecificVersion},
Pkg: cdxTopQuarkusPack,
DepPkg: cdxMicroprofilePack,
IsDependency: &model.IsDependencyInputSpec{
DependencyType: model.DependencyTypeUnknown,
VersionRange: "1.2",
Justification: isDepJustifyTopPkgJustification,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Create index "billofmaterials_artifact_id" to table: "bill_of_materials"
CREATE INDEX "billofmaterials_artifact_id" ON "bill_of_materials" ("artifact_id") WHERE ((package_id IS NULL) AND (artifact_id IS NOT NULL));
-- Create index "billofmaterials_package_id" to table: "bill_of_materials"
CREATE INDEX "billofmaterials_package_id" ON "bill_of_materials" ("package_id") WHERE ((package_id IS NOT NULL) AND (artifact_id IS NULL));
-- Create index "certifylegal_package_id" to table: "certify_legals"
CREATE INDEX "certifylegal_package_id" ON "certify_legals" ("package_id") WHERE ((package_id IS NOT NULL) AND (source_id IS NULL));
-- Create index "dependency_dependent_package_version_id" to table: "dependencies"
CREATE INDEX "dependency_dependent_package_version_id" ON "dependencies" ("dependent_package_version_id");
-- Create index "occurrence_artifact_id" to table: "occurrences"
CREATE INDEX "occurrence_artifact_id" ON "occurrences" ("artifact_id");
-- Create index "query_occurrence_package_id" to table: "occurrences"
CREATE INDEX "query_occurrence_package_id" ON "occurrences" ("package_id") WHERE ((package_id IS NOT NULL) AND (source_id IS NULL));
3 changes: 2 additions & 1 deletion pkg/assembler/backends/ent/migrate/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
h1:tylM27WD3aiFco8Hl4NNfSVCY9g42uwOh5O1GMmkWP8=
h1:2v3i5iU6MalDXCn9jNXp+75vnIcNccKwMbKG2r1uBkc=
20240503123155_baseline.sql h1:oZtbKI8sJj3xQq7ibfvfhFoVl+Oa67CWP7DFrsVLVds=
20240626153721_ent_diff.sql h1:FvV1xELikdPbtJk7kxIZn9MhvVVoFLF/2/iT/wM5RkA=
20240702195630_ent_diff.sql h1:y8TgeUg35krYVORmC7cN4O96HqOc3mVO9IQ2lYzIzwg=
20240712131658_ent_diff.sql h1:N54EB3Wh2NC2v9RToXo/BfpezLnSeHJBP1ha6VXfxD8=
20240712193834_ent_diff.sql h1:gHTfEzlqvgYi6NKwT/Mb+wooWsVjAkp98zfg1OvdoZw=
20240716182144_ent_diff.sql h1:Pm0/+7zkBUGOY/AiF3bCJzW8giL5+uSg/j/0SUDsuNg=
42 changes: 42 additions & 0 deletions pkg/assembler/backends/ent/migrate/schema.go

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

2 changes: 2 additions & 0 deletions pkg/assembler/backends/ent/schema/billofmaterials.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ func (BillOfMaterials) Indexes() []ent.Index {
index.Fields("algorithm", "digest", "uri", "download_location", "known_since", "included_packages_hash",
"included_artifacts_hash", "included_dependencies_hash", "included_occurrences_hash", "origin", "collector", "document_ref").Edges("artifact").Unique().
Annotations(entsql.IndexWhere("package_id IS NULL AND artifact_id IS NOT NULL")).StorageKey("sbom_artifact_id"),
index.Fields("package_id").Annotations(entsql.IndexWhere("package_id IS NOT NULL AND artifact_id IS NULL")), // query when subject is package ID
index.Fields("artifact_id").Annotations(entsql.IndexWhere("package_id IS NULL AND artifact_id IS NOT NULL")), // query when subject is artifact ID
}
}
1 change: 1 addition & 0 deletions pkg/assembler/backends/ent/schema/certifylegal.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ func (CertifyLegal) Indexes() []ent.Index {
"origin", "collector", "document_ref", "declared_licenses_hash", "discovered_licenses_hash").
Unique().
Annotations(entsql.IndexWhere("package_id IS NOT NULL AND source_id IS NULL")),
index.Fields("package_id").Annotations(entsql.IndexWhere("package_id IS NOT NULL AND source_id IS NULL")), // query when subject is package ID
}
}
3 changes: 2 additions & 1 deletion pkg/assembler/backends/ent/schema/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (Dependency) Edges() []ent.Edge {
func (Dependency) Indexes() []ent.Index {
return []ent.Index{
index.Fields("dependency_type", "justification", "origin", "collector", "document_ref", "package_id", "dependent_package_version_id").Unique(),
index.Fields("package_id"), // speed up frequently run queries to check for deps with a certain package ID
index.Fields("package_id"), // speed up frequently run queries to check for deps with a certain package ID
index.Fields("dependent_package_version_id"), // query via the dependent package ID
}
}
2 changes: 2 additions & 0 deletions pkg/assembler/backends/ent/schema/occurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,7 @@ func (Occurrence) Indexes() []ent.Index {
Annotations(entsql.IndexWhere("package_id IS NOT NULL AND source_id IS NULL")).StorageKey("occurrence_package_id"),
index.Fields("justification", "origin", "collector", "document_ref").Edges("artifact", "source").Unique().
Annotations(entsql.IndexWhere("package_id IS NULL AND source_id IS NOT NULL")).StorageKey("occurrence_source_id"),
index.Fields("package_id").Annotations(entsql.IndexWhere("package_id IS NOT NULL AND source_id IS NULL")).StorageKey("query_occurrence_package_id"), //querying subject - package ID
index.Fields("artifact_id"), //querying object - artifact ID
}
}
Loading