dpgaspar commented on code in PR #31332:
URL: https://github.com/apache/superset/pull/31332#discussion_r1875805292


##########
superset/migrations/shared/security_converge.py:
##########
@@ -94,7 +95,10 @@ def __repr__(self) -> str:
 
 class PermissionView(Base):  # type: ignore
     __tablename__ = "ab_permission_view"
-    __table_args__ = (UniqueConstraint("permission_id", "view_menu_id"),)
+    __table_args__ = (
+        sqla.Index("idx_permission_view_menu_id", "view_menu_id"),
+        sqla.Index("idx_permission_permission_id", "permission_id"),

Review Comment:
   Adding more info here, FAB already has a compound index since it defines a 
unique constraint on these FK: 
https://github.com/preset-io/Flask-AppBuilder/blob/master/flask_appbuilder/security/sqla/models.py#L73
   
   <img width="1389" alt="Screenshot 2024-12-09 at 10 36 03" 
src="https://github.com/user-attachments/assets/af8e6d7e-df96-4bd5-b760-80d14ee0f7dd";>
   
   Checked the security converge code, and we have the following queries:
   ``` python
   session.query(ViewMenu).filter(ViewMenu.name == view_name).one_or_none()
   ```
   ``` python
   session.query(Permission).filter(Permission.name == 
permission_name).one_or_none()
   ```
   ``` python
   session.query(PermissionView)
           .filter(
               PermissionView.view_menu_id == view_menu.id,
               PermissionView.permission_id == permission.id,
           )
   ```
   ``` python
           session.query(PermissionView)
           .join(Permission)
           .join(ViewMenu)
           .filter(ViewMenu.name == view_name, Permission.name == 
permission_name)
   ```
   ``` python
               session.query(PermissionView)
               .join(Permission)
               .filter(Permission.name == old_permission_name)
   ```
   ``` python
               session.query(PermissionView)
               .join(ViewMenu)
               .filter(ViewMenu.name == old_view_name)
   ```
   
   We have indexes to efficiently query all of these:
   - index on `ViewMenu.name`
   - index on `Permission.name`
   - Indexes on `Permission.id` and `ViewMenu.id`
    
   Yet we can have more eficient joins by adding indexes on the FK for 
`ab_permission_view_role` and `ab_permission_view`
   https://github.com/dpgaspar/Flask-AppBuilder/pull/2293



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to