Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9jYO-0003TI-I6 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 01:42:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b9jYO-0004Yv-3i for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 01:42:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b9jX1-0002yS-7z for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 01:40:43 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b9jWt-0003Y2-QY for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 01:40:41 +0000 Received: by mail-wm0-x22c.google.com with SMTP id n184so70348827wmn.1 for ; Sun, 05 Jun 2016 18:40:35 -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=7mwz0H2gE9jKmO2SZyu5UyLYETvzFAqnOUuedhNBdb0=; b=Kz+z/q0GJglY9gKxG8Jb0Ir0VCf0M9SlZIQfAk1lKsJFdYWxMfYkkMpTiJSaDbyw8O yTOtme3h8pl7OPE8/i2BqfkHfWUsw1qRbxyv41tfFgjexjoLJLg5hnIOBpeFq/1ZGign u10QIGvriOLFnVb4Fc0syabwvoXP2ENyVr4QyOKhoq63xdO+5G+Al0c2OzXxEkrJ/+QW SsuolNwVU/sDiUwIbGPdTtfNzb7HYVF19I9ctxq6Uty4SalaUj7CY9SrrDDxSD8HGsAS y9vCtd9/7X8/YaFd0ImqtBtY+Kev0hNEqTzCCz6eQy3n3fNi1IXc66Z7KnwHopeHM3Zv /7iQ== 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=7mwz0H2gE9jKmO2SZyu5UyLYETvzFAqnOUuedhNBdb0=; b=Zb6nheceKbOafOCDP6rSjxTLW3mXUTrTQFd7MEWTWM3ueqSmM2xPHgUv9ukQVvYh5r 22UwVjXDMzjx6AU5gQ4i+a3FB/1FAdaeu7loonVKP1q32SqQxE7cWEzyeXdrjcrQ7+QO 24rJxkBYWdFKaLpvgFpSu8lQVLXP0mdf60u5KbJhrzUWuSvtgZ08l6Ys2QKoT6Tamwuq TOMIQoQ/URbtiRlcoFc/Da7DVjQhviI+KMdhCwuO2Yd3o/8kWJgCDjzW5Ru09wzVjzy7 gzUvwXDGAAM6rfHAJ7mEhz4YtzIIah/bddgQurUxHgzTR7+GzlUboLA+11ODP+PoGHRx mfbw== X-Gm-Message-State: ALyK8tIvwfULJCk1sbM4SnG5PpRiKolTJrtLN48icgQqa/0AIisZHwD9r9K43CQvZ5W2lWbDs+PYDf2szQe/AUE1aGz07Cp9lZOY0Jn79a05et5l0//Tl0VAaEMF/Uy9nYMTwub/5VZfayl8EWJMyoKDVcq0HeXgIYvwczaFYZILHK///6opdivFFZI7a+5MScFIo4rOakGW X-Received: by 10.194.119.233 with SMTP id kx9mr2755707wjb.87.1465177233859; Sun, 05 Jun 2016 18:40:33 -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 a128sm11596830wme.16.2016.06.05.18.40.32 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 05 Jun 2016 18:40:32 -0700 (PDT) Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates) To: Tom Lane , Robert Haas References: <57238E64.8010702@dalibo.com> <22731.1462037712@sss.pgh.pa.us> <8344835e-18af-9d40-aed7-bd2261be9162@2ndquadrant.com> <16807.1462388069@sss.pgh.pa.us> <20160529053601.GE496776@tornado.leadboat.com> <20160602012954.GA619629@tornado.leadboat.com> <28109.1465064127@sss.pgh.pa.us> Cc: Noah Misch , Simon Riggs , David Rowley , Julien Rouhaud , Michael Paquier , Stefan Huehner , PostgreSQL mailing lists From: Tomas Vondra Message-ID: <039fca3d-890a-d09a-e0df-e045187eb69e@2ndquadrant.com> Date: Mon, 6 Jun 2016 03:40:30 +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: <28109.1465064127@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; 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, While this thread was effectively superseded by the 'new design' thread [1], I'd like to address a few points raised here, as they are relevant for the new design (at least I believe so). [1] https://www.postgresql.org/message-id/31041.1465069446@sss.pgh.pa.us On 06/04/2016 08:15 PM, Tom Lane wrote: ... > > * Make RelationGetFKeyList cache a list of ForeignKeyOptInfo structs, > not just constraint OIDs. It's insane that the relcache scans > pg_constraint to collect those OIDs and then the planner re-reads all > those same rows on every planning cycle. Allow the relcache to return > a pointer to the list in-cache, and require the planner to copy that > data before making any more cache requests. The planner would run > through the list, skipping single-key entries and entries leading to > irrelevant tables, and copy out just the items that are useful for > the current query (probably adding query-specific table RTE indexes > at the same time). That seems like a fairly straightforward change, and I'm not opposed to doing that. However RelationGetFKeyList is basically a modified copy of RelationGetIndexList, so it shares the same general behavior, including caching of OIDs and then constructing IndexOptInfo objects on each get_relation_info() call. Why is it 'insane' for foreign keys but not for indexes? Or what am I missing? > > * Personally I'd probably handle the "ignore irrelevant tables" test > with a list_member_oid test on a list of relation OIDs, not a > hashtable. It's unlikely that there are enough tables in the query to > justify building a hashtable. OK > > * All of the above should happen only if the query contains multiple > tables; there is no reason to expend even one cycle on loading FK data > in a simple single-table query. OK > > ... snip the part about nested loops (new design thread) ... > > Also, there are serious bugs remaining, even without considering planning > speed. An example I just noticed is that quals_match_foreign_key actually > fails entirely to ensure that it's found a match to the FK, because there > is no check on whether foreignrel has anything to do with the FK. That > is, this bit: > > * We make no attempt in checking that this foreign key actually > * references 'foreignrel', the reasoning here is that we may be able > * to match the foreign key to an eclass member Var of a RestrictInfo > * that's in qualslist, this Var may belong to some other relation. > > would be okay if you checked after identifying a matching eclass member > that it belonged to the FK's referenced table, but AFAICS there is no such > check anywhere. > Perhaps I'm missing something, but I thought this is checked by these conditions in quals_match_foreign_key(): 1) with ECs (line 3990) if (foreignrel->relid == var->varno && fkinfo->confkeys[i] == var->varattno) foundvarmask |= 1; 2) without ECs (line 4019) if ((foreignrel->relid == leftvar->varno) && (fkrel->relid == rightvar->varno) && (fkinfo->confkeys[i] == leftvar->varattno) && (fkinfo->conkeys[i] == rightvar->varattno)) { ... } else if ((foreignrel->relid == rightvar->varno) && (fkrel->relid == leftvar->varno) && (fkinfo->confkeys[i] == rightvar->varattno) && (fkinfo->conkeys[i] == leftvar->varattno)) { ... } Or does that fail for some reason? 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