Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuland committed Jun 16, 2024
2 parents 0fd83a5 + 2241b38 commit 1d9d0f5
Show file tree
Hide file tree
Showing 60 changed files with 713 additions and 276 deletions.
2 changes: 1 addition & 1 deletion h2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<lucene.version>9.7.0</lucene.version>
<osgi.version>5.0.0</osgi.version>
<osgi.jdbc.version>1.1.0</osgi.jdbc.version>
<pgjdbc.version>42.5.4</pgjdbc.version>
<pgjdbc.version>42.7.2</pgjdbc.version>
<javax.servlet.version>4.0.1</javax.servlet.version>
<jakarta.servlet.version>5.0.0</jakarta.servlet.version>
<slf4j.version>2.0.7</slf4j.version>
Expand Down
17 changes: 17 additions & 0 deletions h2/src/docsrc/html/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ <h1>Change Log</h1>

<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #701: An available index is never used for ordering, when the requested order is DESC
</li>
<li>Issue #4036: NULLS NOT DISTINCT constraint changed after column dropped
</li>
<li>Issue #4033: Wrong array produced when using ARRAY_AGG() on UNNEST(ARRAY[CAST(? AS INT)]) expression
in a PreparedStatement
</li>
<li>Issue #3909: Maintenance taking too much resources since 2.2.222
</li>
<li>Issue #4010: org.h2.jdbc.JdbcConnection.getTypeMap() returns null
</li>
<li>PR #4007: Update pom.xml related to CVE-2024-1597
</li>
<li>Issue #3907: MvStoreTool unable to Repair() or Rollback() [2.1.214]
</li>
<li>RP #3997: Server-side batch execution for prepared statements
</li>
<li>Issue #3106: Trailing commas in SELECT are accepted by the parser
</li>
<li>PR #3992: Add IPv6 support to H2 Console
Expand Down
11 changes: 11 additions & 0 deletions h2/src/docsrc/html/performance.html
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,17 @@ <h3>Special Optimizations</h3>
</p><p>
For queries of the form <code>SELECT * FROM TEST ORDER BY ID</code>, the query plan includes the line
<code>/* index sorted */</code> to indicate there is no separate sorting required.
<code>/* index sorted: 2 of 3 columns */</code> indicates that only some columns are sorted with an index.
An additional sorting is still required, but queries with the FETCH (TOP, LIMIT) clause
may still stop their execution earlier.
An index on <code>(A ASC, B ASC)</code> columns can be used for <code>ORDER BY A</code>, <code>ORDER BY A DESC</code>,
<code>ORDER BY A, B</code> or <code>ORDER BY A DESC, B DESC</code>.
With <code>ORDER BY A, B DESC</code> this index can only be used for ordering on the column <code>A</code>.
If columns are nullable, order of nulls is also important. Index on <code>(A ASC NULLS FIRST)</code> cannot be used for
<code>ORDER BY A ASC NULLS LAST</code>, but can be used for <code>ORDER BY A ASC NULLS FIRST</code> or
<code>ORDER BY A DESC NULLS LAST</code>.
When neither <code>NULLS FIRST</code> nor <code>NULLS LAST</code> is specified, a default is used, this default
is controlled by <a href="commands.html#set_default_null_ordering"><code>DEFAULT_NULL_ORDERING</code></a> setting.
</p><p>
For queries of the form <code>SELECT * FROM TEST GROUP BY ID ORDER BY ID</code>, the query plan includes the line
<code>/* group sorted */</code> to indicate there is no separate sorting required.
Expand Down
9 changes: 6 additions & 3 deletions h2/src/main/org/h2/bnf/context/DbContextRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public boolean autoComplete(Sentence sentence) {
best = quotedName;
bestSchema = schema;
}
} else if (s.isEmpty() || StringUtils.startsWithIgnoringCase(name, query) || StringUtils.startsWithIgnoringCase(quotedName, query)) {
} else if (s.isEmpty() || StringUtils.startsWithIgnoringCase(name, query)
|| StringUtils.startsWithIgnoringCase(quotedName, query)) {
if (s.length() < name.length()) {
sentence.add(name, name.substring(s.length()), type);
sentence.add(schema.quotedName + ".",
Expand All @@ -116,12 +117,14 @@ public boolean autoComplete(Sentence sentence) {
String name = table.getName();
String quotedName = StringUtils.quoteIdentifier(name);

if (StringUtils.startsWithIgnoringCase(query, name) || StringUtils.startsWithIgnoringCase("\"" + query, quotedName)) {
if (StringUtils.startsWithIgnoringCase(query, name)
|| StringUtils.startsWithIgnoringCase("\"" + query, quotedName)) {
if (best == null || name.length() > best.length()) {
best = name;
bestTable = table;
}
} else if (s.isEmpty() || StringUtils.startsWithIgnoringCase(name, query) || StringUtils.startsWithIgnoringCase(quotedName, query)) {
} else if (s.isEmpty() || StringUtils.startsWithIgnoringCase(name, query)
|| StringUtils.startsWithIgnoringCase(quotedName, query)) {
if (s.length() < name.length()) {
sentence.add(table.getQuotedName(),
table.getQuotedName().substring(s.length()),
Expand Down
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/command/CommandContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public CommandContainer(SessionLocal session, String sql, Prepared prepared) {
@Override
public ArrayList<? extends ParameterInterface> getParameters() {
ArrayList<Parameter> parameters = prepared.getParameters();
if (parameters.size() > 0 && prepared.isWithParamValues()) {
if (!parameters.isEmpty() && prepared.isWithParamValues()) {
parameters = new ArrayList<>();
}
return parameters;
Expand Down
11 changes: 6 additions & 5 deletions h2/src/main/org/h2/command/CommandList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class CommandList extends Command {

private CommandContainer command;
private final CommandContainer command;
private final ArrayList<Prepared> commands;
private final ArrayList<Parameter> parameters;
private String remaining;
Expand All @@ -42,20 +42,21 @@ public ArrayList<? extends ParameterInterface> getParameters() {

private void executeRemaining() {
for (Prepared prepared : commands) {
CommandContainer commandContainer = new CommandContainer(session, prepared.getSQL(), prepared);
prepared.prepare();
if (prepared.isQuery()) {
prepared.query(0);
executeQuery(0, false);
} else {
prepared.update();
commandContainer.executeUpdate(null);
}
}
if (remaining != null) {
remainingCommand = session.prepareLocal(remaining);
remaining = null;
if (remainingCommand.isQuery()) {
remainingCommand.query(0);
remainingCommand.executeQuery(0, false);
} else {
remainingCommand.update(null);
remainingCommand.executeUpdate(null);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions h2/src/main/org/h2/command/CommandRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ public BatchResult executeBatchUpdate(ArrayList<Value[]> batchParameters, Object
}
if (readGeneratedKeys) {
int columnCount = transfer.readInt();
ResultRemote remoteGeneratedKeys = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE);
ResultRemote remoteGeneratedKeys = new ResultRemote(session, transfer, objectId,
columnCount, Integer.MAX_VALUE);
generatedKeys.add(remoteGeneratedKeys);
remoteGeneratedKeys.close();
}
Expand All @@ -310,7 +311,8 @@ public BatchResult executeBatchUpdate(ArrayList<Value[]> batchParameters, Object
autoCommit = transfer.readBoolean();
if (readGeneratedKeys) {
int columnCount = transfer.readInt();
ResultRemote remoteGeneratedKeys = new ResultRemote(session, transfer, objectId, columnCount, Integer.MAX_VALUE);
ResultRemote remoteGeneratedKeys = new ResultRemote(session, transfer, objectId,
columnCount, Integer.MAX_VALUE);
generatedKeys.add(remoteGeneratedKeys);
remoteGeneratedKeys.close();
}
Expand Down
8 changes: 2 additions & 6 deletions h2/src/main/org/h2/command/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4414,12 +4414,8 @@ private ArrayTableFunction readUnnestFunction() {
do {
Expression expr = readExpression();
TypeInfo columnType = TypeInfo.TYPE_NULL;
boolean constant = expr.isConstant();
if (constant || expr instanceof CastSpecification) {
if (constant) {
expr = expr.optimize(session);
}
TypeInfo exprType = expr.getType();
TypeInfo exprType = expr.getTypeIfStaticallyKnown(session);
if (exprType != null) {
switch (exprType.getValueType()) {
case Value.JSON:
columnType = TypeInfo.TYPE_JSON;
Expand Down
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/command/ddl/Analyze.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static void analyzeTable(SessionLocal session, Table table, int sample, b
if (columnCount == 0) {
return;
}
Cursor cursor = table.getScanIndex(session).find(session, null, null);
Cursor cursor = table.getScanIndex(session).find(session, null, null, false);
if (cursor.next()) {
SelectivityData[] array = new SelectivityData[columnCount];
for (int i = 0; i < columnCount; i++) {
Expand Down
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/command/dml/ScriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private static <T extends DbObject> T[] sorted(Collection<T> collection, Class<T
private int generateInsertValues(int count, Table table) throws IOException {
PlanItem plan = table.getBestPlanItem(session, null, null, -1, null, null);
Index index = plan.getIndex();
Cursor cursor = index.find(session, null, null);
Cursor cursor = index.find(session, null, null, false);
Column[] columns = table.getColumns();
boolean withGenerated = false, withGeneratedAlwaysAsIdentity = false;
for (Column c : columns) {
Expand Down
Loading

0 comments on commit 1d9d0f5

Please sign in to comment.