Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axb8X-0003oM-2u for pgsql-hackers@arkaria.postgresql.org; Tue, 03 May 2016 14:17:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1axb8W-00076l-IE for pgsql-hackers@arkaria.postgresql.org; Tue, 03 May 2016 14:17:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1axb8U-00072y-Nt for pgsql-hackers@postgresql.org; Tue, 03 May 2016 14:17:14 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1axb8R-0008DD-13 for pgsql-hackers@postgresql.org; Tue, 03 May 2016 14:17:14 +0000 Received: by mail-wm0-x234.google.com with SMTP id g17so41976104wme.1 for ; Tue, 03 May 2016 07:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=t5G7Rg/iJNc3w/zwP66mWc2upC6elh++j00eTk+GyyY=; b=s9SVgiNmynKcB+MR7v5OSsrekRHD6qqXXBFFq7jEmhHKj/d/ULmo/xhkBD3poxIbVe IhXBpxQ6+9Cfi3AMbtYTnTfcpMqMkU/t1WThczZirHvrqD1Ibli2cjIsyT3rBc6BOL7g 58VB6LHWVOXHkn72skIRvZdhjjRFvNebR2T3B3ib6U9jXk6l/j90Xvv2sEggBdgr20cy G5JLKAFDh7lCyzJ5+n2tnAQ0gVCKXlWaONYweyh2Jl6/7JjGOFwLmo/9yoIJDygV+NOe dpaZTnws2hM21wpMECBMgDhvRoNLSABec3Il3NhVVLzKpJfnTsks7lcwDbonXoYlxeWf jTNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=t5G7Rg/iJNc3w/zwP66mWc2upC6elh++j00eTk+GyyY=; b=SU9+d5Ug+bOMLZoaNi3pkS7yqBcCTr8mg9y0dH0M+C2U8azj/Joby4JRd4iuyvRxVi imI5VxTnGIPEbrCsBnzajVhh8k8DMgh26PPjFdHucQWdFN7oS/uiEm4DndfjHTMhDC4G t58UH1j8E7tAD5ku/1vLa2TXZXDSIoYGeSfjOOmMb4EqPMcu2wRUPwkJ2eLh2OL6YnC9 knRqG5oyA4RN+xLI9t0IlBzSIn6HmfZ7+JR1UgkbSJ5fE0ScgV4IL5+fa04MNCY+0oOw NZch+Ig1R+QZE+iw9oCL6/150z4763Zg8P00H25lymCXfSJ59tYQezDfhz2gGmN3X/qV aALA== X-Gm-Message-State: AOPr4FXEysVUAr6EadGlESxCZSJrGbNPVK+7SrziJOjN+vCbjXtijj9PS3S4m9zmXFqKP9izQdrzd3d0VZId/ijGSd+99T3bZ8Zu/p26RVC3/ZQpakueUW5Ks6JPYkRxF6l4ytYT58vClMhCMq293BPjrqvvOS1IHnEuxCKvhhLZk9A6ZRGmi8xKBIbRT4thiVi5Gy7FRDAX X-Received: by 10.28.139.137 with SMTP id n131mr5053415wmd.13.1462285029779; Tue, 03 May 2016 07:17:09 -0700 (PDT) Received: from [10.137.2.17] (ip-89-177-44-58.net.upcbroadband.cz. [89.177.44.58]) by smtp.gmail.com with ESMTPSA id i11sm4130591wjn.36.2016.05.03.07.17.08 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 03 May 2016 07:17:09 -0700 (PDT) Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates) To: Robert Haas , Tom Lane References: <20160429102531.GA13701@huehner.biz> <572384D7.1020602@dalibo.com> <17639.1461945908@sss.pgh.pa.us> <57238E64.8010702@dalibo.com> <22731.1462037712@sss.pgh.pa.us> Cc: Julien Rouhaud , Simon Riggs , Michael Paquier , Stefan Huehner , PostgreSQL mailing lists From: Tomas Vondra Message-ID: Date: Tue, 3 May 2016 16:17:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, On 05/02/2016 09:18 PM, Robert Haas wrote: > On Sat, Apr 30, 2016 at 1:35 PM, Tom Lane wrote: >> Julien Rouhaud writes: >>> On 29/04/2016 18:05, Tom Lane wrote: >>>> Julien Rouhaud writes: >>>>> The segfault is caused by quals_match_foreign_key() calling get_leftop() >>>>> and get_rightop() on a ScalarArrayOpExpr node. >>>>> >>>>> I'm not sure that assuming this compatibility is the right way to fix >>>>> this though. >> >>>> It certainly isn't. >> >>> Agreed. New attached patch handles explicitly each node tag. >> >> No, this is completely nuts. The problem is that quals_match_foreign_key >> is simply assuming that every clause in the list it's given is an OpExpr, >> which is quite wrong. It should just ignore non-OpExpr quals, since it >> cannot do anything useful with them anyway. There's a comment claiming >> that non-OpExpr quals were already rejected: >> >> * Here since 'usefulquals' only contains bitmap indexes for quals >> * of type "var op var" we can safely skip checking this. >> >> but that doesn't appear to have anything to do with current reality. >> >> While this in itself is about a two-line fix, after reviewing >> 137805f89acb3611 I'm pretty unhappy that it got committed at all. >> I think this obvious bug is a good sign that it wasn't ready. >> Other unfinished aspects like invention of an undocumented GUC >> don't leave a good impression either. >> >> Moreover, it looks to me like this will add quite a lot of overhead, >> probably far more than is justified, because clauselist_join_selectivity >> is basically O(N^2) in the relation-footprint of the current join --- and >> not with a real small multiplier, either, as the functions it calls >> contain about four levels of nested loops themselves. Maybe that's >> unmeasurable on trivial test cases but it's going to be disastrous in >> large queries, or for relations with large numbers of foreign keys. >> >> I think this should be reverted and pushed out to 9.7 development. >> It needs a significant amount of rewriting to fix the performance >> issue, and now's not the time to be doing that. > > If this gets reverted, then probably > 015e88942aa50f0d419ddac00e63bb06d6e62e86 should also be reverted. Probably. I think the code is fine / correct, but as the FK estimation patch was the only user, there's not much point in keeping it if that gets reverted. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers