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 km...@apache.org on 2009/04/02 14:26:39 UTC
svn commit: r761265 - in /db/derby/code/branches/10.5/java:
engine/org/apache/derby/impl/sql/execute/
testing/org/apache/derbyTesting/functionTests/tests/lang/
testing/org/apache/derbyTesting/junit/
Author: kmarsden
Date: Thu Apr 2 12:26:38 2009
New Revision: 761265
URL: http://svn.apache.org/viewvc?rev=761265&view=rev
Log:
DERBY-4116 SYSCS_UTIL.SYSCS_UPDATE_STATISTICS should update the store estimated row count for the table
Added:
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SelectivityTest.java
- copied unchanged from r760497, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SelectivityTest.java
Modified:
db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=761265&r1=761264&r2=761265&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java Thu Apr 2 12:26:38 2009
@@ -645,7 +645,9 @@
UUID[] objectUUID;
GroupFetchScanController gsc;
DependencyManager dm = dd.getDependencyManager();
-
+ //initialize numRows to -1 so we can tell if we scanned an index.
+ long numRows = -1;
+
td = dd.getTableDescriptor(tableId);
if (updateStatisticsAll)
{
@@ -702,7 +704,7 @@
int numCols = indexRow[indexNumber].nColumns() - 1;
long[] cardinality = new long[numCols];
- long numRows = 0;
+ numRows = 0;
initializeRowBuffers(indexRow[indexNumber]);
/* Read uncommited, with record locking. Actually CS store may
@@ -744,6 +746,7 @@
rowBufferArray[GROUP_FETCH_SIZE - 1] = lastUniqueKey;
lastUniqueKey = tmp;
} // while
+ gsc.setEstimatedRowCount(numRows);
} // try
finally
{
@@ -754,7 +757,7 @@
if (numRows == 0)
{
/* if there is no data in the table: no need to write anything
- * to sys.systatstics.
+ * to sys.sysstatstics
*/
break;
}
@@ -779,6 +782,33 @@
} // for each leading column (c1) (c1,c2)....
} // for each index.
+
+ // DERBY-4116 if there were indexes we scanned, we now know the row count.
+ // Update statistics should update the store estimated row count for the table.
+ // If we didn't scan an index and don't know, numRows will still be -1 and
+ // we skip the estimatedRowCount update.
+
+ if (numRows == -1)
+ return;
+
+ ScanController heapSC = tc.openScan(td.getHeapConglomerateId(),
+ false, // hold
+ 0, // openMode: for read
+ TransactionController.MODE_RECORD, // locking
+ TransactionController.ISOLATION_READ_UNCOMMITTED, //isolation level
+ null, // scancolumnlist-- want everything.
+ null, // startkeyvalue-- start from the beginning.
+ 0,
+ null, // qualifiers, none!
+ null, // stopkeyvalue,
+ 0);
+
+ try {
+ heapSC.setEstimatedRowCount(numRows);
+ } finally {
+ heapSC.close();
+ }
+
}
private void initializeRowBuffers(ExecIndexRow ir)
Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=761265&r1=761264&r2=761265&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Thu Apr 2 12:26:38 2009
@@ -137,6 +137,7 @@
suite.addTest(AnsiSignaturesTest.suite());
suite.addTest(PredicatePushdownTest.suite());
suite.addTest(UngroupedAggregatesNegativeTest.suite());
+ suite.addTest(SelectivityTest.suite());
// Add the XML tests, which exist as a separate suite
// so that users can "run all XML tests" easily.
suite.addTest(XMLSuite.suite());
Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=761265&r1=761264&r2=761265&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Thu Apr 2 12:26:38 2009
@@ -38,6 +38,8 @@
import junit.framework.AssertionFailedError;
import org.apache.derby.iapi.services.info.JVMInfo;
+import org.apache.derby.iapi.sql.execute.RunTimeStatistics;
+import org.apache.derby.impl.jdbc.EmbedConnection;
import org.apache.derby.tools.ij;
@@ -1298,6 +1300,25 @@
/**
+ * Return estimated row count for runtime statistics.
+ * Requires caller first turned on RuntimeStatistics, executed a query and closed the ResultSet.
+ *
+ * For client calls we just return as we can't find out this information.
+ * @param conn
+ * @param expectedCount
+ * @throws SQLException
+ */
+ public static void checkEstimatedRowCount(Connection conn, double expectedCount) throws SQLException {
+ if (! (conn instanceof EmbedConnection))
+ return;
+
+ EmbedConnection econn = (EmbedConnection) conn;
+ RunTimeStatistics rts = econn.getLanguageConnection().getRunTimeStatisticsObject();
+ assertNotNull(" RuntimeStatistics is null. Did you call SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)?",rts);
+ assertEquals((long) expectedCount, (long) rts.getEstimatedRowCount());
+ }
+
+ /**
* Check consistency of all tables
*
* @param conn