Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9yFo-0005cE-GO for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 17:23:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b9yFo-0001QM-34 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 17:23:56 +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 1b9yFm-0001P3-DE for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 17:23:54 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b9yFe-0006Yh-8Z for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 17:23:53 +0000 Received: by mail-wm0-x232.google.com with SMTP id k204so36246261wmk.0 for ; Mon, 06 Jun 2016 10:23:46 -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=vZIhTid/FhJZUDpP+pCZhk3Ujkfhw5M2nKB5f4iOuOE=; b=zLo6Fqb3VNFMeUJUHCocHccaxk4jlcUf471GSzplzHNTkrO59Rq8CWNM93pw7lkWbB EZfKWSJ7zKgVcMS779iwYxhXgf8D6p+x5H7oXB/z6eLvZKqFcrzU94BoJLe4PlWcdXSU GCN9iJL99fKk+tUrU1hipmHnBxKSwo7LSvJAK/XmyQSN0M33nbqGw3VbS0FRjYN2GvLw OGiZos/iPLpBtZ/j5Rit2EVS4OcCplxkm376qLgMQTBERxMpfONgpxOtFnEw/9vo6EMD vVXvozTyIGNyq+FpLpLQzcPtxMHSqQUWQzjGiB9gZCxPxzr7LN2jwu5oD6rAMW+YWtbi 2/cg== 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=vZIhTid/FhJZUDpP+pCZhk3Ujkfhw5M2nKB5f4iOuOE=; b=DMj6fRU0STIbxudp0MeKbE9sdePYqKh1eFizhxN2uNKDMWjCnlVh2nvuN42f4MNqOD qrHve4pvAMObcKgZAGsE8uspKSH+I7uyQP9PaClch4z5iKMPOGOOd5YQr8QksRbGRMn3 cua7i6yskyUAOp1lF+zBw+KSOSwqtheU9jg2uMU54NfZ+headd5YkoRpxXQyTBqvRy85 6Bs1ObhgmQ1ZGw3ABVtD6ElTahoEuhEcxnri6sDmMWT519HmLej67YetpXESl/FULEtm mjSOaDFJS7m/LoB+3BrBsIiKj1pblbZNQkuxuFhsxklqUUR82NUwUGmNUNhJjGTIeJ5g rsHA== X-Gm-Message-State: ALyK8tLx9NU/F3ZsSx4utFQGVQqVbhVcBf7XFmMM3Tx76WxMkM55aRWtRCxMHfUWu0IYc14gqh6UjDBU2UMnc92BSqCRV0x/Tuh08ymuVxUP8gOy7g20PMaeTK+Jno2XfSYEbN3cUQtdlsBrdrtr1L3UEOriJuP6STB9coL5mml9GIRKNSJO4thtZlZ1B6Rs4LpC71bejfgU X-Received: by 10.28.131.197 with SMTP id f188mr1063wmd.12.1465233825308; Mon, 06 Jun 2016 10:23:45 -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 dj4sm21232022wjc.13.2016.06.06.10.23.43 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 06 Jun 2016 10:23:44 -0700 (PDT) Subject: Re: pg9.6 segfault using simple query (related to use fk for join estimates) To: Tom Lane 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> <039fca3d-890a-d09a-e0df-e045187eb69e@2ndquadrant.com> <23385.1465229755@sss.pgh.pa.us> <24068.1465230882@sss.pgh.pa.us> Cc: Robert Haas , Noah Misch , Simon Riggs , David Rowley , Julien Rouhaud , Michael Paquier , Stefan Huehner , PostgreSQL mailing lists From: Tomas Vondra Message-ID: <2a8adc56-6eb1-123e-8914-0cf025797262@2ndquadrant.com> Date: Mon, 6 Jun 2016 19:23:42 +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: <24068.1465230882@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 On 06/06/2016 06:34 PM, Tom Lane wrote: > ... BTW, another thought occurred to me yesterday: it seems like the > existing code hasn't thought through its behavior for multiple foreign > keys very carefully. That is, suppose we have both "A.J references B.K" > and "A.X references B.Y", as separate FKs not a single multicolumn FK. > The current code goes to some lengths to decide that one of these is > better than the other and then ignore the other. Why? Seems to me > that in such a case you want to behave more nearly as you would for a > multicolumn FK, that is discard all the join quals matched to either FK > in favor of a single selectivity estimate based on the number of rows in > the referenced table. Discarding only the A.J = B.K clause and then > multiplying by the independent selectivity of A.X = B.Y is surely just as > wrong as what we've historically done for multicolumn FKs. (Correcting > for nulls would take a bit of thought, but I wouldn't be surprised if it > ends up being the same as for the multicolumn-FK case, at least to within > the precision we can hope to get with the available stats for nulls.) Yes, that can be improved. The plan was to improve the common case first, and then look at the more complicated cases. It might seem like a hand-waving but I'd bet 99% tables are joined on a single FK, so this seems like a reasonable approach. When it comes to improving multiple (multi-column) foreign keys, I think it may get way more complicated that it might seem. What if the foreign keys overlap, for example? Or what if the keys go in opposite directions (cycle). And so on ... 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