﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32143	Use EXISTS to exclude multi-valued relationships	Simon Charette	Simon Charette	"The current logic that is invoked when excluding a multi-valued relationship (`sql.Query.split_exclude`) pushes down the filtering criteria in a `parent.id NOT IN (SELECT child.parent_id ...)` subquery.

[https://dev.mysql.com/doc/refman/8.0/en/subquery-optimization-with-exists.html These kind of operations can be really hard for some query planners to optimize] and also tricky to get right due to how the `IN` operator treats `NULL` values [https://github.com/django/django/blob/a56586eafeb6d1212bc291d1a2e7d33c87edbc33/django/db/models/sql/query.py#L1762-L1764 which is something we've known for a while].

The `NOT EXISTS` function should be used instead of `NOT IN`."	Cleanup/optimization	closed	Database layer (models, ORM)	3.1	Normal	fixed			Ready for checkin	1	0	0	0	0	0
