db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6693) Assert failure/ArrayIndexOutOfBoundsException when using COUNT in MERGE matching clause
Date Thu, 07 Aug 2014 11:41:11 GMT

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

Knut Anders Hatlen commented on DERBY-6693:

The patch looks fine to me.

I was wondering if the code might be slightly simpler if we instead changed MatchingClauseNode.bindExpressions()
to check the contents of the ArrayList<AggregateNode> that is passed recursively to
rcl.bindExpressions(), and raised an error if it was not empty. Then we wouldn't need to collect
the aggregates twice. But then I realized that we would have to add similar code to MergeNode.bindExpression()
in order to cover the refinement clauses as well, so I suppose there's not much to save by
changing it after all.

Maybe we should add a test case for aggregates in the refinement clauses, though. Your fix
does cover those clauses, but since they are bound in a different code path than the other
parts of the matching clause, it might be worthwhile adding a separate test case for them.
For example this statement which fails with an assert before your patch, and fails with the
expected 42Z09 error after your patch:

merge into t1 using t2 on (t1.x=t2.x) when not matched and count(t2.x) > 1 then insert
values (1)

> Assert failure/ArrayIndexOutOfBoundsException when using COUNT in MERGE matching clause
> ---------------------------------------------------------------------------------------
>                 Key: DERBY-6693
>                 URL: https://issues.apache.org/jira/browse/DERBY-6693
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions:,
>            Reporter: Dag H. Wanvik
>            Priority: Minor
>         Attachments: derby-6693.diff, derby-6693.status
> This (meaningless) statement gives NPE in insane builds and
> assert failure in sane builds:
> {code}
> s.execute("create table t2(x int)");
> s.execute("create table t1(x int)");
> s.execute("insert into t2 values 3,4");
> s.executeUpdate("merge into t1 using t2 on (t1.x=t2.x) " + 
>    "when not matched then insert values (count(*))");
> {code}
> I see it also applies to other aggregates, e.g. MAX.
> stack trace (insane):
> {code}
> Exception in thread "main" java.sql.SQLException: Java exception: '-1: java.lang.ArrayIndexOutOfBoundsException'.
>         at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>         at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>         at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>         at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>         at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
>         at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
>         at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
>         at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
>         at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>         at org.apache.derby.impl.jdbc.EmbedStatement.executeLargeUpdate(Unknown Source)
>         at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source)
>         at derby6565.Derby6565.main(Derby6565.java:46)
> Caused by: ERROR XJ001: Java exception: '-1: java.lang.ArrayIndexOutOfBoundsException'.
>         at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
>         at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>         ... 12 more
> Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
>         at org.apache.derby.impl.services.bytecode.BCMethod.popStack(Unknown Source)
>         at org.apache.derby.impl.services.bytecode.BCMethod.callMethod(Unknown Source)
>         at org.apache.derby.impl.sql.compile.ResultColumnList.generateEvaluatedRow(Unknown
>         at org.apache.derby.impl.sql.compile.MatchingClauseNode.generateInsertUpdateRow(Unknown
>         at org.apache.derby.impl.sql.compile.MatchingClauseNode.generate(Unknown Source)
>         at org.apache.derby.impl.sql.compile.MergeNode.generate(Unknown Source)
>         at org.apache.derby.impl.sql.compile.StatementNode.generate(Unknown Source)
>         at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
>         at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
>         at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown
>         ... 4 more
> {code}

This message was sent by Atlassian JIRA

View raw message