h2database / h2database/h2database
numericWithBooleanComparison is ignored in the ConditionIn Optimizer
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.6k
- Forks
- 1.3k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 9
Description
When running H2 in a Mode where numericWithBooleanComparison is set to true (e.g. LEGACY), certain queries where boolean and integers are compared still do not work.
For example, in the following select query
create table data (a boolean, b boolean);
select * from data d where d.a = 1 or d.b = 1;
the following exception will be thrown:
org.h2.jdbc.JdbcSQLSyntaxErrorException: Values of types "INTEGER" and "BOOLEAN" are not comparable:
at org.h2.message.DbException.getJdbcSQLException(DbException.java:644) ~[h2-2.2.224.jar:2.2.224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489) ~[h2-2.2.224.jar:2.2.224]
at org.h2.message.DbException.get(DbException.java:223) ~[h2-2.2.224.jar:2.2.224]
at org.h2.value.TypeInfo.checkComparable(TypeInfo.java:766) ~[h2-2.2.224.jar:2.2.224]
at org.h2.expression.condition.ConditionIn.optimize(ConditionIn.java:110) ~[h2-2.2.224.jar:2.2.224]
at org.h2.expression.condition.ConditionAndOrN.optimize(ConditionAndOrN.java:229) ~[h2-2.2.224.jar:2.2.224]
at org.h2.expression.SearchedCase.optimize(SearchedCase.java:46) ~[h2-2.2.224.jar:2.2.224]
at org.h2.expression.ConcatenationOperation.determineType(ConcatenationOperation.java:201) ~[h2-2.2.224.jar:2.2.224]
at org.h2.expression.ConcatenationOperation.optimize(ConcatenationOperation.java:141) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.query.Select.prepareExpressions(Select.java:1170) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.query.Query.prepare(Query.java:218) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.Parser.prepareCommand(Parser.java:489) ~[h2-2.2.224.jar:2.2.224]
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:639) ~[h2-2.2.224.jar:2.2.224]
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:559) ~[h2-2.2.224.jar:2.2.224]
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1166) ~[h2-2.2.224.jar:2.2.224]
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:93) ~[h2-2.2.224.jar:2.2.224]
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:316) ~[h2-2.2.224.jar:2.2.224]
Version: 2.2.224
Independent from this ticket: I believe numericWithBooleanComparison should also be set to true for Mode=ORACLE
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the LEGACY-mode query from the issue and then read org.h2.expression.condition.ConditionIn.java around the reported optimize failure. Trace how numericWithBooleanComparison is handled during optimization, and add regression coverage showing that the boolean/integer comparison query completes without the reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100