Trying to understand databases better in general, and sqlite3 in particular:
Are views in sqlite3 mainly an organizational feature, allowing complex queries to be broken into a series of smaller ones; or do views actually affect the performance of queries that use them?
I noticed that views are stored in the database itself as part of the schema. Are views stored on disk, updated dynamically as dependent tables are updated; or are they evaluated on demand?
Thanks.
Views will always be executed on demand (sqlite3 or otherwise), so the results they return are never persistently stored.
As for performance, while I can’t speak to sqlite3 specifically, usually using views will have slightly less overhead as the query parser/planner doesn’t have to reparse the raw sql on each execution. It can parse it once, store its execution strategy, and then use that each time the query is actually run.
The performance boost you see with this will generally be small, in the grand scheme of things. It really only helps if its a fast query that you’re executing frequently. If its a slow query you execute infrequently, the overhead associated with parsing the query is insignificant. Views do, of course, provide a level of organization which is nice.