Skip to content

Commit c982612

Browse files
committed
Change: Speed up CPEs update by using COPY
The CPEs and their refs are now loaded into the new SCAP schema using COPY statements and with most indexes removed. This is faster than using INSERT statements and having the indexes in place.
1 parent 8d0079c commit c982612

File tree

5 files changed

+496
-83
lines changed

5 files changed

+496
-83
lines changed

src/manage_pg.c

+35-12
Original file line numberDiff line numberDiff line change
@@ -3848,6 +3848,40 @@ manage_db_add_constraints (const gchar *name)
38483848
return 0;
38493849
}
38503850

3851+
/**
3852+
* @brief Create the indexes for the CPEs table in the scap2 schema.
3853+
*/
3854+
void
3855+
create_cpe_indexes ()
3856+
{
3857+
sql ("CREATE UNIQUE INDEX cpe_idx"
3858+
" ON scap2.cpes (name);");
3859+
sql ("CREATE INDEX cpes_by_creation_time_idx"
3860+
" ON scap2.cpes (creation_time);");
3861+
sql ("CREATE INDEX cpes_by_modification_time_idx"
3862+
" ON scap2.cpes (modification_time);");
3863+
sql ("CREATE INDEX cpes_by_severity"
3864+
" ON scap2.cpes (severity);");
3865+
sql ("CREATE INDEX cpes_by_uuid"
3866+
" ON scap2.cpes (uuid);");
3867+
sql ("CREATE INDEX cpes_by_cpe_name_id"
3868+
" ON scap2.cpes(cpe_name_id);");
3869+
}
3870+
3871+
/**
3872+
* @brief Remove the indexes for the CPEs table in the scap2 schema.
3873+
*/
3874+
void
3875+
drop_cpe_indexes ()
3876+
{
3877+
sql ("DROP INDEX IF EXISTS scap2.cpe_idx");
3878+
sql ("DROP INDEX IF EXISTS scap2.cpes_by_creation_time_idx");
3879+
sql ("DROP INDEX IF EXISTS scap2.cpes_by_modification_time_idx");
3880+
sql ("DROP INDEX IF EXISTS scap2.cpes_by_severity");
3881+
sql ("DROP INDEX IF EXISTS scap2.cpes_by_uuid");
3882+
sql ("DROP INDEX IF EXISTS scap2.cpes_by_cpe_name_id");
3883+
}
3884+
38513885
/**
38523886
* @brief Init external database.
38533887
*
@@ -3869,18 +3903,7 @@ manage_db_init_indexes (const gchar *name)
38693903
sql ("CREATE INDEX cves_by_severity"
38703904
" ON scap2.cves (severity);");
38713905

3872-
sql ("CREATE UNIQUE INDEX cpe_idx"
3873-
" ON scap2.cpes (name);");
3874-
sql ("CREATE INDEX cpes_by_creation_time_idx"
3875-
" ON scap2.cpes (creation_time);");
3876-
sql ("CREATE INDEX cpes_by_modification_time_idx"
3877-
" ON scap2.cpes (modification_time);");
3878-
sql ("CREATE INDEX cpes_by_severity"
3879-
" ON scap2.cpes (severity);");
3880-
sql ("CREATE INDEX cpes_by_uuid"
3881-
" ON scap2.cpes (uuid);");
3882-
sql ("CREATE INDEX cpes_by_cpe_name_id"
3883-
" ON scap2.cpes(cpe_name_id);");
3906+
create_cpe_indexes ();
38843907

38853908
sql ("CREATE INDEX cpe_match_nodes_by_root_id"
38863909
" ON scap2.cpe_match_nodes(root_id);");

src/manage_sql.h

+6
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,10 @@ cleanup_nvt_sequences ();
543543
int
544544
cleanup_ids_for_table (const char *);
545545

546+
void
547+
create_cpe_indexes ();
548+
549+
void
550+
drop_cpe_indexes ();
551+
546552
#endif /* not _GVMD_MANAGE_SQL_H */

0 commit comments

Comments
 (0)