Repository navigation
fix(explore): prevent full table scan when SQL expression is used as x-axis - #41339
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41339 +/- ##
=======================================
Coverage 85.86% 85.87%
=======================================
Files 3117 3117
Lines 216005 216015 +10
Branches 51231 51236 +5
=======================================
+ Hits 185482 185499 +17
+ Misses 27108 27101 -7
Partials 3415 3415
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
43ad8c9 to
53ae505
Compare
53ae505 to
ace7a65
Compare
Code Review Agent Run #510666Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
Code and tests lookin' good... say the word if you want help with the rebase. |
|
Still looking good on my end. It's gone conflicting with master again since I last checked - say the word if you want a hand with the rebase, @betodealmeida. |
|
Nice diagnosis on the ClickHouse full-table-scan issue, and the |
rusackas
left a comment
There was a problem hiding this comment.
As noted, the ClickHouse diagnosis and the main_dttm_col fallback (plus the catalog/schema fix in datetime_format_detector.py) look right to me, and the test coverage is solid. Approving to get this off the review-required list, just needs a rebase before it can merge since GitHub's showing conflicts with master again.
…dent fix Master landed its own fix for the same ClickHouse full-table-scan bug (#42052) after this PR was approved, via a differently-guarded `should_infer_filter_granularity` check. This PR's own unguarded `elif` branch would have regressed master's `test_granularity_not_inferred_from_another_temporal_filter` by firing in a case master's guard exists to prevent, so it's dropped in favor of master's check. The one piece master's fix was still missing - a dedupe of a pre-existing TEMPORAL_RANGE filter already on the inferred main_dttm_col, to avoid a duplicate WHERE clause - is ported forward into master's guarded branch instead. Also restores the catalog/schema argument-order fix in datetime_format_detector.py's get_df call, which master's own later ClickHouse read-limit retry refactor had reintroduced. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
05182f9 to
970301c
Compare
| # The inferred column supplies the time-filter subject. It must not be | ||
| # treated as an explicitly selected granularity, which would rewrite | ||
| # the x-axis or remove an independent temporal filter below. | ||
| query_object.granularity = main_dttm_col |
There was a problem hiding this comment.
Suggestion: For timeseries charts, the query builder selects and groups by this inferred column, splitting expression-axis results by the physical timestamp.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Api mismatch
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/common/query_context_factory.py
**Line:** 321:321
**Comment:**
*Api Mismatch: For timeseries charts, the query builder selects and groups by this inferred column, splitting expression-axis results by the physical timestamp.
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| query_object.filter = [ | ||
| filter_ | ||
| for filter_ in query_object.filter | ||
| if not ( | ||
| filter_["op"] == "TEMPORAL_RANGE" | ||
| and filter_["col"] == main_dttm_col | ||
| ) | ||
| ] |
There was a problem hiding this comment.
Suggestion: When time_range is absent but explicit bounds coexist with a different range filter on main_dttm_col, this drops that filter and can broaden results.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Logic error
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/common/query_context_factory.py
**Line:** 326:333
**Comment:**
*Logic Error: When `time_range` is absent but explicit bounds coexist with a different range filter on `main_dttm_col`, this drops that filter and can broaden results.
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|
This PR has been quiet for a while. We'd like to help get it across the finish line, so we'll push updates here. Thanks for the contribution! We merged master and added this PR's new warning string to the translation template (messages.pot) so the translation drift check passes. |
* origin/master: (393 commits) fix(a11y): name the semantic view description input (apache#46458) docs(semantic): explain datasource list modification eligibility (apache#46462) docs(semantic-layer): document NULL-preserving exclusion filters (apache#46447) fix(uploads): skip folder and system entries in columnar ZIP uploads (apache#45617) fix(i18n-es): promote 47 of the zero-context backfill entries (apache#45847) fix(mcp): return structured ChartError on SQLAlchemyError in get_chart_sql (apache#44351) fix(datasets): follow semantic view modification permissions (apache#46448) fix(docker): account for container memory limits in frontend-mem-nag.sh (apache#46373) fix(reports): carry the report's native filters in the email and Slack link (apache#46062) fix(explore): apply the dataset timezone to grained temporal filter values (apache#46175) fix(i18n): enforce the do-not-translate registry across the catalogs (apache#45974) chore(logging): log unparseable virtual dataset SQL at debug in the RLS lookup (apache#46139) fix(i18n): split parameter-suggestion plural into two messages (apache#46049) test(partition-mapping): cover Hive/Impala mirrored SQL, cache outage and migration (apache#46319) perf(dashboard): look up the dashboard once per filter_state read (apache#46314) fix(i18n): load the dayjs locale for every language with a catalog (apache#45982) test(semantic-layer): make date export parametrization deterministic (apache#46449) fix(oauth2): idempotent OAuth2 completion and resilient listener (apache#40292) fix(explore): prevent full table scan when SQL expression is used as x-axis (apache#41339) feat(mcp): radar chart type plugin (apache#43571) ... # Conflicts: # .github/workflows/docker.yml # .github/workflows/superset-frontend.yml
SUMMARY
On ClickHouse (and other engines with row-read limits like
max_rows_to_read), using a SQL expression as the x-axis in a timeseries line chart triggers a full table scan and fails, while using a plain physical temporal column works fine.Root cause: In
_apply_granularity(query_context_factory.py),from_dttm/to_dttmare only applied as a WHERE clause whengranularity(a physical time column) is explicitly configured. When a user sets the x-axis to an adhoc SQL expression liketoStartOfDay(ts)orduration * 0.05, the frontend'sisTemporalColumn()check returns false — so no TEMPORAL_RANGE filter is created for the expression, and no automatic WHERE clause is generated. The result is an unfiltered query that reads every row in the table.Backend fix: Added an
elifbranch in_apply_granularity. When the x-axis is an adhoc SQL expression, a time range is set (from_dttm/to_dttmare not null), but nogranularityis configured, the method falls back todatasource.main_dttm_col(if it exists and is temporal) and sets it as the granularity. This causeshelpers.pyto emit aWHERE main_dttm_col >= from_dttm AND main_dttm_col < to_dttmclause automatically. Any pre-existingTEMPORAL_RANGEfilter for that column is also removed to prevent the condition from appearing twice.Frontend fix: Added a
useEffectinControlPanelsContainerthat shows a warning modal when the user sets the x-axis to a SQL expression, pointing them to add a time column filter in the Filters section.Workaround for existing users (no upgrade required): Add a
TEMPORAL_RANGEfilter on the dataset's time column in the chart's Filters section. The backend fix then picks it up automatically.This PR also fixes a pre-existing bug in
DatetimeFormatDetectorwhereget_dfwas called withschemain thecatalogposition, causing incorrect behavior on databases that use both catalogs and schemas.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
max_rows_to_readto a value smaller than the total row count of a test table (e.g.max_rows_to_read = 100000on a 500K-row table ordered by aDateTimecolumnts).toStartOfDay(ts). Leave the Filters section empty.Code: 158. DB::Exception: Limit for rows (max_rows_to_read) exceeded.TEMPORAL_RANGEfilter onts(e.g. "Last year") in the Filters section and run again.WHERE ts >= ... AND ts < ...clause should appear, with no duplication.ADDITIONAL INFORMATION