pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ayub M <hiayub@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: hash joins are causing no space left error
Date: Wed, 12 Aug 2020 20:06:24 -0400
Message-ID: <328867.1597277184@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOS0qEu9u6H3D0r3N4_+sgS4OLQBXLxTdSR2M6CLy=bvvHnBLA@mail.gmail.com>
References: <CAOS0qEu9u6H3D0r3N4_+sgS4OLQBXLxTdSR2M6CLy=bvvHnBLA@mail.gmail.com>

Ayub M <hiayub@gmail.com> writes:
> This is PostgreSQL 11 on AWS, there is a mview query in this OLAP database,
> the tables involved are huge - 50-100m records on average records hundreds
> of columns in most cases. The query runs for a while and then errors out
> saying "No space left on device". I could see it generating around 500gb of
> temp file data. At times it goes thru and at times it fails - probably due
> to other queries running at the same time and causing failure.

Are you sure that these queries are actually producing the answers you
want?  It sounds suspiciously like you are computing underconstrained
joins.

> The joins are happening on around 10 tables and all are joining on the PK
> and FK columns. I see partition pruning happening but the hash joins are
> killing the query.
> Is there any way to avoid hash joins?

TBH, you are asking the wrong question.  A merge join would take about as
much temporary space, and a nestloop join over so much data would probably
not finish in an amount of time you're willing to wait.  Indexes are NOT
a magic solution here.  What you need to be thinking about is how to not
need to process so much data.

If you really need to have this proven to you, you can try "set
enable_hashjoin = off", but I don't think you'll find that better.

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <328867.1597277184@sss.pgh.pa.us>
Permalink:  ../328867.1597277184@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/328867.1597277184@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, hiayub@gmail.com
  Subject: Re: hash joins are causing no space left error
  In-Reply-To: <328867.1597277184@sss.pgh.pa.us>
  References: <CAOS0qEu9u6H3D0r3N4_+sgS4OLQBXLxTdSR2M6CLy=bvvHnBLA@mail.gmail.com> <328867.1597277184@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox