# ERR 执行 GRAPH.QUERY 时出错：查询在 10000 毫秒后超时

- **ID:** `redis/redisgraph-query-timeout`
- **领域:** redis
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

由于复杂的图遍历、大型结果集或低效的 Cypher 查询，RedisGraph 查询超过了配置的超时限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| RedisGraph 2.10.0 | active | — | — |
| Redis Stack 7.2.0 | active | — | — |
| RedisGraph 2.12.0 | active | — | — |

## 解决方案

1. ```
   通过添加索引优化 Cypher 查询：GRAPH.QUERY mygraph 'CREATE INDEX ON :Person(age)'，然后重写查询以在 WHERE 子句中使用索引属性。
   ```
2. ```
   使用 GRAPH.EXPLAIN 进行查询分析以识别瓶颈，然后将复杂查询分解为更小的步骤或使用 LIMIT 减少结果集大小。
   ```
3. ```
   通过在 GRAPH.QUERY 命令中设置更高的 TIMEOUT 值来增加特定查询的超时，例如：GRAPH.QUERY mygraph 'MATCH ...' --timeout 30000。
   ```

## 无效尝试

- **** — Increasing the timeout globally via GRAPH.CONFIG SET TIMEOUT may allow slow queries to run but can cause resource exhaustion or block other operations. (65% 失败率)
- **** — Removing all indexes to speed up writes actually slows down graph queries, making the timeout worse. (70% 失败率)
- **** — Restarting Redis clears the query cache but doesn't optimize the underlying query pattern, so the timeout will recur. (50% 失败率)
