korbit-ai[bot] commented on code in PR #35009:
URL: https://github.com/apache/superset/pull/35009#discussion_r2321220569


##########
superset/sqllab/query_render.py:
##########
@@ -74,6 +74,10 @@ def _validate(
         sql_template_processor: BaseTemplateProcessor,
     ) -> None:
         if is_feature_enabled("ENABLE_TEMPLATE_PROCESSING"):
+            original_sql = execution_context.query.sql.strip().strip(";")
+            if rendered_query == original_sql:
+                return
+
             syntax_tree = sql_template_processor.env.parse(rendered_query)

Review Comment:
   ### Redundant Template Parsing <sub>![category 
Performance](https://img.shields.io/badge/Performance-4f46e5)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The template parsing is performed twice - once during process_template() and 
again during validation, leading to redundant computation.
   
   
   ###### Why this matters
   Parsing the template twice unnecessarily increases CPU usage and processing 
time, especially for large SQL queries or high request volumes.
   
   ###### Suggested change ∙ *Feature Preview*
   Pass the syntax tree from the initial parsing during process_template() to 
the validation method, or restructure the code to only parse once. Example:
   ```python
   # In process_template, return both result and syntax_tree
   rendered_query, syntax_tree = 
sql_template_processor.process_template_with_ast(...)
   self._validate(execution_context, rendered_query, syntax_tree, 
sql_template_processor)
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/331e27e5-3fb3-40b2-ab1c-826e846d4995/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/331e27e5-3fb3-40b2-ab1c-826e846d4995?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/331e27e5-3fb3-40b2-ab1c-826e846d4995?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/331e27e5-3fb3-40b2-ab1c-826e846d4995?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/331e27e5-3fb3-40b2-ab1c-826e846d4995)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:8eaa0553-06f0-4f78-ad6b-546f261bb4dc -->
   
   
   [](8eaa0553-06f0-4f78-ad6b-546f261bb4dc)



-- 
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]

Reply via email to