- This function is broken up into a number of clauses, described
- below.
-
- Note on query optimization:
-
- Each clause in a "with" statement is called a "common table
- expression" or CTE.
-
- In Postgres, they are evaluated in sequence and results of each CTE
- is stored in a temporary table. This means Postgres does not
- propagate constraints from later subqueries to earlier subqueries
- when they are CTEs.
-
- This is a problem if, for example, a later subquery chooses 10
- items out of a set of 1000000 defined by an earlier subquery,
- because it will always compute all 1000000 rows even if the query
- on the 1000000 rows could have been constrained. This is why
- permission_graph_edges is a view -- views are inlined so and can be
- optimized using external constraints.
-
- The query optimizer does sort the temporary tables for later use in
- joins.
-
- Final note, this query would have been almost impossible to write
- (and certainly impossible to read) without splitting it up using
- SQL "with" but unfortunately it also stumbles into a frustrating
- Postgres optimizer bug, see
- lib/refresh_permission_view.rb#update_permissions
- for details and a partial workaround.
+ perm_edge_id: Identifies the permission edge that is being updated.
+ Changes of ownership, this is starting_uuid.
+ For links, this is the uuid of the link object.
+ This is used to override the edge value in the database
+ with starting_perm. This is necessary when revoking
+ permissions because the update happens before edge is
+ actually removed.