Model naming conventions in dbt - Time & Space Complexity
We want to understand how the time it takes to run dbt models changes as the number of models grows.
Specifically, how does naming models affect the process of selecting and running them?
Analyze the time complexity of the following dbt model selection snippet.
-- Select models with a specific prefix
models:
+materialized: table
+tags: [finance]
select * from {{ ref('finance_revenue') }}
select * from {{ ref('finance_expenses') }}
select * from {{ ref('marketing_campaigns') }}
This snippet shows selecting models by name prefixes and tags to run specific models.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Searching through the list of model names to find matches by prefix or tag.
- How many times: Once for each model in the project during selection.
As the number of models increases, the time to check each model's name or tag grows linearly.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The number of operations grows directly with the number of models.
Time Complexity: O(n)
This means the time to select models grows in direct proportion to how many models there are.
[X] Wrong: "Naming models with prefixes makes selection instant regardless of project size."
[OK] Correct: Even with prefixes, dbt still checks each model name once, so time grows with the number of models.
Understanding how naming affects model selection time helps you design scalable dbt projects and shows you think about efficiency in real work.
"What if we indexed model names in a dictionary for selection? How would the time complexity change?"