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

📄 predicatelist.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*   Derby - Class org.apache.derby.impl.sql.compile.PredicateList   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.loader.GeneratedMethod;import org.apache.derby.iapi.services.compiler.MethodBuilder;import org.apache.derby.iapi.services.compiler.LocalField;import org.apache.derby.iapi.reference.ClassName;import org.apache.derby.iapi.services.classfile.VMOpcode;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface;import org.apache.derby.iapi.sql.compile.OptimizablePredicate;import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;import org.apache.derby.iapi.sql.compile.Optimizable;import org.apache.derby.iapi.sql.compile.AccessPath;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.execute.ExecIndexRow;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.Row;import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.dictionary.StatisticsDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;import org.apache.derby.impl.sql.compile.ActivationClassBuilder;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.util.JBitSet;import java.lang.reflect.Modifier;import java.sql.Types;import java.util.ArrayList;import java.util.Enumeration;import java.util.Properties;import java.util.Vector;/** * A PredicateList represents the list of top level predicates. * Each top level predicate consists of an AndNode whose leftOperand is the * top level predicate and whose rightOperand is true.  It extends  * QueryTreeNodeVector. * * @author Jerry Brenner */public class PredicateList extends QueryTreeNodeVector implements OptimizablePredicateList{	private int	numberOfStartPredicates;	private int numberOfStopPredicates;	private int numberOfQualifiers;	public PredicateList()	{	}	/*	 * OptimizableList interface	 */	/**	 * @see org.apache.derby.iapi.sql.compile.OptimizablePredicateList#getOptPredicate	 */	public OptimizablePredicate getOptPredicate(int index)	{		return (OptimizablePredicate) elementAt(index);	}	/**	 * @see org.apache.derby.iapi.sql.compile.OptimizablePredicateList#removeOptPredicate	 *	 * @exception StandardException		Thrown on error	 */	public final void removeOptPredicate(int predCtr) throws StandardException	{		Predicate predicate = (Predicate) remove(predCtr);        if (predicate.isStartKey())            numberOfStartPredicates--;        if (predicate.isStopKey())            numberOfStopPredicates--;        if (predicate.isQualifier())            numberOfQualifiers--;	}	/**	 * Another version of removeOptPredicate that takes the Predicate to be	 * removed, rather than the position of the Predicate.  This is not part	 * any interface (yet).	 */	public final void removeOptPredicate(OptimizablePredicate pred)	{		removeElement((Predicate) pred);        if (pred.isStartKey())            numberOfStartPredicates--;        if (pred.isStopKey())            numberOfStopPredicates--;        if (pred.isQualifier())            numberOfQualifiers--;	}	/** @see OptimizablePredicateList#addOptPredicate */	public void addOptPredicate(OptimizablePredicate optPredicate)	{		addElement((Predicate)optPredicate);        if (optPredicate.isStartKey())            numberOfStartPredicates++;        if (optPredicate.isStopKey())            numberOfStopPredicates++;        if (optPredicate.isQualifier())            numberOfQualifiers++;	}	/**	 * Another flavor of addOptPredicate that inserts the given predicate	 * at a given position.  This is not yet part of any interface.	 */	public void addOptPredicate(OptimizablePredicate optPredicate, int position)	{		insertElementAt((Predicate) optPredicate, position);        if (optPredicate.isStartKey())            numberOfStartPredicates++;        if (optPredicate.isStopKey())            numberOfStopPredicates++;        if (optPredicate.isQualifier())            numberOfQualifiers++;	}	/**	 * @see OptimizablePredicateList#useful	 * @exception StandardException		Thrown on error	 */	public boolean useful(Optimizable optTable, ConglomerateDescriptor cd)		throws StandardException	{		boolean			retval = false;		/*		** Most of this assumes BTREE,		** so should move into a configurable module		*/		/* If the conglomerate isn't an index, the predicate isn't useful */		if ( ! cd.isIndex())			return false;		/*		** A PredicateList is useful for a BTREE if it contains a relational		** operator directly below a top-level AND comparing the first column		** in the index to an expression that does not contain a reference		** to the table in question.  Let's look for that.		*/		int size = size();		for (int index = 0; index < size; index++)		{			Predicate	pred = (Predicate) elementAt(index);			/*			** Skip over it if it's not a relational operator (this includes			** BinaryComparisonOperators and IsNullNodes.			*/			RelationalOperator relop = pred.getRelop();			boolean isIn = false;			InListOperatorNode inNode = null;			if (relop == null)			{				/* if it's "in" operator, we generate dynamic start and stop key				 * to improve index scan performance, beetle 3858.				 */				if (pred.getAndNode().getLeftOperand() instanceof InListOperatorNode &&					! ((InListOperatorNode)pred.getAndNode().getLeftOperand()).getTransformed())				{					isIn = true;					inNode = (InListOperatorNode) pred.getAndNode().getLeftOperand();				}				else					continue;			}			/*			** If the relational operator is neither a useful start key			** nor a useful stop key for this table, it is not useful			** for limiting an index scan.			*/			if ( (! isIn) && ( ! relop.usefulStartKey(optTable) ) &&				 ( ! relop.usefulStopKey(optTable) ) )			{				continue;			}			/*			** Look for a the first column of the index on one side of the			** relop.  If it's not found, this Predicate is not optimizable.			*/			ColumnReference indexCol = null;			if (isIn)			{				if (inNode.getLeftOperand() instanceof ColumnReference)				{					indexCol = (ColumnReference) inNode.getLeftOperand();					if (indexCol.getColumnNumber() !=                             cd.getIndexDescriptor().baseColumnPositions()[0])                    {						indexCol = null;                    }				}			}			else			{				indexCol =                     relop.getColumnOperand(                        optTable,                         cd.getIndexDescriptor().baseColumnPositions()[0]);			}			if (indexCol == null)			{				continue;			}			/*			** Look at the expression that the index column is compared to.			** If it contains columns from the table in question, the			** Predicate is not optimizable.			*/			if ((isIn && inNode.selfReference(indexCol)) ||                 (! isIn && relop.selfComparison(indexCol)))			{				continue;			}						/* The Predicate is optimizable */			retval = true;			break;		}		return retval;	}	/**	 * @see OptimizablePredicateList#pushUsefulPredicates	 *	 * @exception StandardException		Thrown on error	 */	public void pushUsefulPredicates(Optimizable optTable)						throws StandardException	{		AccessPath ap = optTable.getTrulyTheBestAccessPath();		orderUsefulPredicates(optTable,							ap.getConglomerateDescriptor(),							true,							ap.getNonMatchingIndexScan(),							ap.getCoveringIndexScan());	}	/**	 * @see OptimizablePredicateList#classify	 *	 * @exception StandardException		Thrown on error	 */	public void classify(Optimizable optTable, ConglomerateDescriptor cd)			throws StandardException	{		/*		** Don't push the predicates - at this point, we are only determining		** which predicates are useful.  Also, we don't know yet whether		** we have a non-matching index scan or a covering index scan -		** this method call will help determine that.  So, let's say they're		** false for now.		*/		orderUsefulPredicates(optTable, cd, false, false, false);	}	/** @see OptimizablePredicateList#markAllPredicatesQualifiers */	public void markAllPredicatesQualifiers()	{		int size = size();		for (int index = 0; index < size; index++)		{			((Predicate) elementAt(index)).markQualifier();		}		numberOfQualifiers = size;	}	/**	 * @see OptimizablePredicateList#hasOptimizableEqualityPredicate	 *	 * @exception StandardException		Thrown on error	 */	public boolean hasOptimizableEqualityPredicate(Optimizable optTable,													  int columnNumber,													  boolean isNullOkay)							throws StandardException	{		int size = size();		for (int index = 0; index < size; index++)		{			AndNode			andNode;			Predicate		predicate;			predicate = (Predicate) elementAt(index);			andNode = (AndNode) predicate.getAndNode();			// skip non-equality predicates			ValueNode opNode = andNode.getLeftOperand();			if (opNode.optimizableEqualityNode(optTable,											   columnNumber,											   isNullOkay))			{				return true;			}		}		return false;	}	/**	 * @see OptimizablePredicateList#hasOptimizableEquijoin	 *	 * @exception StandardException		Thrown on error	 */	public boolean hasOptimizableEquijoin(Optimizable optTable,										  int columnNumber)					throws StandardException	{		int size = size();		for (int index = 0; index < size; index++)		{			AndNode			andNode;			Predicate		predicate;			predicate = (Predicate) elementAt(index);			// This method is used by HashJoinStrategy to determine if			// there are any equality predicates that can be used to			// perform a hash join (see the findHashKeyColumns()			// method in HashJoinStrategy.java).  That said, if the			// predicate was scoped and pushed down from an outer query,			// then it's no longer possible to perform the hash join			// because one of the operands is in an outer query and			// the other (scoped) operand is down in a subquery. Thus			// we skip this predicate if it has been scoped.			if (predicate.isScopedForPush())			{				continue;			}			andNode = (AndNode) predicate.getAndNode();			ValueNode opNode = andNode.getLeftOperand();			if ( ! opNode.optimizableEqualityNode(optTable,												  columnNumber,												  false))			{				continue;			}			/*			** Skip comparisons that are not qualifiers for the table			** in question.			*/			if ( ! ((RelationalOperator) opNode).isQualifier(optTable))			{				continue;			}			/*			** Skip non-join comparisons.			*/			if (predicate.getReferencedMap().hasSingleBitSet())			{				continue;			}			// We found a match			return true;		}		return false;	}	/**	 * @see OptimizablePredicateList#putOptimizableEqualityPredicateFirst	 *	 * @exception StandardException		Thrown on error	 */	public void putOptimizableEqualityPredicateFirst(Optimizable optTable,														int columnNumber)					throws StandardException	{		int size = size();		for (int index = 0; index < size; index++)		{			Predicate		predicate = (Predicate) elementAt(index);			AndNode			andNode;

⌨️ 快捷键说明

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