[ http://issues.apache.org/jira/browse/DERBY-1644?page=all ]
Bryan Pendleton updated DERBY-1644:
-----------------------------------
Attachment: d1644_combined_v3.diff
I'm not quite sure what I was thinking when I thought that the two code
changes could be separated, but they cannot. They are linked and really
it needs to be a single patch proposal.
Attached is d1644_combined_v3.diff, a patch proposal which combines
the two previous code change patches. The new patch also adds the
new tests suggested by Army.
There are several ideas involved in this patch:
- When an INSERT statement will insert multiple rows from the VALUES
clause, the compiler will compile the various values into a tree of
UnionNodes with RowResultSetNodes at the leaves of the three
- The columns specified in the INSERT statement may be a subset
of the rows in the table. The "extra" columns need to be constructed by
the INSERT statement, either by generating NULL values for those
columns which are nullable, or by compiling a default values for those
columns which have DEFAULT values, or by generating a value for an IDENTITY
column which is GENERATED. The work of constructing these extra
column values is done by genNewRCForInsert.
- For columns which are GENERATED ALWAYS, we must make sure that
the INSERT statement doesn't allow the user to insert their own value for
the generated column.
- The columns which are specified in the INSERT column spec may not match
the order in which the columns arise in the table. Therefore, the column
values may need to be re-ordered by the INSERT statement so that they
occur in the proper order.
- In the case when the ResultSet which provides the values for the INSERT
statement is not just a single node, but is rather a tree of UnionNodes, the
above processing needs to happen throughout the tree, not just at the root
node.
The combined patch proposal accomplishes all of this.
There is one aspect to this patch that I can't fully explain yet. If somebody
knows
the reason behind it, that would be very nice; I am hoping to continue studying
this in the near future. This question involves the ProjectRestrictNode at the
root of the ResultSetNode tree. With the current code, when the VALUES clause
results in multiple rows, and is compiled into a UnionNode tree with
RowResultSetNodes at the leaves, InsertNode.bind calls SetOperatorNode.
enhanceRCLForInsert(), which constructs a brand-new ProjectRestrictNode to
be the new root of the UnionNode tree. With my patch proposal, the PRN is
no longer built; the ResultSetNode tree is left with a UnionNode at the root.
>From what I can tell, this works fine: the PRN is no longer needed once we are
sure to generate and re-order the ResultSet columns at *all* nodes in the
ResultSetNode tree. The new rows can be inserted directly from the UnionNodes.
I think this patch is correct, but it is possible that there is some other
aspect to
having the PRN at the root of the tree which I haven't discovered yet, which
will
cause a problem if we don't generate that PRN. If anybody knows what such a
problem might be, please let me know.
> NPE when inserting values to a table that has a column declared as generated
> by default as identity
> ---------------------------------------------------------------------------------------------------
>
> Key: DERBY-1644
> URL: http://issues.apache.org/jira/browse/DERBY-1644
> Project: Derby
> Issue Type: Bug
> Components: SQL
> Affects Versions: 10.2.1.6
> Environment: Sun JDK 1.4.2
> Reporter: Yip Ng
> Assigned To: Bryan Pendleton
> Priority: Minor
> Attachments: d1644_combined_v3.diff, d1644_recursivelyCheck_v1.diff,
> RSN_EnhanceRCL_Simplify_v2.diff, RSNCommentFixup_v1.diff
>
>
> The following scenario triggers a NullPointerException in statement
> compilation:
> ij> create table t1 (c1 int, c2 int generated by default as identity);
> 0 rows inserted/updated/deleted
> ij> insert into t1 (c2) values default, 10;
> ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
> Stacktrace from derby.log:
> Database Class Loader started - derby.database.classpath=''
> 2006-08-04 06:31:17.235 GMT Thread[main,5,main] (XID = 235), (SESSIONID = 0),
> (DATABASE = wombat), (DRDAID = null), Cleanup action starting
> 2006-08-04 06:31:17.235 GMT Thread[main,5,main] (XID = 235), (SESSIONID = 0),
> (DATABASE = wombat), (DRDAID = null), Failed Statement is: insert into t1
> (c2) values default, 10
> java.lang.NullPointerException
> at
> org.apache.derby.impl.sql.compile.ResultColumnList.generateCore(ResultColumnList.java:1033)
> at
> org.apache.derby.impl.sql.compile.ResultColumnList.generate(ResultColumnList.java:893)
> at
> org.apache.derby.impl.sql.compile.RowResultSetNode.generate(RowResultSetNode.java:690)
> at
> org.apache.derby.impl.sql.compile.UnionNode.generate(UnionNode.java:589)
> at
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generateMinion(ProjectRestrictNode.java:1424)
> at
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generate(ProjectRestrictNode.java:1286)
> at
> org.apache.derby.impl.sql.compile.NormalizeResultSetNode.generate(NormalizeResultSetNode.java:122)
> at
> org.apache.derby.impl.sql.compile.InsertNode.generate(InsertNode.java:764)
> at
> org.apache.derby.impl.sql.compile.StatementNode.generate(StatementNode.java:232)
> at
> org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:477)
> at
> org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:118)
> at
> org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:713)
> at
> org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:567)
> at
> org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:516)
> at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:313)
> at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:478)
> at
> org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:347)
> at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:248)
> at org.apache.derby.impl.tools.ij.Main.go(Main.java:203)
> at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:169)
> at org.apache.derby.impl.tools.ij.Main14.main(Main14.java:55)
> at org.apache.derby.tools.ij.main(ij.java:69)
> sysinfo:
> ------------------ Java Information ------------------
> Java Version: 1.4.2_12
> Java Vendor: Sun Microsystems Inc.
> Java home: C:\jdk142\jre
> Java classpath: classes;.
> OS name: Windows XP
> OS architecture: x86
> OS version: 5.1
> Java user name: yip
> Java user home: C:\Documents and Settings\Administrator
> Java user dir: C:\derby\trunk
> java.specification.name: Java Platform API Specification
> java.specification.version: 1.4
> --------- Derby Information --------
> JRE - JDBC: J2SE 1.4.2 - JDBC 3.0
> [C:\derby\trunk\classes] 10.2.0.5 alpha - (1)
> ------------------------------------------------------
> ----------------- Locale Information -----------------
> Current Locale : [English/United States [en_US]]
> Found support for locale: [de_DE]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [es]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [fr]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [it]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [ja_JP]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [ko_KR]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [pt_BR]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [zh_CN]
> version: 10.2.0.5 alpha - (1)
> Found support for locale: [zh_TW]
> version: 10.2.0.5 alpha - (1)
> ------------------------------------------------------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira