1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.context.ContextManager; 25 26 import org.apache.derby.iapi.sql.compile.AccessPath; 27 import org.apache.derby.iapi.sql.compile.CostEstimate; 28 import org.apache.derby.iapi.sql.compile.Optimizable; 29 import org.apache.derby.iapi.sql.compile.OptimizableList; 30 import org.apache.derby.iapi.sql.compile.OptimizablePredicate; 31 import org.apache.derby.iapi.sql.compile.OptimizablePredicateList; 32 import org.apache.derby.iapi.sql.compile.Optimizer; 33 import org.apache.derby.iapi.sql.compile.Visitable; 34 import org.apache.derby.iapi.sql.compile.Visitor; 35 import org.apache.derby.iapi.sql.compile.RequiredRowOrdering; 36 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 37 38 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 39 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 40 41 import org.apache.derby.iapi.sql.Activation; 42 import org.apache.derby.iapi.sql.ResultSet; 43 44 import org.apache.derby.iapi.error.StandardException; 45 46 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 47 48 import org.apache.derby.iapi.services.sanity.SanityManager; 49 50 import org.apache.derby.iapi.util.JBitSet; 51 52 import java.util.Properties ; 53 import java.util.Vector ; 54 55 60 61 abstract class SingleChildResultSetNode extends FromTable 62 { 63 66 ResultSetNode childResult; 67 68 protected boolean hasTrulyTheBestAccessPath; 70 71 72 78 79 public void init(Object childResult, Object tableProperties) 80 { 81 82 super.init(null, tableProperties); 83 this.childResult = (ResultSetNode) childResult; 84 85 86 if (this.childResult.getReferencedTableMap() != null) 87 { 88 referencedTableMap = 89 (JBitSet) this.childResult.getReferencedTableMap().clone(); 90 } 91 } 92 93 94 public AccessPath getTrulyTheBestAccessPath() 95 { 96 if (hasTrulyTheBestAccessPath) 97 { 98 return super.getTrulyTheBestAccessPath(); 99 } 100 101 if (childResult instanceof Optimizable) 102 return ((Optimizable) childResult).getTrulyTheBestAccessPath(); 103 104 return super.getTrulyTheBestAccessPath(); 105 } 106 107 112 public ResultSetNode getChildResult() 113 { 114 return childResult; 115 } 116 117 122 void setChildResult(ResultSetNode childResult) 123 { 124 this.childResult = childResult; 125 } 126 127 132 public void pullOptPredicates( 133 OptimizablePredicateList optimizablePredicates) 134 throws StandardException 135 { 136 if (childResult instanceof Optimizable) 137 { 138 ((Optimizable) childResult).pullOptPredicates(optimizablePredicates); 139 } 140 } 141 142 143 public boolean forUpdate() 144 { 145 if (childResult instanceof Optimizable) 146 { 147 return ((Optimizable) childResult).forUpdate(); 148 } 149 else 150 { 151 return super.forUpdate(); 152 } 153 } 154 155 158 public void initAccessPaths(Optimizer optimizer) 159 { 160 super.initAccessPaths(optimizer); 161 if (childResult instanceof Optimizable) 162 { 163 ((Optimizable) childResult).initAccessPaths(optimizer); 164 } 165 } 166 167 175 public void updateBestPlanMap(short action, 176 Object planKey) throws StandardException 177 { 178 super.updateBestPlanMap(action, planKey); 179 180 186 if (childResult instanceof Optimizable) 187 { 188 ((Optimizable)childResult). 189 updateBestPlanMap(action, planKey); 190 } 191 else if (childResult.getOptimizerImpl() != null) 192 { 193 childResult.getOptimizerImpl(). 194 updateBestPlanMaps(action, planKey); 195 } 196 } 197 198 204 205 public void printSubNodes(int depth) 206 { 207 if (SanityManager.DEBUG) 208 { 209 super.printSubNodes(depth); 210 211 if (childResult != null) 212 { 213 printLabel(depth, "childResult: "); 214 childResult.treePrint(depth + 1); 215 } 216 } 217 } 218 219 229 public boolean referencesTarget(String name, boolean baseTable) 230 throws StandardException 231 { 232 return childResult.referencesTarget(name, baseTable); 233 } 234 235 242 public boolean referencesSessionSchema() 243 throws StandardException 244 { 245 return childResult.referencesSessionSchema(); 246 } 247 248 253 public void setLevel(int level) 254 { 255 super.setLevel(level); 256 if (childResult instanceof FromTable) 257 { 258 ((FromTable) childResult).setLevel(level); 259 } 260 } 261 262 273 boolean subqueryReferencesTarget(String name, boolean baseTable) 274 throws StandardException 275 { 276 return childResult.subqueryReferencesTarget(name, baseTable); 277 } 278 279 303 304 public ResultSetNode preprocess(int numTables, 305 GroupByList gbl, 306 FromList fromList) 307 throws StandardException 308 { 309 childResult = childResult.preprocess(numTables, gbl, fromList); 310 311 312 referencedTableMap = (JBitSet) childResult.getReferencedTableMap().clone(); 313 314 return this; 315 } 316 317 328 public ResultSetNode addNewPredicate(Predicate predicate) 329 throws StandardException 330 { 331 childResult = childResult.addNewPredicate(predicate); 332 return this; 333 } 334 335 346 public void pushExpressions(PredicateList predicateList) 347 throws StandardException 348 { 349 if (childResult instanceof FromTable) 350 { 351 ((FromTable) childResult).pushExpressions(predicateList); 352 } 353 } 354 355 367 public boolean flattenableInFromSubquery(FromList fromList) 368 { 369 372 373 return false; 374 } 375 376 384 public ResultSetNode ensurePredicateList(int numTables) 385 throws StandardException 386 { 387 return this; 388 } 389 390 402 403 public ResultSetNode optimize(DataDictionary dataDictionary, 404 PredicateList predicates, 405 double outerRows) 406 throws StandardException 407 { 408 411 childResult = childResult.optimize( 412 dataDictionary, 413 predicates, 414 outerRows); 415 416 Optimizer optimizer = 417 getOptimizer( 418 (FromList) getNodeFactory().getNode( 419 C_NodeTypes.FROM_LIST, 420 getNodeFactory().doJoinOrderOptimization(), 421 getContextManager()), 422 predicates, 423 dataDictionary, 424 (RequiredRowOrdering) null); 425 costEstimate = optimizer.newCostEstimate(); 426 costEstimate.setCost(childResult.getCostEstimate().getEstimatedCost(), 427 childResult.getCostEstimate().rowCount(), 428 childResult.getCostEstimate().singleScanRowCount()); 429 430 return this; 431 } 432 433 438 public ResultSetNode modifyAccessPaths() throws StandardException 439 { 440 childResult = childResult.modifyAccessPaths(); 441 442 return this; 443 } 444 445 450 public ResultSetNode changeAccessPath() throws StandardException 451 { 452 childResult = childResult.changeAccessPath(); 453 return this; 454 } 455 456 469 protected FromTable getFromTableByName(String name, String schemaName, boolean exactMatch) 470 throws StandardException 471 { 472 return childResult.getFromTableByName(name, schemaName, exactMatch); 473 } 474 475 481 void decrementLevel(int decrement) 482 { 483 super.decrementLevel(decrement); 484 childResult.decrementLevel(decrement); 485 } 486 487 494 public int updateTargetLockMode() 495 { 496 return childResult.updateTargetLockMode(); 497 } 498 499 514 boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, Vector fbtVector) 515 throws StandardException 516 { 517 return childResult.isOrderedOn(crs, permuteOrdering, fbtVector); 518 } 519 520 529 public boolean isOneRowResultSet() throws StandardException 530 { 531 return childResult.isOneRowResultSet(); 533 } 534 535 540 public boolean isNotExists() 541 { 542 return childResult.isNotExists(); 543 } 544 545 553 protected boolean reflectionNeededForProjection() 554 { 555 return ! (resultColumns.allExpressionsAreColumns(childResult)); 556 } 557 558 566 void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl) 567 throws StandardException 568 { 569 childResult.replaceDefaults(ttd, tcl); 570 } 571 572 577 void markOrderingDependent() 578 { 579 childResult.markOrderingDependent(); 580 } 581 582 588 public CostEstimate getFinalCostEstimate() 589 throws StandardException 590 { 591 597 if (costEstimate == null) 598 return childResult.getFinalCostEstimate(); 599 else 600 { 601 return costEstimate; 602 } 603 } 604 605 613 public Visitable accept(Visitor v) 614 throws StandardException 615 { 616 if (v.skipChildren(this)) 617 { 618 return v.visit(this); 619 } 620 621 Visitable returnNode = super.accept(v); 622 623 if (childResult != null && !v.stopTraversal()) 624 { 625 childResult = (ResultSetNode)childResult.accept(v); 626 } 627 628 return returnNode; 629 } 630 } 631 | Popular Tags |