Skip to content

fix(semantic-layer): avoid truncating cached rollups - #46022

Open
mikebridge wants to merge 2 commits into
apache:masterfrom
mikebridge:sc-128656-null-placement-reduced
Open

mikebridge wants to merge 2 commits into
apache:masterfrom
mikebridge:sc-128656-null-placement-reduced

Conversation

@mikebridge

Copy link
Copy Markdown
Contributor

TL;DR: Superset asks the provider for a limited result when a cached rollup could select different rows.

SUMMARY

Background: Superset's result cache can reuse an unlimited result by rolling it up to the requested grain. It re-sorts the rolled-up rows in pandas before applying the query's limit.

Problem: That local sort can keep different rows than the provider would return, for example when an engine sorts NULLs first, a limit splits tied rows, or string ordering differs.

Changes:

  • Serve a limited query from a rollup only when the whole post-filter, rolled-up result fits within offset + limit; otherwise ask the provider. Unlimited rollups and fitting results remain reusable.
  • Keep the SDK's NULL placement and tie order provider-defined. A cache-served rollup may order NULLs and tied rows differently while keeping the rows the provider would return.
  • Count these expected refusals with semantic_cache.containment.rollup_refused; genuine transformation failures keep their existing counter.

This supersedes #45912 and drops that PR's NULL-placement conformance checker. No provider update or cache reset is required.

@aminghadersohi's reviews of #45912 informed this narrower change.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable: backend cache reuse and SDK documentation.

TESTING INSTRUCTIONS

Run the semantic-layer unit and integration suites and superset-core/tests.

The regression cases cache an unlimited result, then request a limited rollup where either a NULL-first provider or a split tie would choose a different page. They verify fallback to the provider, the rollup_refused and miss counters, and a subsequent exact cache hit of the provider's page. Fitting limits, NULL values and ties remain covered.

Local validation: 2,268 unit/SDK tests passed with four capability skips; 38 semantic integration tests passed with four dedicated Redis/Sentinel skips; semantic package coverage reached 100%; changed-file hooks passed.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: existing SEMANTIC_LAYERS and SEMANTIC_LAYER_CONTAINMENT_CACHE for containment reuse
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Nov 4, 2026
@netlify

netlify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 84da49f
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6aebaf8260113088f62df4db
😎 Deploy Preview https://deploy-preview-46022--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.02%. Comparing base (fcc13d4) to head (84da49f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #46022      +/-   ##
==========================================
+ Coverage   85.00%   85.02%   +0.02%     
==========================================
  Files        3080     3085       +5     
  Lines      209266   209901     +635     
  Branches    49296    49297       +1     
==========================================
+ Hits       177895   178477     +582     
- Misses      27989    28043      +54     
+ Partials     3382     3381       -1     
Flag Coverage Δ
hive 34.19% <12.50%> (-0.01%) ⬇️
mysql 52.02% <12.50%> (-0.01%) ⬇️
postgres 52.04% <12.50%> (+<0.01%) ⬆️
presto 35.85% <12.50%> (-0.01%) ⬇️
python 87.96% <100.00%> (+<0.01%) ⬆️
sqlite 51.78% <12.50%> (-0.01%) ⬇️
superset-extensions-cli 91.24% <ø> (?)
unit 82.90% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mikebridge
mikebridge marked this pull request as ready for review November 5, 2026 02:09
Comment on lines +270 to +273
frame = _rollup(frame, query)
if (
query.limit is not None
and len(frame) > (query.offset or 0) + query.limit

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.

Suggestion: Oversized limited rollups aggregate every group before refusal, then the provider runs too, duplicating work and slowing high-cardinality requests.

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Performance

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/semantic_layers/cache_transform.py
**Line:** 270:273
**Comment:**
	*Performance: Oversized limited rollups aggregate every group before refusal, then the provider runs too, duplicating work and slowing high-cardinality requests.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging.
  • Limited cache rollups fully group the cached frame before refusing oversized results, then execute the provider query, duplicating work for high-cardinality requests.

Assessed commit: 84da49f8c3af

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Namespace | Anything related to documentation size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant