Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions api/src/org/labkey/api/data/MaterializedQueryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ boolean load(SQLFragment selectQuery, boolean isSelectInto)
{
new SqlExecutor(_mqh._scope).execute(StringUtils.replace(index, "${NAME}", _tableName));
}
analyze();
}

_loadingState.set(LoadingState.LOADED);
Expand All @@ -194,6 +195,22 @@ boolean load(SQLFragment selectQuery, boolean isSelectInto)
}
}

/** SELECT INTO leaves the table with no statistics, so the planner guesses until autovacuum eventually analyzes it. */
private void analyze()
{
try
{
SQLFragment sql = _mqh._scope.getSqlDialect().getAnalyzeCommandForTable(_fromSql);
if (null != sql)
new SqlExecutor(_mqh._scope).execute(sql);
}
catch (RuntimeException x)
{
// Statistics are an optimization, so a dialect that can't analyze must not fail the materialization
LOG.warn("Failed to update statistics for materialized table {}", _tableName, x);
}
}

public void setError(RuntimeException rex)
{
_loadException = rex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,8 @@ void recordPendingUpdate(@NotNull Timestamp changedSince)
}
}

static final BlockingCache<String,_MaterializedQueryHelper> _materializedQueries = CacheManager.getBlockingStringKeyCache(CacheManager.UNLIMITED, CacheManager.HOUR, "materialized sample types", null);
// TTL is a backstop for missed invalidations. Admins can manually clear via Admin Console->Caches
static final BlockingCache<String,_MaterializedQueryHelper> _materializedQueries = CacheManager.getBlockingStringKeyCache(CacheManager.UNLIMITED, 12 * CacheManager.HOUR, "materialized sample types", null);
static final Map<String, InvalidationCounters> _invalidationCounters = Collections.synchronizedMap(new HashMap<>());
static final AtomicBoolean initializedListeners = new AtomicBoolean(false);

Expand Down