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

📄 binaryrelationaloperatornode.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 */	protected int columnOnOneSide(Optimizable optTable)	{		ColumnReference	cr;		boolean			left = false;		/* Is a column on the left */		if (leftOperand instanceof ColumnReference)		{			/*			** The left operand is a column reference.			** Is it the correct column?			*/			cr = (ColumnReference) leftOperand;			if (cr.getTableNumber() == optTable.getTableNumber())			{				/* Key column found on left */				return LEFT;			}		}		if (rightOperand instanceof ColumnReference)		{			/*			** The right operand is a column reference.			** Is it the correct column?			*/			cr = (ColumnReference) rightOperand;			if (cr.getTableNumber() == optTable.getTableNumber())			{				/* Key column found on right */				return RIGHT;			}		}		return NEITHER;	}	/** @see RelationalOperator#usefulStopKey */	public boolean usefulStopKey(Optimizable optTable)	{		/*		** Determine whether this operator is a useful start operator		** with knowledge of whether the key column is on the left or right.		*/		int	columnSide = columnOnOneSide(optTable);		if (columnSide == NEITHER)			return false;		else			return usefulStopKey(columnSide == LEFT);	}	/**	 * Determine whether this comparison operator is a useful stop key	 * with knowledge of whether the key column is on the left or right.	 *	 * @param left	true means the key column is on the left, false means	 *				it is on the right.	 *	 * @return	true if this is a useful stop key	 */	/** @see RelationalOperator#generateAbsoluteColumnId */	public void generateAbsoluteColumnId(MethodBuilder mb,											   Optimizable optTable)	{		// Get the absolute column position for the column		int columnPosition = getAbsoluteColumnPosition(optTable);		mb.push(columnPosition);	}	/** @see RelationalOperator#generateRelativeColumnId */	public void generateRelativeColumnId(MethodBuilder mb,											   Optimizable optTable)	{		// Get the absolute column position for the column		int columnPosition = getAbsoluteColumnPosition(optTable);		// Convert the absolute to the relative 0-based column position		columnPosition = optTable.convertAbsoluteToRelativeColumnPosition(								columnPosition);		mb.push(columnPosition);	}	/**	 * Get the absolute 0-based column position of the ColumnReference from 	 * the conglomerate for this Optimizable.	 *	 * @param optTable	The Optimizable	 *	 * @return The absolute 0-based column position of the ColumnReference	 */	private int getAbsoluteColumnPosition(Optimizable optTable)	{		ColumnReference	cr;		ConglomerateDescriptor bestCD;		int columnPosition;		if (keyColumnOnLeft(optTable))		{			cr = (ColumnReference) leftOperand;		}		else		{			cr = (ColumnReference) rightOperand;		}		bestCD = optTable.getTrulyTheBestAccessPath().												getConglomerateDescriptor();		/*		** Column positions are one-based, store is zero-based.		*/		columnPosition = cr.getSource().getColumnPosition();		/*		** If it's an index, find the base column position in the index		** and translate it to an index column position.		*/		if (bestCD != null && bestCD.isIndex())		{			columnPosition = bestCD.getIndexDescriptor().			  getKeyColumnPosition(columnPosition);			if (SanityManager.DEBUG)			{				SanityManager.ASSERT(columnPosition > 0,					"Base column not found in index");			}		}		// return the 0-based column position		return columnPosition - 1;	}	/**	 * @exception StandardException		Thrown on error	 */	public void generateQualMethod(ExpressionClassBuilder acb,								   MethodBuilder mb,								   Optimizable optTable)						throws StandardException	{		/* Generate a method that returns the expression */		MethodBuilder qualMethod = acb.newUserExprFun();		/*		** Generate the expression that's on the opposite side		** of the key column		*/		if (keyColumnOnLeft(optTable))		{			rightOperand.generateExpression(acb, qualMethod);		}		else		{			leftOperand.generateExpression(acb, qualMethod);		}		qualMethod.methodReturn();		qualMethod.complete();		/* push an expression that evaluates to the GeneratedMethod */		acb.pushMethodReference(mb, qualMethod);	}	/** @see RelationalOperator#generateOrderedNulls */	public void generateOrderedNulls(MethodBuilder mb)	{		mb.push(false);	}	/** @see RelationalOperator#orderedNulls */	public boolean orderedNulls()	{		return false;	}	/** @see RelationalOperator#isQualifier 	 *	 * @exception StandardException		Thrown on error	 */	public boolean isQualifier(Optimizable optTable)		throws StandardException	{		FromTable	ft;		ValueNode	otherSide = null;		JBitSet		tablesReferenced;		ColumnReference	cr = null;		boolean	found = false;		ft = (FromTable) optTable;		if (leftOperand instanceof ColumnReference)		{			/*			** The left operand is a column reference.			** Is it the correct column?			*/			cr = (ColumnReference) leftOperand;			if (cr.getTableNumber() == ft.getTableNumber())			{				otherSide = rightOperand;				found = true;			}		}		if ( ( ! found) && (rightOperand instanceof ColumnReference) )		{			/*			** The right operand is a column reference.			** Is it the correct column?			*/			cr = (ColumnReference) rightOperand;			if (cr.getTableNumber() == ft.getTableNumber())			{				otherSide = leftOperand;				found = true;			}		}		/* Have we found a ColumnReference on either side? */		if ( ! found)		{			/*			** Neither side is a ColumnReference to the table we're looking			** for, so it can't be a Qualifier			*/			return false;		}		/*		** One side is a ColumnReference to the correct table.  It is a		** Qualifier if the other side does not refer to the table we are		** optimizing.		*/		tablesReferenced = otherSide.getTablesReferenced();		return  ! (tablesReferenced.get(ft.getTableNumber()));	}	/** 	 * @see RelationalOperator#getOrderableVariantType 	 *	 * @exception StandardException	thrown on error	 */	public int getOrderableVariantType(Optimizable optTable) 		throws StandardException	{		/* The Qualifier's orderable is on the opposite side from		 * the key column.		 */		if (keyColumnOnLeft(optTable))		{			return rightOperand.getOrderableVariantType();		}		else		{			return leftOperand.getOrderableVariantType();		}	}	/** @see RelationalOperator#compareWithKnownConstant */	public boolean compareWithKnownConstant(Optimizable optTable, boolean considerParameters)	{		ValueNode	node = null;		node = keyColumnOnLeft(optTable) ? rightOperand : leftOperand;		if (considerParameters)		{			return (node instanceof ConstantNode) ||						((node.isParameterNode()) &&						 (((ParameterNode)node).getDefaultValue() != null));		}		else		{			return node instanceof ConstantNode;		}	}	/**	 * @see RelationalOperator#getCompareValue	 *	 * @exception StandardException		Thrown on error	 */	public DataValueDescriptor getCompareValue(Optimizable optTable)         throws StandardException	{		ValueNode	node = null;		/* The value being compared to is on the opposite side from		** the key column.		*/		node = keyColumnOnLeft(optTable) ? rightOperand : leftOperand;		if (node instanceof ConstantNode) 		{			return ((ConstantNode)node).getValue();		}		else if (node.isParameterNode())		{			return ((ParameterNode)node).getDefaultValue();		}		else		{				return null;		}	}	/**	 * Return 50% if this is a comparison with a boolean column, a negative	 * selectivity otherwise.	 */	protected double booleanSelectivity(Optimizable optTable)	{		TypeId	typeId = null;		double				retval = -1.0d;		int					columnSide;		columnSide = columnOnOneSide(optTable);		if (columnSide == LEFT)			typeId = leftOperand.getTypeId();		else if (columnSide == RIGHT)			typeId = rightOperand.getTypeId();		if (typeId != null && (typeId.getJDBCTypeId() == Types.BIT ||		typeId.getJDBCTypeId() == JDBC30Translation.SQL_TYPES_BOOLEAN))			retval = 0.5d;		return retval;	}	/**	 * The methods generated for this node all are on Orderable.  	 * Overrides this method	 * in BooleanOperatorNode for code generation purposes.	 */	public String getReceiverInterfaceName() {	    return ClassName.DataValueDescriptor;	}		/**	 * Returns the negation of this operator; negation of Equals is NotEquals.	 */	BinaryOperatorNode getNegation(ValueNode leftOperand, 										  ValueNode rightOperand)		throws StandardException	{		BinaryOperatorNode negation;		if (SanityManager.DEBUG)			SanityManager.ASSERT(dataTypeServices != null,								 "dataTypeServices is expected to be non-null");		/* xxxRESOLVE: look into doing this in place instead of allocating a new node */		negation = (BinaryOperatorNode)			getNodeFactory().getNode(getNegationNode(),									 leftOperand, rightOperand,									 getContextManager());		negation.setType(dataTypeServices);		return negation;	}	/* map current node to its negation */	private int getNegationNode()	{		switch (getNodeType())		{			case C_NodeTypes.BINARY_EQUALS_OPERATOR_NODE:				return C_NodeTypes.BINARY_NOT_EQUALS_OPERATOR_NODE;			case C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE:				return C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE;			case C_NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE:				return C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE;			case C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE:				return C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE;							case C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE:				return C_NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE;			case C_NodeTypes.BINARY_NOT_EQUALS_OPERATOR_NODE:								return C_NodeTypes.BINARY_EQUALS_OPERATOR_NODE;		}				if (SanityManager.DEBUG)		{			SanityManager.THROWASSERT("getNegationNode called with invalid nodeType: " + getNodeType());		}		return -1;	}			/**	 * is this is useful start key? for example a predicate of the from	 * <em>column Lessthan 5</em> is not a useful start key but is a useful stop	 * key. However <em>5 Lessthan column </em> is a useful start key.	 *	 * @param columnOnLeft 	is true if the column is the left hand side of the	 * binary operator.	 */	protected boolean usefulStartKey(boolean columnOnLeft)	{		switch (operatorType)		{			case RelationalOperator.EQUALS_RELOP:				return true;			case RelationalOperator.NOT_EQUALS_RELOP:				return false;			case RelationalOperator.GREATER_THAN_RELOP:			case RelationalOperator.GREATER_EQUALS_RELOP:				// col > 1				return columnOnLeft;			case RelationalOperator.LESS_THAN_RELOP:			case RelationalOperator.LESS_EQUALS_RELOP:				// col < 1				return !columnOnLeft;			default:				return false;		}	}	/** @see RelationalOperator#usefulStopKey */	protected boolean usefulStopKey(boolean columnOnLeft)	{		switch (operatorType)		{			case RelationalOperator.EQUALS_RELOP:				return true;			case RelationalOperator.NOT_EQUALS_RELOP:				return false;			case RelationalOperator.GREATER_THAN_RELOP:			case RelationalOperator.GREATER_EQUALS_RELOP:				// col > 1				return !columnOnLeft;

⌨️ 快捷键说明

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