CTE materialized/not materialized
От | Voillequin, Jean-Marc |
---|---|
Тема | CTE materialized/not materialized |
Дата | |
Msg-id | MW3PR20MB3338A498F87D99C38C645006BEF90@MW3PR20MB3338.namprd20.prod.outlook.com обсуждение исходный текст |
Ответы |
Re: CTE materialized/not materialized
|
Список | pgsql-sql |
Hello,
In PG12, a CTE is automatically materialized as soon as it is used more than once in the outer query.
with big_query as (…) select * from big_query where …
Ok, good plan: PG inlined the big_query in the outer query (using indexed columns avoiding full scan, etc)
Then:
with big_query as (…) select * from big_query where … union all select * from big_query where …
Poor plan: PG materialized big_query because it appears twice in the outer sql
Ok, let’s enforce:
With big_query as not materialized as (…) select * from big_query where … union all select * from big_query where …
Back to a good plan!
The problem I have now, is that I have to decide the plan that PG must follow. It’s a kind of Oracle hint.
Is it possible, for PG, to decide, by its own, the best way to go (materialized or inlined) for each CTE encountered in the query,
rather than deciding to materialized as soon as the CTE is found more than once in the outer query?
Am I clear?
Regards.
This email was sent to you by Moody’s Investors Service EMEA Limited
Registered office address:
One Canada Square
Canary Wharf
London, E14 5FA
Registered in England and Wales No: 8922701
В списке pgsql-sql по дате отправления: