Changes between Version 1 and Version 2 of Ticket #34811, comment 2
- Timestamp:
- Sep 2, 2023, 9:04:01 PM (15 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #34811, comment 2
v1 v2 1 1 If that can be of any help, we've observed that MySQL's query planer can be pretty bad at using composite indexes when `OR` conditions are involved and had to resort to using `UNION` to target them. 2 2 3 Re-writing your lookup to move the `filling_id=pk` outside of the `OR` should help MySQL atfiguring out that the `filing_id` index can be used at least.3 Re-writing your lookup to move the `filling_id=pk` outside of the `OR`, since it's used by both, might help MySQL figuring out that the `filing_id` index can be used at least. 4 4 5 5 {{{#!python … … 21 21 OR `taxobjects_taxinput` . `deleted` > ? 22 22 ) 23 LIMIT24 ?25 23 }}} 24 25 Otherwise I'm pretty sure that using `union` will perform great but it comes with some ORM limitations #28519. 26 27 {{{#!python 28 TaxInput.objects.filter( 29 filling_id=pk, 30 updated_at__gt=last_engine.created_at, 31 ).union( 32 TaxInput.objects.filter( 33 filling_id=pk, 34 deleted__gt=last_engine.created_at, 35 ) 36 ) 37 }}} 38 39 {{{#!sql 40 SELECT 41 * 42 FROM 43 `taxobjects_taxinput` 44 WHERE 45 `taxobjects_taxinput` . `filling_id` = ? 46 AND `taxobjects_taxinput` . `updated_at` > ? 47 UNION 48 SELECT 49 * 50 FROM 51 `taxobjects_taxinput` 52 WHERE 53 `taxobjects_taxinput` . `filling_id` = ? 54 AND `taxobjects_taxinput` . `deletedt` > ? 55 }}}