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 30 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 31 32 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 33 34 import org.apache.derby.iapi.error.StandardException; 35 36 import org.apache.derby.iapi.services.compiler.MethodBuilder; 37 38 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 39 40 import org.apache.derby.iapi.sql.Activation; 41 import org.apache.derby.iapi.sql.ResultSet; 42 43 import org.apache.derby.iapi.services.loader.GeneratedMethod; 44 45 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo; 46 47 import org.apache.derby.iapi.services.io.FormatableBitSet; 48 49 import org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl; 50 import org.apache.derby.iapi.reference.ClassName; 51 import org.apache.derby.iapi.services.classfile.VMOpcode; 52 53 import java.util.Properties ; 54 import java.util.Vector ; 55 56 62 public class IndexToBaseRowNode extends FromTable 63 { 64 protected FromBaseTable source; 65 protected ConglomerateDescriptor baseCD; 66 protected boolean cursorTargetTable; 67 protected PredicateList restrictionList; 68 protected boolean forUpdate; 69 private FormatableBitSet heapReferencedCols; 70 private FormatableBitSet indexReferencedCols; 71 72 public void init( 73 Object source, 74 Object baseCD, 75 Object resultColumns, 76 Object cursorTargetTable, 77 Object heapReferencedCols, 78 Object indexReferencedCols, 79 Object restrictionList, 80 Object forUpdate, 81 Object tableProperties) 82 { 83 super.init(null, tableProperties); 84 this.source = (FromBaseTable) source; 85 this.baseCD = (ConglomerateDescriptor) baseCD; 86 this.resultColumns = (ResultColumnList) resultColumns; 87 this.cursorTargetTable = ((Boolean ) cursorTargetTable).booleanValue(); 88 this.restrictionList = (PredicateList) restrictionList; 89 this.forUpdate = ((Boolean ) forUpdate).booleanValue(); 90 this.heapReferencedCols = (FormatableBitSet) heapReferencedCols; 91 this.indexReferencedCols = (FormatableBitSet) indexReferencedCols; 92 } 93 94 95 public boolean forUpdate() 96 { 97 return source.forUpdate(); 98 } 99 100 101 public AccessPath getTrulyTheBestAccessPath() 102 { 103 return ((Optimizable) source).getTrulyTheBestAccessPath(); 105 } 106 107 public CostEstimate getCostEstimate() 108 { 109 return source.getTrulyTheBestAccessPath().getCostEstimate(); 110 } 111 112 public CostEstimate getFinalCostEstimate() 113 { 114 return source.getFinalCostEstimate(); 115 } 116 117 132 boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, Vector fbtVector) 133 throws StandardException 134 { 135 return source.isOrderedOn(crs, permuteOrdering, fbtVector); 136 } 137 138 148 public void generate(ActivationClassBuilder acb, 149 MethodBuilder mb) 150 throws StandardException 151 { 152 ValueNode restriction = null; 153 154 158 assignResultSetNumber(); 159 160 costEstimate = getFinalCostEstimate(); 162 163 164 if (restrictionList != null) 165 { 166 restriction = restrictionList.restorePredicates(); 167 170 restrictionList = null; 171 } 172 173 179 187 188 189 int heapColRefItem = -1; 190 int indexColRefItem = -1; 191 if (heapReferencedCols != null) 192 { 193 heapColRefItem = acb.addItem(heapReferencedCols); 194 } 195 if (indexReferencedCols != null) 196 { 197 indexColRefItem = acb.addItem(indexReferencedCols); 198 } 199 200 203 int indexColMapItem = acb.addItem(new ReferencedColumnsDescriptorImpl(getIndexColMapping())); 204 long heapConglomNumber = baseCD.getConglomerateNumber(); 205 StaticCompiledOpenConglomInfo scoci = getLanguageConnectionContext(). 206 getTransactionCompile(). 207 getStaticCompiledConglomInfo(heapConglomNumber); 208 209 acb.pushGetResultSetFactoryExpression(mb); 210 211 mb.push(heapConglomNumber); 212 mb.push(acb.addItem(scoci)); 213 source.generate(acb, mb); 214 215 mb.upCast(ClassName.NoPutResultSet); 216 217 resultColumns.generateHolder(acb, mb, heapReferencedCols, indexReferencedCols); 218 mb.push(resultSetNumber); 219 mb.push(source.getBaseTableName()); 220 mb.push(heapColRefItem); 221 mb.push(indexColRefItem); 222 mb.push(indexColMapItem); 223 224 if (restriction == null) 226 { 227 mb.pushNull(ClassName.GeneratedMethod); 228 } 229 else 230 { 231 MethodBuilder userExprFun = acb.newUserExprFun(); 235 236 238 246 restriction.generate(acb, userExprFun); 247 userExprFun.methodReturn(); 248 249 userExprFun.complete(); 251 252 acb.pushMethodReference(mb, userExprFun); 259 } 260 261 mb.push(forUpdate); 262 mb.push(costEstimate.rowCount()); 263 mb.push(costEstimate.getEstimatedCost()); 264 265 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "getIndexRowToBaseRowResultSet", 266 ClassName.NoPutResultSet, 13); 267 268 269 270 274 if (cursorTargetTable) 275 { 276 acb.rememberCursorTarget(mb); 277 } 278 } 279 280 289 public boolean isOneRowResultSet() throws StandardException 290 { 291 return source.isOneRowResultSet(); 293 } 294 295 300 public boolean isNotExists() 301 { 302 return source.isNotExists(); 303 } 304 305 311 void decrementLevel(int decrement) 312 { 313 source.decrementLevel(decrement); 314 } 315 316 323 public int updateTargetLockMode() 324 { 325 return source.updateTargetLockMode(); 326 } 327 328 333 void markOrderingDependent() 334 { 335 340 source.disableBulkFetch(); 341 } 342 343 348 private int[] getIndexColMapping() 349 { 350 int rclSize = resultColumns.size(); 351 int[] indexColMapping = new int[rclSize]; 352 353 for (int index = 0; index < rclSize; index++) 354 { 355 ResultColumn rc = (ResultColumn) resultColumns.elementAt(index); 356 if (indexReferencedCols != null && rc.getExpression() instanceof VirtualColumnNode) 357 { 358 VirtualColumnNode vcn = (VirtualColumnNode) rc.getExpression(); 360 indexColMapping[index] = 361 vcn.getSourceColumn().getVirtualColumnId() - 1; 362 } 363 else 364 { 365 indexColMapping[index] = -1; 367 } 368 } 369 370 return indexColMapping; 371 } 372 373 } 374 | Popular Tags |