Skip to content

Commit 4bdf928

Browse files
committed
Change: Use SQL COPY for loading CVEs
When loading the CVEs with secinfo_fast_init enabled, COPY statements will be used to load the CVEs, including references, configurations and affected products. This is much faster than using INSERT and UPDATE statements.
1 parent 772dfb5 commit 4bdf928

File tree

3 files changed

+1163
-251
lines changed

3 files changed

+1163
-251
lines changed

src/manage_pg.c

+40-17
Original file line numberDiff line numberDiff line change
@@ -3820,9 +3820,7 @@ manage_db_add_constraints (const gchar *name)
38203820
sql ("ALTER TABLE scap2.affected_products"
38213821
" ALTER cve SET NOT NULL,"
38223822
" ALTER cpe SET NOT NULL,"
3823-
" ADD UNIQUE (cve, cpe),"
3824-
" ADD FOREIGN KEY(cve) REFERENCES cves(id),"
3825-
" ADD FOREIGN KEY(cpe) REFERENCES cpes(id);");
3823+
" ADD UNIQUE (cve, cpe);");
38263824

38273825
sql ("ALTER TABLE scap2.epss_scores"
38283826
" ALTER cve SET NOT NULL,"
@@ -3884,6 +3882,44 @@ drop_indexes_cpe ()
38843882
sql ("DROP INDEX IF EXISTS scap2.cpes_by_cpe_name_id");
38853883
}
38863884

3885+
/**
3886+
* @brief Create the indexes for the CVEs tables in the scap2 schema.
3887+
*/
3888+
void
3889+
create_indexes_cve ()
3890+
{
3891+
sql ("CREATE UNIQUE INDEX cve_idx"
3892+
" ON scap2.cves (name);");
3893+
sql ("CREATE INDEX cves_by_creation_time_idx"
3894+
" ON scap2.cves (creation_time);");
3895+
sql ("CREATE INDEX cves_by_modification_time_idx"
3896+
" ON scap2.cves (modification_time);");
3897+
sql ("CREATE INDEX cves_by_severity"
3898+
" ON scap2.cves (severity);");
3899+
3900+
sql ("CREATE INDEX cpe_match_nodes_by_root_id"
3901+
" ON scap2.cpe_match_nodes(root_id);");
3902+
3903+
sql ("CREATE INDEX cpe_nodes_match_criteria_by_node_id"
3904+
" ON scap2.cpe_nodes_match_criteria(node_id);");
3905+
}
3906+
3907+
/**
3908+
* @brief Remove the indexes for the CVEs tables in the scap2 schema.
3909+
*/
3910+
void
3911+
drop_indexes_cve ()
3912+
{
3913+
sql ("DROP INDEX IF EXISTS scap2.cve_idx");
3914+
sql ("DROP INDEX IF EXISTS scap2.cves_by_creation_time_idx");
3915+
sql ("DROP INDEX IF EXISTS scap2.cves_by_modification_time_idx");
3916+
sql ("DROP INDEX IF EXISTS scap2.cves_by_severity");
3917+
3918+
sql ("DROP INDEX IF EXISTS scap2.cpe_match_nodes_by_root_id");
3919+
3920+
sql ("DROP INDEX IF EXISTS scap2.cpe_nodes_match_criteria_by_node_id");
3921+
}
3922+
38873923
/**
38883924
* @brief Init external database.
38893925
*
@@ -3896,22 +3932,9 @@ manage_db_init_indexes (const gchar *name)
38963932
{
38973933
if (strcasecmp (name, "scap") == 0)
38983934
{
3899-
sql ("CREATE UNIQUE INDEX cve_idx"
3900-
" ON scap2.cves (name);");
3901-
sql ("CREATE INDEX cves_by_creation_time_idx"
3902-
" ON scap2.cves (creation_time);");
3903-
sql ("CREATE INDEX cves_by_modification_time_idx"
3904-
" ON scap2.cves (modification_time);");
3905-
sql ("CREATE INDEX cves_by_severity"
3906-
" ON scap2.cves (severity);");
3907-
39083935
create_indexes_cpe ();
39093936

3910-
sql ("CREATE INDEX cpe_match_nodes_by_root_id"
3911-
" ON scap2.cpe_match_nodes(root_id);");
3912-
3913-
sql ("CREATE INDEX cpe_nodes_match_criteria_by_node_id"
3914-
" ON scap2.cpe_nodes_match_criteria(node_id);");
3937+
create_indexes_cve ();
39153938

39163939
sql ("CREATE INDEX afp_cpe_idx"
39173940
" ON scap2.affected_products (cpe);");

src/manage_sql.h

+6
Original file line numberDiff line numberDiff line change
@@ -549,4 +549,10 @@ create_indexes_cpe ();
549549
void
550550
drop_indexes_cpe ();
551551

552+
void
553+
create_indexes_cve ();
554+
555+
void
556+
drop_indexes_cve ();
557+
552558
#endif /* not _GVMD_MANAGE_SQL_H */

0 commit comments

Comments
 (0)