Performance
The SRS engine generates and executes SQL queries within the database. To optimize performance, consider the following recommendations:
1. Validate and Prepare Data with srssetup
Use srssetup
to validate input, check business logic, and prepare data before running SRS queries.
2. Use Proper Parameter Types
Ensure that parameter types match the expected data type in the database.
Example: Defining a uniqueidentifier
Parameter
XML | |
---|---|
Refer to Parameter Types Documentation for a full list of supported types.
3. Simplify Queries and Use Indexes
- Keep queries simple to enhance readability and performance.
- Preprocess parameters when applicable.
Example: Preprocessing Parameters
Before:
XML | |
---|---|
After:
XML | |
---|---|
4. Avoid Casting Between Data Types
Prevent performance issues by avoiding unnecessary casting. For instance, in MSSQL Server:
- Default text parameter type:
nvarchar
- Avoid casting between
nvarchar
andvarchar
.
To specify varchar
, use type="ansi"
in your parameter definition.
5. Optimize Queries with SRS Engine Hints
For complex queries with numerous joins, subqueries, or nullable parameters, the SQL Server optimizer may generate inefficient plans. Use the SRS engine hint /*jq-comment-if-null*/
to dynamically comment out null parameters.
Example: Optimized Query
Before:
SQL | |
---|---|
After:
SQL | |
---|---|
Result (when all parameters are null):
SQL | |
---|---|
How It Works
- The SRS engine checks the parameters passed.
- If a parameter is
null
, the corresponding line is commented out. - Only the first parameter in a line is validated for nullability.
Adopting these practices ensures efficient and maintainable SQL query execution in your SRS engine.