Re: cached plan must not change result type - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: cached plan must not change result type
Date
Msg-id CADK3HHJn79rvd0Si7XtQ8EfsaGK04A4fPhoBDng8A8aJkR8hrQ@mail.gmail.com
Whole thread Raw
In response to Re: cached plan must not change result type  (Dave Cramer <davecramer@postgres.rocks>)
Responses Re: cached plan must not change result type  (Laurenz Albe <laurenz.albe@cybertec.at>)
List pgsql-jdbc


On Sat, 30 Mar 2024 at 06:14, Dave Cramer <davecramer@postgres.rocks> wrote:


On Fri, 29 Mar 2024 at 19:42, James Pang <jamespang886@gmail.com> wrote:
   we did DDL "alter table ... alter column increase varchar(512) to varchar(1024)", after that done, hours later, new query select on this table still failed this error.  From this https://jdbc.postgresql.org/documentation/server-prepare/#re-execution-of-failed-statements , looks like pgjdbc try to handle this exception and retry, but in our case, it did not happen.  Could you direct me how to make this retry work? we only want new transactions,queries work that after the DDL changes. 

protected boolean willHealViaReparse(SQLException e) {
    if (e == null || e.getSQLState() == null) {
      return false;
    }

    // "prepared statement \"S_2\" does not exist"
    if (PSQLState.INVALID_SQL_STATEMENT_NAME.getState().equals(e.getSQLState())) {
      return true;
    }
    if (!PSQLState.NOT_IMPLEMENTED.getState().equals(e.getSQLState())) {
      return false;
    }

    if (!(e instanceof PSQLException)) {
      return false;
    }

    PSQLException pe = (PSQLException) e;

    ServerErrorMessage serverErrorMessage = pe.getServerErrorMessage();
    if (serverErrorMessage == null) {
      return false;
    }
    // "cached plan must not change result type"
    String routine = serverErrorMessage.getRoutine();
    return "RevalidateCachedQuery".equals(routine) // 9.2+
        || "RevalidateCachedPlan".equals(routine); // <= 9.1
  }


This only works if there was no transaction.


Dave
Thanks,

 


I think the best option for you is to turn off server side prepared statements with prepareThreshold=0

 Dave

pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: cached plan must not change result type
Next
From: Laurenz Albe
Date:
Subject: Re: cached plan must not change result type