Re: Avoiding OOM in a hash join with many duplicate inner keys
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>,
David Hinkle <hinkle@cipafilter.com>
Date: 2017-02-16T22:13:31Z
Lists: pgsql-hackers
Attachments
- check-hash-bucket-size-against-work_mem-2.patch (text/x-diff) patch
Robert Haas <robertmhaas@gmail.com> writes: > On Thu, Feb 16, 2017 at 3:51 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote: >> No, it'd be the *most* common MCV, because we're concerned about the >> worst-case (largest) bucket size. But that's good, really, because the >> highest MCV frequency will be the one we have most statistical >> confidence in. There's generally a whole lot of noise in the tail-end >> MCV numbers. > Oh, right. That's reassuring, as it seems like it has a much better > chance of actually being right. Here's a version that does it that way. Unsurprisingly, it doesn't cause any regression test changes, but you can confirm it's having an effect with this test case: create table tt(f1 int); insert into tt select 1 from generate_series(1,1000000) g; insert into tt select g from generate_series(1,1000000) g; analyze tt; explain select * from tt a natural join tt b; Unpatched code will go for a hash join on this example. For application to the back branches, we could do it just like this (leaving the existing fields alone, and allowing sizeof(RestrictInfo) to grow), or we could change the datatypes of the four fields involved to float4 so that sizeof(RestrictInfo) stays the same. I'm not entirely sure which way is the more hazardous from an ABI standpoint. If there are any external modules doing their own palloc(sizeof(RestrictInfo)) calls, the first way would be bad, but really there shouldn't be; I'd expect people to be using make_restrictinfo() and friends. (Note that palloc's power-of-2 padding wouldn't save us, because sizeof(RestrictInfo) is currently exactly 128 on 32-bit machines in several of the back branches.) Conversely, if any non-core code is touching the bucketsize fields, changing those field widths would break that; but that doesn't seem all that likely either. On balance I think I might go for the first way, because it would remove doubt about whether reducing the precision of the bucketsize estimates would cause any unexpected plan changes. Or we could decide not to back-patch because the problem doesn't come up often enough to justify taking any risk for. But given that we've gotten one confirmed field report, I'm not voting that way. regards, tom lane
Commits
-
Avoid out-of-memory in a hash join with many duplicate inner keys.
- 4867d7f62f73 11.0 landed