/// Initialize a planner for the given query.
///
/// Before the plan is available, the scans need to be initialized.
/// Separating this step from the constuctor allows the planner to be reused
/// for different permutations of the statements, at the cost of introducing
/// invalid states of the planner.
Initialize a planner for the given query.
Before the plan is available, the scans need to be initialized.
Separating this step from the constuctor allows the planner to be reused
for different permutations of the statements, at the cost of introducing
invalid states of the planner.
Initialize a planner for the given query . Before the plan is available the scans need to be initialized . Separating this step from the constuctor allows the planner to be reused for different permutations of the statements at the cost of introducing invalid states of the planner .
pub fn new(query: &Query) -> Planner {
        let mut slots = Vec::new();
        let mut statements = Vec::with_capacity(query.where_statements.len());
        assert!(
            query.variable_names.len() <= 0xffff,
            "Can have at most 2^16 slots, slot index is u16."
        );
        for variable_name in &query.variable_names {
            let def = SlotDefinition::Variable {
                name: variable_name.clone(),
            };
            slots.push(def);
        }
        for statement in &query.where_statements {
            let slot_entity = Slot(statement.entity.0);
            let attribute = match statement.attribute {
                QueryAttribute::Fixed(aid) => aid,
                QueryAttribute::Named(..) => {
                    panic!("Attributes should have been fixed before planning.");
                }
            };
            let slot_value = match statement.value {
                QueryValue::Var(var) => Slot(var.0),
                QueryValue::Const(v) => {
                    let def = SlotDefinition::Constant { value: v };
                    slots.push(def);
                    Slot((slots.len() - 1) as u16)
                }
            };
            statements.push((slot_entity, attribute, slot_value));
            assert!(
                slots.len() <= 0xffff,
                "Can have at most 2^16 slots, slot index is u16."
            );
        }
        let plan = Plan {
            // Every where statement will be translated in exactly one scan.
            scans: Vec::with_capacity(query.where_statements.len()),
            slots: slots,
            // As we mapped 1:1 to the first n slots, we can pass along the
            // selects without modification.
            select: query.select.iter().map(|&Var(i)| Slot(i)).collect(),
        };
        Planner {
            statements: statements,
            plan: plan,
        }
    }
pub fn new ( query : & Query ) -> Planner { let mut slots = Vec :: new ( ) ; let mut statements = Vec :: with_capacity ( query . where_statements . len ( ) ) ; assert ! ( query variable_names len ( ) 0xffff " " ) ; for variable_name in & query . variable_names { let def = SlotDefinition :: Variable { name : variable_name . clone ( ) , } ; slots . push ( def ) ; } for statement in & query . where_statements { let slot_entity = Slot ( statement . entity . 0 ) ; let attribute = match statement . attribute { QueryAttribute :: Fixed ( aid ) => aid , QueryAttribute :: Named ( .. ) => { panic ! ( " " ) ; } } ; let slot_value = match statement . value { QueryValue :: Var ( var ) => Slot ( var . 0 ) , QueryValue :: Const ( v ) => { let def = SlotDefinition :: Constant { value : v } ; slots . push ( def ) ; Slot ( ( slots . len ( ) - 1 ) as u16 ) } } ; statements . push ( ( slot_entity , attribute , slot_value ) ) ; assert ! ( slots len ( ) 0xffff " " ) ; } let plan = Plan { // Every where statement will be translated in exactly one scan. scans : Vec :: with_capacity ( query . where_statements . len ( ) ) , slots : slots , // As we mapped 1:1 to the first n slots, we can pass along the // selects without modification. select : query . select . iter ( ) . map ( | & Var ( i ) | Slot ( i ) ) . collect ( ) , } ; Planner { statements : statements , plan : plan , } }
Initialize a planner for the given query.
Initialize a planner for the given query .
query
&Query