Обсуждение: setFetchSize() and preferQueryMode incompatible?

Поиск
Список
Период
Сортировка

setFetchSize() and preferQueryMode incompatible?

От
Alan Stange
Дата:
Hello all,

I've been playing around a little with using preferQueryMode set to 
extendedForPrepared to avoid the multiple round trips to the server.   
The default setting is a significant performance impact if there is any 
meaningful network latency.     We were also attempting to setFetchSize 
and found these two settings will not work together in any of the 
42.2.1, 42.1.4 or 9.4.1202 jdbc client builds running against a 9.6.x 
version server.

Is this a bug or a "feature"?

Below is the sample code.  The fetch size will not be respected with the 
preferQueryMode property present.

Thank you for having a look.

-- Alan



public class Work {

     public static void main(String ... args) throws SQLException {

         // make obvious changes here....
         String url = "jdbc:postgresql://host:5432/db";
         String user = "user";
         String passwd = "pass";

         Properties props = new Properties();
         props.put("user", user);
         props.put("password", passwd);
         props.put("preferQueryMode", "extendedForPrepared");

         Connection conn = DriverManager.getConnection(url, props);
         conn.setAutoCommit(false);
         Statement st = conn.createStatement();
         st.setFetchSize(1024);
         ResultSet rs = st.executeQuery("select * from reallyBigTable");
         while (rs.next()) {
             rs.getObject(1);
         }
     }
}


Re: setFetchSize() and preferQueryMode incompatible?

От
Vladimir Sitnikov
Дата:
Hi,

TL;DR: it works as expected/designed.

Alan>extendedForPrepared to avoid the multiple round trips to the server.  
The default setting is a significant performance impact if there is any
meaningful network latency

Would you please elaborate and/or provide a test case for the "performance impact"?
Note: you might want to collect some trace logs (loggerLevel=TRACE&loggerFile=pgjdbc-trace.log) in order to count the roundtrips.

Alan>The fetch size will not be respected with the
preferQueryMode property present

That setting means pgjdbc would use "Simple Query" to execute con.createStatement() kind of statements.
"Simple query" does not support portals, and there is no room to specify "fetch size".
It is just <<'Q' len:Int32 text:string>> message to the server, and it always replies with full set of rows.

In case you absolutely need to use preferQueryMode=extendedForPrepared, you can make fetchsize to work by using con.prepareStatement(...)

Vladimir