fix(sql): preserve duplicate OceanBase Oracle projections when paging

Closes #10722
This commit is contained in:
t8y2 committed 2026-10-02 18:40:46 +00:00
1 parent c30b198455
commit 6d1c3c8373
10 files changed
+702 -18

No files matched your search

@@ -100,7 +100,13 @@ public final class OceanBaseOracleAgent extends ConfiguredJdbcAgent {
@Override
public QueryPageResult executeQueryPage(String sql, String schema, QueryPageOptions options) {
try (QueryTiming timing = QueryTiming.begin()) {
QueryPageResult result = super.executeQueryPage(sql, schema, options);
long prepareStarted = System.nanoTime();
Connection connection = requireConnected();
uncheckedVoid(() -> beforeQueryExecution(connection, options.getTimeoutSecs()));
QueryTiming.record("session_prepare", prepareStarted);
QueryPageResult result = JdbcExecutor.current().executeBoundedPage(
connection, sql, schema, this::setSchemaSQL, this::resetSchemaSQL, options, resultValueReader()
);
result.setQuery_timings_ms(timing.finish());
return result;
}
@@ -147,7 +147,8 @@ class OceanBaseOracleAgentTest {
List<String> auditSql = new ArrayList<>();
Connection auditConnection = auditTimingConnection(1, 2, false, auditSql, new ArrayList<>(), auditLimits);
int[] row = {-1};
int[] queryLimit = {0}; // JDBC's default, independent of the client-side cap.
int[] queryLimit = {0};
int[] queryFetchSize = {0};
boolean[] queryStarted = {false};
boolean[] resultClosed = {false};
boolean[] statementClosed = {false};
@@ -167,6 +168,7 @@ class OceanBaseOracleAgentTest {
});
Statement statement = proxy(Statement.class, (method, args) -> {
if ("setMaxRows".equals(method.getName())) queryLimit[0] = (Integer) args[0];
if ("setFetchSize".equals(method.getName())) queryFetchSize[0] = (Integer) args[0];
if ("execute".equals(method.getName())) {
queryStarted[0] = !String.valueOf(args[0]).startsWith("ALTER SESSION");
statementClosed[0] = false;
@@ -198,7 +200,8 @@ class OceanBaseOracleAgentTest {
Assertions.assertFalse(result.getHas_more());
Assertions.assertEquals(truncated, result.getTruncated());
Assertions.assertEquals(truncated ? List.of(List.of(1)) : List.of(List.of(1), List.of(2)), rows);
Assertions.assertEquals(0, queryLimit[0], "the paging cap must not change the JDBC statement limit");
Assertions.assertEquals(maxRows + 1, queryLimit[0]);
Assertions.assertTrue(queryFetchSize[0] > 0);
Assertions.assertTrue(auditSql.isEmpty(), "completed queries must not read trace or audit records");
Assertions.assertTrue(auditLimits.isEmpty());
Assertions.assertNull(result.getServer_execute_time_us());
@@ -0,0 +1,78 @@
package com.dbx.agent.oceanbaseoracle;
import com.dbx.agent.JdbcExecutor;
import com.dbx.agent.QueryPageOptions;
import com.oceanbase.jdbc.OceanBaseConnection;
import com.oceanbase.jdbc.UrlParser;
import com.oceanbase.jdbc.internal.com.read.dao.Results;
import com.oceanbase.jdbc.internal.protocol.MasterProtocol;
import com.oceanbase.jdbc.internal.util.pool.GlobalStateInfo;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import static org.junit.jupiter.api.Assertions.*;
class OceanBaseOracleCursorTransportTest {
@Test
void connectorKeepsSqlAndAppliesCumulativeLimitIncludingLookahead() throws Exception {
for (String sql : List.of("SELECT a.name, a.* FROM people a", "SELECT name, name FROM people",
"SELECT a.*, b.* FROM people a JOIN people b ON a.id=b.id")) {
for (int max : new int[]{0, 1, 10000, Integer.MAX_VALUE}) {
for (boolean fallback : new boolean[]{false, true}) {
Capture protocol = new Capture(fallback);
OceanBaseConnection connection = new OceanBaseConnection(protocol);
JdbcExecutor executor = new JdbcExecutor();
RuntimeException error = assertThrows(RuntimeException.class, () -> executor.executeBoundedPage(
connection, sql, null, schema -> "", () -> "", new QueryPageOptions(2, null, max),
executor::defaultResultValue));
assertTrue(error.toString().contains("STOP_BEFORE_NETWORK"));
assertEquals("set @@_ORACLE_SQL_SELECT_LIMIT = " + JdbcExecutor.statementMaxRows(max), protocol.sent.get(0));
if (fallback) assertEquals("set @@SQL_SELECT_LIMIT = " + JdbcExecutor.statementMaxRows(max), protocol.sent.get(1));
assertEquals(sql, protocol.sent.get(protocol.sent.size() - 1));
assertFalse(executor.hasActiveStatements());
assertFalse(executor.hasOpenSessions());
protocol.sent.clear();
try (Statement statement = connection.createStatement()) {
assertThrows(SQLException.class, () -> statement.execute("SELECT 1 FROM DUAL"));
}
assertEquals("set @@_ORACLE_SQL_SELECT_LIMIT = DEFAULT", protocol.sent.get(0));
if (fallback) assertEquals("set @@SQL_SELECT_LIMIT = DEFAULT", protocol.sent.get(1));
}
}
}
}
private static final class Capture extends MasterProtocol {
final List<String> sent = new ArrayList<>();
final boolean fallback;
Capture(boolean fallback) throws Exception {
super(UrlParser.parse("jdbc:oceanbase://localhost:1/test"), new GlobalStateInfo(), new ReentrantLock(), null);
this.fallback = fallback;
connected = true;
}
@Override
public boolean isOracleMode() { return true; }
@Override
public boolean versionGreaterOrEqual(int major, int minor, int patch) { return false; }
@Override
public void executeQuery(String sql) throws SQLException {
sent.add(sql);
if (fallback && sql.contains("_ORACLE_SQL_SELECT_LIMIT")) throw new SQLException("unsupported variable fixture");
}
@Override
public void executeQuery(boolean master, Results results, String sql) throws SQLException {
sent.add(sql);
throw new SQLException("STOP_BEFORE_NETWORK", "ZZZZZ");
}
}
}