From b8fcb1f23d394ceac010a7d1b5b702a0e1671ae8 Mon Sep 17 00:00:00 2001 From: Akhil S <52134111+akhil018@users.noreply.github.com> Date: Wed, 20 Dec 2023 23:31:13 +0530 Subject: [PATCH] Add index to foreign key(parent_id) column for optimized record deletion This commit addresses performance issues related to both record deletion and retrieval in the sqlalchemy_mptt library. Adding an index to the foreign key(parent_id) column improves the efficiency of both operations, significantly reducing the time taken for deletion and retrieval. --- sqlalchemy_mptt/mixins.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlalchemy_mptt/mixins.py b/sqlalchemy_mptt/mixins.py index 5cdda2d..5cd5b9a 100644 --- a/sqlalchemy_mptt/mixins.py +++ b/sqlalchemy_mptt/mixins.py @@ -86,6 +86,7 @@ def parent_id(cls): ForeignKey( "{}.{}".format(cls.__tablename__, pk.name), ondelete="CASCADE" ), + index=True ) @declared_attr