# TiFlash 主要功能: 引擎智能选择

__*TiFlash 引擎智能选择*__

![`smart`](TiFlashSmartSelection_aa_004_20220513.png)

-------------------------------------------------------------
TiDB server 作为协调器, 可以根据 SQL 语句进行评估, 自动选择将 SQL 在 TiKV 还是 TiFlash 上执行, 或者分别从 TiKV 和 TiFlash 中读取。如图。

由于 "product" 表不取任何列, 只过滤 `product.batch_id = 'B1328'` 条件, 而在 "product" 表中又有 `(pid,batch_id)` 的索引, 所以可以选择在 TiKV 中做索引读, 过滤出 "product" 表满足条件的数据。

而 "sales" 表取 "price" 一列做聚合（AVG）, 没有过滤条件, 相当于大表扫描, 所以更适合在 TiFlash 中进行表扫描。

最终, 将满足条件的两路数据在 TiDB server 上进行汇总, 得出结果。 
