Skip to content

Commit

Permalink
Merge pull request #2247 from greenbone/fix-nvt-indexes
Browse files Browse the repository at this point in the history
Fix: Also create NVT indexes after rebuild
  • Loading branch information
a-h-abdelsalam committed Aug 21, 2024
2 parents 5ce67ca + 0ba2653 commit fa866ab
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,33 @@ create_tables_nvt (const gchar *suffix)
suffix);
}

/**
* @brief Create NVT related indexes.
*
* @param[in] suffix String to append to table names.
*/
void
create_indexes_nvt ()
{
sql ("SELECT create_index ('nvts_by_creation_time',"
" 'nvts',"
" 'creation_time');");
sql ("SELECT create_index ('nvts_by_family', 'nvts', 'family');");
sql ("SELECT create_index ('nvts_by_name', 'nvts', 'name');");
sql ("SELECT create_index ('nvts_by_modification_time',"
" 'nvts', 'modification_time');");
sql ("SELECT create_index ('nvts_by_cvss_base',"
" 'nvts', 'cvss_base');");
sql ("SELECT create_index ('nvts_by_solution_type',"
" 'nvts', 'solution_type');");

sql ("SELECT create_index ('vt_refs_by_vt_oid',"
" 'vt_refs', 'vt_oid');");

sql ("SELECT create_index ('vt_severities_by_vt_oid',"
" 'vt_severities', 'vt_oid');");
}

/**
* @brief Create all tables.
*/
Expand Down Expand Up @@ -3078,17 +3105,8 @@ create_tables ()
sql ("SELECT create_index ('nvt_selectors_by_name',"
" 'nvt_selectors',"
" 'name');");
sql ("SELECT create_index ('nvts_by_creation_time',"
" 'nvts',"
" 'creation_time');");
sql ("SELECT create_index ('nvts_by_family', 'nvts', 'family');");
sql ("SELECT create_index ('nvts_by_name', 'nvts', 'name');");
sql ("SELECT create_index ('nvts_by_modification_time',"
" 'nvts', 'modification_time');");
sql ("SELECT create_index ('nvts_by_cvss_base',"
" 'nvts', 'cvss_base');");
sql ("SELECT create_index ('nvts_by_solution_type',"
" 'nvts', 'solution_type');");

create_indexes_nvt ();

sql ("SELECT create_index ('permissions_by_name',"
" 'permissions', 'name');");
Expand Down Expand Up @@ -3120,12 +3138,6 @@ create_tables ()
" 'tls_certificate_origins',"
" 'origin_id, origin_type')");

sql ("SELECT create_index ('vt_refs_by_vt_oid',"
" 'vt_refs', 'vt_oid');");

sql ("SELECT create_index ('vt_severities_by_vt_oid',"
" 'vt_severities', 'vt_oid');");

/* Previously this included the value column but that can be bigger than 8191,
* the maximum size that Postgres can handle. For example, this can happen
* for "ports". Mostly value is short, like a CPE for the "App" detail,
Expand Down
3 changes: 3 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ add_role_permission_resource (const gchar *, const gchar *, const gchar *,
void
create_view_vulns ();

void
create_indexes_nvt ();

void
create_view_result_vt_epss ();

Expand Down
3 changes: 3 additions & 0 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,9 @@ update_nvts_from_vts (element_t *get_vts_response,
sql ("ALTER TABLE nvts_rebuild RENAME TO nvts;");

create_view_vulns ();

create_indexes_nvt ();

create_view_result_vt_epss ();
}

Expand Down

0 comments on commit fa866ab

Please sign in to comment.