Loading...
Loading...
Compare original and translation side by side
tenant_idWHERE tenant_id = :tenant_idundefinedtenant_idWHERE tenant_id = :tenant_idundefined
Defer deep checks to the `tenancy-auditor` agent.
将深度检查委托给`tenancy-auditor` Agent。undefinedundefinedundefinedundefinedundefinedundefined
Watch for: `for x in result: query(x.related)`. Use `selectinload`, `joinedload`, or a single JOIN.
注意此类模式:`for x in result: query(x.related)`。使用`selectinload`、`joinedload`或单次JOIN操作。WHEREJOINORDER BY(tenant_id, status, created_at)grep -rn "Index\|index=True\|__table_args__" backend/app/models/<file>.pyWHEREJOINORDER BY(tenant_id, status, created_at)grep -rn "Index\|index=True\|__table_args__" backend/app/models/<file>.py.limit(...)limitoffset.execution_options(stream_results=True)LIMIT/OFFSET.limit(...)limitoffset.execution_options(stream_results=True)LIMIT/OFFSETundefinedundefined
Sounds obvious. Has happened.
这听起来显而易见,但确实发生过此类事故。db.add(...)commit()db.execute(insert(Model).values([...]))bulk_insert_mappingsdb.add(...)commit()db.execute(insert(Model).values([...]))bulk_insert_mappingsundefinedundefined
- Look for `Seq Scan` on large tables → missing index.
- `Buffers: shared read=N` where N is large → not in cache, will be slow on cold start.
- `Rows Removed by Filter` >> `Rows` → query is over-fetching then filtering in memory.
- 注意大型表上的`Seq Scan` → 缺失索引。
- `Buffers: shared read=N`中N值较大 → 数据不在缓存中,冷启动时会很慢。
- `Rows Removed by Filter`远大于`Rows` → 查询过度获取数据后在内存中过滤。migration-auditormigration-auditorundefinedundefinedundefinedundefined| Pattern | Why it's risky |
|---|---|
| Almost always N+1 |
| Unbounded result set |
| Index can't be used unless there's a functional index |
| Postgres often can't use either |
| Same — kills index usage on |
| Sequential scan unless you have a trigram index |
| Subquery in SELECT clause | Often an N+1 in disguise |
| 模式 | 风险原因 |
|---|---|
| 几乎肯定是N+1问题 |
| 无限制的结果集 |
| 除非存在函数索引,否则无法使用现有索引 |
两个列使用单独索引且通过 | PostgreSQL通常无法使用任何一个索引 |
| 同样会导致 |
| 除非有 trigram 索引,否则会触发顺序扫描 |
| SELECT子句中包含子查询 | 通常是伪装的N+1问题 |
migration-auditortenancy-auditormigration-auditorCONCURRENTLYmigration-auditortenancy-auditormigration-auditorCONCURRENTLY