dosubot[bot] commented on issue #40731: URL: https://github.com/apache/superset/issues/40731#issuecomment-4616546533
<!-- Answer --> Hi @jhastingsiii! I'm [Dosu](https://go.dosu.dev/dosubot) and I'm helping the Apache Superset team. Unfortunately, there is currently **no way to control the ordering of inherited dashboard filters relative to chart-level filters** in the WHERE clause. Here's why: Dashboard filters are merged into the chart's `adhoc_filters` array (marked with an `isExtra` flag) *before* SQL generation begins [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/core.py#L924-L931). When the query is built, all filters in that combined array are processed sequentially and joined with `AND` logic [[2]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py#L1955-L1958). Dashboard filters are appended to the end of the array during merging, which is why they appear last in your WHERE clause. The overall WHERE clause order is: 1. Adhoc filters (chart-level first, then dashboard-inherited) 2. Row Level Security filters 3. `extras.where` clauses 4. Time range filters (if granularity is set) [[3]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py#L1747-L1959) **Regarding your index concern**: Since all conditions are combined with `AND`, the SQL engine's query optimizer *should* be able to use appropriate indexes regardless of the filter order in the WHERE clause — the textual order of AND predicates generally doesn't determine index usage for most databases (PostgreSQL, MySQL, etc.). The query planner evaluates all predicates and picks the best execution plan. If your database isn't using your temporal index, the issue is more likely related to: - Query planner statistics being stale (try `ANALYZE` on the table) - The temporal filter expression not being sargable (e.g., wrapping the column in a function) - The optimizer deciding a full scan is cheaper given the selectivity **Workaround**: If you absolutely need the temporal filter to appear first in the WHERE clause for a specific database engine that is sensitive to predicate order, you could define the temporal filter directly on the chart (as a chart-level adhoc filter) rather than relying on the inherited dashboard filter. Chart-level filters are processed before dashboard-inherited ones in the combined array. This is a limitation in the current architecture since there's no API or UI to reorder inherited filters. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).* --- Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset). [](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=64a99701-220a-435e-a86e-b5755561033a) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
