db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mamta A. Satoor (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-3872) NullPoinerException thrown when INTEGER function used as a predicate in a WHERE clause of a SELECT .. GROUP BY .. HAVING statement
Date Tue, 07 Oct 2008 16:30:44 GMT

    [ https://issues.apache.org/jira/browse/DERBY-3872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12637536#action_12637536
] 

Mamta A. Satoor commented on DERBY-3872:
----------------------------------------

I did code walk through during the code generation phase of the above query. Different resultsets
and columns get their RSNs assigned to them during the code generation phase.

The stack trace below shows when the column belonging to HAVING clause indirectly gets the
RSN 3 assigned to it.
Thread [main] (Suspended (breakpoint at line 413 in ResultColumn))	
	ResultColumn.setResultSetNumber(int) line: 413	
	ResultColumnList.setResultSetNumber(int) line: 2141	
	FromBaseTable(ResultSetNode).assignResultSetNumber() line: 213	
	FromBaseTable.generateResultSet(ExpressionClassBuilder, MethodBuilder) line: 3098	
	FromBaseTable.generate(ActivationClassBuilder, MethodBuilder) line: 3065	
	ProjectRestrictNode.generateMinion(ExpressionClassBuilder, MethodBuilder, boolean) line:
1385	
	ProjectRestrictNode.generate(ActivationClassBuilder, MethodBuilder) line: 1336	
	JoinNode.getJoinArguments(ActivationClassBuilder, MethodBuilder, ValueNode) line: 1577	
	JoinNode.generateCore(ActivationClassBuilder, MethodBuilder, int, ValueNode, SubqueryList)
line: 1555	
	JoinNode.generate(ActivationClassBuilder, MethodBuilder) line: 1479	
	ProjectRestrictNode.generateMinion(ExpressionClassBuilder, MethodBuilder, boolean) line:
1472	
	ProjectRestrictNode.generate(ActivationClassBuilder, MethodBuilder) line: 1336	
	GroupByNode.generate(ActivationClassBuilder, MethodBuilder) line: 1013	
	ProjectRestrictNode.generateMinion(ExpressionClassBuilder, MethodBuilder, boolean) line:
1472	
	ProjectRestrictNode.generate(ActivationClassBuilder, MethodBuilder) line: 1336	
	ScrollInsensitiveResultSetNode.generate(ActivationClassBuilder, MethodBuilder) line: 109

	CursorNode.generate(ActivationClassBuilder, MethodBuilder) line: 564	
	CursorNode(StatementNode).generate(ByteArray) line: 347	
	GenericStatement.prepMinion(LanguageConnectionContext, boolean, Object[], SchemaDescriptor,
boolean) line: 447	
	GenericStatement.prepare(LanguageConnectionContext, boolean) line: 88	
	GenericLanguageConnectionContext.prepareInternalStatement(SchemaDescriptor, String, boolean,
boolean) line: 796	
	EmbedStatement40(EmbedStatement).execute(String, boolean, boolean, int, int[], String[])
line: 606	
	EmbedStatement40(EmbedStatement).execute(String) line: 555	
	ij.executeImmediate(String) line: 329	
	utilMain.doCatch(String) line: 508	
	utilMain.runScriptGuts() line: 350	
	utilMain.go(LocalizedInput[], LocalizedOutput, Properties) line: 248	
	Main.go(LocalizedInput, LocalizedOutput, Properties) line: 215	
	Main.mainCore(String[], Main) line: 181	
	Main.main(String[]) line: 73	
	ij.main(String[]) line: 59	

The stack trace above is handling the first part of the use query(the first part is shown
below)
select q1."DEPTNO" from DEPTTAB q1, EMPTAB q2 -- DERBY-PROPERTIES joinStrategy = HASH 
where ( q2."DEPT_DEPTNO" = q1."DEPTNO") 
GROUP BY q1."DEPTNO" 
Note that we are not dealing with the HAVING clause at all at this point in the stack trace
but the problem arises from the fact that the ResultColumn associated with the HAVING clause
is the same object that is associated with the join node. Because of that, even though we
are setting the RSN number 3 for the join node column, the ResultColumn associated with the
HAVING clause ends up getting the same RSN 3 associated with it. I have tried to show below
how different language ResultSet and column objects are associated with the entire user query
this	org.apache.derby.impl.sql.compile.ProjectRestrictNode  (id=192)	
   childResult	org.apache.derby.impl.sql.compile.GroupByNode  (id=156)	
      childResult	org.apache.derby.impl.sql.compile.ProjectRestrictNode  (id=151)	
         childResult	org.apache.derby.impl.sql.compile.JoinNode  (id=221)	
            leftResultSet	org.apache.derby.impl.sql.compile.ProjectRestrictNode  (id=233)

               childResult	org.apache.derby.impl.sql.compile.FromBaseTable  (id=241)	
                  resultColumns	org.apache.derby.impl.sql.compile.ResultColumnList  (id=317)

                     v	java.util.Vector<E>  (id=2084)	
                        elementCount	1	
                        elementData	java.lang.Object[10]  (id=2089)	
                           [0]	org.apache.derby.impl.sql.compile.ResultColumn  (id=218)	
   restriction	org.apache.derby.impl.sql.compile.AndNode  (id=98)	
      leftOperand	org.apache.derby.impl.sql.compile.BinaryRelationalOperatorNode  (id=85)

         rightOperand	org.apache.derby.impl.sql.compile.SubqueryNode  (id=93)	
            resultSet	org.apache.derby.impl.sql.compile.ProjectRestrictNode  (id=135)	
               childResult	org.apache.derby.impl.sql.compile.ProjectRestrictNode  (id=121)

                  childResult	org.apache.derby.impl.sql.compile.IndexToBaseRowNode  (id=193)

                     source	org.apache.derby.impl.sql.compile.FromBaseTable  (id=195)	
                        restrictionList	org.apache.derby.impl.sql.compile.PredicateList  (id=196)

                           v	java.util.Vector<E>  (id=198)	
                              elementCount	1	
                              elementData	java.lang.Object[10]  (id=200)	
                                 [0]	org.apache.derby.impl.sql.compile.Predicate  (id=212)

                                    andNode	org.apache.derby.impl.sql.compile.AndNode  (id=120)

                                       leftOperand	org.apache.derby.impl.sql.compile.BinaryRelationalOperatorNode
 (id=89)	
                                          rightOperand	org.apache.derby.impl.sql.compile.ColumnReference
 (id=124)	
                                             columnName	"DEPTNO"	
                                             source	org.apache.derby.impl.sql.compile.ResultColumn
 (id=218)		

In the object association above, if you search for string id=218, you will find that ResultColumn
object with id=218 is hanging off the SubqueryNode as well as the JoinNode. I think this is
the cause of the problem. 

> NullPoinerException thrown when INTEGER function used as a predicate in a WHERE clause
of a SELECT .. GROUP BY ..  HAVING statement
> -----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-3872
>                 URL: https://issues.apache.org/jira/browse/DERBY-3872
>             Project: Derby
>          Issue Type: Bug
>    Affects Versions: 10.3.3.0
>            Reporter: Stan Bradbury
>            Assignee: Mamta A. Satoor
>         Attachments: NPE_Reproduction.sql, QueryWithoutTruePred.out, QueryWithTruePred.out
>
>
> Use attached SQL script to create two tables , execute the following SQL and throw the
exception and stack trace below.  NOTE:  removing the 'always true' clause '.. ( integer (1.1)
= 1) .." from the SQL and the query does not fail.  Releated??
> select  q1."DEPTNO" from DEPTTAB q1, EMPTAB q2 where  ( integer (1.1) = 1)  and  ( q2."DEPT_DEPTNO"
=  q1."DEPTNO")  
> GROUP BY q1."DEPTNO" 
> HAVING  max( q2."SALARY") >=  ( select  q3."SALARY" from EMPTAB q3 where  ( q3."EMPID"
=  q1."DEPTNO") ) 
> ERROR 38000: The exception 'java.lang.NullPointerException' was thrown while evaluating
an expression.
> . . .derby.iapi.error.StandardException.newException
> . . .derby.iapi.error.StandardException.unexpectedUserException
> . . .derby.impl.services.reflect.DirectCall.invoke
> . . .derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore
> . . .derby.impl.sql.execute.BasicNoPutResultSetImpl.getNextRow
> . . .derby.impl.jdbc.EmbedResultSet.movePosition
> . . .derby.impl.jdbc.EmbedResultSet.next
> . . .derby.tools.JDBCDisplayUtil.indent_DisplayResults
> . . .derby.tools.JDBCDisplayUtil.indent_DisplayResults
> . . .derby.tools.JDBCDisplayUtil.indent_DisplayResults
> . . .derby.tools.JDBCDisplayUtil.DisplayResults
> . . .derby.impl.tools.ij.utilMain.displayResult
> . . .derby.impl.tools.ij.utilMain.doCatch
> . . .derby.impl.tools.ij.utilMain.runScriptGuts
> . . .derby.impl.tools.ij.utilMain.go
> . . .derby.impl.tools.ij.Main.go
> . . .derby.impl.tools.ij.Main.mainCore
> . . .derby.impl.tools.ij.Main14.main
> . . .derby.tools.ij.main
> Caused by: java.lang.NullPointerException
> . . .derby.iapi.types.NumberDataType.compare
> . . .derby.impl.store.access.btree.ControlRow.compareIndexRowFromPageToKey
> . . .derby.impl.store.access.btree.ControlRow.searchForEntry
> . . .derby.impl.store.access.btree.LeafControlRow.search
> . . .derby.impl.store.access.btree.BTreeScan.positionAtStartForForwardScan
> . . .derby.impl.store.access.btree.BTreeForwardScan.positionAtStartPosition
> . . .derby.impl.store.access.btree.BTreeForwardScan.fetchRows
> . . .derby.impl.store.access.btree.BTreeScan.fetchNext
> . . .derby.impl.sql.execute.TableScanResultSet.getNextRowCore
> . . .derby.impl.sql.execute.IndexRowToBaseRowResultSet.getNextRowCore
> . . .derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore
> . . .derby.impl.sql.execute.OnceResultSet.getNextRowCore
> . . .derby.exe.ac601a400fx011cx480cx5eacx00000010d8100.g0
> . . .derby.exe.ac601a400fx011cx480cx5eacx00000010d8100.e6
> 	... 17 more
> ============= begin nested exception, level (1) ===========
> java.lang.NullPointerException
> . . .derby.iapi.types.NumberDataType.compare
> . . .derby.impl.store.access.btree.ControlRow.compareIndexRowFromPageToKey
> . . .derby.impl.store.access.btree.ControlRow.searchForEntry
> . . .derby.impl.store.access.btree.LeafControlRow.search
> . . .derby.impl.store.access.btree.BTreeScan.positionAtStartForForwardScan
> . . .derby.impl.store.access.btree.BTreeForwardScan.positionAtStartPosition
> . . .derby.impl.store.access.btree.BTreeForwardScan.fetchRows
> . . .derby.impl.store.access.btree.BTreeScan.fetchNext
> . . .derby.impl.sql.execute.TableScanResultSet.getNextRowCore
> . . .derby.impl.sql.execute.IndexRowToBaseRowResultSet.getNextRowCore
> . . .derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore
> . . .derby.impl.sql.execute.OnceResultSet.getNextRowCore
> . . .derby.exe.ac601a400fx011cx480cx5eacx00000010d8100.g0
> . . .derby.exe.ac601a400fx011cx480cx5eacx00000010d8100.e6
> . . .derby.impl.services.reflect.DirectCall.invoke
> . . .derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore
> . . .derby.impl.sql.execute.BasicNoPutResultSetImpl.getNextRow
> . . .derby.impl.jdbc.EmbedResultSet.movePosition
> . . .derby.impl.jdbc.EmbedResultSet.next
> . . .derby.tools.JDBCDisplayUtil.indent_DisplayResults
> . . .derby.tools.JDBCDisplayUtil.indent_DisplayResults
> . . .derby.tools.JDBCDisplayUtil.indent_DisplayResults
> . . .derby.tools.JDBCDisplayUtil.DisplayResults
> . . .derby.impl.tools.ij.utilMain.displayResult
> . . .derby.impl.tools.ij.utilMain.doCatch
> . . .derby.impl.tools.ij.utilMain.runScriptGuts
> . . .derby.impl.tools.ij.utilMain.go
> . . .derby.impl.tools.ij.Main.go
> . . .derby.impl.tools.ij.Main.mainCore
> . . .derby.impl.tools.ij.Main14.main
> . . .derby.tools.ij.main
> ============= end nested exception, level (1) ===========
> Cleanup action completed

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message