You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2007/05/12 10:11:09 UTC
svn commit: r537353 - in /db/derby/code/trunk/java/engine/org/apache/derby:
iapi/sql/execute/ iapi/types/ impl/sql/execute/ impl/store/access/heap/
Author: kahatlen
Date: Sat May 12 01:11:08 2007
New Revision: 537353
URL: http://svn.apache.org/viewvc?view=rev&rev=537353
Log:
DERBY-827 (partial) Performance can be improved by re-using language
ResultSets across Activation executions
Reset candidate row array between executions. Based on patch/ideas
from Dyre Tjeldvoll.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecRow.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexValueRow.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ValueRow.java
db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapRowLocation.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecRow.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecRow.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecRow.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/execute/ExecRow.java Sat May 12 01:11:08 2007
@@ -64,6 +64,13 @@
*/
ExecRow getNewNullRow();
+ /**
+ * Reset all the <code>DataValueDescriptor</code>s in the row array to
+ * (SQL) null values. This method may reuse (and therefore modify) the
+ * objects currently contained in the row array.
+ */
+ void resetRowArray();
+
/**
* Get a clone of a DataValueDescriptor from an ExecRow.
*
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java Sat May 12 01:11:08 2007
@@ -245,6 +245,16 @@
return getString();
}
+ /**
+ * Recycle this DataType object.
+ *
+ * @return this object with value set to null
+ */
+ public DataValueDescriptor recycle() {
+ restoreToNull();
+ return this;
+ }
+
/*
* Column interface
*/
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java Sat May 12 01:11:08 2007
@@ -289,6 +289,15 @@
*/
public DataValueDescriptor getClone();
+ /**
+ * Recycle this DataValueDescriptor if possible. Create and return a new
+ * object if it cannot be recycled.
+ *
+ * @return this object with the value set to null, or a new
+ * DataValueDescriptor of the same type as this
+ */
+ DataValueDescriptor recycle();
+
/**
* Get a new null value of the same type as this data value.
*
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBoolean.java Sat May 12 01:11:08 2007
@@ -176,6 +176,20 @@
return TypeId.BOOLEAN_NAME;
}
+ /**
+ * Recycle this SQLBoolean object if possible. If the object is immutable,
+ * create and return a new object.
+ *
+ * @return a new SQLBoolean if this object is immutable; otherwise, this
+ * object with value set to null
+ */
+ public DataValueDescriptor recycle() {
+ if (immutable) {
+ return new SQLBoolean();
+ }
+ return super.recycle();
+ }
+
/*
* Storable interface, implies Externalizable, TypedFormat
*/
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DependentResultSet.java Sat May 12 01:11:08 2007
@@ -58,7 +58,7 @@
* rows that needs to be deleted on dependent tables. Using the row location
* we got from the index , base row is fetched.
*/
-class DependentResultSet extends NoPutResultSetImpl implements CursorResultSet
+class DependentResultSet extends ScanResultSet implements CursorResultSet
{
@@ -90,7 +90,6 @@
protected boolean firstScan = true;
protected ExecIndexRow startPosition;
protected ExecIndexRow stopPosition;
- protected ExecRow candidate;
// set in constructor and not altered during
// life of object.
@@ -111,9 +110,6 @@
public int rowsPerRead;
public boolean forUpdate;
private boolean sameStartStopPosition;
- public int isolationLevel;
- public int lockMode;
-
// Run time statistics
private Properties scanProperties;
@@ -145,7 +141,7 @@
int colRefItem,
int lockMode,
boolean tableLocked,
- int isolationLevel,
+ int isolationLevel, // ignored
int rowsPerRead,
boolean oneRowScan,
double optimizerEstimatedRowCount,
@@ -156,10 +152,14 @@
int rltItem
) throws StandardException
{
- super(activation,
- resultSetNumber,
- optimizerEstimatedRowCount,
- optimizerEstimatedCost);
+ super(activation, resultSetNumber, resultRowAllocator,
+ lockMode, tableLocked,
+ //Because the scan for the tables in this result set are done
+ //internally for delete cascades, isolation should be set to
+ //REPEATABLE READ irrespective what the user level isolation
+ //level is.
+ TransactionController.ISOLATION_REPEATABLE_READ,
+ optimizerEstimatedRowCount, optimizerEstimatedCost);
this.conglomId = conglomId;
@@ -206,31 +206,9 @@
getSavedObject(colRefItem));
}
-
- //unless the table locking is specified in sys.systables,
- //irrespective of what optimizer says choose record level
- //locking for dependent result sets.
- if (! tableLocked)
- {
- this.lockMode = TransactionController.MODE_RECORD;
- }else
- {
- this.lockMode = lockMode;
- }
-
-
- //Because the scan for the tables in this result set are done
- //internally for delete cascades, isolation should be set to
- //REPEATABLE READ irrespective what the user level isolation level is.
- this.isolationLevel = TransactionController.ISOLATION_REPEATABLE_READ;
-
runTimeStatisticsOn = (activation != null &&
activation.getLanguageConnectionContext().getRunTimeStatisticsMode());
- /* Only call row allocators once */
- candidate = (ExecRow) resultRowAllocator.invoke(activation);
-
-
tc = activation.getTransactionController();
//values required to scan the forein key index.
indexDcoci = tc.getDynamicCompiledConglomInfo(fkIndexConglomId);
@@ -552,7 +530,7 @@
public void openCore() throws StandardException
{
-
+ initIsolationLevel();
sVector = activation.getParentResultSet(parentResultSetId);
int size = sVector.size();
sourceRowHolders = new TemporaryRowHolder[size];
@@ -601,7 +579,7 @@
* Can we get instantaneous locks when getting share row
* locks at READ COMMITTED.
*/
- private boolean canGetInstantaneousLocks()
+ boolean canGetInstantaneousLocks()
{
return false;
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java Sat May 12 01:11:08 2007
@@ -73,7 +73,6 @@
private boolean hashtableBuilt;
private ExecIndexRow startPosition;
private ExecIndexRow stopPosition;
- protected ExecRow candidate; // candidate row is sparse
protected ExecRow compactRow;
// Variable for managing next() logic on hash entry
@@ -153,6 +152,7 @@
{
super(activation,
resultSetNumber,
+ resultRowAllocator,
lockMode, tableLocked, isolationLevel,
optimizerEstimatedRowCount,
optimizerEstimatedCost);
@@ -211,8 +211,6 @@
runTimeStatisticsOn =
getLanguageConnectionContext().getRunTimeStatisticsMode();
- /* Only call row allocators once */
- candidate = (ExecRow) resultRowAllocator.invoke(activation);
compactRow =
getCompactRow(candidate, accessedCols, (FormatableBitSet) null, false);
constructorTime += getElapsedMillis(beginTime);
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexValueRow.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexValueRow.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexValueRow.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/IndexValueRow.java Sat May 12 01:11:08 2007
@@ -115,6 +115,13 @@
return new IndexValueRow(valueRow.getNewNullRow());
}
+ /**
+ * Reset all columns in the row array to null values.
+ */
+ public void resetRowArray() {
+ valueRow.resetRowArray();
+ }
+
// position is 1-based
public DataValueDescriptor cloneColumn(int columnPosition)
{
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/LastIndexKeyResultSet.java Sat May 12 01:11:08 2007
@@ -57,8 +57,6 @@
*/
class LastIndexKeyResultSet extends ScanResultSet
{
- protected ExecRow candidate;
-
// set in constructor and not altered during
// life of object.
protected long conglomId;
@@ -128,6 +126,7 @@
{
super(activation,
resultSetNumber,
+ resultRowAllocator,
lockMode, tableLocked, isolationLevel,
optimizerEstimatedRowCount,
optimizerEstimatedCost);
@@ -152,8 +151,6 @@
runTimeStatisticsOn = getLanguageConnectionContext().getRunTimeStatisticsMode();
- /* Only call row allocators once */
- candidate = (ExecRow) resultRowAllocator.invoke(activation);
constructorTime += getElapsedMillis(beginTime);
/*
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScanResultSet.java Sat May 12 01:11:08 2007
@@ -20,7 +20,9 @@
package org.apache.derby.impl.sql.execute;
import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.loader.GeneratedMethod;
import org.apache.derby.iapi.sql.Activation;
+import org.apache.derby.iapi.sql.execute.ExecRow;
import org.apache.derby.iapi.sql.execute.ExecutionContext;
import org.apache.derby.iapi.store.access.TransactionController;
import org.apache.derby.shared.common.sanity.SanityManager;
@@ -46,11 +48,15 @@
/** The scan isolation level. */
int isolationLevel;
+ /** The candidate row. */
+ final ExecRow candidate;
+
/**
* Construct a <code>ScanResultSet</code>.
*
* @param activation the activation
* @param resultSetNumber number of the result set (unique within statement)
+ * @param resultRowAllocator method which generates rows
* @param lockMode lock mode (record or table)
* @param tableLocked true if marked as table locked in SYS.SYSTABLES
* @param isolationLevel language isolation level for the result set
@@ -58,9 +64,10 @@
* @param optimizerEstimatedCost estimated cost
*/
ScanResultSet(Activation activation, int resultSetNumber,
+ GeneratedMethod resultRowAllocator,
int lockMode, boolean tableLocked, int isolationLevel,
double optimizerEstimatedRowCount,
- double optimizerEstimatedCost) {
+ double optimizerEstimatedCost) throws StandardException {
super(activation, resultSetNumber,
optimizerEstimatedRowCount,
optimizerEstimatedCost);
@@ -78,6 +85,9 @@
this.lockMode = getLockMode(isolationLevel);
this.isolationLevel =
translateLanguageIsolationLevel(isolationLevel);
+
+ /* Only call row allocators once */
+ candidate = (ExecRow) resultRowAllocator.invoke(activation);
}
/**
@@ -184,6 +194,8 @@
public void close() throws StandardException {
// need to update isolation level on next open if it was unspecified
isolationLevelNeedsUpdate = unspecifiedIsolationLevel;
+ // Prepare row array for reuse (DERBY-827).
+ candidate.resetRowArray();
super.close();
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/TableScanResultSet.java Sat May 12 01:11:08 2007
@@ -80,7 +80,6 @@
protected boolean firstScan = true;
protected ExecIndexRow startPosition;
protected ExecIndexRow stopPosition;
- protected ExecRow candidate;
// set in constructor and not altered during
// life of object.
@@ -179,6 +178,7 @@
{
super(activation,
resultSetNumber,
+ resultRowAllocator,
lockMode, tableLocked, isolationLevel,
optimizerEstimatedRowCount,
optimizerEstimatedCost);
@@ -237,8 +237,6 @@
runTimeStatisticsOn = (activation != null &&
activation.getLanguageConnectionContext().getRunTimeStatisticsMode());
- /* Only call row allocators once */
- candidate = (ExecRow) resultRowAllocator.invoke(activation);
constructorTime += getElapsedMillis(beginTime);
/* Always qualify the first time a row is being read */
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ValueRow.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ValueRow.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ValueRow.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ValueRow.java Sat May 12 01:11:08 2007
@@ -213,6 +213,17 @@
return new ValueRow(ncols);
}
+ /**
+ * Reset all columns in the row array to null values.
+ */
+ public void resetRowArray() {
+ for (int i = 0; i < column.length; i++) {
+ if (column[i] != null) {
+ column[i] = column[i].recycle();
+ }
+ }
+ }
+
// position is 1-based
public final DataValueDescriptor cloneColumn(int columnPosition)
{
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapRowLocation.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapRowLocation.java?view=diff&rev=537353&r1=537352&r2=537353
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapRowLocation.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/heap/HeapRowLocation.java Sat May 12 01:11:08 2007
@@ -114,6 +114,18 @@
return new HeapRowLocation(this);
}
+ /**
+ * Recycle this HeapRowLocation object.
+ *
+ * @return this object reset to its initial state
+ */
+ public DataValueDescriptor recycle() {
+ pageno = 0L;
+ recid = 0;
+ rh = null;
+ return this;
+ }
+
public int getLength() {
return 10;
}