Practical Guide实用指南

Predicate Pushdown: Move Filters Closer to the Data谓词下推:把过滤条件移到更靠近数据的位置

Predicate pushdown moves an eligible filter toward a scan, file reader, connector or remote source so fewer rows travel through the rest of the plan. It is valuable only when semantics remain identical and execution evidence confirms less work.

谓词下推会把符合条件的过滤表达式移向扫描算子、文件读取器、连接器或远端数据源,使更少的行继续流经计划。只有语义保持一致,且执行证据确认工作量减少时,这项优化才真正有价值。

Updated August 10, 2026更新于2026年8月10日11-minute read阅读约11分钟InfiniSynapse
Predicate pushdown diagram comparing a large unfiltered transfer with source-side filtering, semantic safety gates, and plan, telemetry, and result verification
On this page本页目录

    What Is Predicate Pushdown?什么是谓词下推?

    Place this specific workflow in context with the federated queries and data virtualization guide, which connects the definitions, alternatives, validation steps, and related implementation guides.

    可通过联邦查询与数据虚拟化指南理解本专题在整体流程中的位置;该指南串联了定义、替代方案、验证步骤与相关实施文章。

    Predicate pushdown is a query optimization that evaluates an eligible filter as close as legally and technically possible to the data scan or source. Instead of transferring every candidate row and filtering later, an engine may apply all or part of a WHERE or join condition inside a scan, columnar reader, connector-generated remote query, or storage service.

    谓词下推是一种查询优化:它在语义合法且技术可行的前提下,把过滤条件放到尽可能靠近数据扫描或数据源的位置执行。引擎不必传输所有候选行后再过滤,而可以在扫描算子、列式读取器、连接器生成的远端查询或存储服务中执行全部或部分WHERE条件或连接条件。

    A predicate is an expression that evaluates to true, false or unknown under SQL's three-valued logic. Pushdown changes where that expression is evaluated, not what it means. The optimizer must prove that moving it across joins, aggregations, windows, casts and source boundaries preserves the same rows, duplicates and NULL behavior.

    谓词是在SQL三值逻辑下求值为真、假或未知的表达式。下推改变的是表达式的求值位置,而不是含义。优化器必须证明:把条件跨越连接、聚合、窗口、类型转换或数据源边界移动后,行、重复项与NULL行为仍然一致。

    Quick test: if a plan or remote query shows the filter at the scan/source and rows or bytes are reduced before the next boundary, pushdown probably occurred. Confirm it with source telemetry and result-equivalence tests; SQL text alone is not proof.

    快速判断:如果计划或远端查询显示过滤在扫描端或源端执行,并且行数或字节在跨越下一边界前减少,通常说明发生了下推。仍需用源端遥测与结果等价测试确认;仅凭SQL文本不能证明。

    How Predicate Pushdown Works Through a Query Plan谓词下推如何穿过查询计划

    1. Resolve the predicate.解析谓词。

      The engine binds names and types, expands views where supported, and represents the condition in its logical plan. Valid syntax does not guarantee pushdown.

      引擎绑定名称与类型,在支持时展开视图,并在逻辑计划中表示条件。语法合法并不保证可以下推。

    2. Prove a legal movement.证明移动合法。

      Rewrite rules determine whether the predicate can cross projections, joins, aggregates or other operators without changing semantics. Sometimes only one conjunct is movable.

      重写规则判断谓词能否在不改变语义的情况下跨越投影、连接、聚合或其他算子。有时只有一个合取项可以移动。

    3. Ask the scan or connector what it supports.询问扫描器或连接器支持范围。

      A file reader may accept limited comparisons; a connector may translate expressions to a remote dialect. Capability varies by type, operator, function and release.

      文件读取器可能只接受有限比较;连接器可能把表达式翻译为远端方言。能力会因类型、操作符、函数与版本而变化。

    4. Split accepted and residual filters.拆分已接受与残余过滤。

      The source handles the accepted constraint. The engine keeps a residual when the source returns a safe superset, handles only part, or cannot guarantee identical semantics.

      数据源执行已接受约束;当源端返回安全超集、只处理部分条件或无法保证语义一致时,引擎保留残余过滤。

    5. Cost and execute the new plan.估算并执行新计划。

      The optimizer compares legal placements using estimated selectivity, scan, transfer and source costs. Runtime reduction can differ from estimates, so measurement remains necessary.

      优化器利用估算选择率、扫描、传输与源端成本比较合法位置。实际减少量可能偏离估算,因此仍需测量。

    Predicate Pushdown vs Partition Pruning and Projection Pushdown谓词下推与分区裁剪、投影下推有什么区别?

    Adjacent optimizations reduce different work相邻优化减少不同工作
    Mechanism机制Reduces减少内容Input输入Not proof of不能证明
    Predicate pushdown谓词下推Rows above a scan/source扫描/源端以上的行Eligible row condition符合条件的行表达式Physical block skipping物理块一定被跳过
    Partition pruning分区裁剪Partitions or partition files opened打开的分区或分区文件Partition-key condition分区键条件Filtering inside retained partitions保留分区内部过滤
    Data skipping数据跳过Files, row groups or pages read读取的文件、行组或页面Min/max, dictionary, index or Bloom metadata最小/最大值、字典、索引或布隆元数据Every retained row matches保留的每行都匹配
    Projection pushdown投影下推Columns and column bytes列与列字节Required-column list必需列清单Fewer rows行数减少
    Dynamic filtering动态过滤Probe data after runtime values exist运行时值已知后的探测数据Values derived from another input从另一输入得到的值A compile-time static predicate编译期静态谓词

    These mechanisms can compound. A date condition may prune partitions, row-group statistics may skip blocks, projection pushdown may avoid unused columns, and a residual filter may remove nonmatches inside retained groups. Report each effect separately.

    这些机制可以叠加:日期条件裁剪分区,行组统计跳过数据块,投影下推避免读取无用列,残余过滤再删除保留行组中的不匹配行。应分别报告每种效果。

    Semantic Safety Comes Before Filter Placement过滤位置必须服从语义安全

    A pushdown is legal only when the moved expression produces an equivalent multiset of rows. SQL's NULL and duplicate semantics make apparently obvious rewrites dangerous. Source translation adds risk because systems may compare strings, timestamps, decimals or invalid values differently.

    只有移动后的表达式产生等价行多重集时,下推才合法。SQL的NULL与重复项语义会让看似显然的重写变得危险;源端翻译还会增加风险,因为不同系统比较字符串、时间戳、小数或无效值的方式可能不同。

    Outer joins and NULL preservation外连接与NULL保留

    A predicate on the null-supplying side can turn an outer join into an inner join if moved incorrectly. Conditions in ON and WHERE are not interchangeable.如果错误移动空值补充端的条件,外连接可能变成内连接。ONWHERE中的条件不能随意互换。

    Determinism and side effects确定性与副作用

    Random, clock-dependent, sequence, user-context or volatile functions may differ when evaluated earlier, fewer times or elsewhere.随机、依赖时钟、序列、用户上下文或易变函数,在更早、次数更少或其他位置执行时可能产生不同结果。

    Types, casts and errors类型、转换与错误

    Conversion order, overflow, rounding and malformed-value behavior can differ. A pushed cast may raise an error the original plan never reaches.转换顺序、溢出、舍入与格式错误值的处理可能不同。下推转换可能触发原计划不会遇到的错误。

    Collation, locale and time zone排序规则、区域与时区

    Case sensitivity, accent ordering, trailing spaces and timestamp boundaries must match. Trino warns that a case-insensitive source cannot exactly enforce a case-sensitive constraint.大小写敏感性、重音排序、尾随空格与时间戳边界必须一致。Trino提醒:大小写不敏感的源端不能精确执行大小写敏感约束。

    Why Predicate Pushdown Does Not Happen为什么谓词下推没有发生?

    A filter can remain above the scan because movement is illegal, the implementation lacks a translation, the connector rejects the expression, or another placement is estimated cheaper. Diagnose the category before rewriting SQL.

    过滤留在扫描上方,可能是移动不合法、实现缺少翻译、连接器拒绝表达式,或其他位置估算成本更低。重写SQL前,应先判断类别。

    • Expression shape: a function or cast wraps the column; an unsupported operator, correlated subquery or complex disjunction blocks translation.表达式形态:函数或转换包裹源列,或不受支持的操作符、相关子查询、复杂析取阻止翻译。
    • Operator boundary: an aggregate, window, limit, set operation or outer join changes which rows the predicate may see.算子边界:聚合、窗口、限制、集合操作或外连接改变了谓词可见的行。
    • Source mismatch: types, collation, time zone, decimal scale, NULL or function semantics differ.源端不匹配:类型、排序规则、时区、小数精度、NULL或函数语义不同。
    • Capability and permissions: the connector lacks support, remote syntax cannot express it, or a function is not allowed.能力与权限:连接器不支持、远端语法无法表达,或函数不允许调用。
    • Late values: parameters or variables may prevent a compile-time constraint in some products.延迟值:某些产品中的参数或变量可能阻止编译期约束。
    • Cost: a legal pushdown may lose when estimated selectivity is weak or source/network costs favor local work.成本:估算选择性较弱,或源端/网络成本支持本地执行时,合法下推也可能不采用。

    Predicate Pushdown SQL Example谓词下推SQL示例

    Consider this hypothetical query. Names and numbers are illustrative; they do not describe a customer or benchmark.

    考虑下面的假设查询。名称与数字仅用于说明,不代表客户或基准测试。

    SELECT o.order_id, c.segment
    FROM remote_orders o
    JOIN customers c ON c.customer_id = o.customer_id
    WHERE o.order_date >= DATE '2026-07-01'
      AND o.status = 'OPEN';

    Without connector pushdown, the remote scan might return all orders to the coordinator, which applies both conditions. With safe pushdown, the connector can generate a remote request containing the date and status constraints, so only qualifying rows cross the network before the local join. A local residual may remain as a safety check.

    如果连接器没有下推,远端扫描可能把所有订单返回协调器,再执行两个条件。安全下推后,连接器可以生成包含日期与状态约束的远端请求,使只有符合条件的行在本地连接前跨越网络。本地残余过滤仍可能保留作为安全检查。

    Illustrative measurement: suppose one test reads 12 million source rows and transfers 8 million without pushdown, then transfers 180,000 with it. This supports lower transfer for that fixture; it does not prove fewer source pages, lower source CPU or better results for other values. Measure those separately.

    示例测量:假设一次测试无下推时读取1200万源端行并传输800万行,下推后传输18万行。这只能支持“该样本传输减少”,不能证明源端页更少、源端CPU更低或其他参数也更快;这些指标必须分别测量。

    How to Verify Predicate Pushdown Step by Step如何逐步验证谓词下推

    1. Freeze the baseline.固定基线。

      Record query, versions, parameters, cache state, concurrency and source load. Capture results and a plan before changes.

      记录查询、版本、参数、缓存状态、并发与源端负载,并在变更前保存结果与计划。

    2. Locate filters and boundaries.定位过滤与边界。

      Mark scan predicates, join conditions, residuals, exchanges, connectors and remote operators. Identify the earliest legal placement.

      标记扫描谓词、连接条件、残余过滤、数据交换、连接器与远端算子,并确定最早合法位置。

    3. Inspect the delegated expression.检查已委派表达式。

      Read scan properties, pushed-filter fields, remote SQL or API parameters. Confirm types, casts and literal boundaries.

      读取扫描属性、下推字段、远端SQL或API参数,并核对类型、转换与字面值边界。

    4. Measure both sides.测量边界两侧。

      Compare rows and bytes scanned/returned, transfer, files or groups opened, source CPU/I/O, coordinator work, latency and variance.

      比较扫描/返回行与字节、传输、打开的文件或行组、源端CPU/I/O、协调器工作、延迟与波动。

    5. Prove result equivalence.证明结果等价。

      Compare counts, keys, duplicates, NULLs and totals over typical and adversarial fixtures. A faster wrong result fails.

      在典型与对抗样本上比较计数、键、重复项、NULL与汇总。结果错误时,再快也不合格。

    6. Test one reversible change.测试一个可逆变更。

      Change one supported expression, connector option, layout or access path at a time. Keep rollback and rerun the evidence set.

      每次只修改一个受支持的表达式、连接器选项、布局或访问路径。保留回滚并重跑证据集。

    Review Filter Structure Before Engine-Native Pushdown Testing在引擎原生下推测试前审查过滤结构

    Prepare sanitized, complete SQL and identify its dialect. The visible InfiniSynapse SQL Complexity Checker performs browser-side static analysis of nested queries, CTEs, joins, windows, aggregations and dialect-specific constructs. It can help locate filters wrapped in complex query blocks and prioritize plan inspection.

    请准备经过脱敏的完整SQL,并确认方言。InfiniSynapse SQL Complexity Checker会在浏览器中静态分析嵌套查询、CTE、连接、窗口、聚合与方言特定结构,可帮助定位复杂查询块中的过滤并安排计划检查优先级。

    The checker does not execute SQL, inspect schema, partitions, row-group metadata, connectors, generated remote SQL or plans. It cannot prove pushdown or predict bytes saved. Use it for structural review, then collect engine-native evidence. The existing InfiniSynapse SQL query optimization guide explains the broader workflow; the local query optimization guide, cost based optimizer guide and data federation guide provide related context without claiming these local files are deployed.

    该检查器不会执行SQL,不会检查Schema、分区、行组元数据、连接器、生成的远端SQL或计划,不能证明下推,也不能预测节省的字节。完成结构审查后,应收集引擎原生证据。现有InfiniSynapse SQL查询优化指南解释更广泛流程;本地查询优化指南基于成本的优化器指南数据联邦指南提供相关背景,但不声称这些本地文件已部署。

    Inspect SQL structure without executing it无需执行即可检查SQL结构

    Remove credentials, secrets, personal data and sensitive literals. Paste the sanitized statement, select its dialect, and use structural findings to plan native EXPLAIN, connector and telemetry checks.

    请移除凭据、密钥、个人数据与敏感字面值。粘贴脱敏语句并选择方言,再根据结构发现规划原生EXPLAIN、连接器与遥测检查。

    Explore InfiniSynapse Tools查看InfiniSynapse工具

    Predicate Pushdown FAQ谓词下推常见问题

    What is predicate pushdown?

    什么是谓词下推?

    Predicate pushdown is a query optimization that evaluates an eligible filter closer to a table scan, columnar file reader, connector or remote source. Its goal is to reduce rows or bytes that flow through later operators, but the move must preserve SQL semantics.

    谓词下推是一种查询优化,会把符合条件的过滤表达式放到更靠近表扫描、列式文件读取器、连接器或远端数据源的位置执行。目标是减少流向后续算子的行或字节,但移动必须保持SQL语义。

    How does predicate pushdown work?

    谓词下推如何工作?

    The optimizer proves that a filter can legally move downward, asks the scan or connector which expressions it supports, delegates the accepted part, retains any required residual predicate, and costs the resulting plan. Exact behavior varies by engine, source, format and version.

    优化器先证明过滤可以合法向下移动,再询问扫描器或连接器支持哪些表达式,委派已接受部分,保留任何必要的残余谓词,并估算新计划的成本。具体行为因引擎、数据源、格式与版本而异。

    Is predicate pushdown the same as partition pruning?

    谓词下推与分区裁剪相同吗?

    No. Predicate pushdown changes where a row condition is evaluated. Partition pruning avoids opening partitions selected by partition metadata. One condition can enable both, but the plan and metrics should report their effects separately.

    不同。谓词下推改变行过滤条件的执行位置;分区裁剪利用分区元数据避免打开某些分区。一个条件可能同时启用两者,但计划与指标应分别报告它们的效果。

    What is the difference between predicate and projection pushdown?

    谓词下推与投影下推有什么区别?

    Predicate pushdown aims to reduce rows; projection pushdown aims to avoid reading or transferring unneeded columns. They often work together, but proof of one does not prove the other.

    谓词下推旨在减少行数;投影下推旨在避免读取或传输不需要的列。两者经常同时工作,但证明其中一个并不能证明另一个。

    Why can a filter not be pushed down?

    为什么过滤条件不能下推?

    Common blockers include outer-join or aggregation semantics, volatile functions, casts, unsupported operators, collation or time-zone differences, connector limitations, late-bound values, permissions, and an optimizer estimate that local evaluation is cheaper.

    常见阻碍包括外连接或聚合语义、易变函数、类型转换、不受支持的操作符、排序规则或时区差异、连接器限制、延迟绑定值、权限,以及优化器估算本地执行成本更低。

    Can predicate pushdown change query results?

    谓词下推会改变查询结果吗?

    A correct pushdown must not change results. An unsafe manual rewrite or faulty translation can change NULL preservation, duplicates, case comparison, timestamp boundaries, rounding or error behavior. Test result equivalence over typical and boundary data.

    正确下推不得改变结果。不安全的人工重写或错误翻译可能改变NULL保留、重复项、大小写比较、时间戳边界、舍入或错误行为。应使用典型与边界数据测试结果等价性。

    How do I verify predicate pushdown in EXPLAIN?

    如何在EXPLAIN中验证谓词下推?

    Look for the filter at the scan or remote operator, pushed-filter properties, generated remote SQL, and any residual filter. Then confirm rows and bytes before and after the boundary, source work, network transfer and equivalent results. Plan labels alone are insufficient.

    检查过滤是否位于扫描或远端算子、已下推属性、生成的远端SQL,以及是否存在残余过滤;再确认边界前后的行和字节、源端工作、网络传输与结果等价。仅有计划标记还不够。

    Does the InfiniSynapse SQL Complexity Checker prove predicate pushdown?

    InfiniSynapse SQL Complexity Checker能证明谓词下推吗?

    No. The visible tool statically analyzes SQL structure in the browser. It does not execute SQL, inspect schemas, connectors, file metadata, generated remote requests or execution plans. Use it to prioritize structural review before engine-native verification.

    不能。其可见功能只在浏览器中静态分析SQL结构,不执行SQL,也不检查Schema、连接器、文件元数据、生成的远端请求或执行计划。可用它安排结构审查优先级,随后仍需进行引擎原生验证。

    Official Predicate Pushdown Sources谓词下推权威来源

    These first-party sources cover different products and layers. Support, syntax, plan labels, remote-query visibility and metrics vary by engine, connector, source and version. Verify the exact environment before changing SQL, connector configuration or physical layout.

    这些一手资料针对不同产品与层级。支持范围、语法、计划标记、远端查询可见性与指标会随引擎、连接器、数据源和版本变化。修改SQL、连接器配置或物理布局前,必须核对准确环境。