mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[3.1.x] Fixed #31965 -- Adjusted multi-table fast-deletion on MySQL/MariaDB.
The optimization introduced in7acef095d7did not properly handle deletion involving filters against aggregate annotations. It initially was surfaced by a MariaDB test failure but misattributed to an undocumented change in behavior that resulted in the systemic generation of poorly performing database queries in5b83bae031. Thanks Anton Plotkin for the report. Refs #23576. Backport off6405c0b8efrom master
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							655e1ce6b1
						
					
				
				
					commit
					2986ec031d
				
			| @@ -709,3 +709,16 @@ class FastDeleteTests(TestCase): | ||||
|         referer = Referrer.objects.create(origin=origin, unique_field=42) | ||||
|         with self.assertNumQueries(2): | ||||
|             referer.delete() | ||||
|  | ||||
|     def test_fast_delete_aggregation(self): | ||||
|         # Fast-deleting when filtering against an aggregation result in | ||||
|         # a single query containing a subquery. | ||||
|         Base.objects.create() | ||||
|         with self.assertNumQueries(1): | ||||
|             self.assertEqual( | ||||
|                 Base.objects.annotate( | ||||
|                     rels_count=models.Count('rels'), | ||||
|                 ).filter(rels_count=0).delete(), | ||||
|                 (1, {'delete.Base': 1}), | ||||
|             ) | ||||
|         self.assertIs(Base.objects.exists(), False) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user