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.Optimizable; 27 import org.apache.derby.iapi.sql.compile.OptimizablePredicate; 28 import org.apache.derby.iapi.sql.compile.OptimizablePredicateList; 29 import org.apache.derby.iapi.sql.compile.Optimizer; 30 import org.apache.derby.iapi.sql.compile.CostEstimate; 31 import org.apache.derby.iapi.sql.compile.OptimizableList; 32 import org.apache.derby.iapi.sql.compile.Visitable; 33 import org.apache.derby.iapi.sql.compile.Visitor; 34 import org.apache.derby.iapi.sql.compile.RequiredRowOrdering; 35 import org.apache.derby.iapi.sql.compile.RowOrdering; 36 import org.apache.derby.iapi.sql.compile.AccessPath; 37 import org.apache.derby.iapi.reference.ClassName; 38 39 40 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 41 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 42 43 import org.apache.derby.iapi.sql.Activation; 44 import org.apache.derby.iapi.sql.ResultSet; 45 46 import org.apache.derby.iapi.error.StandardException; 47 48 import org.apache.derby.iapi.store.access.TransactionController; 49 50 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 51 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 52 53 import org.apache.derby.iapi.services.compiler.MethodBuilder; 54 55 import org.apache.derby.iapi.services.loader.GeneratedMethod; 56 57 import org.apache.derby.iapi.services.sanity.SanityManager; 58 59 import org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl; 60 61 import org.apache.derby.iapi.services.io.FormatableArrayHolder; 62 import org.apache.derby.iapi.services.io.FormatableIntHolder; 63 import org.apache.derby.iapi.util.JBitSet; 64 import org.apache.derby.iapi.services.classfile.VMOpcode; 65 66 import java.util.Properties ; 67 68 73 74 public class HashTableNode extends SingleChildResultSetNode 75 { 76 PredicateList searchPredicateList; 77 PredicateList joinPredicateList; 78 79 SubqueryList pSubqueryList; 80 SubqueryList rSubqueryList; 81 82 96 97 public void init( 98 Object childResult, 99 Object tableProperties, 100 Object resultColumns, 101 Object searchPredicateList, 102 Object joinPredicateList, 103 Object accessPath, 104 Object costEstimate, 105 Object pSubqueryList, 106 Object rSubqueryList, 107 Object hashKeyColumns) 108 { 109 super.init(childResult, tableProperties); 110 this.resultColumns = (ResultColumnList) resultColumns; 111 this.searchPredicateList = (PredicateList) searchPredicateList; 112 this.joinPredicateList = (PredicateList) joinPredicateList; 113 this.trulyTheBestAccessPath = (AccessPathImpl) accessPath; 114 this.costEstimate = (CostEstimate) costEstimate; 115 this.pSubqueryList = (SubqueryList) pSubqueryList; 116 this.rSubqueryList = (SubqueryList) rSubqueryList; 117 setHashKeyColumns((int[]) hashKeyColumns); 118 } 119 120 123 124 129 public Optimizable modifyAccessPath(JBitSet outerTables, Optimizer optimizer) 130 throws StandardException 131 { 132 return this; 133 } 134 135 141 142 public void printSubNodes(int depth) 143 { 144 if (SanityManager.DEBUG) 145 { 146 super.printSubNodes(depth); 147 148 if (searchPredicateList != null) 149 { 150 printLabel(depth, "searchPredicateList: "); 151 searchPredicateList.treePrint(depth + 1); 152 } 153 154 if (joinPredicateList != null) 155 { 156 printLabel(depth, "joinPredicateList: "); 157 joinPredicateList.treePrint(depth + 1); 158 } 159 } 160 } 161 162 174 public void generate(ActivationClassBuilder acb, 175 MethodBuilder mb) 176 throws StandardException 177 { 178 if (SanityManager.DEBUG) 179 SanityManager.ASSERT(resultColumns != null, "Tree structure bad"); 180 181 generateMinion( acb, mb, false); 182 } 183 184 195 196 public void generateResultSet(ExpressionClassBuilder acb, 197 MethodBuilder mb) 198 throws StandardException 199 { 200 generateMinion( acb, mb, true); 201 } 202 203 211 212 private void generateMinion(ExpressionClassBuilder acb, 213 MethodBuilder mb, boolean genChildResultSet) 214 throws StandardException 215 { 216 MethodBuilder userExprFun; 217 ValueNode searchClause = null; 218 ValueNode equijoinClause = null; 219 220 221 225 verifyProperties(getDataDictionary()); 226 227 229 230 if (searchPredicateList != null) 231 { 232 searchPredicateList.removeRedundantPredicates(); 234 searchClause = searchPredicateList.restorePredicates(); 235 238 searchPredicateList = null; 239 } 240 241 247 255 256 257 258 259 int[] mapArray = resultColumns.mapSourceColumns(); 261 int mapArrayItem = acb.addItem(new ReferencedColumnsDescriptorImpl(mapArray)); 262 263 265 FormatableIntHolder[] fihArray = 266 FormatableIntHolder.getFormatableIntHolders(hashKeyColumns()); 267 FormatableArrayHolder hashKeyHolder = new FormatableArrayHolder(fihArray); 268 int hashKeyItem = acb.addItem(hashKeyHolder); 269 270 288 289 acb.pushGetResultSetFactoryExpression(mb); 290 291 if (genChildResultSet) 292 childResult.generateResultSet(acb, mb); 293 else 294 childResult.generate((ActivationClassBuilder) acb, mb); 295 296 299 assignResultSetNumber(); 300 301 304 if (pSubqueryList != null && pSubqueryList.size() > 0) 305 { 306 pSubqueryList.setPointOfAttachment(resultSetNumber); 307 if (SanityManager.DEBUG) 308 { 309 SanityManager.ASSERT(pSubqueryList.size() == 0, 310 "pSubqueryList.size() expected to be 0"); 311 } 312 } 313 if (rSubqueryList != null && rSubqueryList.size() > 0) 314 { 315 rSubqueryList.setPointOfAttachment(resultSetNumber); 316 if (SanityManager.DEBUG) 317 { 318 SanityManager.ASSERT(rSubqueryList.size() == 0, 319 "rSubqueryList.size() expected to be 0"); 320 } 321 } 322 323 costEstimate = childResult.getFinalCostEstimate(); 325 326 if (searchClause == null) 328 { 329 mb.pushNull(ClassName.GeneratedMethod); 330 } 331 else 332 { 333 userExprFun = acb.newUserExprFun(); 337 338 340 348 349 searchClause.generateExpression(acb, userExprFun); 350 userExprFun.methodReturn(); 351 352 353 356 357 userExprFun.complete(); 359 360 acb.pushMethodReference(mb, userExprFun); 367 } 368 371 joinPredicateList.generateQualifiers(acb, mb, (Optimizable) childResult, 372 false); 373 374 378 if (reflectionNeededForProjection()) 379 { 380 389 390 resultColumns.generateCore(acb, mb, false); 391 } 392 else 393 { 394 mb.pushNull(ClassName.GeneratedMethod); 395 } 396 397 mb.push(resultSetNumber); 398 mb.push(mapArrayItem); 399 mb.push(resultColumns.reusableResult()); 400 mb.push(hashKeyItem); 401 mb.push(false); 402 mb.push(-1L); 403 mb.push(initialCapacity); 404 mb.push(loadFactor); 405 mb.push(costEstimate.singleScanRowCount()); 406 mb.push(costEstimate.getEstimatedCost()); 407 408 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "getHashTableResultSet", 409 ClassName.NoPutResultSet, 14); 410 } 411 412 420 public Visitable accept(Visitor v) 421 throws StandardException 422 { 423 if (v.skipChildren(this)) 424 { 425 return v.visit(this); 426 } 427 428 Visitable returnNode = super.accept(v); 429 430 if (searchPredicateList != null && !v.stopTraversal()) 431 { 432 searchPredicateList = (PredicateList)searchPredicateList.accept(v); 433 } 434 435 if (joinPredicateList != null && !v.stopTraversal()) 436 { 437 joinPredicateList = (PredicateList)joinPredicateList.accept(v); 438 } 439 440 return returnNode; 441 } 442 } 443 | Popular Tags |