I've got Postgres 11 version and production server. A procedure is rather slow and query (a piece of code in procedure) is something like that:
create temp table tmp_pos_source as
with ... (
...
)
, cte_emp as (
...
)
, cte_all as (
...
)
select ...
from cte_all;
analyze tmp_pos_source;
The query is slow and I want to create an index to improve speed.
create index idx_pos_obj_id on tmp_pos_source(pos_obj_id);
Where should I put it? After command ANALYZE or before?