From b97097bfe37872367917a8fe8a53501b382f93d2 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Mon, 31 Aug 2026 17:19:18 -0700 Subject: [PATCH] Optimize StorageTerminalLocation and related columns --- .../query/sql/CalculatedExpressionColumn.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java b/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java index eba8446b5c2..34bb8014095 100644 --- a/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java +++ b/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java @@ -121,6 +121,22 @@ public Set getReferencedFieldKeys() return Collections.unmodifiableSet(_allFieldKeys); } + /* getValueSql() inlines the value SQL of every column the expression references, so any join those columns + * declare has to be declared here too -- otherwise the inlined SQL names a table alias that is not in the FROM. + * Lookups and self-reference are rejected during binding, so every referenced key is a plain column on this table. + */ + @Override + public void declareJoins(String parentAlias, Map map) + { + getBoundExpression(); // populates _allFieldKeys + for (FieldKey key : getReferencedFieldKeys()) + { + ColumnInfo col = getParentTable().getColumn(key); + if (null != col && col != this) + col.declareJoins(parentAlias, map); + } + } + public void computeMetaData(Map columns) { if (null == columns)