Re: BUG #5145: Complex query with lots of LEFT JOIN causes segfault - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #5145: Complex query with lots of LEFT JOIN causes segfault
Date
Msg-id 14790.1256929430@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #5145: Complex query with lots of LEFT JOIN causes segfault  (Stefan Kaltenbrunner <stefan@kaltenbrunner.cc>)
List pgsql-bugs
Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> writes:
> However the error seems to go away after an ANALYZE... so I wonder if
> this is just another case of "if we missestimated the size of the
> hashtable we are doomed"

Actually, what seems to be happening on a 32-bit machine is that
ExecChooseHashTableSize sets nbatch = INT_MAX/2, and then when we
try to do

        hashtable->outerBatchFile = (BufFile **)
            palloc0(nbatch * sizeof(BufFile *));

the memory size calculation overflows to zero, so we get an empty
outerBatchFile array.  So the fix is to make sure we limit the
number of batches to something sane, perhaps work_mem / sizeof(pointer).

            regards, tom lane

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #5145: Complex query with lots of LEFT JOIN causes segfault
Next
From: Heikki Linnakangas
Date:
Subject: Re: BUG #5151: autovacuum process segfaults when max_fsm_pages are too low