db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1243878 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java
Date Tue, 14 Feb 2012 11:10:14 GMT
Author: kristwaa
Date: Tue Feb 14 11:10:13 2012
New Revision: 1243878

URL: http://svn.apache.org/viewvc?rev=1243878&view=rev
Log:
DERBY-5530: SQLChar.getCollationKey NPE in index-stat-thread 

Propagate collation information to the new indexes on TRAUNCATE TABLE.

Patch file: derby-5530-1a-propagate_collation_info.diff (trivially modified)


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=1243878&r1=1243877&r2=1243878&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
Tue Feb 14 11:10:13 2012
@@ -86,7 +86,6 @@ import org.apache.derby.iapi.types.DataV
 import org.apache.derby.iapi.types.RowLocation;
 import org.apache.derby.iapi.util.IdUtil;
 import org.apache.derby.iapi.util.StringUtil;
-import org.apache.derby.impl.sql.catalog.DDColumnDependableFinder;
 import org.apache.derby.impl.sql.compile.CollectNodesVisitor;
 import org.apache.derby.impl.sql.compile.ColumnDefinitionNode;
 import org.apache.derby.impl.sql.compile.ColumnReference;
@@ -2367,9 +2366,10 @@ class AlterTableConstantAction extends D
 
 			for (int index = 0; index < numIndexes; index++)
 			{
+                IndexRowGenerator curIndex = compressIRGs[index];
 				// create a single index row template for each index
-				indexRows[index] = compressIRGs[index].getIndexRowTemplate();
-				compressIRGs[index].getIndexRow(emptyHeapRow, 
+                indexRows[index] = curIndex.getIndexRowTemplate();
+                curIndex.getIndexRow(emptyHeapRow, 
 											  rl, 
 											  indexRows[index],
 											  (FormatableBitSet) null);
@@ -2378,15 +2378,15 @@ class AlterTableConstantAction extends D
 				 * No need to try to enforce uniqueness here as
 				 * index should be valid.
 				 */
-				int[] baseColumnPositions = 
-                    compressIRGs[index].baseColumnPositions();
+                int[] baseColumnPositions = curIndex.baseColumnPositions();
 
-				boolean[] isAscending = compressIRGs[index].isAscending();
+                boolean[] isAscending = curIndex.isAscending();
 
 				int numColumnOrderings;
 				numColumnOrderings = baseColumnPositions.length + 1;
 				ordering[index]    = new ColumnOrdering[numColumnOrderings];
-                collation[index]   = new int[baseColumnPositions.length + 1];
+                collation[index]   = curIndex.getColumnCollationIds(
+                                                td.getColumnDescriptorList());
 
 				for (int ii =0; ii < numColumnOrderings - 1; ii++) 
 				{

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java?rev=1243878&r1=1243877&r2=1243878&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest2.java
Tue Feb 14 11:10:13 2012
@@ -1828,6 +1828,39 @@ public class CollationTest2 extends Base
     }
 
     /**
+     * Tests that truncating a table with indexes leaves us with a valid set
+     * of conglomerates.
+     */
+    private void runDerby5530TruncateIndex()
+            throws SQLException {
+        setAutoCommit(false);
+        Statement s = createStatement();
+        s.executeUpdate("create table d5530i (val varchar(10))");
+        s.executeUpdate("create index idx on d5530i(val)");
+        s.executeUpdate("truncate table d5530i");
+        s.executeUpdate("insert into d5530i values 'one', 'two'");
+        ResultSet rs = s.executeQuery("select * from d5530i");
+        JDBC.assertUnorderedResultSet(rs, new String[][] {{"one"}, {"two"}});
+        rollback();
+    }
+
+    /**
+     * Tests that truncating a table without indexes leaves us with a valid
+     * conglomerate.
+     */
+    private void runDerby5530TruncateNoIndex()
+            throws SQLException {
+        setAutoCommit(false);
+        Statement s = createStatement();
+        s.executeUpdate("create table d5530 (val varchar(10))");
+        s.executeUpdate("truncate table d5530");
+        s.executeUpdate("insert into d5530 values 'one', 'two'");
+        ResultSet rs = s.executeQuery("select * from d5530");
+        JDBC.assertUnorderedResultSet(rs, new String[][] {{"one"}, {"two"}});
+        rollback();
+    }
+
+    /**
      * Shared code to run all test cases against a single collation.
      * <p>
      * Pass in the index of which TEST_DATABASE database to test.  So
@@ -1894,6 +1927,8 @@ public class CollationTest2 extends Base
 
         runLikeTests(db_index);
 
+        runDerby5530TruncateNoIndex();
+        runDerby5530TruncateIndex();
 
         /*
         TODO -MIKEM, this test does not work yet.



Mime
View raw message