C
C
Crunchor2021-02-26 09:40:33
PostgreSQL
Crunchor, 2021-02-26 09:40:33

How many records does the View load?

In PostgreSQL DBMS I have a lot of tables.
I create a view, let's say somedata, which consists of

select a.col1, b.col2, c.col3, ....
from a
left join b on a.id=b.id
.......

Some kind of complex query that displays a huge number of records.
Now I have a question, how many records will be loaded into memory if I execute such a query? Will it first load all the data, from all tables, into somedata and only then filter them by the condition, or will the DBMS immediately execute the view request with the specified condition?
select * from somedata where col2 = 10

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2021-02-26
@Crunkor

In the case of a normal view, yours will select * from somedata where col2 = 10roughly expand into a query that forms the view. In the case of materialized, reading will be carried out in the same way as from a regular table. So in both cases, no more records than needed will be loaded into memory.

M
Melkij, 2021-02-26
@melkij

Do explain and find out. It will be seen how deep the conditions have gone, and the replacement of left join with inner join, and, probably, the reverse order of joining tables.
The view for the scheduler is transparent and the entire query tree is rescheduled.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question