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

📄 frombasetable.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.FromBaseTable   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.catalog.IndexDescriptor;import org.apache.derby.iapi.util.StringUtil;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.services.io.FormatableArrayHolder;import org.apache.derby.iapi.services.io.FormatableIntHolder;import org.apache.derby.iapi.util.JBitSet;import org.apache.derby.iapi.util.ReuseFactory;import org.apache.derby.iapi.services.classfile.VMOpcode;import org.apache.derby.iapi.services.loader.GeneratedMethod;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.property.PropertyUtil;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;import org.apache.derby.iapi.sql.compile.Optimizer;import org.apache.derby.iapi.sql.compile.OptimizablePredicate;import org.apache.derby.iapi.sql.compile.Optimizable;import org.apache.derby.iapi.sql.compile.CostEstimate;import org.apache.derby.iapi.sql.compile.AccessPath;import org.apache.derby.iapi.sql.compile.JoinStrategy;import org.apache.derby.iapi.sql.compile.RowOrdering;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList;import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;import org.apache.derby.iapi.sql.execute.CursorResultSet;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.LanguageProperties;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;import org.apache.derby.iapi.store.access.StoreCostController;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.impl.sql.compile.ActivationClassBuilder;import org.apache.derby.impl.sql.execute.HashScanResultSet;import java.sql.Connection;import java.util.Enumeration;import java.util.Properties;import java.util.Vector;import java.util.HashSet;import java.util.Set;/** * A FromBaseTable represents a table in the FROM list of a DML statement, * as distinguished from a FromSubquery, which represents a subquery in the * FROM list. A FromBaseTable may actually represent a view.  During parsing, * we can't distinguish views from base tables. During binding, when we * find FromBaseTables that represent views, we replace them with FromSubqueries. * By the time we get to code generation, all FromSubqueries have been eliminated, * and all FromBaseTables will represent only true base tables. * <p> * <B>Positioned Update</B>: Currently, all columns of an updatable cursor * are selected to deal with a positioned update.  This is because we don't * know what columns will ultimately be needed from the UpdateNode above * us.  For example, consider:<pre><i> * * 	get c as 'select cint from t for update of ctinyint' *  update t set ctinyint = csmallint * * </pre></i> Ideally, the cursor only selects cint.  Then, * something akin to an IndexRowToBaseRow is generated to * take the CursorResultSet and get the appropriate columns * out of the base table from the RowLocation retunrned by the * cursor.  Then the update node can generate the appropriate * NormalizeResultSet (or whatever else it might need) to * get things into the correct format for the UpdateResultSet. * See CurrentOfNode for more information. ** @author Jeff Lichtman */public class FromBaseTable extends FromTable{	static final int UNSET = -1;	TableName		tableName;	TableDescriptor	tableDescriptor;	ConglomerateDescriptor		baseConglomerateDescriptor;	ConglomerateDescriptor[]	conglomDescs;	int				updateOrDelete;		/*	** The number of rows to bulkFetch.	** Initially it is unset.  If the user	** uses the bulkFetch table property,		** it is set to that.  Otherwise, it	** may be turned on if it isn't an updatable	** cursor and it is the right type of	** result set (more than 1 row expected to	** be returned, and not hash, which does its	** own bulk fetch, and subquery).	*/	int 			bulkFetch = UNSET;	/* We may turn off bulk fetch for a variety of reasons,	 * including because of the min optimization.  	 * bulkFetchTurnedOff is set to true in those cases.	 */	boolean			bulkFetchTurnedOff;		private double	singleScanRowCount;	private FormatableBitSet referencedCols;	private ResultColumnList templateColumns;	/* A 0-based array of column names for this table used	 * for optimizer trace.	 */	private String[] columnNames;	// true if we are to do a special scan to retrieve the last value	// in the index	private boolean specialMaxScan;	// true if we are to do a distinct scan	private boolean distinctScan;	/**	 *Information for dependent table scan for Referential Actions	 */	private boolean raDependentScan;	private String raParentResultSetId;	private long fkIndexConglomId;		private int[] fkColArray;	/**	 * Restriction as a PredicateList	 */	PredicateList baseTableRestrictionList;	PredicateList nonBaseTableRestrictionList;	PredicateList restrictionList;	PredicateList storeRestrictionList;	PredicateList nonStoreRestrictionList;	PredicateList requalificationRestrictionList;	public static final int UPDATE = 1;	public static final int DELETE = 2;	/* Variables for EXISTS FBTs */	private boolean	existsBaseTable;	private boolean	isNotExists;  //is a NOT EXISTS base table	private JBitSet dependencyMap;	private boolean getUpdateLocks;	/**	 * Initializer for a table in a FROM list.	 *	 * @param tableName			The name of the table	 * @param correlationName	The correlation name	 * @param derivedRCL		The derived column list	 * @param tableProperties	The Properties list associated with the table.	 *	 *  - OR -	 *	 * @param tableName			The name of the table	 * @param correlationName	The correlation name	 * @param updateOrDelete	Table is being updated/deleted from. 	 * @param derivedRCL		The derived column list	 */	public void init(							Object arg1,							Object arg2,				  			Object arg3,							Object arg4)	{		if (arg3 instanceof Integer)		{			init(arg2, null);			this.tableName = (TableName) arg1;			this.updateOrDelete = ((Integer) arg3).intValue();			resultColumns = (ResultColumnList) arg4;		}		else		{			init(arg2, arg4);			this.tableName = (TableName) arg1;			resultColumns = (ResultColumnList) arg3;		}		templateColumns = resultColumns;	}	/**	 * no LOJ reordering for base table.	 */	public boolean LOJ_reorderable(int numTables)				throws StandardException	{		return false;	}	public JBitSet LOJgetReferencedTables(int numTables)				throws StandardException	{		JBitSet map = new JBitSet(numTables);		fillInReferencedTableMap(map);		return map;	}	/*	 * Optimizable interface.	 */	/**	 * @see Optimizable#nextAccessPath	 *	 * @exception StandardException		Thrown on error	 */	public boolean nextAccessPath(Optimizer optimizer,									OptimizablePredicateList predList,									RowOrdering rowOrdering)					throws StandardException	{		String userSpecifiedIndexName = getUserSpecifiedIndexName();		AccessPath ap = getCurrentAccessPath();		ConglomerateDescriptor currentConglomerateDescriptor =												ap.getConglomerateDescriptor();		optimizer.trace(Optimizer.CALLING_NEXT_ACCESS_PATH,					   ((predList == null) ? 0 : predList.size()),					   0, 0.0, getExposedName());		/*		** Remove the ordering of the current conglomerate descriptor,		** if any.		*/		rowOrdering.removeOptimizable(getTableNumber());		// RESOLVE: This will have to be modified to step through the		// join strategies as well as the conglomerates.		if (userSpecifiedIndexName != null)		{			/*			** User specified an index name, so we should look at only one			** index.  If there is a current conglomerate descriptor, and there			** are no more join strategies, we've already looked at the index,			** so go back to null.			*/			if (currentConglomerateDescriptor != null)			{				if ( ! super.nextAccessPath(optimizer,											predList,											rowOrdering) )				{					currentConglomerateDescriptor = null;				}			}			else			{				optimizer.trace(Optimizer.LOOKING_FOR_SPECIFIED_INDEX,								tableNumber, 0, 0.0, userSpecifiedIndexName);				if (StringUtil.SQLToUpperCase(userSpecifiedIndexName).equals("NULL"))				{					/* Special case - user-specified table scan */					currentConglomerateDescriptor =						tableDescriptor.getConglomerateDescriptor(										tableDescriptor.getHeapConglomerateId()									);				}				else				{					/* User-specified index name */					getConglomDescs();									for (int index = 0; index < conglomDescs.length; index++)					{						currentConglomerateDescriptor = conglomDescs[index];						String conglomerateName =							currentConglomerateDescriptor.getConglomerateName();						if (conglomerateName != null)						{							/* Have we found the desired index? */							if (conglomerateName.equals(userSpecifiedIndexName))							{								break;							}						}					}					/* We should always find a match */					if (SanityManager.DEBUG)					{						if (currentConglomerateDescriptor == null)						{							SanityManager.THROWASSERT(								"Expected to find match for forced index " +								userSpecifiedIndexName);						}					}				}				if ( ! super.nextAccessPath(optimizer,											predList,											rowOrdering))				{					if (SanityManager.DEBUG)					{						SanityManager.THROWASSERT("No join strategy found");					}				}			}		}		else		{			if (currentConglomerateDescriptor != null)			{				/* 				** Once we have a conglomerate descriptor, cycle through				** the join strategies (done in parent).				*/				if ( ! super.nextAccessPath(optimizer,											predList,											rowOrdering))				{					/*					** When we're out of join strategies, go to the next					** conglomerate descriptor.					*/					currentConglomerateDescriptor = getNextConglom(currentConglomerateDescriptor);					/*					** New conglomerate, so step through join strategies					** again.					*/					resetJoinStrategies(optimizer);					if ( ! super.nextAccessPath(optimizer,												predList,												rowOrdering))					{						if (SanityManager.DEBUG)						{							SanityManager.THROWASSERT("No join strategy found");						}					}				}			}			else			{				/* Get the first conglomerate descriptor */				currentConglomerateDescriptor = getFirstConglom();				if ( ! super.nextAccessPath(optimizer,											predList,											rowOrdering))				{					if (SanityManager.DEBUG)					{						SanityManager.THROWASSERT("No join strategy found");					}				}			}		}		if (currentConglomerateDescriptor == null)		{			optimizer.trace(Optimizer.NO_MORE_CONGLOMERATES, tableNumber, 0, 0.0, null);		}		else		{			currentConglomerateDescriptor.setColumnNames(columnNames);			optimizer.trace(Optimizer.CONSIDERING_CONGLOMERATE, tableNumber, 0, 0.0, 							currentConglomerateDescriptor);		}

⌨️ 快捷键说明

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