@@ -13,9 +13,9 @@ use crate::types::index::{IndexInfo, IndexMetaRef, IndexType};
1313use crate :: types:: value:: DataValue ;
1414use crate :: types:: LogicalType ;
1515use itertools:: Itertools ;
16- use std:: mem;
1716use std:: ops:: Bound ;
1817use std:: sync:: LazyLock ;
18+ use std:: { mem, slice} ;
1919
2020static PUSH_PREDICATE_THROUGH_JOIN : LazyLock < Pattern > = LazyLock :: new ( || Pattern {
2121 predicate : |op| matches ! ( op, Operator :: Filter ( _) ) ,
@@ -215,12 +215,17 @@ impl NormalizationRule for PushPredicateIntoScan {
215215 fn apply ( & self , node_id : HepNodeId , graph : & mut HepGraph ) -> Result < ( ) , DatabaseError > {
216216 if let Operator :: Filter ( op) = graph. operator ( node_id) . clone ( ) {
217217 if let Some ( child_id) = graph. eldest_child_at ( node_id) {
218- if let Operator :: TableScan ( child_op) = graph. operator_mut ( child_id) {
219- //FIXME: now only support `unique` and `primary key`
220- for IndexInfo { meta, range } in & mut child_op. index_infos {
218+ if let Operator :: TableScan ( scan_op) = graph. operator_mut ( child_id) {
219+ for IndexInfo {
220+ meta,
221+ range,
222+ covered_deserializers,
223+ } in & mut scan_op. index_infos
224+ {
221225 if range. is_some ( ) {
222226 continue ;
223227 }
228+ // range detach
224229 * range = match meta. ty {
225230 IndexType :: PrimaryKey { is_multiple : false }
226231 | IndexType :: Unique
@@ -232,6 +237,28 @@ impl NormalizationRule for PushPredicateIntoScan {
232237 Self :: composite_range ( & op, meta) ?
233238 }
234239 } ;
240+ // try index covered
241+ let mut deserializers = Vec :: with_capacity ( meta. column_ids . len ( ) ) ;
242+ let mut cover_count = 0 ;
243+ let index_column_types = match & meta. value_ty {
244+ LogicalType :: Tuple ( tys) => tys,
245+ ty => slice:: from_ref ( ty) ,
246+ } ;
247+ for ( i, column_id) in meta. column_ids . iter ( ) . enumerate ( ) {
248+ for column in scan_op. columns . values ( ) {
249+ deserializers. push (
250+ if column. id ( ) . map ( |id| & id == column_id) . unwrap_or ( false ) {
251+ cover_count += 1 ;
252+ column. datatype ( ) . serializable ( )
253+ } else {
254+ index_column_types[ i] . skip_serializable ( )
255+ } ,
256+ ) ;
257+ }
258+ }
259+ if cover_count == scan_op. columns . len ( ) {
260+ * covered_deserializers = Some ( deserializers)
261+ }
235262 }
236263 }
237264 }
0 commit comments