Updated on 2026-11-06 GMT+08:00

Lance Late Read

Late Read is a performance optimization feature for Lance foreign tables, specifically designed for vector top-k queries. By splitting data scan into two phases: early read and late read, this feature significantly reduces the amount of invalid reads on wide columns (such as images, long texts, and original vectors), thereby enhancing query performance.

In a standard execution plan, a query such as SELECT <Wide columns> FROM t ORDER BY vec <-> q LIMIT k requires reading all projected columns for every candidate row in the entire table before sorting and obtaining top-k results. Wide columns are read before sorting and most of them are discarded after sorting.

Late Read divides the scan into two phases:

  1. Early read phase: Only the three system columns (_rowid, xc_node_id, and _distance) along with the columns required by the WHERE predicates and JOIN keys are read. The IVF index is used to generate a candidate set, and the top-k results are obtained after sorting.
  2. Late read phase: The top-k _rowid values are routed back to the DataNodes where the data resides (via the RESTORE stream) based on xc_node_id. Only the Lance take_rows function is called for these k rows to retrieve the wide columns. The amount of data read from wide columns is reduced from O (Number of candidate rows × Width of wide columns) to O (k × Width of wide columns).

Late Read Execution Policies

Late Read supports two execution policies, which can be specified through parameters or automatically selected by the optimizer.

  • Single-phase policy (single_phase)

    A single Late Read operation retrieves vector columns and other wide columns together.

    Figure 1 Single-phase Late Read plan

    Characteristics: The plan has a shallow hierarchy, with only one RESTORE operation and one take_rows operation. However, wide columns are fetched for the coarse-ranking candidate set. Some of them may be eliminated in the subsequent fine-ranking, resulting in I/O waste.

  • Two-phase policy (two_phase)

    This policy splits the Late Read into two distinct steps: First, retrieve only the vector columns to perform fine-ranking and finalize the top-k results. Then, retrieve only the wide columns for the final k rows.

    Figure 2 Two-phase Late Read plan

    Characteristics: Wide columns are read only for the final k rows, minimizing I/O. However, this policy incurs the overheard of an additional RESTORE stream and an extra call to Python's take_rows. This policy is cost-effective only when there are non-vectorized wide columns are sufficiently large or numerous.

GUC Parameters

late_read_strategy
  • Description: Specifies the Late Read policy for top-k queries on Lance DFS tables. The value is a list. none, single_phase, two_phase, and auto options are mutually exclusive options. nested_late_read and join_late_read are independent switches.
  • Values:
    • none: Late Read is disabled. The query follows the original plan, reading all projected columns during the scan phase.
    • auto: The optimizer automatically selects between none, single_phase, and two_phase based on the cost and column width.
    • single_phase: The query is forced to follow a single-phase plan, skipping benefit checks.
    • two_phase: The query is forced to follow a two-phase plan, skipping benefit checks.
    • nested_late_read: An independent switch that allows Late Read to work in nested query blocks (subqueries and CTEs).
      • Default: Late Read is not applied to subqueries and queries in CTEs.
      • Enabled: Late Read is determined independently for each query block. Top-k queries in subqueries and CTEs can use Late Read.
    • join_late_read: An independent switch that allows Late Read to work across INNER JOINs (only Hash Joins are supported). After the setting, Late Read takes effect only when all conditions below are met:
      • All joins are INNER JOINs (presence of OUTER, SEMI, or ANTI joins causes a fallback to the standard plan).
      • There is exactly one Lance top-k driving table in the query, and the total number of Lance tables equals this count.
      • Equi-join conditions exist for the driving table.
      • No aggregation, GROUP BY, DISTINCT, or set operations are present.
  • Default Value: none
enable_topk_compensation
  • Description: Specifies whether to enable top-k compensation read for Lance ANN scans. When enabled, Lance ANN scans use a filter_ratio-based k-value calculation and a while-loop compensation mechanism to ensure that the final output meets the LIMIT n requirement after WHERE filtering.
  • Values:
    • on: The while-loop compensation mechanism is enabled to ensure that the final output row count satisfies the k-value requirement.
    • off: The while-loop compensation mechanism is disabled. If the WHERE filter rate is high, the output row count may be significantly less than the requested k-value.
  • Default Value: off