📄 fromtable.java
字号:
} protected CostEstimate getCostEstimate(Optimizer optimizer) { if (costEstimate == null) { costEstimate = optimizer.newCostEstimate(); } return costEstimate; } /* ** This gets a cost estimate for doing scratch calculations. Typically, ** it will hold the estimated cost of a conglomerate. If the optimizer ** decides the scratch cost is lower than the best cost estimate so far, ** it will copy the scratch cost to the non-scratch cost estimate, ** which is allocated above. */ protected CostEstimate getScratchCostEstimate(Optimizer optimizer) { if (scratchCostEstimate == null) { scratchCostEstimate = optimizer.newCostEstimate(); } return scratchCostEstimate; } /** * Set the cost estimate in this node to the given cost estimate. */ protected void setCostEstimate(CostEstimate newCostEstimate) { costEstimate = getCostEstimate(); costEstimate.setCost(newCostEstimate); } /** * Assign the cost estimate in this node to the given cost estimate. */ protected void assignCostEstimate(CostEstimate newCostEstimate) { costEstimate = newCostEstimate; } /** * Convert this object to a String. See comments in QueryTreeNode.java * for how this should be done for tree printing. * * @return This object as a String */ public String toString() { if (SanityManager.DEBUG) { return "correlation Name: " + correlationName + "\n" + (corrTableName != null ? corrTableName.toString() : "null") + "\n" + "tableNumber " + tableNumber + "\n" + "level " + level + "\n" + super.toString(); } else { return ""; } } /** * Return a ResultColumnList with all of the columns in this table. * (Used in expanding '*'s.) * NOTE: Since this method is for expanding a "*" in the SELECT list, * ResultColumn.expression will be a ColumnReference. * * @param allTableName The qualifier on the "*" * * @return ResultColumnList List of result columns from this table. * * @exception StandardException Thrown on error */ public ResultColumnList getResultColumnsForList(TableName allTableName, ResultColumnList inputRcl, TableName tableName) throws StandardException { ResultColumnList rcList = null; ResultColumn resultColumn; ValueNode valueNode; String columnName; TableName exposedName; TableName toCompare; /* If allTableName is non-null, then we must check to see if it matches * our exposed name. */ if(correlationName == null) toCompare = tableName; else { if(allTableName != null) toCompare = makeTableName(allTableName.getSchemaName(),correlationName); else toCompare = makeTableName(null,correlationName); } if ( allTableName != null && ! allTableName.equals(toCompare)) { return null; } /* Cache exposed name for this table. * The exposed name becomes the qualifier for each column * in the expanded list. */ if (correlationName == null) { exposedName = tableName; } else { exposedName = makeTableName(null, correlationName); } rcList = (ResultColumnList) getNodeFactory().getNode( C_NodeTypes.RESULT_COLUMN_LIST, getContextManager()); /* Build a new result column list based off of resultColumns. * NOTE: This method will capture any column renaming due to * a derived column list. */ int inputSize = inputRcl.size(); for (int index = 0; index < inputSize; index++) { // Build a ResultColumn/ColumnReference pair for the column // columnName = ((ResultColumn) inputRcl.elementAt(index)).getName(); valueNode = (ValueNode) getNodeFactory().getNode( C_NodeTypes.COLUMN_REFERENCE, columnName, exposedName, getContextManager()); resultColumn = (ResultColumn) getNodeFactory().getNode( C_NodeTypes.RESULT_COLUMN, columnName, valueNode, getContextManager()); // Build the ResultColumnList to return // rcList.addResultColumn(resultColumn); } return rcList; } /** * Push expressions down to the first ResultSetNode which can do expression * evaluation and has the same referenced table map. * RESOLVE - This means only pushing down single table expressions to * ProjectRestrictNodes today. Once we have a better understanding of how * the optimizer will work, we can push down join clauses. * * @param predicateList The PredicateList. * * @exception StandardException Thrown on error */ void pushExpressions(PredicateList predicateList) throws StandardException { if (SanityManager.DEBUG) { SanityManager.ASSERT(predicateList != null, "predicateList is expected to be non-null"); } } /** * Get the exposed name for this table, which is the name that can * be used to refer to it in the rest of the query. * * @return The exposed name of this table. * * @exception StandardException Thrown on error */ public String getExposedName() throws StandardException { if (SanityManager.DEBUG) SanityManager.THROWASSERT( "getExposedName() not expected to be called for " + this.getClass().getName()); return null; } /** * Set the table # for this table. * * @param tableNumber The table # for this table. * * @return None. */ public void setTableNumber(int tableNumber) { /* This should only be called if the tableNumber has not been set yet */ if (SanityManager.DEBUG) SanityManager.ASSERT(this.tableNumber == -1, "tableNumber is not expected to be already set"); this.tableNumber = tableNumber; } /** * Return a TableName node representing this FromTable. * Expect this to be overridden (and used) by subclasses * that may set correlationName to null. * * @return a TableName node representing this FromTable. * @exception StandardException Thrown on error */ public TableName getTableName() throws StandardException { if (correlationName == null) return null; if (corrTableName == null) { corrTableName = makeTableName(null, correlationName); } return corrTableName; } /** * Set the (query block) level (0-based) for this FromTable. * * @param level The query block level for this FromTable. * * @return Nothing */ public void setLevel(int level) { this.level = level; } /** * Get the (query block) level (0-based) for this FromTable. * * @return int The query block level for this FromTable. */ public int getLevel() { return level; } /** * Decrement (query block) level (0-based) for this FromTable. * This is useful when flattening a subquery. * * @param decrement The amount to decrement by. */ void decrementLevel(int decrement) { if (SanityManager.DEBUG) { /* NOTE: level doesn't get propagated * to nodes generated after binding. */ if (level < decrement && level != 0) { SanityManager.THROWASSERT( "level (" + level + ") expected to be >= decrement (" + decrement + ")"); } } /* NOTE: level doesn't get propagated * to nodes generated after binding. */ if (level > 0) { level -= decrement; } } /** * Get a schema descriptor for the given table. * Uses this.corrTableName. * * @return Schema Descriptor * * @exception StandardException throws on schema name * that doesn't exist */ public SchemaDescriptor getSchemaDescriptor() throws StandardException { return getSchemaDescriptor(corrTableName); } /** * Get a schema descriptor for the given table. * * @param TableName the table name * * @return Schema Descriptor * * @exception StandardException throws on schema name * that doesn't exist */ public SchemaDescriptor getSchemaDescriptor(TableName tableName) throws StandardException { SchemaDescriptor sd; sd = getSchemaDescriptor(tableName.getSchemaName()); return sd; } /** * Determine whether or not the specified name is an exposed name in * the current query block. * * @param name The specified name to search for as an exposed name. * @param schemaName Schema name, if non-null. * @param exactMatch Whether or not we need an exact match on specified schema and table * names or match on table id. * * @return The FromTable, if any, with the exposed name. * * @exception StandardException Thrown on error */ protected FromTable getFromTableByName(String name, String schemaName, boolean exactMatch) throws StandardException { // Only FromBaseTables have schema names if (schemaName != null) { return null; } if (getExposedName().equals(name)) { return this; } return null; } /** * Is this FromTable a JoinNode which can be flattened into * the parents FromList. * * @return boolean Whether or not this FromTable can be flattened. */ public boolean isFlattenableJoinNode() { return false; } /** * no LOJ reordering for this FromTable. */ public boolean LOJ_reorderable(int numTables) throws StandardException { return false; } /** * Transform any Outer Join into an Inner Join where applicable. * (Based on the existence of a null intolerant * predicate on the inner table.) * * @param predicateTree The predicate tree for the query block * * @return The new tree top (OuterJoin or InnerJoin). * * @exception StandardException Thrown on error */ public FromTable transformOuterJoins(ValueNode predicateTree, int numTables) throws StandardException { return this; } /** * Fill the referencedTableMap with this ResultSetNode. * * @param passedMap The table map to fill in. * * @return Nothing. */ public void fillInReferencedTableMap(JBitSet passedMap) { if (tableNumber != -1) { passedMap.set(tableNumber); } } /** * Mark as updatable all the columns in the result column list of this * FromBaseTable that match the columns in the given update column list. * If the list is null, it means all the columns are updatable. * * @param updateColumns A Vector representing the columns * that can be updated. */ protected void markUpdatableByCursor(Vector updateColumns) { resultColumns.markUpdatableByCursor(updateColumns); } /** * Flatten this FromTable into the outer query block. The steps in * flattening are: * o Mark all ResultColumns as redundant, so that they are "skipped over" * at generate(). * o Append the wherePredicates to the outer list. * o Return the fromList so that the caller will merge the 2 lists * * @param rcl The RCL from the outer query * @param outerPList PredicateList to append wherePredicates to. * @param sql The SubqueryList from the outer query * @param gbl The group by list, if any * * @return FromList The fromList from the underlying SelectNode. * * @exception StandardException Thrown on error */ public FromList flatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl) throws StandardException { if (SanityManager.DEBUG) { SanityManager.THROWASSERT( "flatten() not expected to be called for " + this); } return null; } /** * Optimize any subqueries that haven't been optimized any where * else. This is useful for a RowResultSetNode as a derived table * because it doesn't get optimized otherwise. * * @return Nothing. * * @exception StandardException Thrown on error */ void optimizeSubqueries(DataDictionary dd, double rowCount) throws StandardException { } /** * Tell the given RowOrdering about any columns that are constant * due to their being equality comparisons with constant expressions. */ protected void tellRowOrderingAboutConstantColumns( RowOrdering rowOrdering, OptimizablePredicateList predList) { /* ** Tell the RowOrdering about columns that are equal to constant ** expressions. */ if (predList != null) { for (int i = 0; i < predList.size(); i++) { Predicate pred = (Predicate) predList.getOptPredicate(i); /* Is it an = comparison with a constant expression? */ if (pred.equalsComparisonWithConstantExpression(this)) { /* Get the column being compared to the constant */ ColumnReference cr = pred.getRelop().getColumnOperand(this); if (cr != null) { /* Tell RowOrdering that the column is always ordered */ rowOrdering.columnAlwaysOrdered(this, cr.getColumnNumber()); } } } } } public boolean needsSpecialRCLBinding() { return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -