📄 singlechildresultsetnode.java
字号:
/* Derby - Class org.apache.derby.impl.sql.compile.SingleChildResultSetNode Copyright 1999, 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.context.ContextManager;import org.apache.derby.iapi.sql.compile.AccessPath;import org.apache.derby.iapi.sql.compile.CostEstimate;import org.apache.derby.iapi.sql.compile.Optimizable;import org.apache.derby.iapi.sql.compile.OptimizableList;import org.apache.derby.iapi.sql.compile.OptimizablePredicate;import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;import org.apache.derby.iapi.sql.compile.Optimizer;import org.apache.derby.iapi.sql.compile.Visitable;import org.apache.derby.iapi.sql.compile.Visitor;import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;import org.apache.derby.iapi.sql.compile.C_NodeTypes;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.TableDescriptor;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.error.StandardException;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.util.Properties;import java.util.Vector;/** * A SingleChildResultSetNode represents a result set with a single child. * * @author Jerry Brenner */abstract class SingleChildResultSetNode extends FromTable{ /** * ResultSetNode under the SingleChildResultSetNode */ ResultSetNode childResult; // Does this node have the truly... for the underlying tree protected boolean hasTrulyTheBestAccessPath; /** * Initialilzer for a SingleChildResultSetNode. * * @param childResult The child ResultSetNode * @param tableProperties Properties list associated with the table */ public void init(Object childResult, Object tableProperties) { /* correlationName is always null */ super.init(null, tableProperties); this.childResult = (ResultSetNode) childResult; /* Propagate the child's referenced table map, if one exists */ if (this.childResult.getReferencedTableMap() != null) { referencedTableMap = (JBitSet) this.childResult.getReferencedTableMap().clone(); } } /** @see Optimizable#getTrulyTheBestAccessPath */ public AccessPath getTrulyTheBestAccessPath() { if (hasTrulyTheBestAccessPath) { return super.getTrulyTheBestAccessPath(); } if (childResult instanceof Optimizable) return ((Optimizable) childResult).getTrulyTheBestAccessPath(); return super.getTrulyTheBestAccessPath(); } /** * Return the childResult from this node. * * @return ResultSetNode The childResult from this node. */ public ResultSetNode getChildResult() { return childResult; } /** * Set the childResult for this node. * * @param childResult The new childResult for this node. * * @return Nothing. */ void setChildResult(ResultSetNode childResult) { this.childResult = childResult; } /** * @see Optimizable#pullOptPredicates * * @exception StandardException Thrown on error */ public void pullOptPredicates( OptimizablePredicateList optimizablePredicates) throws StandardException { if (childResult instanceof Optimizable) { ((Optimizable) childResult).pullOptPredicates(optimizablePredicates); } } /** @see Optimizable#forUpdate */ public boolean forUpdate() { if (childResult instanceof Optimizable) { return ((Optimizable) childResult).forUpdate(); } else { return super.forUpdate(); } } /** * @see Optimizable#initAccessPaths */ public void initAccessPaths(Optimizer optimizer) { super.initAccessPaths(optimizer); if (childResult instanceof Optimizable) { ((Optimizable) childResult).initAccessPaths(optimizer); } } /** * @see Optimizable#addOrLoadBestPlanMapping * * Makes a call to add/load the plan mapping for this node, * and then makes the necessary call to recurse on this node's * child, in order to ensure that we have a full plan mapped. */ public void addOrLoadBestPlanMapping(boolean doAdd, Object planKey) throws StandardException { super.addOrLoadBestPlanMapping(doAdd, planKey); // Now walk the child. Note that if the child is not an // Optimizable and the call to child.getOptimizerImpl() // returns null, then that means we haven't tried to optimize // the child yet. So in that case there's nothing to // add/load. if (childResult instanceof Optimizable) { ((Optimizable)childResult). addOrLoadBestPlanMapping(doAdd, planKey); } else if (childResult.getOptimizerImpl() != null) { childResult.getOptimizerImpl(). addOrLoadBestPlanMappings(doAdd, planKey); } } /** * 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) { super.printSubNodes(depth); if (childResult != null) { printLabel(depth, "childResult: "); childResult.treePrint(depth + 1); } } } /** * Search to see if a query references the specifed table name. * * @param name Table name (String) to search for. * @param baseTable Whether or not name is for a base table * * @return true if found, else false * * @exception StandardException Thrown on error */ public boolean referencesTarget(String name, boolean baseTable) throws StandardException { return childResult.referencesTarget(name, baseTable); } /** * Return true if the node references SESSION schema tables (temporary or permanent) * * @return true if references SESSION schema tables, else false * * @exception StandardException Thrown on error */ public boolean referencesSessionSchema() throws StandardException { return childResult.referencesSessionSchema(); } /** * 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) { super.setLevel(level); if (childResult instanceof FromTable) { ((FromTable) childResult).setLevel(level); } } /** * Return whether or not this ResultSetNode contains a subquery with a * reference to the specified target. * * @param name The table name. * @param baseTable Whether or not the name is for a base table. * * @return boolean Whether or not a reference to the table was found. * * @exception StandardException Thrown on error */ boolean subqueryReferencesTarget(String name, boolean baseTable) throws StandardException { return childResult.subqueryReferencesTarget(name, baseTable); } /** * Put a ProjectRestrictNode on top of each FromTable in the FromList. * ColumnReferences must continue to point to the same ResultColumn, so * that ResultColumn must percolate up to the new PRN. However, * that ResultColumn will point to a new expression, a VirtualColumnNode, * which points to the FromTable and the ResultColumn that is the source for * the ColumnReference. * (The new PRN will have the original of the ResultColumnList and * the ResultColumns from that list. The FromTable will get shallow copies * of the ResultColumnList and its ResultColumns. ResultColumn.expression * will remain at the FromTable, with the PRN getting a new * VirtualColumnNode for each ResultColumn.expression.) * We then project out the non-referenced columns. If there are no referenced * columns, then the PRN's ResultColumnList will consist of a single ResultColumn * whose expression is 1. * * @param numTables Number of tables in the DML Statement * @param gbl The group by list, if any * @param fromList The from list, if any * * @return The generated ProjectRestrictNode atop the original FromTable. * * @exception StandardException Thrown on error */ public ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException { childResult = childResult.preprocess(numTables, gbl, fromList); /* Build the referenced table map */ referencedTableMap = (JBitSet) childResult.getReferencedTableMap().clone(); return this; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -