Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite3 views affect performance?

Tags:

sql

sqlite

views

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.

like image 540
Mayur Patel Avatar asked Feb 14 '12 18:02

Mayur Patel


People also ask

Do views affect performance?

All views have impact on database performance. Think of it as just that a "view" into the underlining data. As long as there are data reads and writes it will affect the performance and response to your database.

Do SQL views affect performance?

SQL Server views are helpful in many ways, for example in encapsulating complex multi-table query logic, allowing us to simplify client code. Views make queries faster to write, but they don't improve the underlying query performance.

Why is SQLite so slow?

The SQLite docs explains why this is so slow: Transaction speed is limited by disk drive speed because (by default) SQLite actually waits until the data really is safely stored on the disk surface before the transaction is complete. That way, if you suddenly lose power or if your OS crashes, your data is still safe.


1 Answers

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.

like image 67
dave mankoff Avatar answered Nov 03 '22 13:11

dave mankoff