如何阅读 EXPLAIN 执行计划和 PROFILE 的输出?

上次更新时间 2024 年 3 月 22 日

问题

如何阅读 EXPLAIN 执行计划和 PROFILE 的输出?

答案

让我们考虑一个混合向量相似性搜索查询的解释计划,该查询还执行全文搜索和标签搜索。

FT.EXPLAIN doc_idx (@content:(carbonara) @genre:{technical})=>[KNN 2 @embedding $vec AS score] 
RETURN 1 score 
DIALECT 2 
LIMIT 0 10 
params 2 vec \x0e\xaf\xae<\xac\x92\x96< [...]

这是 FT.EXPLAIN 命令产生的输出

VECTOR {
  INTERSECT {
    @content:carbonara
    TAG:@genre {
      technical
    }
  }
} => {K=2 nearest vectors to `$vec` in vector index associated with field @embedding, yields distance as `score`}

内部部分(在本例中为 INTERSECT)是一个预过滤器,并从诱导子空间返回 KNN 结果。这适用于 FLATHNSW 索引方法。

相反,同一查询的 FT.PROFILE 命令将返回以下输出。

(Result{0 total, docs: []}, {'Total profile time': 1.0, 'Parsing time': 1.0, 'Pipeline creation time': 0.0, 'Iterators profile': {'Type': 'VECTOR', 'Time': 0.0, 'Counter': 0.0, 'Child iterators': [{'Type': 'INTERSECT', 'Time': 0.0, 'Counter': 0.0, 'Child iterators': [{'Type': 'TEXT', 'Term': 'carbonara', 'Time': 0.0, 'Counter': 4.0, 'Size': 4.0}, {'Type': 'TAG', 'Term': 'technical', 'Time': 0.0, 'Counter': 3.0, 'Size': 4.0}]}]}, 'Result processors profile': {'Type': 'Index', 'Time': 0.0, 'Counter': 0.0}})

参考

了解更多关于 FT.EXPLAINFT.INFO 命令的信息。