Re: [RFC] How about changing the default value of defaultRowFetchSize?

From: "Tsunakawa, Takayuki" <tsunakawa(dot)takay(at)jp(dot)fujitsu(dot)com>
To: 'Jorge Solorzano' <jorsol(at)gmail(dot)com>, Mark Rotteveel <mark(at)lawinegevaar(dot)nl>
Cc: Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>, List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: [RFC] How about changing the default value of defaultRowFetchSize?
Date: 2016-10-21 04:11:59
Message-ID: 0A3221C70F24FB45833433255569204D1F634A8B@G01JPEXMBYT05
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi, all,

Thanks for many comments and information. First, let me make consensus on the interpretation of JDBC spec.

The value given to setFetchSize() is a hint, not the actual number of rows. The default hint is 0. e.g. The Java SE 7 API doc says:

"Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects genrated by this Statement. If the value specified is zero, then the hint is ignored. The default value is zero."

On the other hand, the JDBC spec and the API doc say different thing regarding the return value of getFetchSize(). The JDBC doc says that it returns the hint value, while the API doc says that it returns the number of rows (not the hint).

[JDBC spec]
"The methods getFetchDirection and getFetchSize return the current value of the
hints. If either of these methods is called before the corresponding setter method has
been called, the value returned is implementation-defined."

[Java SE 7 API doc]
"Retrieves the number of result set rows that is the default fetch size for ResultSet objects generated from this Statement object. If this Statement object has not set a fetch size by calling the method setFetchSize, the return value is implementation-specific."

However, the API doc should be correct. If the return value were the hint value, it should be 0 before calling setFetchSize(). But both docs say the return value is "implementation-defined." The implementation-defined value is the number of rows when the current hint is 0.

Then, I'd like to propose the following behavior. Is this OK?

* The default value of defaultRowFetchSize is 100.

* When setFetchSize() is not called, or setFetchSize(0) was called
getFetchSize() returns 100.
The actual number of rows fetched is 100.

* When setFetchSize() was called with a non-zero argument value
getFetchSize() returns that value.
The actual number of rows fetched is that value.

It's unfortunate that the fetch size works only when autocommit is off, but the above change will mitigate the risk of bad impression that newcomers from other DBMSs may have on PostgreSQL.

Should I submit a patch, or is there someone who wants to do it?

Regards
Takayuki Tsunakawa

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tsunakawa, Takayuki 2016-10-21 04:33:55 Re: [RFC] How about changing the default value of defaultRowFetchSize?
Previous Message Brad DeJong 2016-10-20 20:46:02 Re: setCharacterStream(int, Reader)