Skip to content

Commit

Permalink
edk2toollib/database: Add env index to large tables
Browse files Browse the repository at this point in the history
Most queries rely on a specific env value when generating results;
this commit adds an index on the env column for the junction and
instanced_inf tables as they get extremely large and index's here
will improve performance when filtering on a specific env value.
  • Loading branch information
Javagedes committed Sep 20, 2023
1 parent a2c523d commit 63776aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions edk2toollib/database/edk2_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
)
"""

CREATE_JUNCTION_INDEX = """
CREATE INDEX IF NOT EXISTS junction_idx
ON junction (env);
"""

class Edk2DB:
"""A SQLite3 database manager for a EDKII workspace.
Expand Down Expand Up @@ -97,6 +102,7 @@ def parse(self, env: dict) -> None:
not exist, and a row is added for each call of this command.
"""
self.connection.execute(CREATE_JUNCTION_TABLE)
self.connection.execute(CREATE_JUNCTION_INDEX)
id = str(uuid.uuid4().hex)

# Create all tables
Expand Down
8 changes: 7 additions & 1 deletion edk2toollib/database/tables/instanced_inf_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ class TEXT,
dsc TEXT,
component TEXT,
FOREIGN KEY(env) REFERENCES environment(env)
)
);
'''

CREATE_INSTANCED_INF_INDEX = '''
CREATE INDEX IF NOT EXISTS instanced_inf_idx
ON instanced_inf (env);
'''

INSERT_INSTANCED_INF_ROW = '''
Expand All @@ -55,6 +60,7 @@ def __init__(self, *args, **kwargs):
def create_tables(self, db_cursor: Cursor) -> None:
"""Create the tables necessary for this parser."""
db_cursor.execute(CREATE_INSTANCED_INF_TABLE)
db_cursor.execute(CREATE_INSTANCED_INF_INDEX)

def inf(self, inf: str) -> InfP:
"""Returns a parsed INF object.
Expand Down

0 comments on commit 63776aa

Please sign in to comment.