GitHub user dosubot[bot] added a comment to the discussion: SQL Server query 
hints

<!-- Answer -->
This is a known limitation with how Superset processes SQL queries differently 
between SQL Lab and charts.

**Why it happens:** When creating charts, Superset wraps queries in subqueries 
to apply limits and other transformations. SQL Server's `OPTION` clauses must 
appear at the end of the *outermost* query, so when your query gets wrapped, 
the `OPTION (MAXDOP 1)` ends up inside a subquery where it's syntactically 
invalid.

This is part of a [broader pattern affecting T-SQL 
features](https://github.com/apache/superset/issues/31913) since Superset 
adopted sqlglot for SQL parsing in 4.1.0+.

**Workarounds:**
1. **Create a database view** - Encapsulate your query with the OPTION hint in 
a SQL Server view, then query that view from Superset charts
2. **Set MAXDOP at the database level** - Configure query governor settings in 
SQL Server itself rather than per-query hints
3. **Use SQL Lab for reporting** - If you don't need the chart visualization, 
SQL Lab can execute the query directly


<!-- Dosu Comment Footer -->
*To reply, just mention 
[@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/450659a3-0abf-4a4c-b25c-69c4a9fcd940?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/450659a3-0abf-4a4c-b25c-69c4a9fcd940?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/450659a3-0abf-4a4c-b25c-69c4a9fcd940?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/450659a3-0abf-4a4c-b25c-69c4a9fcd940?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose)
 | [Hallucination](https://app.dosu.dev/response-feedback/450659a3-0abf-4a
 
4c-b25c-69c4a9fcd940?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/450659a3-0abf-4a4c-b25c-69c4a9fcd940?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/450659a3-0abf-4a4c-b25c-69c4a9fcd940?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup>

[![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20limitation%20with%20how%20Superset%20processes%20SQL%20queries%20differently%20between%20SQL%20Lab%20and%20charts.%0A%0A%2A%2AWhy%20it%20happens%3A%2A%2A%20When%20creating%20charts%2C%20Superset%20wraps%20queries%20in%20subqueries%20to%20apply%20limits%20and%20other%20transformations.%20SQL%20Server%27s%20%60OPTION%60%20clauses%20must%20appear%20at%20the%20end%20of%20the%20%2Aoutermost%2A%20query%2C%20so%20when%20your%20query%20gets%20wrapped%2C%20the%20%60OPTION%20%28MAXDOP%201%29%60%20ends%20up%20inside%20a%20subquery%20where%20it%27s%20syntactically%20invalid.%0A%0AThis%20is%20part%20of%20a%20%5Bbroader%20pattern%20affecting%20T-SQL%20features%5D%28h
 
ttps%3A//github.com/apache/superset/issues/31913%29%20since%20Superset%20adopted%20sqlglot%20for%20SQL%20parsing%20in%204.1.0%2B.%0A%0A%2A%2AWorkarounds%3A%2A%2A%0A1.%20%2A%2ACreate%20a%20database%20view%2A%2A%20-%20Encapsulate%20your%20query%20with%20the%20OPTION%20hint%20in%20a%20SQL%20Server%20view%2C%20then%20query%20that%20view%20from%20Superset%20charts%0A2.%20%2A%2ASet%20MAXDOP%20at%20the%20database%20level%2A%2A%20-%20Configure%20query%20governor%20settings%20in%20SQL%20Server%20itself%20rather%20than%20per-query%20hints%0A3.%20%2A%2AUse%20SQL%20Lab%20for%20reporting%2A%2A%20-%20If%20you%20don%27t%20need%20the%20chart%20visualization%2C%20SQL%20Lab%20can%20execute%20the%20query%20directly)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&nbsp;[![Share
 on X](https://img.shields.io/badge/X-share-bla
 
ck)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/38650)

GitHub link: 
https://github.com/apache/superset/discussions/38694#discussioncomment-16181164

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to