-
-
Notifications
You must be signed in to change notification settings - Fork 873
Description
Search before asking
- I searched the issues and found no similar issues.
Description
It would be nice with a rule that warns about unused tables in joins.
I realize that it might need to be opt-in, since there are legitimate reasons to do this, but it is often a bug.
There are already rules for unused aliases and unused CTEs, but first aliasing a CTE, and then joining it in without referring to any of its columns is an edge-case that falls between these rules. I really couldn't find any other issues that matched exactly this use case, but if I overlooked something, I'm sorry!
Use case
If, during the development or the lifetime of a view, you have reduced which columns are selected to the point that a joined-in table is no longer referenced, it would be nice to be warned.
For example if you have had a view
with
widget as (
select * from some_widget_dbt_table
),
inventor as (
select * from some_inventor_dbt_table
)
select
widget.id,
widget.name,
inventor.name
from
widget
left join inventor
on widget.inventor_id = inventor.id
And then you decided at some point that the inventor name doesn't need to be in the output any more, and you get
select
widget.id,
widget.name,
from
widget
left join inventor
on widget.inventor_id = inventor.id
Here, the join with inventor is no longer necessary, but in a big select-statement, you might easily overlook this.
Dialect
I don't think this is specific to any dialects?
But it is particularly helpful in dbt, where convention often leads you to define your "inputs" as CTEs with aliases, and then use those aliases in the join, immediately making them "used".
Are you willing to work on and submit a PR to address the issue?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct