forked from owasp-amass/asset-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add indexes to assets and relations tables
- Index on `$.content.Name` for FQDN assets - index on assets.type - index on assets.last_seen - index on relations.last_seen Closes owasp-amass#19
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- +migrate Up | ||
|
||
-- Index the `name` field of the `content` jsonb when type is `FQDN` | ||
-- Assumes the pg_trgm extension is created in the database | ||
CREATE INDEX idx_fqdn_content_name ON assets USING gin ((content->>'name') gin_trgm_ops) WHERE type = 'FQDN'; | ||
|
||
-- Index assets.type | ||
CREATE INDEX idx_assets_type_hash ON assets USING hash (type); | ||
|
||
-- Index last_seen | ||
CREATE INDEX idx_as_last_seen ON assets (last_seen); | ||
|
||
|
||
-- +migrate Down | ||
|
||
-- drop all the indexes we just created | ||
DROP INDEX idx_fqdn_content_name; | ||
DROP INDEX idx_assets_type_hash; | ||
DROP INDEX idx_as_last_seen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- +migrate Up | ||
|
||
CREATE INDEX idx_rel_last_seen ON assets (last_seen); | ||
|
||
-- +migrate Down | ||
|
||
DROP INDEX idx_rel_last_seen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- +migrate Up | ||
|
||
-- Index the `name` field of the `content` jsonb when type is `FQDN` | ||
-- Assumes the pg_trgm extension is created in the database | ||
CREATE INDEX fqdn_name ON assets (content->>'name' COLLATE NOCASE) WHERE type = 'FQDN'; | ||
|
||
-- Index assets.type | ||
CREATE INDEX idx_assets_type ON assets (type); | ||
|
||
-- Index last_seen | ||
CREATE INDEX idx_as_last_seen ON assets (last_seen); | ||
|
||
|
||
-- +migrate Down | ||
|
||
-- drop all the indexes we just created | ||
DROP INDEX idx_fqdn_content_name; | ||
DROP INDEX idx_assets_type_hash; | ||
DROP INDEX idx_as_last_seen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- +migrate Up | ||
|
||
CREATE INDEX idx_rel_last_seen ON assets (last_seen); | ||
|
||
-- +migrate Down | ||
|
||
DROP INDEX idx_rel_last_seen; |