Skip to content

Commit

Permalink
IGNITE-24514 Get rid of performance drop
Browse files Browse the repository at this point in the history
  • Loading branch information
skorotkov committed Feb 15, 2025
1 parent 4735986 commit f9e3a49
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.h2.engine.Session;
import org.h2.expression.ValueExpression;
import org.h2.jdbc.JdbcConnection;
import org.h2.jdbc.JdbcStatement;
import org.h2.table.RangeTable;
import org.jetbrains.annotations.Nullable;

import static org.h2.engine.Constants.SCHEMA_MAIN;

/**
* Wrapper to store connection with currently used schema and statement cache.
*/
Expand Down Expand Up @@ -61,6 +65,19 @@ public class H2Connection implements AutoCloseable {
this.log = log;

initStatementCache();

// Work around the H2 bug (NPE in Session#removeLocalTempTable).
// Make sure session always contains not-null list of temp tables.
Session sess = (Session)((JdbcConnection)conn).getSession();

RangeTable dummyTbl = new RangeTable(
sess.getDatabase().getSchema(SCHEMA_MAIN),
ValueExpression.getNull(),
ValueExpression.getNull(),
true);

sess.addLocalTempTable(dummyTbl);
sess.removeLocalTempTable(dummyTbl);
}

/**
Expand Down Expand Up @@ -195,11 +212,6 @@ PreparedStatement prepareStatementNoCache(String sql) {
catch (SQLException e) {
throw new IgniteSQLException("Failed to parse query. " + e.getMessage(), IgniteQueryErrorCode.PARSING, e);
}
finally {
Session sess = (Session)((JdbcConnection)conn).getSession();

sess.getLocalTempTables().forEach(sess::removeLocalTempTable);
}
}

/** {@inheritDoc} */
Expand Down

0 comments on commit f9e3a49

Please sign in to comment.