When you are querying a view like this:
SELECT ...
FROM MyView
WHERE ...
then the view gets merged as a subquery, like this:
SELECT ...
FROM (SELECT ...
FROM ...
WHERE ...)
WHERE ...
Futher processing is the same, whether the subquery originated from a view or was written explicitly in the query.
If possible, SQLite tries to flatten the subquery so that the end result is a single, simple query with all the joins and WHERE conditions merged together.
If that is not possible, SQLite tries to implement the subquery as a coroutine, i.e., it executes the inner query until it gets one row, and then applies any processing of the outer query to that row; then outputs the result, if any; then repeats.
Only if the inner query must compute all rows before returning the first one (for example, when using an ORDER BY that cannot be flattened), then using a coroutine is not possible, and the inner query is actually materialized into a temporary table.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…