-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
m2m relations - do not use subquery when not necessary
1. performance optimization for operations on m2m relations `ManyToManyModifyMixin` creates a subquery and moves all filters from the main query into it. > This is done so that we are able to `innerJoin` the join table to the query. Most SQL engines don't allow joins in updates or deletes. Join table is joined so that queries can reference the join table columns. But, the subquery is not really needed in all types of operations - e.g. a query with just a findById(s) operation - usually coming from graph upsert - or when query builder is not operating on the join table but e.g. the target related table 2. Additionally, for mysql: - extract the subquery selecting related ids to separate query run before the main query to avoid `ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG` mysql error when executing a db trigger on a join table which updates related table This workaround is only needed for MySQL. It could possibly be applied to all DBMS, if proven necessary, but others seem to handle such cases just fine. https://stackoverflow.com/a/2314264/3729316 > MySQL triggers can't manipulate the table they are assigned to. All other major DBMS support this feature so hopefully MySQL will add this support soon. > ~ Cory House, 2010
- Loading branch information
1 parent
123efe2
commit d2218da
Showing
1 changed file
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters