feat: add a guide on materialized ctes to query-data #3499
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I just found out about materialized CTEs and thought I really should share this for people in similar situations.
I'm consulting with a company that hides TimescaleDB behind a task queue, & some jobs were taking ages. Using with cache as materialized ( ... ) resulted in a query that was taking days now takes 30 seconds! These last few months I was getting frustrated that the Postgres query planner kept deciding on NestedLoop joins.
I see that you guys cover this in https://www.timescale.com/learn/how-to-use-common-table-expression-sql - however I reckon it could be covered in the
query-data
section of the docs too to force this on people?Links
Fixes #[insert issue link, if any]Writing help
For information about style and word usage, see the style guide
Review checklists
Reviewers: use this section to ensure you have checked everything before approving this PR:
Subject matter expert (SME) review checklist
Documentation team review checklist
and have they been implemented?