Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YGqLY-0000mQ-Tk for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Jan 2015 14:45:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YGqLY-0005g6-8m for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Jan 2015 14:45:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YGqLX-0005fz-KI for pgsql-bugs@postgresql.org; Thu, 29 Jan 2015 14:45:27 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YGqLO-0005Ty-Ma for pgsql-bugs@postgresql.org; Thu, 29 Jan 2015 14:45:26 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 1E0392A043; Thu, 29 Jan 2015 06:45:13 -0800 (PST) Received: from EX13-CAS-002.vmware.com (EX13-CAS-002.vmware.com [10.113.191.52]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 0D7851879F; Thu, 29 Jan 2015 06:45:13 -0800 (PST) Received: from [192.168.42.220] (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.913.22; Thu, 29 Jan 2015 06:45:01 -0800 Message-ID: <54CA4762.3020105@vmware.com> Date: Thu, 29 Jan 2015 16:44:50 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 MIME-Version: 1.0 To: Michael Paquier , CC: Subject: Re: BUG #12694: crash if the number of result rows is lower than gin_fuzzy_search_limit References: <20150128181243.2579.80775@wrigleys.postgresql.org> <54CA3EB5.3030804@vmware.com> In-Reply-To: <54CA3EB5.3030804@vmware.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 01/29/2015 04:07 PM, Heikki Linnakangas wrote: > The problem is in startScan() function: > >> if (GinFuzzySearchLimit > 0) >> { >> /* >> * If all of keys more than threshold we will try to reduce result, we >> * hope (and only hope, for intersection operation of array our >> * supposition isn't true), that total result will not more than >> * minimal predictNumberResult. >> */ >> >> for (i = 0; i < so->totalentries; i++) >> if (so->entries[i]->predictNumberResult <= so->totalentries * GinFuzzySearchLimit) >> return; >> >> for (i = 0; i < so->totalentries; i++) >> if (so->entries[i]->predictNumberResult > so->totalentries * GinFuzzySearchLimit) >> { >> so->entries[i]->predictNumberResult /= so->totalentries; >> so->entries[i]->reduceResult = TRUE; >> } >> } >> >> for (i = 0; i < so->nkeys; i++) >> startScanKey(ginstate, so, so->keys + i); >> } > > If the early return is taken, startScanKey() is not called, and many > fields in the GinScanKey struct are left uninitialized. That causes the > segfault later. > > This was not as big a problem before 9.4, because startScanKey() didn't > do very much. It just reset a few fields, which in a new scan were reset > already by ginNewScanKey(). But it is in fact possible to get an > assertion failure on 9.3 too, if the plan contains a re-scan of GIN > scan, and gin_fuzzy_search_limit is set. Attached is a script that does > it. Not sure why, but I'm not seeing a segfault or assert failure on > earlier branches. The plan of the segfaulting query looks identical > between 9.2 and 9.3, so perhaps there have been some changes to the > executor on how and when it calls rescan. Never mind, I had some debugging code in place in my 9.3 branch that caused the assertion failure. Still, it looks broken on 9.3 and below, too. Either that, or GinNewKey() check in gingetbitmap is always true, and the startScanKey() calls were unnecessary. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs