From 42dc440f05450460196d5b503f3c6e1bfbd73797 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Mon, 23 Nov 2026 16:44:02 -0800 Subject: [PATCH 1/2] Speed up building temp tables for large IN clauses On PostgreSQL, build them UNLOGGED with a single unnest() insert and a unique index, and keep each cached until 5 minutes after its last use. --- .../org/labkey/api/cache/CacheManager.java | 14 +++- .../api/data/TempTableInClauseGenerator.java | 77 ++++++++++++++++--- .../data/dialect/BasePostgreSqlDialect.java | 6 ++ .../labkey/api/data/dialect/SqlDialect.java | 13 ++++ .../core/dialect/PostgreSql92Dialect.java | 12 +++ 5 files changed, 109 insertions(+), 13 deletions(-) diff --git a/api/src/org/labkey/api/cache/CacheManager.java b/api/src/org/labkey/api/cache/CacheManager.java index 59a631f26fa..98e1f51a4d0 100644 --- a/api/src/org/labkey/api/cache/CacheManager.java +++ b/api/src/org/labkey/api/cache/CacheManager.java @@ -84,9 +84,9 @@ public class CacheManager ); @SuppressWarnings("unchecked") - private static SimpleCache getSimpleCache(@NotNull Class keyClass, int limit, long defaultTimeToLive, String debugName, boolean temporary) + private static SimpleCache getSimpleCache(@NotNull Class keyClass, int limit, long defaultTimeToLive, long defaultTimeToIdle, String debugName, boolean temporary) { - SimpleCache cache = PROVIDER.getSimpleCache(debugName, limit, defaultTimeToLive, UNLIMITED, temporary); + SimpleCache cache = PROVIDER.getSimpleCache(debugName, limit, defaultTimeToLive, defaultTimeToIdle, temporary); Function, SimpleCache> mapping = KEY_MAPPINGS.get(keyClass); return (SimpleCache) (null == mapping ? cache : mapping.apply(cache)); } @@ -94,7 +94,13 @@ private static SimpleCache getSimpleCache(@NotNull Class keyClas /** Returns a cache implementation specialized for keyClass, if one is registered */ public static TrackingCache getCache(@NotNull Class keyClass, int limit, long defaultTimeToLive, String debugName) { - CacheWrapper cache = new CacheWrapper<>(getSimpleCache(keyClass, limit, defaultTimeToLive, debugName, false), keyClass, debugName, null, Thread.currentThread().getStackTrace()); + return getCache(keyClass, limit, defaultTimeToLive, UNLIMITED, debugName); + } + + /** Like {@link #getCache(Class, int, long, String)}, but entries also expire defaultTimeToIdle ms after their last get or put */ + public static TrackingCache getCache(@NotNull Class keyClass, int limit, long defaultTimeToLive, long defaultTimeToIdle, String debugName) + { + CacheWrapper cache = new CacheWrapper<>(getSimpleCache(keyClass, limit, defaultTimeToLive, defaultTimeToIdle, debugName, false), keyClass, debugName, null, Thread.currentThread().getStackTrace()); addToKnownCaches(cache); // Permanent cache -- hold onto it LabKeyManagement.register(cache.createDynamicMBean(), debugName, "Cache"); return cache; @@ -109,7 +115,7 @@ public static BlockingCache getBlockingCache(@NotNull Class keyC // Temporary caches must be closed when no longer needed. Their statistics can accumulate to another cache's stats. public static Cache getTemporaryCache(@NotNull Class keyClass, int limit, long defaultTimeToLive, String debugName, @Nullable Stats stats) { - return new CacheWrapper<>(getSimpleCache(keyClass, limit, defaultTimeToLive, debugName, true), keyClass, debugName, stats, null); + return new CacheWrapper<>(getSimpleCache(keyClass, limit, defaultTimeToLive, UNLIMITED, debugName, true), keyClass, debugName, stats, null); } private static final Cache SHARED_CACHE = getCache(String.class, 10000, DEFAULT_TIMEOUT, "Shared"); diff --git a/api/src/org/labkey/api/data/TempTableInClauseGenerator.java b/api/src/org/labkey/api/data/TempTableInClauseGenerator.java index b82c4637be3..005d2c4677a 100644 --- a/api/src/org/labkey/api/data/TempTableInClauseGenerator.java +++ b/api/src/org/labkey/api/data/TempTableInClauseGenerator.java @@ -18,11 +18,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.Assert; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.labkey.api.action.SpringActionController; import org.labkey.api.cache.Cache; import org.labkey.api.cache.CacheManager; +import org.labkey.api.data.dialect.SqlDialect; import org.labkey.api.util.GUID; import org.labkey.api.util.HashHelpers; @@ -43,7 +45,7 @@ public class TempTableInClauseGenerator implements InClauseGenerator { private static final Cache _tempTableCache = - CacheManager.getCache(String.class, 200, CacheManager.MINUTE * 5, "IN clause temp tables"); + CacheManager.getCache(String.class, 200, CacheManager.UNLIMITED, CacheManager.MINUTE * 5, "IN clause temp tables"); // Need to set a supplier instead of setting the default temp schema directly because this class is constructed at // dialect init time, before schemas can be referenced. @@ -132,17 +134,24 @@ else if (jdbcType == JdbcType.VARCHAR) if (null == sortedParameters) return null; - String cacheKey = getCacheKey(jdbcType, sortedParameters); + DbSchema tempSchema = _tempSchemaSupplier.get(); + // UnloggedTableGeneration only detects resets in the LabKey database + boolean unlogged = tempSchema.getScope().isLabKeyScope(); + // Scope by database and schema, so an external temp schema never reuses a LabKey table or vice versa + String cacheKey = tempSchema.getScope().getDataSourceName() + "_" + tempSchema.getName() + "_" + getCacheKey(jdbcType, sortedParameters); + // A reset empties the table, so a new generation must not hit the old entry + if (unlogged) + cacheKey += "_" + UnloggedTableGeneration.current(); TempTableInfo tempTableInfo = _tempTableCache.get(cacheKey); if (tempTableInfo == null) { - DbSchema tempSchema = _tempSchemaSupplier.get(); + SqlDialect dialect = tempSchema.getSqlDialect(); tempTableInfo = new TempTableInfo(tempSchema, "InClause", Collections.singletonList(new BaseColumnInfo("Id", jdbcType, 0, false)), null); - SQLFragment sqlCreate = new SQLFragment("CREATE TABLE "); + SQLFragment sqlCreate = SQLFragment.unsafe(unlogged ? dialect.getCreateUnloggedTableCommand() + " " : "CREATE TABLE "); sqlCreate.append(tempTableInfo) .unsafeAppend("\n(Id ") - .append(tempSchema.getSqlDialect().getSqlTypeName(jdbcType)) - .append(jdbcType == JdbcType.VARCHAR ? "(450)" : "") + .append(dialect.getSqlTypeNameAsSql(jdbcType)) + .unsafeAppend(jdbcType == JdbcType.VARCHAR ? "(450)" : "") .unsafeAppend(")"); // When the in clause receives more parameters than it is set to handle, a temporary table is created to handle the overflow. @@ -155,7 +164,17 @@ else if (jdbcType == JdbcType.VARCHAR) String tableName = tempTableInfo.getSelectName(); String sql1 = "INSERT INTO " + tableName + " (Id) VALUES (?)"; String sql100 = "INSERT INTO " + tableName + " (Id) VALUES (?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?)"; - try + if (dialect.supportsArrays()) + { + // One array-bound statement is several times faster than batched single-row INSERTs + SQLFragment sqlInsert = SQLFragment.unsafe("INSERT INTO " + tableName + " (Id) ") + .append(dialect.array_unnest(jdbcType, sortedParameters)); + try (var ignored = SpringActionController.ignoreSqlUpdates()) + { + new SqlExecutor(tempSchema).execute(sqlInsert); + } + } + else try { try (var ignored = SpringActionController.ignoreSqlUpdates()) { @@ -172,11 +191,12 @@ else if (jdbcType == JdbcType.INTEGER) throw new RuntimeSQLException(e); } - String indexSql = "CREATE INDEX IX_Id" + new GUID().toStringNoDashes() + " ON " + tableName + "(Id)"; + // UNIQUE tells the planner the ids are distinct, so it skips de-duplicating them in IN (SELECT ...) + String indexSql = "CREATE UNIQUE INDEX IX_Id" + new GUID().toStringNoDashes() + " ON " + tableName + "(Id)"; try (var ignored = SpringActionController.ignoreSqlUpdates()) { new SqlExecutor(tempSchema).execute(indexSql); - tempSchema.getSqlDialect().updateStatistics(tempTableInfo); // Immediately analyze the newly populated & indexed table + dialect.updateStatistics(tempTableInfo); // Immediately analyze the newly populated & indexed table } TempTableInfo cacheEntry = tempTableInfo; @@ -290,6 +310,45 @@ public void testString() Assert.assertEquals("Validate SQL matches, indicated cached results", firstSQL, secondSQL); } + @Test + public void testTypesWithNull() + { + record Case(String values, List params) {} + for (Case c : List.of( + new Case("SELECT 'a' UNION SELECT 'b' UNION SELECT 'g'", Arrays.asList("d", "a", null, "b", "a")), + new Case("SELECT 1 UNION SELECT 2 UNION SELECT 7", Arrays.asList(4, 1, null, 2, 1)), + new Case("SELECT CAST(1 AS BIGINT) UNION SELECT 2 UNION SELECT 7", Arrays.asList(4L, 1L, null, 2L, 1L)))) + { + SQLFragment sql = SQLFragment.unsafe("SELECT a FROM (" + c.values() + ") b(a) WHERE a "); + SQLFragment inClause = new TempTableInClauseGenerator().appendInClauseSql(sql, c.params()); + Assert.assertNotNull(c.values(), inClause); + Assert.assertEquals(c.values(), 2, new SqlSelector(_scope, inClause).getRowCount()); + } + } + + @Test + public void testUnlogged() + { + Assume.assumeTrue(_scope.getSqlDialect().isPostgreSQL()); + TempTableInfo tti = new TempTableInClauseGenerator().getTempTableInfo(STRINGS); + Assert.assertNotNull(tti); + SQLFragment sql = SQLFragment.unsafe("SELECT relpersistence FROM pg_class WHERE oid = CAST(? AS regclass)").add(tti.getSelectName()); + Assert.assertEquals("u", new SqlSelector(_scope, sql).getObject(String.class)); + } + + @Test + public void testUnloggedReset() + { + Assume.assumeTrue(_scope.getSqlDialect().isPostgreSQL()); + SQLFragment sql = SQLFragment.unsafe("SELECT a from (SELECT 'a' AS a UNION SELECT 'b' AS a UNION SELECT 'g' AS a) b WHERE a "); + TempTableInfo before = new TempTableInClauseGenerator().getTempTableInfo(STRINGS); + Assert.assertNotNull(before); + new SqlExecutor(_scope).execute(SQLFragment.unsafe("TRUNCATE ").append(before)); + UnloggedTableGeneration.simulateResetForTest(); + SQLFragment after = new TempTableInClauseGenerator().appendInClauseSql(new SQLFragment(sql), STRINGS); + Assert.assertEquals("A reset must rebuild the emptied temp table", 2, new SqlSelector(_scope, after).getRowCount()); + } + @Test public void testJdbcParameterValues() { diff --git a/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java b/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java index 536a12f2fde..9dfdde4e45b 100644 --- a/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java +++ b/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java @@ -497,6 +497,12 @@ public String getTempTableKeyword() return "TEMPORARY"; } + @Override + public String getCreateUnloggedTableCommand() + { + return "CREATE UNLOGGED TABLE"; + } + @Override public String getTempTablePrefix() { diff --git a/api/src/org/labkey/api/data/dialect/SqlDialect.java b/api/src/org/labkey/api/data/dialect/SqlDialect.java index 9ec8f5dcf00..72086480779 100644 --- a/api/src/org/labkey/api/data/dialect/SqlDialect.java +++ b/api/src/org/labkey/api/data/dialect/SqlDialect.java @@ -870,6 +870,12 @@ public final SQLFragment getLsidTypeAsSql() public abstract String getTempTablePrefix(); + /** For disposable tables whose contents may be lost on a database crash */ + public String getCreateUnloggedTableCommand() + { + return "CREATE TABLE"; + } + public abstract String getGlobalTempTablePrefix(); public abstract boolean isNoDatabaseException(SQLException e); @@ -2628,6 +2634,13 @@ public SQLFragment array_not_same_array(SQLFragment a, SQLFragment b) throw new UnsupportedOperationException(getClass().getSimpleName() + " does not implement"); } + // SELECT returning one row per element of the bound array + public SQLFragment array_unnest(JdbcType elementType, Collection values) + { + assert !supportsArrays(); + throw new UnsupportedOperationException(getClass().getSimpleName() + " does not implement"); + } + // true if the array a contains, for EACH given value, some element matching it with a case-insensitive substring public SQLFragment array_element_like(SQLFragment a, String... values) { diff --git a/core/src/org/labkey/core/dialect/PostgreSql92Dialect.java b/core/src/org/labkey/core/dialect/PostgreSql92Dialect.java index 3d092d9fd44..f5cc217709c 100644 --- a/core/src/org/labkey/core/dialect/PostgreSql92Dialect.java +++ b/core/src/org/labkey/core/dialect/PostgreSql92Dialect.java @@ -56,6 +56,7 @@ import org.labkey.core.admin.sql.ScriptReorderer; import org.springframework.jdbc.BadSqlGrammarException; +import java.lang.reflect.Array; import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.Driver; @@ -1314,6 +1315,17 @@ public boolean supportsArrays() return true; } + @Override + public SQLFragment array_unnest(JdbcType elementType, Collection values) + { + // A typed array lets the JDBC driver pick the element type even when the first element is null + Object[] array = values.toArray(n -> (Object[]) Array.newInstance(elementType.getJavaClass(), n)); + return SQLFragment.unsafe("SELECT unnest(CAST(? AS ") + .append(getSqlTypeNameAsSql(elementType)) + .unsafeAppend("[]))") + .add(array); + } + @Override public SQLFragment array_construct(SQLFragment[] elements) { From 80a4961065aec8c589f891a64fd3ea3683ef1f80 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Mon, 23 Nov 2026 17:21:39 -0800 Subject: [PATCH 2/2] Harden IN-clause temp table caching after review Block readers during the UNLOGGED reset check, limit the UNIQUE index to PostgreSQL, cap cached tables at one hour, and length-prefix cache key values so different lists can't collide. --- .../api/data/TempTableInClauseGenerator.java | 78 ++++++++++--------- .../api/data/UnloggedTableGeneration.java | 4 +- .../data/dialect/BasePostgreSqlDialect.java | 6 -- .../labkey/api/data/dialect/SqlDialect.java | 6 -- 4 files changed, 44 insertions(+), 50 deletions(-) diff --git a/api/src/org/labkey/api/data/TempTableInClauseGenerator.java b/api/src/org/labkey/api/data/TempTableInClauseGenerator.java index 005d2c4677a..87f2673b570 100644 --- a/api/src/org/labkey/api/data/TempTableInClauseGenerator.java +++ b/api/src/org/labkey/api/data/TempTableInClauseGenerator.java @@ -45,7 +45,7 @@ public class TempTableInClauseGenerator implements InClauseGenerator { private static final Cache _tempTableCache = - CacheManager.getCache(String.class, 200, CacheManager.UNLIMITED, CacheManager.MINUTE * 5, "IN clause temp tables"); + CacheManager.getCache(String.class, 200, CacheManager.HOUR, CacheManager.MINUTE * 5, "IN clause temp tables"); // Need to set a supplier instead of setting the default temp schema directly because this class is constructed at // dialect init time, before schemas can be referenced. @@ -147,7 +147,7 @@ else if (jdbcType == JdbcType.VARCHAR) { SqlDialect dialect = tempSchema.getSqlDialect(); tempTableInfo = new TempTableInfo(tempSchema, "InClause", Collections.singletonList(new BaseColumnInfo("Id", jdbcType, 0, false)), null); - SQLFragment sqlCreate = SQLFragment.unsafe(unlogged ? dialect.getCreateUnloggedTableCommand() + " " : "CREATE TABLE "); + SQLFragment sqlCreate = SQLFragment.unsafe(unlogged ? "CREATE UNLOGGED TABLE " : "CREATE TABLE "); sqlCreate.append(tempTableInfo) .unsafeAppend("\n(Id ") .append(dialect.getSqlTypeNameAsSql(jdbcType)) @@ -159,43 +159,22 @@ else if (jdbcType == JdbcType.VARCHAR) try (var ignored = SpringActionController.ignoreSqlUpdates()) { new SqlExecutor(tempSchema).execute(sqlCreate); - } - tempTableInfo.track(); - String tableName = tempTableInfo.getSelectName(); - String sql1 = "INSERT INTO " + tableName + " (Id) VALUES (?)"; - String sql100 = "INSERT INTO " + tableName + " (Id) VALUES (?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?)"; - if (dialect.supportsArrays()) - { - // One array-bound statement is several times faster than batched single-row INSERTs - SQLFragment sqlInsert = SQLFragment.unsafe("INSERT INTO " + tableName + " (Id) ") - .append(dialect.array_unnest(jdbcType, sortedParameters)); - try (var ignored = SpringActionController.ignoreSqlUpdates()) + tempTableInfo.track(); + String tableName = tempTableInfo.getSelectName(); + if (dialect.supportsArrays()) { - new SqlExecutor(tempSchema).execute(sqlInsert); + // One array-bound statement is several times faster than batched single-row INSERTs + new SqlExecutor(tempSchema).execute(SQLFragment.unsafe("INSERT INTO " + tableName + " (Id) ") + .append(dialect.array_unnest(jdbcType, sortedParameters))); } - } - else try - { - try (var ignored = SpringActionController.ignoreSqlUpdates()) + else { - if (jdbcType == JdbcType.VARCHAR) - Table.batchExecute1String(tempSchema, sql1, (ArrayList) sortedParameters); - else if (jdbcType == JdbcType.INTEGER) - Table.batchExecute1Integer(tempSchema, sql1, sql100, (ArrayList) sortedParameters); - else - Table.batchExecute1Long(tempSchema, sql1, sql100, (ArrayList) sortedParameters); + batchInsert(tempSchema, tableName, jdbcType, sortedParameters); } - } - catch (SQLException e) - { - throw new RuntimeSQLException(e); - } - // UNIQUE tells the planner the ids are distinct, so it skips de-duplicating them in IN (SELECT ...) - String indexSql = "CREATE UNIQUE INDEX IX_Id" + new GUID().toStringNoDashes() + " ON " + tableName + "(Id)"; - try (var ignored = SpringActionController.ignoreSqlUpdates()) - { - new SqlExecutor(tempSchema).execute(indexSql); + // UNIQUE lets the planner skip de-duplicating ids, but non-PostgreSQL collations may equate values the case-sensitive TreeSet kept apart + String unique = dialect.supportsArrays() ? "UNIQUE " : ""; + new SqlExecutor(tempSchema).execute("CREATE " + unique + "INDEX IX_Id" + new GUID().toStringNoDashes() + " ON " + tableName + "(Id)"); dialect.updateStatistics(tempTableInfo); // Immediately analyze the newly populated & indexed table } @@ -211,6 +190,25 @@ else if (jdbcType == JdbcType.INTEGER) return tempTableInfo; } + @SuppressWarnings("unchecked") + private static void batchInsert(DbSchema tempSchema, String tableName, JdbcType jdbcType, List sortedParameters) + { + String sql1 = "INSERT INTO " + tableName + " (Id) VALUES (?)"; + String sql100 = "INSERT INTO " + tableName + " (Id) VALUES (?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?)"; + try + { + if (jdbcType == JdbcType.VARCHAR) + Table.batchExecute1String(tempSchema, sql1, (List) sortedParameters); + else if (jdbcType == JdbcType.INTEGER) + Table.batchExecute1Integer(tempSchema, sql1, sql100, (List) sortedParameters); + else + Table.batchExecute1Long(tempSchema, sql1, sql100, (List) sortedParameters); + } + catch (SQLException e) + { + throw new RuntimeSQLException(e); + } + } // unique and ordered list private List collectStrings(@NotNull Collection paramsCollection) @@ -278,8 +276,12 @@ else if (i instanceof Integer) private String getCacheKey(@NotNull JdbcType jdbcType, @NotNull Collection params) { StringBuilder paramBuilder = new StringBuilder(); + // Length-prefix each value so different lists can't concatenate to the same string for (Object param : params) - paramBuilder.append(param); + { + String s = String.valueOf(param); + paramBuilder.append(null == param ? -1 : s.length()).append(':').append(s); + } // Hash the param string to avoid very large cache keys filling up memory return jdbcType.name() + "_" + params.size() + "_" + HashHelpers.hash(paramBuilder.toString()); @@ -341,11 +343,13 @@ public void testUnloggedReset() { Assume.assumeTrue(_scope.getSqlDialect().isPostgreSQL()); SQLFragment sql = SQLFragment.unsafe("SELECT a from (SELECT 'a' AS a UNION SELECT 'b' AS a UNION SELECT 'g' AS a) b WHERE a "); - TempTableInfo before = new TempTableInClauseGenerator().getTempTableInfo(STRINGS); + // A value unique to this run keeps the TRUNCATE off any table another caller shares + List values = List.of("a", "b", new GUID().toString()); + TempTableInfo before = new TempTableInClauseGenerator().getTempTableInfo(values); Assert.assertNotNull(before); new SqlExecutor(_scope).execute(SQLFragment.unsafe("TRUNCATE ").append(before)); UnloggedTableGeneration.simulateResetForTest(); - SQLFragment after = new TempTableInClauseGenerator().appendInClauseSql(new SQLFragment(sql), STRINGS); + SQLFragment after = new TempTableInClauseGenerator().appendInClauseSql(new SQLFragment(sql), values); Assert.assertEquals("A reset must rebuild the emptied temp table", 2, new SqlSelector(_scope, after).getRowCount()); } diff --git a/api/src/org/labkey/api/data/UnloggedTableGeneration.java b/api/src/org/labkey/api/data/UnloggedTableGeneration.java index 008103eaf5b..6066c36c2bf 100644 --- a/api/src/org/labkey/api/data/UnloggedTableGeneration.java +++ b/api/src/org/labkey/api/data/UnloggedTableGeneration.java @@ -65,8 +65,10 @@ private UnloggedTableGeneration() */ public static String current() { - if (HeartBeat.currentTimeMillis() - _lastCheck > CHECK_INTERVAL && _checkLock.tryLock()) + if (HeartBeat.currentTimeMillis() - _lastCheck > CHECK_INTERVAL) { + // Block rather than skip: a reader returning the old generation mid-check could reuse an emptied table + _checkLock.lock(); try { if (HeartBeat.currentTimeMillis() - _lastCheck > CHECK_INTERVAL) diff --git a/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java b/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java index 9dfdde4e45b..536a12f2fde 100644 --- a/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java +++ b/api/src/org/labkey/api/data/dialect/BasePostgreSqlDialect.java @@ -497,12 +497,6 @@ public String getTempTableKeyword() return "TEMPORARY"; } - @Override - public String getCreateUnloggedTableCommand() - { - return "CREATE UNLOGGED TABLE"; - } - @Override public String getTempTablePrefix() { diff --git a/api/src/org/labkey/api/data/dialect/SqlDialect.java b/api/src/org/labkey/api/data/dialect/SqlDialect.java index 72086480779..d9771c7edc9 100644 --- a/api/src/org/labkey/api/data/dialect/SqlDialect.java +++ b/api/src/org/labkey/api/data/dialect/SqlDialect.java @@ -870,12 +870,6 @@ public final SQLFragment getLsidTypeAsSql() public abstract String getTempTablePrefix(); - /** For disposable tables whose contents may be lost on a database crash */ - public String getCreateUnloggedTableCommand() - { - return "CREATE TABLE"; - } - public abstract String getGlobalTempTablePrefix(); public abstract boolean isNoDatabaseException(SQLException e);