Avoid calling getPivotValues() to improve PIVOT query performance #3937
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale
In the absence of an explicit
PIVOT ... IN
clause, LabKey must execute portions of PIVOT queries to determine the resulting column list. Depending on the query, this can be very expensive; see https://www.labkey.org/OHSU/Support%20Tickets/issues-details.view?issueId=46881. This PR attempts to avoid callinggetPivotValues()
(the column-list query) unless it's absolutely required. This can improve performance significantly for cases that don't need the query results, e.g., rendering the schema browser tree and populating the linked schema table drop-down list. Approach:AbstractTableInfo
: introduceinitializeColumns()
, called immediately before columns are accessed for the first time. Adding columns in this method (instead of the constructor) avoids the potentially expensive operation in cases where the columns aren't used. CallensureInitialColumnsAreAdded()
from all methods that interact directly with_columnMap
.PivotTableInfo
: populate the initial columns ininitializeColumns()
and defer validation (missing parameter values, etc.) togetAllColumns()
. Rework the exception handling in getPivotValues() and its callers to ensure reasonably friendly error messages.Schema browser tree now avoids executing PIVOT queries.
GetQueriesAction
(used in linked schema admin page) still indirectly invokes getPivotValues() (e.g., for URL handling). We should either parameterize GetQueriesAction further (includeUrls
parameter, maybefalse
by default?) or switch linked schema admin page to callgetSchemaTree.api
instead ofgetQueries.api
, to avoid the expensive query. Will address this in a follow-on PR.