Alex Gleason on Nostr: TIL you can force the SQL query planner to do two different steps if you use a CTE: > ...
TIL you can force the SQL query planner to do two different steps if you use a CTE:
> In PostgreSQL, a CTE (Common Table Expression) is an optimization fence, which means the query planner executes the CTE independently of the rest of the query and stores the result set in temporary memory (it essentially materializes the CTE). Then that result set is scanned one or multiple times depending on its use in the main query.
Published at
2024-07-25 00:22:17Event JSON
{
"id": "da793e52e61d3a22ba3127a281441ee8cbc329c25ab528b55c6c0fdf4a74628a",
"pubkey": "0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd",
"created_at": 1721859737,
"kind": 1,
"tags": [],
"content": "TIL you can force the SQL query planner to do two different steps if you use a CTE:\n\n\u003e In PostgreSQL, a CTE (Common Table Expression) is an optimization fence, which means the query planner executes the CTE independently of the rest of the query and stores the result set in temporary memory (it essentially materializes the CTE). Then that result set is scanned one or multiple times depending on its use in the main query.",
"sig": "224955bbdd6747e9ddbe208942ba32d91d3b2587d8f6d13c7084c64fcf1e2b7cfc24db844c75995ad7db7bec27b70164808040a4a50479d0b183b4fe9c19c4f2"
}