Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7E4C5C6C6 for ; Thu, 7 Aug 2014 15:35:54 +0000 (UTC) Received: (qmail 81811 invoked by uid 500); 7 Aug 2014 15:35:54 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 81788 invoked by uid 500); 7 Aug 2014 15:35:54 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 81779 invoked by uid 99); 7 Aug 2014 15:35:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2014 15:35:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Aug 2014 15:35:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6FFC82389446; Thu, 7 Aug 2014 15:35:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1616511 - in /db/derby/code/branches/10.11: ./ java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java java/engine/org/apache/derby/impl/sql/execute/ValidateCheckConstraintResultSet.java Date: Thu, 07 Aug 2014 15:35:24 -0000 To: derby-commits@db.apache.org From: dag@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140807153524.6FFC82389446@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dag Date: Thu Aug 7 15:35:23 2014 New Revision: 1616511 URL: http://svn.apache.org/r1616511 Log: DERBY-6674 Cleanup brittle code in ValidateCheckConstraintResultSet Backport from trunk as svn merge -c 1614963 https://svn.apache.org/repos/asf/db/derby/code/trunk Patch derby-6674. Refactors the code by reusing getNextRowCore (to avoid the redundancy) for ValidateCheckConstraintResultSet but abstracting out the loop control, which is overridden by ValidateCheckConstraintResultSet. Modified: db/derby/code/branches/10.11/ (props changed) db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/ValidateCheckConstraintResultSet.java Propchange: db/derby/code/branches/10.11/ ------------------------------------------------------------------------------ Merged /db/derby/code/trunk:r1614963 Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java?rev=1616511&r1=1616510&r2=1616511&view=diff ============================================================================== --- db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java (original) +++ db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java Thu Aug 7 15:35:23 2014 @@ -446,6 +446,11 @@ class TableScanResultSet extends ScanRes openTime += getElapsedMillis(beginTime); } + + boolean loopControl(boolean moreRows) throws StandardException { + return scanController.fetchNext(candidate.getRowArray()); + } + /** * Return the next row (if any) from the scan (if open). * @@ -477,11 +482,15 @@ class TableScanResultSet extends ScanRes if (scanControllerOpened) { - boolean moreRows; + boolean moreRows = true; - while (moreRows = - scanController.fetchNext(candidate.getRowArray())) + while (true) { + // loop control overriden by subclass + // ValidateCheckConstraintResultSet.. + if (! (moreRows = loopControl(moreRows))) { + break; + } rowsSeen++; rowsThisScan++; Modified: db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/ValidateCheckConstraintResultSet.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/ValidateCheckConstraintResultSet.java?rev=1616511&r1=1616510&r2=1616511&view=diff ============================================================================== --- db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/ValidateCheckConstraintResultSet.java (original) +++ db/derby/code/branches/10.11/java/engine/org/apache/derby/impl/sql/execute/ValidateCheckConstraintResultSet.java Thu Aug 7 15:35:23 2014 @@ -27,11 +27,8 @@ import org.apache.derby.iapi.reference.S import org.apache.derby.iapi.services.loader.GeneratedMethod; import org.apache.derby.iapi.sql.Activation; import org.apache.derby.iapi.sql.execute.CursorResultSet; -import org.apache.derby.iapi.sql.execute.ExecRow; import org.apache.derby.iapi.store.access.Qualifier; import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo; -import org.apache.derby.iapi.types.RowLocation; -import org.apache.derby.shared.common.sanity.SanityManager; /** * Special result set used when checking deferred CHECK constraints. Activated @@ -97,120 +94,22 @@ final class ValidateCheckConstraintResul optimizerEstimatedCost); } - /** - * Return the current row (if any) from the base table scan, positioned - * correctly by our caller (ProjectRestrictNode). It overrides - * getNextRowCore from TableSCanResultSet, by using "fetch" instead of - * "fetchNext" on the underlying controller, otherwise it's identical. - * (This means it's probably over-general for the usage we have of it, - * but it felt safer to keep the code as similar as possible.) - * @return the row retrieved - * @exception StandardException thrown on failure to get next row - */ @Override - public ExecRow getNextRowCore() throws StandardException { - if (isXplainOnlyMode()) { - return null; - } - - checkCancellationFlag(); - - if (SanityManager.DEBUG) { - SanityManager.ASSERT(scanRepositioned); - } - - if (currentRow == null || scanRepositioned) { - currentRow = getCompactRow(candidate, accessedCols, isKeyed); - } - - beginTime = getCurrentTimeMillis(); - - ExecRow result = null; - - if (isOpen && !nextDone) { - // Only need to do 1 next per scan for 1 row scans. - nextDone = oneRowScan; - - if ( scanControllerOpened) { - boolean moreRows = true; - - while (moreRows) { - try { - scanController.fetch(candidate.getRowArray()); - } catch (StandardException e) { - // Offending rows may have been deleted in the - // transaction. As for compress, we won't even get here - // since we use a normal SELECT query then. - if (e.getSQLState().equals( - ExceptionUtil.getSQLStateFromIdentifier( - SQLState.AM_RECORD_NOT_FOUND))) { - moreRows = false; - break; - } else { - throw e; - } - } - - rowsSeen++; - rowsThisScan++; - - /* - ** Skip rows where there are start or stop positioners - ** that do not implement ordered null semantics and - ** there are columns in those positions that contain - ** null. - ** No need to check if start and stop positions are the - ** same, since all predicates in both will be ='s, - ** and hence evaluated in the store. - */ - if ((! sameStartStopPosition) && skipRow(candidate)) { - rowsFiltered++; - continue; - } - - /* beetle 3865, updateable cursor use index. If we have a - * hash table that holds updated records, and we hit it - * again, skip it, and remove it from hash since we can't - * hit it again, and we have a space in hash, so can stop - * scanning forward. - */ - if (past2FutureTbl != null) { - RowLocation rowLoc = (RowLocation)currentRow.getColumn( - currentRow.nColumns()); - if (past2FutureTbl.remove(rowLoc) != null) { - continue; - } - } - - result = currentRow; - break; - } - - /* - ** If we just finished a full scan of the heap, update - ** the number of rows in the scan controller. - ** - ** NOTE: It would be more efficient to only update the - ** scan controller if the optimizer's estimated number of - ** rows were wrong by more than some threshold (like 10%). - ** This would require a little more work than I have the - ** time for now, however, as the row estimate that is given - ** to this result set is the total number of rows for all - ** scans, not the number of rows per scan. - */ - if (! moreRows) { - setRowCountIfPossible(rowsThisScan); - currentRow = null; - } - } - } - - setCurrentRow(result); - currentRowIsValid = true; - scanRepositioned = false; - qualify = true; - - nextTime += getElapsedMillis(beginTime); - return result; + boolean loopControl(boolean moreRows) throws StandardException { + try { + scanController.fetch(candidate.getRowArray()); + } catch (StandardException e) { + // Offending rows may have been deleted in the + // transaction. As for compress, we won't even get here + // since we use a normal SELECT query then. + if (e.getSQLState().equals( + ExceptionUtil.getSQLStateFromIdentifier( + SQLState.AM_RECORD_NOT_FOUND))) { + moreRows = false; + } else { + throw e; + } + } + return moreRows; } }