Overview
The parameterization system works by:- Executing a parameter query once to get a result set of values
- Mapping columns from that result set to parameters in your main query
- Cycling through parameter values for each iteration
- Each thread gets the next row in sequence (thread-safe)
When to Use Parameterization
Use parameterization when:- Testing queries that filter by different IDs or values
- Simulating real-world usage patterns with varying inputs
- Testing parameter sniffing and plan reuse behavior
- Measuring performance across different data distributions
- Avoiding cached query results that would skew metrics
How It Works
Main Query with Parameters
Your main query includes T-SQL parameters:Parameter Query
A separate query returns the parameter values:Parameter Mappings
You map each parameter to a column from the parameter query:@CustomerId→CustomerIdcolumn@StartDate→StartDatecolumn
Setting Up Parameterization
- GUI Application
- CLI / Configuration File
Configure Database Connection
Choose where to get parameter values:
- Use same database settings: Parameters come from the same database as your main query
- Use separate database settings: Parameters come from a different database
Write Parameter Query
Enter a query that returns parameter values:
The parameter query executes once at the start of the test. Make sure it returns enough rows for your thread count and iterations.
Map Parameters
The tool detects parameters in your main query and displays them.For each parameter:
- Select the parameter from the list
- Choose the corresponding column from the parameter query dropdown
- The mapping is created automatically
@CategoryIdmaps toCategoryId@MaxPricemaps toMaxPrice
Parameter Value Distribution
The ParamServer class distributes parameter values across threads using a thread-safe counter:How Rows Are Assigned
- Thread 1, Iteration 1: Row 1
- Thread 2, Iteration 1: Row 2
- Thread 1, Iteration 2: Row 3
- Thread 2, Iteration 2: Row 4
- And so on…
Cycling Behavior
If you run more iterations than parameter rows, values cycle:- 100 parameter rows
- 10 threads × 50 iterations = 500 total executions
- Each row is used 5 times (500 ÷ 100)
Real-World Examples
Example 1: Testing Customer Lookups
Example 2: Date Range Queries
Example 3: Stored Procedure with Multiple Parameters
Advanced Techniques
Testing Parameter Sniffing
Parameter sniffing occurs when SQL Server creates a query plan based on the first parameter value, which may not be optimal for other values. Test this by:- Using a wide range of parameter values that return different result set sizes
- Comparing metrics across iterations
- Looking for high variance in execution times
Null Parameter Values
Include NULL values in your parameter data to test NULL handling:Cross-Database Parameters
Use a separate database for parameter data:Best Practices
Return Enough Rows
Return Enough Rows
Your parameter query should return at least as many rows as the total number of iterations:If you have fewer rows, values will repeat. This is fine for some tests but may cache results inappropriately.
Randomize Parameter Values
Randomize Parameter Values
Use This prevents caching from skewing your results.
ORDER BY NEWID() to randomize parameter selection:Use Realistic Data Distributions
Use Realistic Data Distributions
Mirror your production data patterns:
Consider Parameter Data Types
Consider Parameter Data Types
Ensure parameter query columns match the expected data types:
Test With and Without Parameters
Test With and Without Parameters
Compare results:
- Without parameters (same value every time)
- With parameters (varying values)
Troubleshooting
Error: Parameter Not Mapped
If you see parameter-related errors:- Verify parameter names match exactly (including
@) - Check that all parameters in MainQuery are mapped
- Ensure parameter query returns the mapped columns
Error: Column Not Found
If a column isn’t found:- Run the parameter query independently to verify column names
- Check for typos in column names
- Ensure case-sensitivity matches
Unexpected Results
If results seem wrong:- Run parameter query manually to inspect values
- Reduce to 1 thread and 1 iteration to debug
- Check SQL Server Profiler to see actual parameter values being used
Next Steps
Interpreting Results
Learn how to analyze performance metrics from parameterized tests
Connection Settings
Configure connection settings for parameter queries
Using the GUI
Set up parameters in the GUI application
Using the CLI
Configure parameters in JSON files