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

📄 predicatelist.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
						removeOptPredicate(thisPred);					// restore origin				}				else if (SanityManager.DEBUG)				{					SanityManager.ASSERT(false,						"pushOptPredicate expected to be true");				}			}			else			{				/*				** We're not pushing the predicates down, so put them at the				** beginning of this predicate list in index order.				*/				removeOptPredicate(thisPred);				addOptPredicate(thisPred, i);			}		}	}	/**	 * Add a Predicate to the list.	 *	 * @param predicate	A Predicate to add to the list	 *	 * @return	Nothing	 *	 * @exception StandardException		Thrown on error	 */	public void addPredicate(Predicate predicate) throws StandardException	{		if (predicate.isStartKey())			numberOfStartPredicates++;		if (predicate.isStopKey())			numberOfStopPredicates++;		if (predicate.isQualifier())			numberOfQualifiers++;		addElement(predicate);	}	/**	 * Transfer the non-qualifiers from this predicate list to the specified      * predicate list.	 * This is useful for arbitrary hash join, where we need to separate the 2      * as the qualifiers get applied when probing the hash table and the      * non-qualifiers get * applied afterwards.	 *	 * @param optTable	The optimizable that we want qualifiers for	 * @param otherPL	ParameterList for non-qualifiers	 *	 * @return	Nothing	 *	 * @exception StandardException		Thrown on error	 */	protected void transferNonQualifiers(Optimizable optTable, PredicateList otherPL)		throws StandardException	{		/* Walk list backwards since we can delete while		 * traversing the list.		 */		for (int index = size() - 1; index >= 0; index--)		{			Predicate	pred = (Predicate) elementAt(index);			RelationalOperator relop = pred.getRelop();			// Transfer each non-qualifier			if (relop == null || ! relop.isQualifier(optTable))			{				pred.clearScanFlags();				removeElementAt(index);				otherPL.addElement(pred);			}		}		// Mark all remaining predicates as qualifiers		markAllPredicatesQualifiers();	}	/**	 * Categorize the predicates in the list.  Initially, this means	 * building a bit map of the referenced tables for each predicate.	 *	 * @return None.	 * @exception StandardException			Thrown on error	 */	public void categorize()		throws StandardException	{		int size = size();		for (int index = 0; index < size; index++)		{			((Predicate) elementAt(index)).categorize();		}	}	/**	 * Prints the sub-nodes of this object.  See QueryTreeNode.java for	 * how tree printing is supposed to work.	 *	 * @param depth		The depth of this node in the tree	 *	 * @return	Nothing	 */	public void printSubNodes(int depth)	{		if (SanityManager.DEBUG)		{			Predicate		predicate;			super.printSubNodes(depth);			for (int index = 0; index < size(); index++)			{				predicate = (Predicate) elementAt(index);				predicate.treePrint(depth + 1);			}		}	}	/**	 *  Eliminate predicates of the form:	 *							AndNode	 *							/	   \	 *	true BooleanConstantNode		true BooleanConstantNode	 *  This is useful when checking for a NOP PRN as the	 *  Like transformation on c1 like 'ASDF%' can leave	 *  one of these predicates in the list.	 *	 * @return Nothing.	 */	public void eliminateBooleanTrueAndBooleanTrue()	{		/* Walk list backwards since we can delete while		 * traversing the list.		 */		for (int index = size() - 1; index >= 0; index--)		{			AndNode			nextAnd;			/* Look at the current predicate from the predicate list */			nextAnd = ((Predicate) elementAt(index)).getAndNode();			if ((nextAnd.getLeftOperand().isBooleanTrue()) &&				(nextAnd.getRightOperand().isBooleanTrue()))			{				removeElementAt(index);			}		}	}	/**	 * Rebuild a constant expression tree from the remaining constant      * predicates and delete those entries from the PredicateList.	 * The rightOperand of every top level AndNode is always a true      * BooleanConstantNode, so we can blindly overwrite that pointer.	 * Optimizations:	 *	 * We take this opportunity to eliminate:	 *							AndNode	 *						 /		   \	 *	true BooleanConstantNode	true BooleanConstantNode	 *	 * We remove the AndNode if the predicate list is a single AndNode:	 *					AndNode	 *				   /	   \	 *		LeftOperand			RightOperand	 *	 * becomes:	 *					LeftOperand	 *	 * If the leftOperand of any AndNode is False, then the entire expression	 * will be False.  The expression simple becomes:	 *					false BooleanConstantNode	 *	 * @return ValueNode	The rebuilt expression tree.	 */	public ValueNode restoreConstantPredicates()	{		AndNode			nextAnd;		AndNode			falseAnd = null;		ValueNode		restriction = null;		/* Walk list backwards since we can delete while		 * traversing the list.		 */		for (int index = size() - 1; index >= 0; index--)		{			/* Look at the current predicate from the predicate list */			nextAnd = ((Predicate) elementAt(index)).getAndNode();			// Skip over the predicate if it is not a constant expression			if (! nextAnd.isConstantExpression())			{				continue;			}			// This node is a constant expression, so we can remove it from the list			removeElementAt(index);			/* We can skip over TRUE AND TRUE */			if ((nextAnd.getLeftOperand().isBooleanTrue()) &&				(nextAnd.getRightOperand().isBooleanTrue()))			{				continue;			}			/* Remember if we see a false BooleanConstantNode */			if (nextAnd.getLeftOperand().isBooleanFalse())			{				falseAnd = nextAnd;			}			if (restriction != null)			{				nextAnd.setRightOperand(restriction);				/* If any of the predicates is nullable, then the resulting				 * tree must be nullable.				 */				if (restriction.getTypeServices().isNullable())				{					nextAnd.getTypeServices().setNullability(true);				}			}			restriction = nextAnd;		}		/* If restriction is a single AndNode, then it's rightOperand must be		 * a true BooleanConstantNode.  We simply chop out the AndNode and set          * restriction to AndNode.leftOperand.		 */		if ((restriction != null) && 			(((AndNode) restriction).getRightOperand().isBooleanTrue()))		{			restriction = ((AndNode) restriction).getLeftOperand();		}		else if (falseAnd != null)		{			/* Expression is ... AND FALSE AND ...			 * Replace the entire expression with a false BooleanConstantNode. 			 */			restriction = falseAnd.getLeftOperand();		}		return restriction;	}	/**	 * Rebuild an expression tree from the remaining predicates and delete those	 * entries from the PredicateList.	 * The rightOperand of every top level AndNode is always a true      * BooleanConstantNode, so we can blindly overwrite that pointer.	 * Optimizations:	 *	 * We take this opportunity to eliminate:	 *						AndNode	 *					   /	   \	 *	true BooleanConstantNode	true BooleanConstantNode	 *	 * We remove the AndNode if the predicate list is a single AndNode:	 *					AndNode	 *				   /	   \	 *		LeftOperand			RightOperand	 *	 * becomes:	 *					LeftOperand	 *	 * If the leftOperand of any AndNode is False, then the entire expression	 * will be False.  The expression simple becomes:	 *					false BooleanConstantNode	 *	 * @return ValueNode	The rebuilt expression tree.	 */	public ValueNode restorePredicates()	{		AndNode			nextAnd;		AndNode			falseAnd = null;		ValueNode		restriction = null;		int size = size();		for (int index = 0; index < size; index++)		{			nextAnd = ((Predicate) elementAt(index)).getAndNode();			/* We can skip over TRUE AND TRUE */			if ((nextAnd.getLeftOperand().isBooleanTrue()) &&				(nextAnd.getRightOperand().isBooleanTrue()))			{				continue;			}			/* Remember if we see a false BooleanConstantNode */			if (nextAnd.getLeftOperand().isBooleanFalse())			{				falseAnd = nextAnd;			}			if (restriction != null)			{				nextAnd.setRightOperand(restriction);				/* If any of the predicates is nullable, then the resulting				 * tree must be nullable.				 */				if (restriction.getTypeServices().isNullable())				{					nextAnd.getTypeServices().setNullability(true);				}			}			restriction = nextAnd;		}		/* If restriction is a single AndNode, then it's rightOperand must be		 * a true BooleanConstantNode.  We simply chop out the AndNode and set          * restriction to AndNode.leftOperand.		 */		if ((restriction != null) && 			(((AndNode) restriction).getRightOperand().isBooleanTrue()))		{			restriction = ((AndNode) restriction).getLeftOperand();		}		else if (falseAnd != null)		{			/* Expression is ... AND FALSE AND ...			 * Replace the entire expression with a simple false              * BooleanConstantNode. 			 */			restriction = falseAnd.getLeftOperand();		}		/* Remove all predicates from the list */		removeAllElements();		return restriction;	}	/**	 * Remap all ColumnReferences in this tree to be clones of the	 * underlying expression.	 *	 * @return Nothing.	 *	 * @exception StandardException			Thrown on error	 */	public void remapColumnReferencesToExpressions() throws StandardException	{		Predicate		pred;		int size = size();		for (int index = 0; index < size; index++)		{			pred = (Predicate) elementAt(index);			pred.setAndNode((AndNode) 						pred.getAndNode().remapColumnReferencesToExpressions());		}	}	/**	 * Break apart the search clause into matching a PredicateList	 * where each top level predicate is a separate element in the list.	 * Build a bit map to represent the FromTables referenced within each	 * top level predicate.	 * NOTE: We want the rightOperand of every AndNode to be true, in order	 * to simplify the algorithm for putting the predicates back into the tree.	 * (As we put an AndNode back into the tree, we can ignore it's rightOperand.)	 *	 * @param numTables			Number of tables in the DML Statement	 * @param searchClause	The search clause to operate on.	 *	 * @return None.	 *	 * @exception StandardException		Thrown on error	 */	void pullExpressions(int numTables,								 ValueNode searchClause)				throws StandardException	{		AndNode		thisAnd;		AndNode		topAnd;		JBitSet		newJBitSet;		Predicate	newPred;		BooleanConstantNode	trueNode = null;		if (searchClause != null)		{			topAnd = (AndNode) searchClause;			searchClause = null;			trueNode = (BooleanConstantNode) getNodeFactory().getNode(											C_NodeTypes.BOOLEAN_CONSTANT_NODE,											Boolean.TRUE,											getContextManager());						while (topAnd.getRightOperand() instanceof AndNode)			{				/* Break out the next top AndNode */				thisAnd = topAnd;				topAnd = (AndNode) topAnd.getRightOperand();				thisAnd.setRightOperand(null);				/* Set the rightOperand to true */				thisAnd.setRightOperand(trueNode);				/* Add the top AndNode to the PredicateList */				newJBitSet = new JBitSet(numTables);				newPred = (Predicate) getNodeFactory().getNode(											C_NodeTypes.PREDICATE,											thisAnd,											newJBitSet,											getContextManager());				addPredicate(newPred);			}						/* Add the last top AndNode to the PredicateList */			newJBitSet = new JBitSet(numTables);			newPred = (Predicate) getNodeFactory().getNode(											C_NodeTypes.PREDICATE,											topAnd,											newJBitSet,											getContextManager());			addPredicate(newPred);		}	}	/** 	 * XOR fromMap with the referenced table map in every remaining	 * Predicate in the list.  This is useful when pushing down 	 * multi-table predicates.	 * 	 * @param fromMap	The JBitSet to XOR with.	 *	 * @return Nothing.	 */	public void xorReferencedSet(JBitSet fromMap)	{		Predicate		predicate;		int size = size();

⌨️ 快捷键说明

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