<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx" -->

---
title: All Your GUCs in a Row: join_collapse_limit | daily.dev
description: PostgreSQL's join_collapse_limit is the closest thing the database has to a real join-order hint. Set to its default of 8, it controls when the planner...
canonical: https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: All Your GUCs in a Row: join_collapse_limit | daily.dev
og:description: PostgreSQL's join_collapse_limit is the closest thing the database has to a real join-order hint. Set to its default of 8, it controls when the planner...
og:url: https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx
og:image: https://api.daily.dev/og/posts/rykVGGydx.png
og:image:alt: All Your GUCs in a Row: join_collapse_limit
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# All Your GUCs in a Row: join_collapse_limit

**[Planet PostgreSQL](https://daily.dev/sources/planet-postgresql)** · 4 min read · 1 upvotes · 1 comments

## Summary

PostgreSQL's join_collapse_limit is the closest thing the database has to a real join-order hint. Set to its default of 8, it controls when the planner flattens explicit JOIN constructs into a single reorderable list versus leaving them nested as written. Setting it to 1 with SET LOCAL inside a transaction forces the planner to join tables in exactly the written order, which explains why queries with more than eight explicit joins (often from ORM-generated SQL or stacked views) can suddenly fall off a performance cliff once a ninth join is added. Raising the limit fixes that but costs planning time, and pushing it past geqo_threshold (default 12) hands planning to the GEQO random-sampling algorithm, so both should be moved together. The piece frames forcing join order as a tourniquet rather than a cure: the durable fix is improving statistics via higher statistics targets, CREATE STATISTICS, and ANALYZE.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://postgr.es/p/9sF>

## Questions this post answers

### How do I force PostgreSQL to join tables in the exact order I wrote them in the query?

Set join_collapse_limit to 1 for the session or transaction, for example with SET LOCAL join_collapse_limit = 1. This prevents the planner from flattening explicit JOIN constructs into a reorderable list, so each JOIN is planned as written. A JOIN nested inside a comma-separated FROM list pins only that construct, leaving the rest of the tables free to be reordered.

_When query plans go sideways after adding a join, daily.dev surfaces PostgreSQL tuning deep dives like this one._

### Why does adding one more join to a PostgreSQL query suddenly make the plan terrible?

The default join_collapse_limit is 8, so a query with more than eight explicit joins can hit a point where the planner stops considering all join orders and just follows the order as written, producing a bad plan. This commonly shows up in ORM-generated SQL or views stacked on views where the join count silently crept past eight.

_Debugging a sudden plan regression after a schema or query change is exactly what daily.dev's PostgreSQL coverage helps with._

### What happens if I raise join_collapse_limit past the geqo_threshold in PostgreSQL?

Raising join_collapse_limit past geqo_threshold, which defaults to 12, hands the query over to the GEQO genetic query optimizer, trading an exhaustive search of a small plan space for a random sample of a much larger one. To avoid this tripwire, move geqo_threshold above join_collapse_limit and from_collapse_limit whenever you raise them.

_daily.dev helps engineers tuning PostgreSQL planner settings keep tripwires like geqo_threshold from biting them._

## Community discussion

Top comments from developers on daily.dev.

**@trevorsuna** · 0 upvotes

> The ninth-join performance cliff is a useful warning for ORM-heavy systems. SET LOCAL seems valuable as a diagnostic or emergency measure, but fixing statistics is the healthier endpoint. I’d also watch planning time when raising this alongside geqo_threshold.

## Similar posts on daily.dev

- [All Your GUCs in a Row: from\_collapse\_limit](https://daily.dev/posts/all-your-gucs-in-a-row-from-collapse-limit-r62ismyyi) · Planet PostgreSQL · 0 upvotes · 0 comments
- [All Your GUCs in a Row: The geqo Family](https://daily.dev/posts/all-your-gucs-in-a-row-the-geqo-family-jnt577kaa) · Planet PostgreSQL · 0 upvotes · 0 comments
- [All Your GUCs in a Row: enable\_nestloop](https://daily.dev/posts/all-your-gucs-in-a-row-enable-nestloop-luca0z9eb) · Planet PostgreSQL · 0 upvotes · 0 comments
- [All Your GUCs in a Row: gin\_fuzzy\_search\_limit](https://daily.dev/posts/all-your-gucs-in-a-row-gin-fuzzy-search-limit-jw9vfi5nr) · Planet PostgreSQL · 1 upvotes · 2 comments

---

Tags: [#sql](https://daily.dev/tags/sql), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"All Your GUCs in a Row: join_collapse_limit","url":"https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx"},"datePublished":"2026-08-19T01:03:05.615Z","dateModified":"2026-09-13T21:10:09.982Z","description":"PostgreSQL's join_collapse_limit is the closest thing the database has to a real join-order hint. Set to its default of 8, it controls when the planner...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/44ba8263c4b8d8b9e3b875e09711a5ee?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/44ba8263c4b8d8b9e3b875e09711a5ee?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Planet PostgreSQL","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Planet PostgreSQL","logo":"https://media.daily.dev/image/upload/logos/placeholder.jpg","url":"https://daily.dev/sources/planet-postgresql"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"sql,postgresql","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet PostgreSQL","item":"https://daily.dev/sources/planet-postgresql"},{"@type":"ListItem","position":3,"name":"All Your GUCs in a Row: join_collapse_limit"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx","comment":[{"@type":"Comment","text":"The ninth-join performance cliff is a useful warning for ORM-heavy systems. SET LOCAL seems valuable as a diagnostic or emergency measure, but fixing statistics is the healthier endpoint. I’d also watch planning time when raising this alongside geqo_threshold.","datePublished":"2026-08-20T04:08:26.071Z","url":"https://daily.dev/posts/rykVGGydx#c-Jceb8BhmI","author":{"@type":"Person","name":"Trevor Suna","url":"https://daily.dev/trevorsuna","image":"https://media.daily.dev/image/upload/s--dZ7gXxpp--/f_auto/v1784081551/avatars/avatar_EMoP47rpuw8DNjhp6R1b6?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/all-your-gucs-in-a-row-join-collapse-limit-rykvggydx#faq","mainEntity":[{"@type":"Question","name":"How do I force PostgreSQL to join tables in the exact order I wrote them in the query?","acceptedAnswer":{"@type":"Answer","text":"Set join_collapse_limit to 1 for the session or transaction, for example with SET LOCAL join_collapse_limit = 1. This prevents the planner from flattening explicit JOIN constructs into a reorderable list, so each JOIN is planned as written. A JOIN nested inside a comma-separated FROM list pins only that construct, leaving the rest of the tables free to be reordered. When query plans go sideways after adding a join, daily.dev surfaces PostgreSQL tuning deep dives like this one."}},{"@type":"Question","name":"Why does adding one more join to a PostgreSQL query suddenly make the plan terrible?","acceptedAnswer":{"@type":"Answer","text":"The default join_collapse_limit is 8, so a query with more than eight explicit joins can hit a point where the planner stops considering all join orders and just follows the order as written, producing a bad plan. This commonly shows up in ORM-generated SQL or views stacked on views where the join count silently crept past eight. Debugging a sudden plan regression after a schema or query change is exactly what daily.dev's PostgreSQL coverage helps with."}},{"@type":"Question","name":"What happens if I raise join_collapse_limit past the geqo_threshold in PostgreSQL?","acceptedAnswer":{"@type":"Answer","text":"Raising join_collapse_limit past geqo_threshold, which defaults to 12, hands the query over to the GEQO genetic query optimizer, trading an exhaustive search of a small plan space for a random sample of a much larger one. To avoid this tripwire, move geqo_threshold above join_collapse_limit and from_collapse_limit whenever you raise them. daily.dev helps engineers tuning PostgreSQL planner settings keep tripwires like geqo_threshold from biting them."}}]}
```

