This rule optimizes simple selections with secondary or primary indexes. The use of an index is expressed as an unnest-map over an index-search function which will be replaced with the appropriate embodiment during codegen. Matches the following operator patterns: Standard secondary index pattern: There must be at least one assign, but there may be more, e.g., when matching similarity-jaccard-check(). (select) <-- (assign | unnest)+ <-- (datasource scan) Primary index lookup pattern: Since no assign is necessary to get the primary key fields (they are already stored fields in the BTree tuples). (select) <-- (datasource scan) Replaces the above patterns with this plan: (select) <-- (assign) <-- (btree search) <-- (sort) <-- (unnest-map(index search)) <-- (assign) The sort is optional, and some access methods implementations may choose not to sort. Note that for some index-based optimizations we do not remove the triggering condition from the select, since the index may only acts as a filter, and the final verification must still be done with the original select condition. The basic outline of this rule is: 1. Match operator pattern. 2. Analyze select condition to see if there are optimizable functions (delegated to IAccessMethods). 3. Check metadata to see if there are applicable indexes. 4. Choose an index to apply (for now only a single index will be chosen). 5. Rewrite plan using index (delegated to IAccessMethods).

  • No labels