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

📄 level2optimizerimpl.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.Level2OptimizerImpl   Copyright 2000, 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.sql.compile;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.compile.JoinStrategy;import org.apache.derby.iapi.sql.compile.Optimizable;import org.apache.derby.iapi.sql.compile.OptimizableList;import org.apache.derby.iapi.sql.compile.OptimizablePredicate;import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;import org.apache.derby.iapi.sql.compile.Optimizer;import org.apache.derby.iapi.sql.compile.CostEstimate;import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;import org.apache.derby.iapi.sql.compile.RowOrdering;import org.apache.derby.iapi.sql.compile.AccessPath;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.impl.sql.compile.OptimizerImpl;import org.apache.derby.impl.sql.compile.CostEstimateImpl;import java.util.Properties;/** * This is the Level 2 Optimizer. */public class Level2OptimizerImpl extends OptimizerImpl{	private LanguageConnectionContext lcc;	Level2OptimizerImpl(OptimizableList optimizableList, 				  OptimizablePredicateList predicateList,				  DataDictionary dDictionary,				  boolean ruleBasedOptimization,				  boolean noTimeout,				  boolean useStatistics,				  int maxMemoryPerTable,				  JoinStrategy[] joinStrategies,				  int tableLockThreshold,				  RequiredRowOrdering requiredRowOrdering,				  int numTablesInQuery,				  LanguageConnectionContext lcc)		throws StandardException	{		super(optimizableList, predicateList, dDictionary,			  ruleBasedOptimization, noTimeout, useStatistics, maxMemoryPerTable,			  joinStrategies, tableLockThreshold, requiredRowOrdering,			  numTablesInQuery);		// Remember whether or not optimizer trace is on;		optimizerTrace = lcc.getOptimizerTrace();		optimizerTraceHtml = lcc.getOptimizerTraceHtml();		this.lcc = lcc;		// Optimization started		if (optimizerTrace)		{			trace(STARTED, 0, 0, 0.0, null);		}	}	/** @see Optimizer#getLevel */	public int getLevel()	{		return 2;	}	/** @see Optimizer#newCostEstimate */	public CostEstimate newCostEstimate()	{		return new Level2CostEstimateImpl();	}	public CostEstimateImpl getNewCostEstimate(double theCost,							double theRowCount,							double theSingleScanRowCount)	{		return new Level2CostEstimateImpl(theCost, theRowCount, theSingleScanRowCount);	}	// Optimzer trace	public void trace(int traceFlag, int intParam1, int intParam2,					  double doubleParam, Object objectParam1)	{		ConglomerateDescriptor cd;		String cdString;		String traceString = null;		// We can get called from outside optimizer when tracing is off		if (!optimizerTrace)		{			return;		}		switch (traceFlag)		{			case STARTED:				traceString = 					"Optimization started at time " +					timeOptimizationStarted +					" using optimizer " + this.hashCode();				break;			case TIME_EXCEEDED:				traceString =					"Optimization time exceeded at time " +							currentTime + "\n" + bestCost();				break;			case NO_TABLES:				traceString = "No tables to optimize.";				break;			case COMPLETE_JOIN_ORDER:				traceString = "We have a complete join order.";				break;			case COST_OF_SORTING:				traceString = 					"Cost of sorting is " + sortCost;				break;			case NO_BEST_PLAN:				traceString =					"No best plan found.";				break;			case MODIFYING_ACCESS_PATHS:				traceString = 					"Modifying access paths using optimizer " + this.hashCode();				break;			case SHORT_CIRCUITING:				String basis = (timeExceeded) ? "time exceeded" : "cost";				Optimizable thisOpt =					optimizableList.getOptimizable(										proposedJoinOrder[joinPosition]);				if (thisOpt.getBestAccessPath().getCostEstimate() == null)					basis = "no best plan found";				traceString = 					"Short circuiting based on " + basis +					" at join position " + joinPosition;				break;			case SKIPPING_JOIN_ORDER:				traceString = buildJoinOrder("\n\nSkipping join order: ", true, intParam1,											 proposedJoinOrder);				break;			case ILLEGAL_USER_JOIN_ORDER:				traceString =					"User specified join order is not legal.";				break;			case USER_JOIN_ORDER_OPTIMIZED:				traceString =					"User-specified join order has now been optimized.";				break;			case CONSIDERING_JOIN_ORDER:				traceString = buildJoinOrder("\n\nConsidering join order: ", false, intParam1,											 proposedJoinOrder);				break;			case TOTAL_COST_NON_SA_PLAN:				traceString =					"Total cost of non-sort-avoidance plan is " +						currentCost;				break;			case TOTAL_COST_SA_PLAN:				traceString =					"Total cost of sort avoidance plan is " +						currentSortAvoidanceCost;				break;			case TOTAL_COST_WITH_SORTING:				traceString = 					"Total cost of non-sort-avoidance plan with sort cost added is " + currentCost;				break;			case CURRENT_PLAN_IS_SA_PLAN:				traceString = 					"Current plan is a sort avoidance plan." + 					"\n\tBest cost is : " + bestCost +					"\n\tThis cost is : " + currentSortAvoidanceCost;				break;			case CHEAPEST_PLAN_SO_FAR:				traceString = 					"This is the cheapest plan so far.";				break;			case PLAN_TYPE:				traceString = 					"Plan is a " +					(intParam1 == Optimizer.NORMAL_PLAN ?						"normal" : "sort avoidance") +					" plan.";				break;			case COST_OF_CHEAPEST_PLAN_SO_FAR:				traceString = 					"Cost of cheapest plan is " + currentCost;				break;			case SORT_NEEDED_FOR_ORDERING:				traceString = 					"Sort needed for ordering: " + 						(intParam1 != Optimizer.SORT_AVOIDANCE_PLAN) +						"\n\tRow ordering: " +						requiredRowOrdering;				break;			case REMEMBERING_BEST_JOIN_ORDER:				traceString = buildJoinOrder("\n\nRemembering join order as best: ", false, intParam1,											 bestJoinOrder);				break;			case SKIPPING_DUE_TO_EXCESS_MEMORY:				traceString = 					"Skipping access path due to excess memory usage, maximum is " +					maxMemoryPerTable;				break;			case COST_OF_N_SCANS:				traceString =						"Cost of " + doubleParam +						" scans is: " +						objectParam1 +						" for table " +						intParam1;				break;			case HJ_SKIP_NOT_MATERIALIZABLE:				traceString = "Skipping HASH JOIN because optimizable is not materializable";				break;			case HJ_SKIP_NO_JOIN_COLUMNS:				traceString = "Skipping HASH JOIN because there are no hash key columns";				break;			case HJ_HASH_KEY_COLUMNS:				int[] hashKeyColumns = (int []) objectParam1;				traceString = "# hash key columns = " + hashKeyColumns.length;				for (int index = 0; index < hashKeyColumns.length; index++)				{					traceString = 						"\n" + traceString + "hashKeyColumns[" + index +						"] = " + hashKeyColumns[index];				}				break;			case CALLING_ON_JOIN_NODE:				traceString = "Calling optimizeIt() for join node";				break;			case CONSIDERING_JOIN_STRATEGY:				JoinStrategy js = (JoinStrategy) objectParam1;				traceString = 					"\nConsidering join strategy " +					js + " for table " + intParam1;				break;			case REMEMBERING_BEST_ACCESS_PATH:				traceString = 					"Remembering access path " +

⌨️ 快捷键说明

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