Skip to content

Grid filter "Choose Values" performance - #8299

Draft
XingY wants to merge 13 commits into
release26.11-SNAPSHOTfrom
26.11_fb_facetedPerf
Draft

XingY wants to merge 13 commits into
release26.11-SNAPSHOTfrom
26.11_fb_facetedPerf

Conversation

@XingY

@XingY XingY commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Rationale

Exposes what the column fact cache already knows so the grid filter dialog can list a column's values, or decide not to ask for them, without a SELECT DISTINCT over the whole table (Kanban 2177). The cache was built to rank grid search suggestions and already holds the distinct count for every column and the values themselves where there are few enough; this adds a read path to it and the few facts the filter dialog needs that it was discarding.

Related Pull Requests

Changes

  • New read-only action returning per-column facts for a grid: the values where the column has few enough to list, the distinct count either way, and whether the list is usable.
  • Distinct counts are kept on the column fact rather than discarded, on both the under- and over-limit paths.
  • Value lists record whether any row is blank, and whether a value had to be dropped for length — in which case callers must query instead of trusting the list.
  • The response reports whether the table behind the query is large, taken from the database's own standing row estimate. A coarse flag rather than the number, which spans containers the caller may not be able to read, and a catalogue lookup rather than a count.
  • Table resolution and fact loading are shared with the suggestions entry point, so permission, PHI and audit-logging exclusions are inherited unchanged.

@Marshal(Marshaller.Jackson)
@RequiresPermission(ReadPermission.class)
@Action(ActionType.SelectData.class)
public static class GetColumnFacetsAction extends ReadOnlyApiAction<FilterSuggestionsRequest>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be handing back information for all columns when the client only ever is looking at a single column. Consider adding a "column" or "facetColumn" to the request parameters so that the server only returns information for that column (when specified).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very appealing idea. I evaluated this but I think I'm gonna hold off on this one. The reason is per column response means each time the user changes a field selection on the filter panel, a different api request is needed. With the current implementation, a single request handles all fields on the filter panel. Changing fields on the filter panel might not be a common scenario, but it still is not clear trade off for smaller payload vs fewer requests.

private static final String FILTER_REGION = "query";
private static final String ALL_COLUMNS = "*";
// Matches the row count at which a grid stops counting exactly and shows "100,000+"
private static final long LARGE_TABLE_ROWS = 100_000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Perhaps we could reuse DataRegionSelection.MAX_QUERY_SELECTION_SIZE instead on introducing another constant.

try
{
// reltuples is a float; cast in SQL because the selector has no getter for Float
SQLFragment sql = new SQLFragment("SELECT CAST(reltuples AS BIGINT) FROM pg_class WHERE oid = to_regclass(?)")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended that we quote the schema/table parts when passing them to to_regclass().

SQLFragment sql = new SQLFragment(
    "SELECT CAST(reltuples AS BIGINT) FROM pg_class " +
    "WHERE oid = to_regclass(quote_ident(?) || '.' || quote_ident(?))"
).add(schemaName).add(tableName);

* @param hasBlank some row holds null or blank, which values never includes. Only meaningful with
* valuesFromData set.
*/
public record ColumnFacet(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than introducing a new type could we use SuggestionColumn directly and extend it for this use case?

@XingY
XingY marked this pull request as draft November 18, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants