db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r960346 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/sql/compile/ java/testing/org/apache/derbyTesting/functionTests/master/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Sun, 04 Jul 2010 15:36:38 GMT
Author: mikem
Date: Sun Jul  4 15:36:37 2010
New Revision: 960346

URL: http://svn.apache.org/viewvc?rev=960346&view=rev
Log:
DERBY-4419: NPE with INSERT .. SELECT .. UNION and identity columns

backporting this fix #831304 from trunk to 10.5 branch.

The following SQL was causing problems:

    create table t3(x int, y int generated always as identity);
    insert into t3(x) select * from t1 union select * from t2;

During the insert, the value of column Y is not specified by the INSERT
statement, and therefore Derby notices that Y's value is to be generated,
and so Derby generates code to compute a value for Y when inserting each
row into T3.

When Derby is compiling the INSERT statement, Derby checks that the
column information for the column(s) to be inserted matches the correpsonding
column information for the column(s) that are selected by the SELECT
clause in the INSERT statement.

In the above example, Derby expands the "*" expression for each of tables
T1 and T2, and verifies that the result is a single integer column, thus
matching column X in T3.

However, at that point in processing, the ResultColumnList also contains
information about column Y, since its value is to be automatically generated.

Therefore, Derby needs to skip over such columns during datatype checking;
these columns are marked isGeneratedForUnmatchedColumnInInsert, so this
change causes Derby to check that value.

A similar behavior (DERBY-4425) occurs for columns which are generated by
expressions, which is a new feature in recent versions of Derby.

This change also fixes DERBY-4425. A separate commit for DERBY-4425 will
add an additional regression test for that situation. 


Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jul  4 15:36:37 2010
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:957000
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,829410,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,909176,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163,959550
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,829410,831304,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,909176,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163,959550

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=960346&r1=960345&r2=960346&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
Sun Jul  4 15:36:37 2010
@@ -1700,7 +1700,7 @@ public class ResultColumnList extends Qu
 			ResultColumn resultColumn = (ResultColumn) elementAt(index);
 
 			/* Skip over generated columns */
-			if (resultColumn.isGenerated())
+			if (resultColumn.isGenerated() || resultColumn.isGeneratedForUnmatchedColumnInInsert())
 			{
 				continue;
 			}

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out?rev=960346&r1=960345&r2=960346&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
Sun Jul  4 15:36:37 2010
@@ -2112,4 +2112,17 @@ alter table d4006_a alter column z defau
 ij(CONN2)> -- should fail DERBY-4011
 drop table d4006_a;
 0 rows inserted/updated/deleted
+ij(CONN2)> -- DERBY-4419 is a variant on DERBY-1644:
+create table d4419_t1(x int);
+0 rows inserted/updated/deleted
+ij(CONN2)> insert into d4419_t1 values 1,2;
+2 rows inserted/updated/deleted
+ij(CONN2)> create table d4419_t2(x int);
+0 rows inserted/updated/deleted
+ij(CONN2)> insert into d4419_t2 values 2,3;
+2 rows inserted/updated/deleted
+ij(CONN2)> create table d4419_t3(x int, y int generated always as identity);
+0 rows inserted/updated/deleted
+ij(CONN2)> insert into d4419_t3(x) select * from d4419_t1 union select * from d4419_t2;
+3 rows inserted/updated/deleted
 ij(CONN2)> 

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql?rev=960346&r1=960345&r2=960346&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
Sun Jul  4 15:36:37 2010
@@ -1119,3 +1119,11 @@ alter table d4006_a alter column z defau
 alter table d4006_a alter column z default null; -- should fail DERBY-4011
 drop table d4006_a;
 
+-- DERBY-4419 is a variant on DERBY-1644:
+create table d4419_t1(x int);
+insert into d4419_t1 values 1,2;
+create table d4419_t2(x int);
+insert into d4419_t2 values 2,3;
+create table d4419_t3(x int, y int generated always as identity);
+insert into d4419_t3(x) select * from d4419_t1 union select * from d4419_t2;
+



Mime
View raw message