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

Fix: Also create NVT indexes after rebuild #2247

Merged
merged 3 commits into from
Aug 21, 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
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 @@
suffix);
}

/**
* @brief Create NVT related indexes.
*
* @param[in] suffix String to append to table names.
*/
void
create_indexes_nvt ()

Check warning on line 1945 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1945

Added line #L1945 was not covered by tests
{
sql ("SELECT create_index ('nvts_by_creation_time',"

Check warning on line 1947 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1947

Added line #L1947 was not covered by tests
" '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',"

Check warning on line 1952 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1950-L1952

Added lines #L1950 - L1952 were not covered by tests
" 'nvts', 'modification_time');");
sql ("SELECT create_index ('nvts_by_cvss_base',"

Check warning on line 1954 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1954

Added line #L1954 was not covered by tests
" 'nvts', 'cvss_base');");
sql ("SELECT create_index ('nvts_by_solution_type',"

Check warning on line 1956 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1956

Added line #L1956 was not covered by tests
" 'nvts', 'solution_type');");

sql ("SELECT create_index ('vt_refs_by_vt_oid',"

Check warning on line 1959 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1959

Added line #L1959 was not covered by tests
" 'vt_refs', 'vt_oid');");

sql ("SELECT create_index ('vt_severities_by_vt_oid',"

Check warning on line 1962 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1962

Added line #L1962 was not covered by tests
" 'vt_severities', 'vt_oid');");
}

/**
* @brief Create all tables.
*/
Expand Down Expand Up @@ -3078,17 +3105,8 @@
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 ();

Check warning on line 3109 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L3109

Added line #L3109 was not covered by tests

sql ("SELECT create_index ('permissions_by_name',"
" 'permissions', 'name');");
Expand Down Expand Up @@ -3120,12 +3138,6 @@
" '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 @@
sql ("ALTER TABLE nvts_rebuild RENAME TO nvts;");

create_view_vulns ();

create_indexes_nvt ();

Check warning on line 1992 in src/manage_sql_nvts.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_nvts.c#L1992

Added line #L1992 was not covered by tests

create_view_result_vt_epss ();
}

Expand Down
Loading