⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 heapcostcontroller.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.store.access.heap.HeapCostController   Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License. */package org.apache.derby.impl.store.access.heap;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.Property;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException; import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.store.access.StoreCostController;import org.apache.derby.iapi.store.access.StoreCostResult;import org.apache.derby.iapi.store.raw.ContainerHandle;import org.apache.derby.iapi.store.raw.LockingPolicy;import org.apache.derby.iapi.store.raw.RawStoreFactory;import org.apache.derby.iapi.store.raw.Transaction;import org.apache.derby.impl.store.access.conglomerate.GenericCostController;import org.apache.derby.impl.store.access.conglomerate.OpenConglomerate;import org.apache.derby.iapi.store.access.RowUtil;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.services.io.FormatableBitSet;import java.util.Properties;/**The StoreCostController interface provides methods that an access client(most likely the system optimizer) can use to get store's estimated cost ofvarious operations on the conglomerate the StoreCostController was openedfor.<p>It is likely that the implementation of StoreCostController will open the conglomerate and will leave the conglomerate open until theStoreCostController is closed.  This represents a significant amount ofwork, so the caller if possible should attempt to open the StoreCostControlleronce per unit of work and rather than close and reopen the controller.  Forinstance if the optimizer needs to cost 2 different scans against a singleconglomerate, it should use one instance of the StoreCostController.<p>The locking behavior of the implementation of a StoreCostController isundefined, it may or may not get locks on the underlying conglomerate.  Itmay or may not hold locks until end of transaction.  An optimal implementation will not get any locks on the underlying conglomerate, thus allowing concurrent access to the table by a executingquery while another query is optimizing.<p>The StoreCostController gives 2 kinds of cost information**/public class HeapCostController     extends GenericCostController implements StoreCostController{    /**     * Only lookup these estimates from raw store once.     **/    long    num_pages;    long    num_rows;    long    page_size;    long    row_size;    /* Private/Protected methods of This class: */    /**     * Initialize the cost controller.     * <p>     * Let super.init() do it's work and then get the initial stats about the     * table from raw store.     *	 * @exception  StandardException  Standard exception policy.     **/    public void init(    OpenConglomerate    open_conglom)        throws StandardException    {        super.init(open_conglom);        ContainerHandle container = open_conglom.getContainer();        // look up costs from raw store.        num_rows  = container.getEstimatedRowCount(/*unused flag*/ 0);        // Don't use 0 rows (use 1 instead), as 0 rows often leads the         // optimizer to produce plans which don't use indexes because of the 0         // row edge case.        //        // Eventually the plan is recompiled when rows are added, but we        // have seen multiple customer cases of deadlocks and timeouts         // because of these 0 row based plans.          if (num_rows == 0)            num_rows = 1;        // eliminate the allocation page from the count.        num_pages = container.getEstimatedPageCount(/* unused flag */ 0);        Properties prop = new Properties();        prop.put(Property.PAGE_SIZE_PARAMETER, "");        container.getContainerProperties(prop);        page_size =             Integer.parseInt(prop.getProperty(Property.PAGE_SIZE_PARAMETER));        row_size = (num_pages * page_size / num_rows);        return;    }    /* Public Methods of This class: */    /* Public Methods of XXXX class: */    /**     * Return the cost of calling ConglomerateController.fetch().     * <p>     * Return the estimated cost of calling ConglomerateController.fetch()     * on the current conglomerate.  This gives the cost of finding a record     * in the conglomerate given the exact RowLocation of the record in     * question.      * <p>     * The validColumns describes what kind of row is being fetched,      * ie. it may be cheaper to fetch a partial row than a complete row.     * <p>     *     *	 * @param validColumns    A description of which columns to return from     *                        row on the page into "templateRow."  templateRow,     *                        and validColumns work together to     *                        describe the row to be returned by the fetch -      *                        see RowUtil for description of how these three      *                        parameters work together to describe a fetched      *                        "row".     *     * @param access_type     Describe the type of access the query will be     *                        performing to the ConglomerateController.       *     *                        STORECOST_CLUSTERED - The location of one fetch     *                            is likely clustered "close" to the next      *                            fetch.  For instance if the query plan were     *                            to sort the RowLocations of a heap and then     *                            use those RowLocations sequentially to      *                            probe into the heap, then this flag should     *                            be specified.  If this flag is not set then     *                            access to the table is assumed to be     *                            random - ie. the type of access one gets      *                            if you scan an index and probe each row     *                            in turn into the base table is "random".     *     *	 * @return The cost of the fetch.     *	 * @exception  StandardException  Standard exception policy.     *	 * @see RowUtil     **/    public double getFetchFromRowLocationCost(    FormatableBitSet      validColumns,    int         access_type)		throws StandardException    {        double ret_cost;        // get "per-byte" cost of fetching a row from the page.        ret_cost = row_size * BASE_ROW_PER_BYTECOST;        long num_pages_per_row = (row_size / page_size) + 1;        if ((access_type & StoreCostController.STORECOST_CLUSTERED) == 0)        {            // this is the "base" unit case.            ret_cost += (BASE_UNCACHED_ROW_FETCH_COST * num_pages_per_row);        }        else        {            ret_cost += (BASE_CACHED_ROW_FETCH_COST * num_pages_per_row);        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -