Modified:
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
Log:
Disable cursor-based fetch by default.
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2005-09-02 00:08:06 UTC (rev 4192)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2005-09-02 18:23:36 UTC (rev 4193)
@@ -5371,4 +5371,8 @@
return this.io.versionMeetsMinimum(major, minor, subminor);
}
+
+ protected boolean isCursorFetchEnabled() throws SQLException {
+ return (versionMeetsMinimum(5, 0, 2) && getUseCursorFetch());
+ }
}
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2005-09-02 00:08:06 UTC (rev 4192)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2005-09-02 18:23:36 UTC (rev 4193)
@@ -1172,6 +1172,13 @@
+ "URL or applying user-specified properties. These configurations are explained in the 'Configurations' of the documentation.",
"3.1.5", CONNECTION_AND_AUTH_CATEGORY, Integer.MAX_VALUE);
+ private BooleanConnectionProperty useCursorFetch = new BooleanConnectionProperty(
+ "useCursorFetch",
+ false,
+ "If connected to MySQL > 5.0.2, and setFetchSize() > 0 on a statement, should "
+ + " that statement use cursor-based fetching to retrieve rows?",
+ "5.0.0", PERFORMANCE_CATEGORY, Integer.MAX_VALUE);
+
private BooleanConnectionProperty useFastIntParsing = new BooleanConnectionProperty(
"useFastIntParsing",
true,
@@ -3463,4 +3470,12 @@
protected boolean useUnbufferedInput() {
return this.useUnbufferedInput.getValueAsBoolean();
}
+
+ protected boolean getUseCursorFetch() {
+ return this.useCursorFetch.getValueAsBoolean();
+ }
+
+ protected void setUseCursorFetch(boolean flag) {
+ this.useCursorFetch.setValue(flag);
+ }
}
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2005-09-02 00:08:06 UTC (rev 4192)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java 2005-09-02 18:23:36 UTC (rev 4193)
@@ -1065,7 +1065,7 @@
// preclude updatable result sets)
// d) The user has set a fetch size
if (this.resultFields != null &&
- this.connection.versionMeetsMinimum(5, 0, 2)
+ this.connection.isCursorFetchEnabled()
&& getResultSetType() == ResultSet.TYPE_FORWARD_ONLY
&& getResultSetConcurrency() == ResultSet.CONCUR_READ_ONLY
&& getFetchSize() > 0) {
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java 2005-09-02 00:08:06 UTC (rev 4192)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java 2005-09-02 18:23:36 UTC (rev 4193)
@@ -775,92 +775,98 @@
// generated from the current Connection (saves
// a query, and network traffic).
synchronized (this.connection.getMutex()) {
- String oldCatalog = null;
-
- if (!this.connection.getCatalog().equals(this.currentCatalog)) {
- oldCatalog = this.connection.getCatalog();
- this.connection.setCatalog(this.currentCatalog);
- }
-
- //
- // Check if we have cached metadata for this query...
- //
- if (this.connection.getCacheResultSetMetadata()) {
- cachedMetaData = getCachedMetaData(sql);
- }
-
- if (this.connection.useMaxRows()) {
- // We need to execute this all together
- // So synchronize on the Connection's mutex (because
- // even queries going through there synchronize
- // on the connection
- if (StringUtils.indexOfIgnoreCase(sql, "LIMIT") != -1) { //$NON-NLS-1$
- this.results = this.connection.execSQL(this, sql,
- this.maxRows, null, this.resultSetType,
- this.resultSetConcurrency,
- createStreamingResultSet(), true,
- this.currentCatalog, (cachedMetaData == null));
- } else {
- if (this.maxRows <= 0) {
- this.connection
- .execSQL(
- this,
- "SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, //$NON-NLS-1$
- java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false, this.currentCatalog, true); //$NON-NLS-1$
+ if (useServerFetch()) {
+ this.results = createResultSetUsingServerFetch(sql);
+
+ return this.results;
+ } else {
+ String oldCatalog = null;
+
+ if (!this.connection.getCatalog().equals(this.currentCatalog)) {
+ oldCatalog = this.connection.getCatalog();
+ this.connection.setCatalog(this.currentCatalog);
+ }
+
+ //
+ // Check if we have cached metadata for this query...
+ //
+ if (this.connection.getCacheResultSetMetadata()) {
+ cachedMetaData = getCachedMetaData(sql);
+ }
+
+ if (this.connection.useMaxRows()) {
+ // We need to execute this all together
+ // So synchronize on the Connection's mutex (because
+ // even queries going through there synchronize
+ // on the connection
+ if (StringUtils.indexOfIgnoreCase(sql, "LIMIT") != -1) { //$NON-NLS-1$
+ this.results = this.connection.execSQL(this, sql,
+ this.maxRows, null, this.resultSetType,
+ this.resultSetConcurrency,
+ createStreamingResultSet(), true,
+ this.currentCatalog, (cachedMetaData == null));
} else {
- this.connection
- .execSQL(
- this,
- "SET OPTION SQL_SELECT_LIMIT=" + this.maxRows, -1, //$NON-NLS-1$
- null,
- java.sql.ResultSet.TYPE_FORWARD_ONLY,
- java.sql.ResultSet.CONCUR_READ_ONLY,
- false, false, this.currentCatalog, true); //$NON-NLS-1$
+ if (this.maxRows <= 0) {
+ this.connection
+ .execSQL(
+ this,
+ "SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1, null, //$NON-NLS-1$
+ java.sql.ResultSet.TYPE_FORWARD_ONLY,
+ java.sql.ResultSet.CONCUR_READ_ONLY,
+ false, false, this.currentCatalog, true); //$NON-NLS-1$
+ } else {
+ this.connection
+ .execSQL(
+ this,
+ "SET OPTION SQL_SELECT_LIMIT=" + this.maxRows, -1, //$NON-NLS-1$
+ null,
+ java.sql.ResultSet.TYPE_FORWARD_ONLY,
+ java.sql.ResultSet.CONCUR_READ_ONLY,
+ false, false, this.currentCatalog, true); //$NON-NLS-1$
+ }
+
+ this.results = this.connection.execSQL(this, sql, -1, null,
+ this.resultSetType, this.resultSetConcurrency,
+ createStreamingResultSet(), true,
+ this.currentCatalog, (cachedMetaData == null));
+
+ if (oldCatalog != null) {
+ this.connection.setCatalog(oldCatalog);
+ }
}
-
+ } else {
this.results = this.connection.execSQL(this, sql, -1, null,
this.resultSetType, this.resultSetConcurrency,
- createStreamingResultSet(), true,
- this.currentCatalog, (cachedMetaData == null));
-
- if (oldCatalog != null) {
- this.connection.setCatalog(oldCatalog);
- }
+ createStreamingResultSet(), true, this.currentCatalog,
+ (cachedMetaData == null));
}
+
+ if (oldCatalog != null) {
+ this.connection.setCatalog(oldCatalog);
+ }
+ }
+
+ this.lastInsertId = this.results.getUpdateID();
+
+ /*
+ * if (!this.results.reallyResult()) { if
+ * (!this.connection.getAutoCommit()) { this.connection.rollback(); }
+ *
+ * throw new SQLException(Messages.getString("Statement.40"),
+ * //$NON-NLS-1$ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ }
+ */
+ if (cachedMetaData != null) {
+ initializeResultsMetadataFromCache(sql, cachedMetaData,
+ this.results);
} else {
- this.results = this.connection.execSQL(this, sql, -1, null,
- this.resultSetType, this.resultSetConcurrency,
- createStreamingResultSet(), true, this.currentCatalog,
- (cachedMetaData == null));
+ if (this.connection.getCacheResultSetMetadata()) {
+ initializeResultsMetadataFromCache(sql,
+ null /* will be created */, this.results);
+ }
}
-
- if (oldCatalog != null) {
- this.connection.setCatalog(oldCatalog);
- }
+
+ return this.results;
}
-
- this.lastInsertId = this.results.getUpdateID();
-
- /*
- * if (!this.results.reallyResult()) { if
- * (!this.connection.getAutoCommit()) { this.connection.rollback(); }
- *
- * throw new SQLException(Messages.getString("Statement.40"),
- * //$NON-NLS-1$ SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ }
- */
- if (cachedMetaData != null) {
- initializeResultsMetadataFromCache(sql, cachedMetaData,
- this.results);
- } else {
- if (this.connection.getCacheResultSetMetadata()) {
- initializeResultsMetadataFromCache(sql,
- null /* will be created */, this.results);
- }
- }
-
- return this.results;
}
/**
@@ -1833,7 +1839,7 @@
*/
private boolean useServerFetch() throws SQLException {
- return this.connection.versionMeetsMinimum(5, 0, 2)
+ return this.connection.isCursorFetchEnabled()
&& this.fetchSize > 0
&& this.resultSetConcurrency == ResultSet.CONCUR_READ_ONLY
&& this.resultSetType == ResultSet.TYPE_FORWARD_ONLY;
| Thread |
|---|
| • Connector/J commit: r4193 - branches/branch_5_0/connector-j/src/com/mysql/jdbc | mmatthews | 2 Sep |