impossibl / pgjdbc-ng

A new JDBC driver for PostgreSQL aimed at supporting the advanced features of JDBC and Postgres
https://impossibl.github.io/pgjdbc-ng
Other
600 stars 108 forks source link

Prepared statement already exists #589

Open kcbanner opened 1 year ago

kcbanner commented 1 year ago
 com.impossibl.postgres.jdbc.PGSQLSimpleException: prepared statement "cached-b87c258b" already exists
         at com.impossibl.postgres.jdbc.ErrorUtils.makeSQLException(ErrorUtils.java:197) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.ErrorUtils.makeSQLException(ErrorUtils.java:174) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.ErrorUtils.makeSQLException(ErrorUtils.java:161) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.PGDirectConnection.execute(PGDirectConnection.java:514) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.PGPreparedStatement.lambda$parseIfNeeded$3(PGPreparedStatement.java:289) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.PGDirectConnection.getCachedPreparedStatement(PGDirectConnection.java:1608) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.PGPreparedStatement.parseIfNeeded(PGPreparedStatement.java:284) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.PGPreparedStatement.execute(PGPreparedStatement.java:329) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.PGPreparedStatement.executeQuery(PGPreparedStatement.java:357) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.impossibl.postgres.jdbc.PGPreparedStatement.executeQuery(PGPreparedStatement.java:106) ~[pgjdbc-ng-0.8.9.jar:0.8.9]
         at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-3.3.1.jar:?]
         at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-3.3.1.jar:?]
         at com.j256.ormlite.jdbc.JdbcCompiledStatement.runQuery(JdbcCompiledStatement.java:66) ~[ormlite-jdbc-5.7.jar:?]
         at com.j256.ormlite.stmt.SelectIterator.<init>(SelectIterator.java:56) ~[ormlite-core-5.7.jar:?]
         at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:254) ~[ormlite-core-5.7.jar:?]
         at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:203) ~[ormlite-core-5.7.jar:?]
         at com.j256.ormlite.dao.BaseDaoImpl.query(BaseDaoImpl.java:282) ~[ormlite-core-5.7.jar:?]
         at com.j256.ormlite.stmt.QueryBuilder.query(QueryBuilder.java:384) ~[ormlite-core-5.7.jar:?]
         at com.j256.ormlite.stmt.Where.query(Where.java:517) ~[ormlite-core-5.7.jar:?]

... snip ...

I have a query that for only particular users, hits this exception. The cache key is always the same, and it's always on the same query.

The query itself is built as follows:

        List<ManufacturingJobResult> manufacturingJobResults = database
          .getManufacturingJobResultDao()
          .queryBuilder()
          .orderBy("completeddate", true)
          .where()
          .eq("producttypeid", requiredTypeId)
          .and()
          .in("characterid", characterIds)
          .and()
          .lt("completeddate", beforeDate)
          .and()
          .raw("(quantity_sold + quantityconsumed) < quantity")
          .and()
          .eq("materialsincomplete", false)
          .query();

It seems that something is going wrong in the caching layer - but I'm not sure how to properly debug this. Is this just an unlucky hash collision?