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

feat: add indexes to assets and relations tables #21

Closed
wants to merge 3 commits into from

Conversation

rynmrtn
Copy link
Collaborator

@rynmrtn rynmrtn commented Aug 4, 2023

  • Index on $.content.Name for FQDN assets
  • index on assets.type
  • index on assets.last_seen
  • index on relations.last_seen

Closes #19

rynmrtn added 3 commits August 4, 2023 15:36
- 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
includes important details related to postgres
@rynmrtn rynmrtn changed the base branch from master to develop August 4, 2023 20:42

```sql
-- Create a new database to store assets and relations.
CREATE SCHEMA assetdb;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to database

Copy link
Collaborator Author

@rynmrtn rynmrtn Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely need to create a schema, update default schema for user if postgres 15 (public schema is no longer accessible by standard users / roles).

not using the public schema is also a security best practice for postgres but not everyone follows this


-- Create a user
CREATE USER your_username WITH PASSWORD 'your_password';
GRANT ALL ON ALL TABLES IN SCHEMA assetdb to your_username;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grants will need to be validated once the schema part is fixed

Comment on lines +5 to +11
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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding IF NOT EXISTS to these

@@ -0,0 +1,7 @@
-- +migrate Up

CREATE INDEX idx_rel_last_seen ON assets (last_seen);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding IF NOT EXISTS here as well

Comment on lines +5 to +11
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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF NOT EXISTS here as well

@@ -0,0 +1,7 @@
-- +migrate Up

CREATE INDEX idx_rel_last_seen ON assets (last_seen);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF NOT EXISTS here as well

@rynmrtn
Copy link
Collaborator Author

rynmrtn commented Aug 4, 2023

This is in draft as the migration currently requires an admin to create extension pg_trgm.

the user_guide.md & migrations can only be run by someone with a super user for postgres 15. this needs to be fixed before this is ready

@rynmrtn rynmrtn closed this Aug 5, 2023
@rynmrtn rynmrtn deleted the feat/indexes branch August 5, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexes to improve performance
1 participant