You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Important**: Never suggest adding a default value to `options.get()` calls. All options are registered via `register()` in `defaults.py` which requires a default value. The options system will always return the registered default if no value is set, making a second default parameter redundant and potentially inconsistent.
337
+
322
338
### Logging Pattern
323
339
324
340
```python
@@ -394,6 +410,61 @@ class MultiProducer:
394
410
4. Add indexes for queries on 1M+ row tables
395
411
5. Use `db_index=True` or `db_index_together`
396
412
413
+
#### Composite Index Strategy: Match Your Query Patterns
414
+
415
+
**Critical Rule**: When writing a query that filters on multiple columns simultaneously, you MUST verify that a composite index exists covering those columns in the filter order.
416
+
417
+
**How to Identify When You Need a Composite Index:**
418
+
419
+
1.**Look for Multi-Column Filters**: Any query using multiple columns in `.filter()` or `WHERE` clause
420
+
2.**Check Index Coverage**: Verify the model's `Meta.indexes` includes those columns
421
+
3.**Consider Query Order**: Index column order should match the most selective filters first
422
+
423
+
**Common Patterns Requiring Composite Indexes:**
424
+
425
+
```python
426
+
# NEEDS COMPOSITE INDEX: Filtering on foreign_key_id AND id
427
+
Model.objects.filter(
428
+
foreign_key_id__in=ids, # First column
429
+
id__gt=last_id # Second column
430
+
)[:batch_size]
431
+
# Required: Index(fields=["foreign_key", "id"])
432
+
433
+
# NEEDS COMPOSITE INDEX: Status + timestamp range queries
0 commit comments