Forum Discussion
SQL: Better to connect to raw table and apply steps or filter/join with query?
Some general comments about SQL data access:
If your data is in a single table and is not large then querying a table will be faster than creating a view first and querying it for required data as it will avoid a step. If your data is not large and the columns your where clause are properly indexed then in most cases queries will be faster going directly against tables. Views should be used when you have a very large data set in a single table and you need to operate on small subset very frequently. In this case views will fetch the required data only once thus this will help minimize re-execution of search queries (on single table or a join). Bottom line, it is going to depend on your data and what your queries are so you are probably just going to have to test each approach and see what works for your situation.
Now, for the other perspective, there is a school of thought that in general you should simplify queries as much as possible by using views. The prudent use of views makes management of your application simpler and also helps you avoid repetition of query logic (joins, WHERE clauses, etc.). However, views can be ill-suited for a particular query and thus lead to poor performance as they might lead to unnecessary operations for particular queries.
- WESTi10 years agoHelper I
Thanks for the responses everyone. Your insights are much appreciated.
The issues with transforming data in PowerBi while using Direct Query was the key chain of thought in determining whether to use views so that I could consistently refer to the same data set if it was going to be utilized over multiple data models. Relying on written queries could become difficult to manage if I need to change how they work (with a view I could update one object and have that flow through to all data models). For now I will stick with a standard query and implement views should the need arise.
I think from here I will write the queries to build out the base data for the model and to reduce the amount of steps that PowerBi needs to apply. Though, when I get time I do plan on testing to see exactly what is happening when PowerBi is connecting to the database when the data model has been 'clicked' together, i.e. run a trace to understand the mechanics of what is going on.
Any further thoughts are welcome :)