pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
[pgjdbc/pgjdbc] issue #3781: Performance Optimization: PgPreparedStatement.getMetaData Should Not Use QUERY_ONESHOT
3+ messages / 2 participants
[nested] [flat]

* [pgjdbc/pgjdbc] issue #3781: Performance Optimization: PgPreparedStatement.getMetaData Should Not Use QUERY_ONESHOT
@ 2025-08-22 04:40  "ShenFeng312 (@ShenFeng312)" <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: ShenFeng312 (@ShenFeng312) @ 2025-08-22 04:40 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Description:
Currently, `PgPreparedStatement.getMetaData` uses `QUERY_ONESHOT` before `execute` is invoked, which results in `query.setStatementName(statementName, deallocateEpoch)` not being executed. Consequently, the binary protocol cannot be used to receive the result set.

```java
    if (!oneShot) {
      // Generate a statement name to use.
      statementName = "S_" + (nextUniqueID++);

      // And prepare the new statement.
      // NB: Must clone the OID array, as it's a direct reference to
      // the SimpleParameterList's internal array that might be modified
      // under us.
      query.setStatementName(statementName, deallocateEpoch);
      query.setPrepareTypes(typeOIDs);
      registerParsedQuery(query, statementName);
    }
```

```java
public @Nullable ResultSetMetaData getMetaData() throws SQLException {
    checkClosed();
    ResultSet rs = getResultSet();

    if (rs == null || ((PgResultSet) rs).isResultSetClosed()) {
      // OK, we haven't executed it yet, or it was closed
      // we've got to go to the backend
      // for more info. We send the full query, but just don't
      // execute it.

      int flags = QueryExecutor.QUERY_ONESHOT | QueryExecutor.QUERY_DESCRIBE_ONLY
          | QueryExecutor.QUERY_SUPPRESS_BEGIN;
      StatementResultHandler handler = new StatementResultHandler();
      connection.getQueryExecutor().execute(preparedQuery.query, preparedParameters, handler, 0, 0,
          flags);
      ResultWrapper wrapper = handler.getResults();
      if (wrapper != null) {
        rs = wrapper.getResultSet();
      }
    }

    if (rs != null) {
      return rs.getMetaData();
    }

    return null;
  }
```

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #3781: Performance Optimization: PgPreparedStatement.getMetaData Should Not Use QUERY_ONESHOT
@ 2025-08-22 09:24  "davecramer (@davecramer)" <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: davecramer (@davecramer) @ 2025-08-22 09:24 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Makes sense I guess if you have a lot of metadata queries. Please provide a PR

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [pgjdbc/pgjdbc] issue #3781: Performance Optimization: PgPreparedStatement.getMetaData Should Not Use QUERY_ONESHOT
@ 2025-09-03 05:22  "ShenFeng312 (@ShenFeng312)" <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: ShenFeng312 (@ShenFeng312) @ 2025-09-03 05:22 UTC (permalink / raw)
  To: pgjdbc/pgjdbc <[email protected]>

Closed by #3783

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-09-03 05:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-08-22 04:40 [pgjdbc/pgjdbc] issue #3781: Performance Optimization: PgPreparedStatement.getMetaData Should Not Use QUERY_ONESHOT "ShenFeng312 (@ShenFeng312)" <[email protected]>
2025-08-22 09:24 ` "davecramer (@davecramer)" <[email protected]>
2025-09-03 05:22 ` "ShenFeng312 (@ShenFeng312)" <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox