📄 indexrowtobaserowresultset.java
字号:
boolean restrict = false; DataValueDescriptor restrictBoolean; long beginRT = 0; beginTime = getCurrentTimeMillis(); if ( ! isOpen ) { throw StandardException.newException(SQLState.LANG_RESULT_SET_NOT_OPEN, "next"); } /* beetle 3865, updateable cursor using index. When in-memory hash table was full, we * read forward and saved future row id's in a virtual-memory-like temp table. So if * we have rid's saved, and we are here, it must be non-covering index. Intercept it * here, so that we don't have to go to underlying index scan. We get both heap cols * and index cols together here for better performance. */ if (sourceIsForUpdateIndexScan && ((TableScanResultSet) source).futureForUpdateRows != null) { currentRowPrescanned = false; TableScanResultSet src = (TableScanResultSet) source; if (src.futureRowResultSet == null) { src.futureRowResultSet = (TemporaryRowHolderResultSet) src.futureForUpdateRows.getResultSet(); src.futureRowResultSet.openCore(); } ExecRow ridRow = src.futureRowResultSet.getNextRowCore(); currentRow = null; if (ridRow != null) { /* To maximize performance, we only use virtual memory style heap, no * position index is ever created. And we save and retrieve rows from the * in-memory part of the heap as much as possible. We can also insert after * we start retrieving, the assumption is that we delete the current row right * after we retrieve it. */ src.futureRowResultSet.deleteCurrentRow(); baseRowLocation = (RowLocation) ridRow.getColumn(1); baseCC.fetch( baseRowLocation, compactRow.getRowArray(), accessedAllCols); currentRow = compactRow; currentRowPrescanned = true; } else if (src.sourceDrained) currentRowPrescanned = true; if (currentRowPrescanned) { setCurrentRow(currentRow); nextTime += getElapsedMillis(beginTime); return currentRow; } } /* Loop until we get a row from the base page that qualifies or * there's no more rows from the index that qualify. (If the RID * returned by the index does not qualify, then we have to go back * to the index to see if there is another RID to consider.) */ do { sourceRow = source.getNextRowCore(); if (sourceRow != null) { if (SanityManager.DEBUG) { SanityManager.ASSERT( sourceRow.getColumn(sourceRow.nColumns()) instanceof RowLocation, "Last column of source row is not a RowLocation" ); } baseRowLocation = (RowLocation) sourceRow.getColumn(sourceRow.nColumns()); // Fetch the columns coming from the heap boolean row_exists = baseCC.fetch( baseRowLocation, rowArray, accessedHeapCols); if (row_exists) { /* We only need to copy columns from the index row * to our result row once as we will be reusing the * wrappers in that case. * NOTE: When the underlying ResultSet got an * instantaneous lock (BulkTableScan or HashScan) * then we will be getting all of the columns anew * from the index (indexCols == null). */ if (! copiedFromSource) { copiedFromSource = true; // Copy the columns coming from the index into resultRow for (int index = 0; index < indexCols.length; index++) { if (indexCols[index] != -1) { compactRow.setColumn( index + 1, sourceRow.getColumn(indexCols[index] + 1)); } } } setCurrentRow(compactRow); restrictBoolean = (DataValueDescriptor) ((restriction == null) ? null : restriction.invoke(activation)); restrictionTime += getElapsedMillis(beginRT); // if the result is null, we make it false -- // so the row won't be returned. restrict = (restrictBoolean == null) || ((! restrictBoolean.isNull()) && restrictBoolean.getBoolean()); } if (! restrict || ! row_exists) { rowsFiltered++; clearCurrentRow(); baseRowLocation = null; currentRow = null; } else { currentRow = compactRow; } /* Update the run time statistics */ rowsSeen++; retval = currentRow; } else { currentRow = null; clearCurrentRow(); baseRowLocation = null; retval = null; } } while ( (sourceRow != null) && (! restrict ) ); nextTime += getElapsedMillis(beginTime); return retval; } /** * If the result set has been opened, * close the open scan. * * @exception StandardException thrown on error */ public void close() throws StandardException { beginTime = getCurrentTimeMillis(); if ( isOpen ) { // we don't want to keep around a pointer to the // row ... so it can be thrown away. // REVISIT: does this need to be in a finally // block, to ensure that it is executed? clearCurrentRow(); if (closeCleanup != null) { closeCleanup.invoke(activation); // let activation tidy up } currentRow = null; if (closeBaseCCHere) { // This check should only be needed in the error case where // we may call this close() routine as part of transaction // backout cleanup if any of the following routines fail. // If one of the subsequent statements gets an error, we // will try to close this result set as part of transaction // cleanup, and without this check we get a null pointer // exception because we have null'd out baseCC. if (baseCC != null) baseCC.close(); } /* Make sure to null out baseCC since * we check for null baseCC after looking * in the StatementContext. */ baseCC = null; source.close(); super.close(); } else if (SanityManager.DEBUG) { SanityManager.DEBUG("CloseRepeatInfo","Close of IndexRowToBaseRowResultSet repeated"); } closeTime += getElapsedMillis(beginTime); } /** * Return the total amount of time spent in this ResultSet * * @param type CURRENT_RESULTSET_ONLY - time spent only in this ResultSet * ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below. * * @return long The total amount of time spent (in milliseconds). */ public long getTimeSpent(int type) { long totTime = constructorTime + openTime + nextTime + closeTime; if (type == NoPutResultSet.CURRENT_RESULTSET_ONLY) { return totTime - source.getTimeSpent(ENTIRE_RESULTSET_TREE); } else { return totTime; } } // // CursorResultSet interface // /** * Return the RowLocation of the base row. * * @see CursorResultSet * * @return the row location of the current cursor row. * @exception StandardException thrown on failure. */ public RowLocation getRowLocation() throws StandardException { return baseRowLocation; } /** * Gets last row returned. * * @see CursorResultSet * * @return the last row returned. * @exception StandardException thrown on failure. */ /* RESOLVE - this should return activation.getCurrentRow(resultSetNumber), * once there is such a method. (currentRow is redundant) */ public ExecRow getCurrentRow() throws StandardException { ExecRow sourceRow = null; if (SanityManager.DEBUG) { SanityManager.ASSERT(isOpen, "IndexRowToBaseRowResultSet is expected to be open"); } if (currentRowPrescanned) return currentRow; /* Nothing to do if we're not currently on a row */ if (currentRow == null) { return null; } /* Call the child result set to get it's current row. * If no row exists, then return null, else requalify it * before returning. */ sourceRow = ((CursorResultSet) source).getCurrentRow(); if (sourceRow != null) { /* ** Presumably, if the index row is still there, the RowLocation ** it contains is still valid. This means we don't have to ** check whether the row is still there. */ if (SanityManager.DEBUG) { SanityManager.ASSERT( sourceRow.getColumn(sourceRow.nColumns()) instanceof RowLocation, "Last column of source row is not a RowLocation" ); } baseRowLocation = (RowLocation) sourceRow.getColumn(sourceRow.nColumns()); // Fetch the columns coming from the heap boolean row_exists = baseCC.fetch( baseRowLocation, rowArray, (FormatableBitSet) null); if (row_exists) { // Copy the columns coming from the index into resultRow for (int index = 0; index < indexCols.length; index++) { if (indexCols[index] != -1) { compactRow.setColumn( index + 1, sourceRow.getColumn(indexCols[index] + 1)); } } setCurrentRow(compactRow); currentRow = compactRow; } else { clearCurrentRow(); currentRow = null; } } else { clearCurrentRow(); currentRow = null; } return currentRow; } /** * Is this ResultSet or it's source result set for update. * beetle 3865: updateable cursor using index scan. We didn't need this function * before because we couldn't use index for update cursor. * * @return Whether or not the result set is for update. */ public boolean isForUpdate() { return source.isForUpdate(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -