NullpointerException if i use select with where clause on some tables. (H2 1.4.177/1.4.178)

550 views
Skip to first unread message

David Pentzlin

unread,
May 13, 2014, 2:49:57 AM5/13/14
to h2-da...@googlegroups.com
Hi,


After adding a primary key to a table i cant use select with where clause anymore (select without working fine).
If i remove the primary the error is gone.

SELECT * FROM ALARM_VISIBILITY  where accountix=1;
General error: "java.lang.NullPointerException"; SQL statement:
SELECT * FROM ALARM_VISIBILITY  where accountix=1 [50000-178] HY000/50000 (Hilfe)
org.h2.jdbc.JdbcSQLException: General error: "java.lang.NullPointerException"; SQL statement:
SELECT * FROM ALARM_VISIBILITY  where accountix=1 [50000-178] 
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:344) 
    at org.h2.message.DbException.get(DbException.java:167) 
    at org.h2.message.DbException.convert(DbException.java:294) 
    at org.h2.command.Command.executeQuery(Command.java:209) 
    at org.h2.server.TcpServerThread.process(TcpServerThread.java:321) 
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:160) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.NullPointerException 
    at org.h2.engine.SessionRemote.done(SessionRemote.java:610) 
    at org.h2.command.CommandRemote.executeQuery(CommandRemote.java:159) 
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:181) 
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:160) 
    at org.h2.server.web.WebApp.getResult(WebApp.java:1391) 
    at org.h2.server.web.WebApp.query(WebApp.java:1064) 
    at org.h2.server.web.WebApp$1.next(WebApp.java:1026) 
    at org.h2.server.web.WebApp$1.next(WebApp.java:1013) 
    at org.h2.server.web.WebThread.process(WebThread.java:168) 
    at org.h2.server.web.WebThread.run(WebThread.java:94) 
    at java.lang.Thread.run(Unknown Source) 

Best regards 

David Pentzlin

unread,
May 13, 2014, 3:35:25 AM5/13/14
to h2-da...@googlegroups.com
just want to add:
i downgraded the database to 1.3.176 and the problem is gone. seems an issue with 1.4

Noel Grandin

unread,
May 13, 2014, 3:40:20 AM5/13/14
to h2-da...@googlegroups.com
I think you cut a piece off the stacktrace, and we need that piece to debug the problem :-)

David Pentzlin

unread,
May 13, 2014, 4:41:07 AM5/13/14
to h2-da...@googlegroups.com
This is everything i get in the H2 console: 
SELECT * FROM ALARM_VISIBILITY  where accountix=1;
General error: "java.lang.NullPointerException"; SQL statement:
SELECT * FROM ALARM_VISIBILITY  where accountix=1 [50000-178] HY000/50000 (Hilfe)
org.h2.jdbc.JdbcSQLException: General error: "java.lang.NullPointerException"; SQL statement:
SELECT * FROM ALARM_VISIBILITY  where accountix=1 [50000-178] 
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:344) 
    at org.h2.message.DbException.get(DbException.java:167) 
    at org.h2.message.DbException.convert(DbException.java:294) 
    at org.h2.command.Command.executeQuery(Command.java:209) 
    at org.h2.server.TcpServerThread.process(TcpServerThread.java:321) 
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:160) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.NullPointerException 
    at org.h2.mvstore.db.MVPrimaryIndex.getRow(MVPrimaryIndex.java:212) 
    at org.h2.mvstore.db.MVTable.getRow(MVTable.java:367) 
    at org.h2.mvstore.db.MVSecondaryIndex$MVStoreCursor.get(MVSecondaryIndex.java:491) 
    at org.h2.index.IndexCursor.get(IndexCursor.java:261) 
    at org.h2.table.TableFilter.getValue(TableFilter.java:898) 
    at org.h2.expression.ExpressionColumn.getValue(ExpressionColumn.java:187) 
    at org.h2.command.dml.Select.queryFlat(Select.java:540) 
    at org.h2.command.dml.Select.queryWithoutCache(Select.java:646) 
    at org.h2.command.dml.Query.query(Query.java:323) 
    at org.h2.command.dml.Query.query(Query.java:291) 
    at org.h2.command.dml.Query.query(Query.java:37) 
    at org.h2.command.CommandContainer.query(CommandContainer.java:91) 
    at org.h2.command.Command.executeQuery(Command.java:197) 
    ... 3 more 

    at org.h2.engine.SessionRemote.done(SessionRemote.java:610) 
    at org.h2.command.CommandRemote.executeQuery(CommandRemote.java:159) 
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:181) 
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:160) 
    at org.h2.server.web.WebApp.getResult(WebApp.java:1391) 
    at org.h2.server.web.WebApp.query(WebApp.java:1064) 
    at org.h2.server.web.WebApp$1.next(WebApp.java:1026) 
    at org.h2.server.web.WebApp$1.next(WebApp.java:1013) 
    at org.h2.server.web.WebThread.process(WebThread.java:168) 
    at org.h2.server.web.WebThread.run(WebThread.java:94) 
    at java.lang.Thread.run(Unknown Source) 

Best regards

Noel Grandin

unread,
May 13, 2014, 5:08:11 AM5/13/14
to h2-da...@googlegroups.com
Thanks, that's points us in the right direction.

Hmmm, that's definitely a bug in our new MVTable stuff.

Is there any chance you could post a reproducible test-case?

David Pentzlin

unread,
May 13, 2014, 5:28:16 AM5/13/14
to h2-da...@googlegroups.com
Hi,

The attached sql script should trigger this bug
alarm.sql

Noel Grandin

unread,
May 13, 2014, 8:11:20 AM5/13/14
to h2-da...@googlegroups.com

I can confirm that this triggers the bug.

I have traced the problem all the way back to this line of code in MVSecondaryIndex

private Cursor find(Session session, SearchRow first, boolean bigger, SearchRow last) {
ValueArray min = getKey(first);
if (min != null) {
min.getList()[keyColumns - 1] = ValueLong.get(Long.MIN_VALUE); // <<<<<<<<<<<<<<<<<<<<<<
}

I have no idea what it is trying to do, but the Long.MIN_VALUE percolates all the way back up the chain of iterators and
cursors until it tries to be used as a key into the MVPrimaryIndex#getRow(Session,long) method, where it causes an NPE.

I suspect that Thomas will be able to fix this given the above information.

Thomas Mueller

unread,
May 13, 2014, 12:30:51 PM5/13/14
to h2-da...@googlegroups.com
Hi,

Thanks a lot! I will fix it. I think it is related to the "create index" optimization, as it fails only with 5000 or more rows. That's why it was not found in the unit tests, as most unit tests use less rows, and this setting is no longer a system property and so no longer tested with a lower value (TestAll uses System.setProperty("h2.maxMemoryRowsDistinct", "128"), but that doesn't help). I have a simpler test case:

drop table if exists test;      
create table test as select x, 0 from system_range(1, 5000);
create unique index on test(x);
select * from test where x=1;

Regards,
Thomas
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Thomas Mueller

unread,
May 13, 2014, 2:53:55 PM5/13/14
to h2-da...@googlegroups.com
Hi,

This is now fixed in the trunk. Thanks a lot!

Regards,
Thomas
Reply all
Reply to author
Forward
0 new messages