Skip to main content

optimize

Function optimize 

Source
pub fn optimize(plan: SqlPlan, catalog: &dyn SqlCatalog) -> Result<SqlPlan>
Expand description

If a Scan has a single equality filter on the collection’s primary key, convert it to a PointGet.

The primary key is resolved from the catalog rather than assumed to be the conventional id / document_id / key: a collection created without an explicit PRIMARY KEY gets an auto-generated _rowid key, so a filter on a regular id column is NOT a point lookup and must stay a scan (routing it to PointGet would resolve a surrogate for the wrong key and return zero rows). A declared key of any name is a point lookup: WHERE sku = 'p1' reads the one row keyed p1, as WHERE id = 'p1' does. When the catalog cannot resolve a primary key (unknown collection), the conventional names apply. A catalog error fails the plan: RetryableSchemaChanged must reach the caller.

A point lookup returns the whole stored row and runs no expression. A computed SELECT item over it becomes Projection::CpComputed: the Control Plane evaluates it once on the returned row. SELECT to_jsonb(*) ... WHERE <key> = $1 stays a point lookup that way.