Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bE7a1-00018E-SF for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jun 2016 04:09:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bE7a1-0004v9-5p for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Jun 2016 04:09:57 +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 1bE7a0-0004v3-Is for pgsql-hackers@postgresql.org; Sat, 18 Jun 2016 04:09:56 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bE7Zx-00016p-DM for pgsql-hackers@postgresql.org; Sat, 18 Jun 2016 04:09:55 +0000 Received: by mail-wm0-x235.google.com with SMTP id k184so1412616wme.1 for ; Fri, 17 Jun 2016 21:09:52 -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=McWqKzNUzwx8apPzaf2n3xsSh1xKhOTeolmVUnB6kis=; b=rXXduw+qrdYsLFruqsyQdQmCrwWYxOadI4x6Sl3yFvqIg4aJbXYtPksd/iU/Q1mrTl odszktkfE8tPW3p6a22xpnaPJAKjlEEsFXA0KlIZBFgXSrqgPEG2xsoeQHyPEpTr1aZV QP6JuHWmzfvbv4iqId31k6DhJ71kfChUKFORF8zSOf1H/4mnYHH4ldgZKXopj3sBdA25 IPO84F+nz1Qjz/38jVj1aACgSBeUKVXQFRpKCTKyg6TgCiRxqZfHqru3aXvpvo5N68UT ItCzQZQ7AjXBkD07vRdaZzr+2mFRbWHGR9IrX4vF+NpakgF8b6bH5Jb78SKwyrP9mDLB G9vg== 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=McWqKzNUzwx8apPzaf2n3xsSh1xKhOTeolmVUnB6kis=; b=YlKvcQr2Gt2IMRBGqfn8gJvuC8FCzO838p9wdUFsyAdtTnhkrqH1LL5K4PycZ1/mDW 1Zs/sYNf7TtV90IWnFaqSM5DkPKaCSxPU4UxESB0q5YjxAmVf2fCz79PcaAQiTeRqcuQ 3zLjjbBbmEp1cC6rwS/DHpoFPMItkKVhcwtHzyYnSpx/YBC0NfwVRoyybYvc9z96BK7l 7Jbj1fnnwub6XzJ+ITyHp9RKAkfvaZ6MlfqbBJrkUPhi3z+LpXC/uS3OOTbHfgi54azv BOi9OqgAYtf0tL6T57wGXI/aTzDy3E02usyEAbAs1ydcMXEQn4dc7ejhHCzL5f+JShjt Xe2A== X-Gm-Message-State: ALyK8tJyAkIdtWrVQY59zklFmK9DRSMewGAhKGbqCRodGUEJ248LQ7Gd3dkkpveSLuT8mRy2WtCS+S2Iurb/SMYDeHzJALNMZU85ZWJSB9xw2+em5jCra3ty5K2yesokRx626xwqEXN0TORTo5j1HdphAqYzbq999WZnRetZdx65YY33bBYgCIMoLxD50siXIws/xmUw3UtU X-Received: by 10.194.221.37 with SMTP id qb5mr4762489wjc.171.1466222991487; Fri, 17 Jun 2016 21:09:51 -0700 (PDT) Received: from [10.137.2.20] (cst-prg-234-27.cust.vodafone.cz. [46.135.234.27]) by smtp.gmail.com with ESMTPSA id v200sm1700522wmv.4.2016.06.17.21.09.47 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2016 21:09:50 -0700 (PDT) Subject: Re: New design for FK-based join selectivity estimation To: Tom Lane References: <31041.1465069446@sss.pgh.pa.us> <25469.1465138626@sss.pgh.pa.us> <15245.1466031608@sss.pgh.pa.us> <20877.1466175216@sss.pgh.pa.us> Cc: pgsql-hackers@postgresql.org From: Tomas Vondra Message-ID: Date: Sat, 18 Jun 2016 06:09:39 +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: <20877.1466175216@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, A few more comments, about re-reading the patch more thoroughly. I wouldn't say any of those qualify as bugs, but rather as discussion about some of the design choices: 1) NULL handling I'd argue that we should do something about this, although I agree it's non-trivial to estimate - at least until we get some sort of correlation stats (e.g. my patch already provides most of the pieces, I believe). But I'd argue that in the case of multi-column foreign keys we can do better even without it - my experience is that in such cases either all values are NULL or none of them, and a single NULL value breaks the FK of course. So I think max(null_frac) would work. 2) get_foreign_key_join_selectivity vs. incomplete matches The comment right before checking (removedlist == NIL) says: * For a multi-column FK, it's possible that we found matches to some * columns but not all, implying that one of the above effects applied * to just some of the columns. For the moment, we go ahead and * remove those clauses and apply the FK's selectivity anyway. It * might be better to put back the removed clauses and ignore the FK; * but that amounts to betting on independence of the clauses, which * doesn't seem like a good bet in such messy cases. Is this a good idea? I'd probably vote to do what's proposed (and rejected) in the second half of the comment, i.e. put back the clauses and skip the FK as that pretty much says "improve estimate or keep the current one, but don't risk making it worse." 3) ForeignKeyOptInfo->rinfos as a List Can we actually get a list of matching RestrictInfos for a single foreign key? I've been unable to construct such query. 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