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

📄 fromtable.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.FromTable   Copyright 1997, 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.context.ContextManager;import org.apache.derby.iapi.sql.compile.Optimizable;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.JoinStrategy;import org.apache.derby.iapi.sql.compile.AccessPath;import org.apache.derby.iapi.sql.compile.RowOrdering;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.dictionary.*;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.impl.sql.execute.HashScanResultSet;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.util.StringUtil;import org.apache.derby.catalog.UUID;import java.util.Enumeration;import java.util.Properties;import java.util.Vector;import java.util.HashMap;/** * A FromTable represents a table in the FROM clause of a DML statement. * It can be either a base table, a subquery or a project restrict. * * @see FromBaseTable * @see FromSubquery * @see ProjectRestrictNode * * @author Jeff Lichtman */public abstract class FromTable extends ResultSetNode implements Optimizable{	Properties		tableProperties;	String		correlationName;	TableName	corrTableName;	int			tableNumber;	/* (Query block) level is 0-based. */	/* RESOLVE - View resolution will have to update the level within	 * the view tree.	 */	int			level;	// hashKeyColumns are 0-based column #s within the row returned by the store for hash scans	int[]			hashKeyColumns;	// overrides for hash join	int				initialCapacity = HashScanResultSet.DEFAULT_INITIAL_CAPACITY;	float			loadFactor = HashScanResultSet.DEFAULT_LOADFACTOR;	int				maxCapacity = HashScanResultSet.DEFAULT_MAX_CAPACITY;	AccessPathImpl			currentAccessPath;	AccessPathImpl			bestAccessPath;	AccessPathImpl			bestSortAvoidancePath;	AccessPathImpl			trulyTheBestAccessPath;	private int		joinStrategyNumber;	protected String userSpecifiedJoinStrategy;	protected CostEstimate bestCostEstimate;	private FormatableBitSet refCols;    private double perRowUsage = -1;    	private boolean considerSortAvoidancePath;	// Set of optimizer->trulyTheBestAccessPath mappings used to keep track	// of which of this Optimizable's "trulyTheBestAccessPath" was the best	// with respect to a specific outer query; the outer query is represented	// by an instance of Optimizer.  Each outer query could potentially have	// a different idea of what this Optimizable's "best access path" is, so	// we have to keep track of them all.	HashMap optimizerToBestPlanMap;  //this flag tells you if all the columns from this table are projected using * from it.  //Used by replication enabled databases where the target-only view failure is detected  //using this boolean  private boolean allColumnsProjected;  public boolean areAllColumnsProjected() {    return allColumnsProjected;  }  public void setAllColumnsProjected(boolean flag) {    allColumnsProjected = flag;  }	/**	 * Initializer for a table in a FROM list.	 *	 * @param correlationName	The correlation name	 * @param tableProperties	Properties list associated with the table	 */	public void init(Object correlationName, Object tableProperties)	{		this.correlationName = (String) correlationName;		this.tableProperties = (Properties) tableProperties;		tableNumber = -1;		optimizerToBestPlanMap = null;	}	/*	 *  Optimizable interface	 */	/**	 * @see org.apache.derby.iapi.sql.compile.Optimizable#optimizeIt	 *	 * @exception StandardException		Thrown on error	 *	 */	public CostEstimate optimizeIt(							Optimizer optimizer,							OptimizablePredicateList predList,							CostEstimate outerCost,							RowOrdering rowOrdering)			throws StandardException	{		// It's possible that a call to optimize the left/right will cause		// a new "truly the best" plan to be stored in the underlying base		// tables.  If that happens and then we decide to skip that plan		// (which we might do if the call to "considerCost()" below decides		// the current path is infeasible or not the best) we need to be		// able to revert back to the "truly the best" plans that we had		// saved before we got here.  So with this next call we save the		// current plans using "this" node as the key.  If needed, we'll		// then make the call to revert the plans in OptimizerImpl's		// getNextDecoratedPermutation() method.		addOrLoadBestPlanMapping(true, this);		CostEstimate singleScanCost = estimateCost(predList,												(ConglomerateDescriptor) null,												outerCost,												optimizer,												rowOrdering);		/* Make sure there is a cost estimate to set */		getCostEstimate(optimizer);		setCostEstimate(singleScanCost);		/* Optimize any subqueries that need to get optimized and		 * are not optimized any where else.  (Like those		 * in a RowResultSetNode.)		 */		optimizeSubqueries(getDataDictionary(), costEstimate.rowCount());		/*		** Get the cost of this result set in the context of the whole plan.		*/		getCurrentAccessPath().			getJoinStrategy().				estimateCost(							this,							predList,							(ConglomerateDescriptor) null,							outerCost,							optimizer,							getCostEstimate()							);		optimizer.considerCost(this, predList, getCostEstimate(), outerCost);		return getCostEstimate();	}	/**		@see Optimizable#nextAccessPath		@exception StandardException	Thrown on error	 */	public boolean nextAccessPath(Optimizer optimizer,									OptimizablePredicateList predList,									RowOrdering rowOrdering)					throws StandardException	{		int	numStrat = optimizer.getNumberOfJoinStrategies();		boolean found = false;		AccessPath ap = getCurrentAccessPath();		/*		** Most Optimizables have no ordering, so tell the rowOrdering that		** this Optimizable is unordered, if appropriate.		*/		if (userSpecifiedJoinStrategy != null)		{			/*			** User specified a join strategy, so we should look at only one			** strategy.  If there is a current strategy, we have already			** looked at the strategy, so go back to null.			*/			if (ap.getJoinStrategy() != null)			{  				ap.setJoinStrategy((JoinStrategy) null);				found = false;			}			else			{				ap.setJoinStrategy(								optimizer.getJoinStrategy(userSpecifiedJoinStrategy));				if (ap.getJoinStrategy() == null)				{					throw StandardException.newException(SQLState.LANG_INVALID_JOIN_STRATEGY, 						userSpecifiedJoinStrategy, getBaseTableName());				}				found = true;			}		}		else if (joinStrategyNumber < numStrat)		{			/* Step through the join strategies. */			ap.setJoinStrategy(optimizer.getJoinStrategy(joinStrategyNumber));			joinStrategyNumber++;			found = true;			optimizer.trace(Optimizer.CONSIDERING_JOIN_STRATEGY, tableNumber, 0, 0.0,							ap.getJoinStrategy());		}		/*		** Tell the RowOrdering about columns that are equal to constant		** expressions.		*/		tellRowOrderingAboutConstantColumns(rowOrdering, predList);		return found;	}	/** Most Optimizables cannot be ordered */	protected boolean canBeOrdered()	{		return false;	}	/** @see Optimizable#getCurrentAccessPath */	public AccessPath getCurrentAccessPath()	{		return currentAccessPath;	}	/** @see Optimizable#getBestAccessPath */	public AccessPath getBestAccessPath()	{		return bestAccessPath;	}	/** @see Optimizable#getBestSortAvoidancePath */	public AccessPath getBestSortAvoidancePath()	{		return bestSortAvoidancePath;	}	/** @see Optimizable#getTrulyTheBestAccessPath */	public AccessPath getTrulyTheBestAccessPath()	{		return trulyTheBestAccessPath;	}	/** @see Optimizable#rememberSortAvoidancePath */	public void rememberSortAvoidancePath()	{		considerSortAvoidancePath = true;	}	/** @see Optimizable#considerSortAvoidancePath */	public boolean considerSortAvoidancePath()	{		return considerSortAvoidancePath;	}	/** @see Optimizable#rememberJoinStrategyAsBest */	public void rememberJoinStrategyAsBest(AccessPath ap)	{		Optimizer optimizer = ap.getOptimizer();		ap.setJoinStrategy(getCurrentAccessPath().getJoinStrategy());		optimizer.trace(Optimizer.REMEMBERING_JOIN_STRATEGY, tableNumber, 0, 0.0,			  getCurrentAccessPath().getJoinStrategy());		if (ap == bestAccessPath)		{			optimizer.trace(Optimizer.REMEMBERING_BEST_ACCESS_PATH_SUBSTRING, 							tableNumber, 0, 0.0, ap);		}		else if (ap == bestSortAvoidancePath)		{			optimizer.trace(Optimizer.REMEMBERING_BEST_SORT_AVOIDANCE_ACCESS_PATH_SUBSTRING, 							tableNumber, 0, 0.0, ap);		}		else		{			/* We currently get here when optimizing an outer join.			 * (Problem predates optimizer trace change.)			 * RESOLVE - fix this at some point.			if (SanityManager.DEBUG)			{				SanityManager.THROWASSERT(					"unknown access path type");			}			 */			optimizer.trace(Optimizer.REMEMBERING_BEST_UNKNOWN_ACCESS_PATH_SUBSTRING, 							tableNumber, 0, 0.0, ap);		}	}	/** @see Optimizable#getTableDescriptor */	public TableDescriptor getTableDescriptor()	{		if (SanityManager.DEBUG)		{			SanityManager.THROWASSERT(				"getTableDescriptor() not expected to be called for "				+ getClass().toString());		}		return null;	}	/**	 * @see org.apache.derby.iapi.sql.compile.Optimizable#pushOptPredicate	 *	 * @exception StandardException		Thrown on error	 */	public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)		throws StandardException	{		return false;	}	/**	 * @see Optimizable#pullOptPredicates	 *	 * @exception StandardException		Thrown on error	 */	public void pullOptPredicates(								OptimizablePredicateList optimizablePredicates)				throws StandardException	{		/* For most types of Optimizable, do nothing */		return;	}	/**	 * @see Optimizable#modifyAccessPath	 *	 * @exception StandardException		Thrown on error	 */	public Optimizable modifyAccessPath(JBitSet outerTables) throws StandardException	{		/* For most types of Optimizable, do nothing */		return this;	}	/** 	 * @see Optimizable#isCoveringIndex	 * @exception StandardException		Thrown on error	 */	public boolean isCoveringIndex(ConglomerateDescriptor cd) throws StandardException	{		return false;	}	/** @see Optimizable#getProperties */	public Properties getProperties()	{		return tableProperties;	}	/** @see Optimizable#setProperties */	public void setProperties(Properties tableProperties)	{		this.tableProperties = tableProperties;	}	/** @see Optimizable#verifyProperties 	 * @exception StandardException		Thrown on error	 */	public void verifyProperties(DataDictionary dDictionary)		throws StandardException	{		if (tableProperties == null)		{			return;		}		/* Check here for:		 *		invalid properties key		 *		invalid joinStrategy		 *		invalid value for hashInitialCapacity		 *		invalid value for hashLoadFactor		 *		invalid value for hashMaxCapacity		 */		boolean indexSpecified = false;		Enumeration e = tableProperties.keys();		while (e.hasMoreElements())		{			String key = (String) e.nextElement();			String value = (String) tableProperties.get(key);			if (key.equals("joinStrategy"))			{				userSpecifiedJoinStrategy = StringUtil.SQLToUpperCase(value);			}			else if (key.equals("hashInitialCapacity"))			{				initialCapacity = getIntProperty(value, key);				// verify that the specified value is valid				if (initialCapacity <= 0)				{					throw StandardException.newException(SQLState.LANG_INVALID_HASH_INITIAL_CAPACITY, 							String.valueOf(initialCapacity));				}			}			else if (key.equals("hashLoadFactor"))			{				try				{					loadFactor = Float.valueOf(value).floatValue();				}				catch (NumberFormatException nfe)				{					throw StandardException.newException(SQLState.LANG_INVALID_NUMBER_FORMAT_FOR_OVERRIDE, 							value, key);				}				// verify that the specified value is valid				if (loadFactor <= 0.0 || loadFactor > 1.0)				{					throw StandardException.newException(SQLState.LANG_INVALID_HASH_LOAD_FACTOR, 							value);				}			}			else if (key.equals("hashMaxCapacity"))			{				maxCapacity = getIntProperty(value, key);				// verify that the specified value is valid				if (maxCapacity <= 0)				{					throw StandardException.newException(SQLState.LANG_INVALID_HASH_MAX_CAPACITY, 							String.valueOf(maxCapacity));				}			}			else			{				// No other "legal" values at this time				throw StandardException.newException(SQLState.LANG_INVALID_FROM_TABLE_PROPERTY, key,					"joinStrategy");			}		}	}	/** @see Optimizable#getName 	 * @exception StandardException		Thrown on error	 */

⌨️ 快捷键说明

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