Some documentations explain that you have to use views when the queries becomes to complex with more than 2 nested relationships.
When Should You Create Views in Your Database?
Creating views in a database can offer significant performance improvements and simplifications, particularly when dealing with complex queries or aggregations. In this article, we'll explore when to use views and materialized views in your database, why they are useful, and how they can optimize your system's performance for faster results.
What are Database Views? A view in a database is a stored query that can be treated like a table. Views are not physical but virtual tables that provide an abstraction layer over your database schema. The query underlying a view is executed each time the view is queried, simplifying complex queries or aggregations.
Materialized views are similar but differ in that they store the query results physically, updating periodically or on-demand, which can lead to significant performance benefits.
When to Create Views in the Database
- Complex Joins and Aggregations
If your queries involve multiple tables with complex joins and aggregations, creating a view can simplify the query structure and improve performance. For example, joining data from articles, authors, and tags can become tedious if repeated in every query. Instead, you can create a view that encapsulates the complex logic. read more at
https://dev.to/arkdevsolutions/when-should-you-create-views-in-your-database-52hb
Please or to participate in this conversation.