Running tests with dbt test - Time & Space Complexity
When running tests with dbt test, we want to know how the time it takes grows as the number of tests or data size increases.
We ask: How does running more tests or bigger data affect the total time?
Analyze the time complexity of the following dbt test command snippet.
-- Run all tests defined in the project
dbt test
-- Example of a simple test definition
select * from {{ ref('my_model') }} where id is null
This runs all tests defined in the dbt project, checking data quality rules like null values.
Look for repeated actions that take time.
- Primary operation: Running each test query against the database.
- How many times: Once per test defined in the project.
As the number of tests grows, the total time grows roughly in direct proportion.
| Input Size (number of tests) | Approx. Operations (test queries run) |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: Doubling the number of tests roughly doubles the total time.
Time Complexity: O(n)
This means the total time grows linearly with the number of tests run.
[X] Wrong: "Running more tests will take the same time because they run in parallel."
[OK] Correct: While some parallelism may happen, each test still requires database work, so total time grows with test count.
Understanding how test execution time grows helps you plan and optimize data quality checks in real projects.
"What if we only run tests on changed models instead of all models? How would the time complexity change?"