Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2019 February PostgreSQL: join_collapse_limit to force join order laid out by explicit JOINs

PostgreSQL: join_collapse_limit to force join order laid out by explicit JOINs

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

Recently, I have published one article on Database Design about do not use comma separated table names in queries and use explicit joins.
You must visit this:

Database Design: Don’t use, comma separated Tables in SELECT Query, Use Explicit JOINs

I am observing one bad query practice. People are using multiple tables in the SELECT query by separating using commas.

1
2
SELECT * FROM a, b, c
WHERE a.id = b.id AND b.id = c.id;

When you write a query like above sample, internally Query Planner creates a virtual join between these tables and this is not a straightforward joins creation.

A Query Planner has to check all possible combinations like: first join A TO B and then join C, join A TO C and then join B, join B TO C and then join A.

PostgreSQL provides one server parameter to control the order of Joins and force join order laid out by explicit JOINs using join_collapse_limit.

You can set join_collapse_limit = 1 which force to planner join the tables in explicit order.
One thing we must sure about it, the correct explicit order of Joins otherwise it creates performance issue.

Limitation of this:

After setting this parameter, the planner has less freedom to prepare an execution plan based on join conditions.
If you are using subquery – inner join condition, it executes outer join first and then execute subquery – inner join condition which is wrong.

For example,

1
SELECT * FROM a LEFT JOIN (b JOIN c ON (b.id = c.id)) ON (a.id = b.id);

Feb 11, 2019Anvesh Patel
Database Design: Please do not use DISTINCTPostgreSQL: What is IMMUTABLE, STABLE, VOLATILE and COST of Function

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

February 11, 2019 PostgreSQLAnvesh Patel, database, database research and development, dbrnd, explicit join, force joins order, improve joins, join_collapse_limit, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Programming, PostgreSQL Tips and Tricks
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....