Skip to content

Commit

Permalink
feat: add indexes to assets and relations tables
Browse files Browse the repository at this point in the history
- 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
rynmrtn committed Aug 4, 2023
1 parent 0b35dd3 commit fbf0f7d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
19 changes: 19 additions & 0 deletions migrations/postgres/005_assets_indexes.sql
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;
7 changes: 7 additions & 0 deletions migrations/postgres/006_relations_indexes.sql
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;
19 changes: 19 additions & 0 deletions migrations/sqlite3/004_assets_indexes.sql
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;
7 changes: 7 additions & 0 deletions migrations/sqlite3/005_relations_indexes.sql
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;

0 comments on commit fbf0f7d

Please sign in to comment.