001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.server.xdbm.search;
021
022
023import org.apache.directory.api.ldap.model.exception.LdapException;
024import org.apache.directory.api.ldap.model.filter.ExprNode;
025import org.apache.directory.server.core.api.partition.PartitionTxn;
026
027
028/**
029 * An optimizer applies heuristics to determine best execution path to a search
030 * filter based on scan counts within database indices.  It annotates the nodes
031 * of an expression subtree by setting a "count" key in the node.  Its goal is
032 * to annotate nodes with counts to indicate which nodes to iterate over thereby
033 * minimizing the number cycles in a search.  The SearchEngine relies on these
034 * count markers to determine the appropriate path.
035 * 
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 */
038public interface Optimizer
039{
040    /**
041     * Annotates the expression node tree for optimized traversal metrics.
042     *
043     * @param partitionTxn The transaction to use
044     * @param node the root of the expression node tree
045     * @return The computed value for this node
046     * @throws LdapException if there are failures while optimizing
047     */
048    Long annotate( PartitionTxn partitionTxn, ExprNode node ) throws LdapException;
049}