1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.sql.execute.CursorResultSet; 25 import org.apache.derby.iapi.error.StandardException; 26 27 import org.apache.derby.iapi.types.RowLocation; 28 import org.apache.derby.iapi.types.DataValueDescriptor; 29 30 import org.apache.derby.iapi.sql.ResultSet; 31 import org.apache.derby.iapi.sql.execute.ExecRow; 32 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 33 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 34 35 import org.apache.derby.iapi.sql.Activation; 36 37 import org.apache.derby.iapi.store.access.GroupFetchScanController; 38 import org.apache.derby.iapi.store.access.Qualifier; 39 import org.apache.derby.iapi.store.access.ScanController; 40 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo; 41 import org.apache.derby.iapi.store.access.TransactionController; 42 43 import org.apache.derby.iapi.types.RowLocation; 44 45 import org.apache.derby.iapi.services.sanity.SanityManager; 46 import org.apache.derby.iapi.services.loader.GeneratedMethod; 47 48 import org.apache.derby.iapi.services.io.FormatableBitSet; 49 50 70 class BulkTableScanResultSet extends TableScanResultSet 71 implements CursorResultSet 72 { 73 private DataValueDescriptor[][] rowArray; 74 private int curRowPosition; 75 private int numRowsInArray; 76 77 private static int OUT_OF_ROWS = 0; 78 79 87 BulkTableScanResultSet(long conglomId, 88 StaticCompiledOpenConglomInfo scoci, Activation activation, 89 GeneratedMethod resultRowAllocator, 90 int resultSetNumber, 91 GeneratedMethod startKeyGetter, int startSearchOperator, 92 GeneratedMethod stopKeyGetter, int stopSearchOperator, 93 boolean sameStartStopPosition, 94 Qualifier[][] qualifiers, 95 String tableName, 96 String userSuppliedOptimizerOverrides, 97 String indexName, 98 boolean isConstraint, 99 boolean forUpdate, 100 int colRefItem, 101 int indexColItem, 102 int lockMode, 103 boolean tableLocked, 104 int isolationLevel, 105 int rowsPerRead, 106 boolean oneRowScan, 107 double optimizerEstimatedRowCount, 108 double optimizerEstimatedCost) 109 throws StandardException 110 { 111 super(conglomId, 112 scoci, 113 activation, 114 resultRowAllocator, 115 resultSetNumber, 116 startKeyGetter, 117 startSearchOperator, 118 stopKeyGetter, 119 stopSearchOperator, 120 sameStartStopPosition, 121 qualifiers, 122 tableName, 123 userSuppliedOptimizerOverrides, 124 indexName, 125 isConstraint, 126 forUpdate, 127 colRefItem, 128 indexColItem, 129 lockMode, 130 tableLocked, 131 isolationLevel, 132 rowsPerRead, 133 oneRowScan, 134 optimizerEstimatedRowCount, 135 optimizerEstimatedCost); 136 137 if (SanityManager.DEBUG) 138 { 139 142 if (rowsPerRead == 1) 143 { 144 SanityManager.THROWASSERT( 145 "rowsPerRead not expected to be 1"); 146 } 147 150 if (oneRowScan) 151 { 152 SanityManager.THROWASSERT( 153 "oneRowScan expected to be false - " + 154 "rowsPerRead = " + rowsPerRead); 155 } 156 } 157 } 158 159 166 protected void openScanController(TransactionController tc) 167 throws StandardException 168 { 169 DataValueDescriptor[] startPositionRow = startPosition == null ? null : startPosition.getRowArray(); 170 DataValueDescriptor[] stopPositionRow = stopPosition == null ? null : stopPosition.getRowArray(); 171 172 if (qualifiers != null) 174 { 175 clearOrderableCache(qualifiers); 176 } 177 178 if (tc == null) 180 tc = activation.getTransactionController(); 181 scanController = tc.openCompiledScan( 182 activation.getResultSetHoldability(), 183 (forUpdate ? TransactionController.OPENMODE_FORUPDATE : 0), 184 lockMode, 185 isolationLevel, 186 accessedCols, 187 startPositionRow, 188 startSearchOperator, 190 qualifiers, 191 stopPositionRow, 192 stopSearchOperator, 194 scoci, 195 dcoci); 196 197 198 scanControllerOpened = true; 199 200 rowsThisScan = 0; 201 202 207 activation.informOfRowCount( 208 this, 209 scanController.getEstimatedRowCount() 210 ); 211 } 212 213 221 public void openCore() throws StandardException 222 { 223 super.openCore(); 224 229 beginTime = getCurrentTimeMillis(); 230 rowArray = new DataValueDescriptor[rowsPerRead][]; 231 232 rowArray[0] = candidate.getRowArrayClone(); 236 numRowsInArray = 0; 237 curRowPosition = -1; 238 239 openTime += getElapsedMillis(beginTime); 240 } 241 242 249 public void reopenCore() throws StandardException 250 { 251 super.reopenCore(); 252 numRowsInArray = 0; 253 curRowPosition = -1; 254 } 255 256 262 public ExecRow getNextRowCore() throws StandardException 263 { 264 ExecRow result = null; 265 266 checkCancellationFlag(); 267 268 beginTime = getCurrentTimeMillis(); 269 if (isOpen && scanControllerOpened) 270 { 271 if (currentRow == null) 272 { 273 currentRow = 274 getCompactRow(candidate, 275 accessedCols, 276 (FormatableBitSet) null, 277 isKeyed); 278 } 279 280 outer: for (;;) 281 { 282 if (curRowPosition >= numRowsInArray - 1) 283 { 284 if (reloadArray() == OUT_OF_ROWS) 285 { 286 setCurrentRow(null); 287 setRowCountIfPossible(rowsThisScan); 288 return null; 289 } 290 } 291 292 while (++curRowPosition < numRowsInArray) 293 { 294 candidate.setRowArray(rowArray[curRowPosition]); 295 currentRow = setCompactRow(candidate, currentRow); 296 rowsSeen++; 297 rowsThisScan++; 298 299 305 if (skipRow(candidate)) 306 { 307 rowsFiltered++; 308 continue; 309 } 310 311 result = currentRow; 312 break outer; 313 } 314 } 315 } 316 317 setCurrentRow(result); 318 nextTime += getElapsedMillis(beginTime); 319 return result; 320 } 321 322 326 private int reloadArray() throws StandardException 327 { 328 curRowPosition = -1; 329 numRowsInArray = 330 ((GroupFetchScanController) scanController).fetchNextGroup( 331 rowArray, (RowLocation[]) null); 332 333 return numRowsInArray; 334 335 } 336 343 public void close() throws StandardException 344 { 345 350 super.close(); 351 numRowsInArray = -1; 352 curRowPosition = -1; 353 rowArray = null; 354 } 355 356 360 protected boolean canGetInstantaneousLocks() 361 { 362 return true; 363 } 364 365 368 public boolean requiresRelocking() 369 { 370 return( 372 isolationLevel == TransactionController.ISOLATION_READ_COMMITTED || 373 isolationLevel == TransactionController.ISOLATION_READ_COMMITTED_NOHOLDLOCK || 374 isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED); 375 } 376 } 377 | Popular Tags |