Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bF2EG-00080A-Tz for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jun 2016 16:39: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 1bF2EG-0006Ah-Gq for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jun 2016 16:39:16 +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 1bF2EF-00067T-1B for pgsql-hackers@postgresql.org; Mon, 20 Jun 2016 16:39:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bF2EC-0001iF-Fy for pgsql-hackers@postgresql.org; Mon, 20 Jun 2016 16:39:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u5KGdB4k028280; Mon, 20 Jun 2016 12:39:11 -0400 From: Tom Lane To: Tomas Vondra cc: pgsql-hackers@postgresql.org Subject: Re: New design for FK-based join selectivity estimation In-reply-to: <0cc0ee1c-7c47-7971-767a-0cf22b7f0a93@2ndquadrant.com> 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> <15396.1466268742@sss.pgh.pa.us> <13294.1466278050@sss.pgh.pa.us> <0cc0ee1c-7c47-7971-767a-0cf22b7f0a93@2ndquadrant.com> Comments: In-reply-to Tomas Vondra message dated "Sun, 19 Jun 2016 12:44:38 +0200" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <27917.1466440274.0@sss.pgh.pa.us> Date: Mon, 20 Jun 2016 12:39:11 -0400 Message-ID: <28279.1466440751@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) 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 ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27917.1466440274.1@sss.pgh.pa.us> Tomas Vondra writes: > OK, thanks. The one thing we haven't done is testing the performance, to > see how this fares. So I've repeated the tests I've done on the original > version of the patch here Hmm. I'm not that excited about these results, for a couple of reasons: * AFAICS, all the numbers are collected from the first execution of a query within a session, meaning caches aren't populated and everything has to be loaded from disk (or at least shared buffers). * I do not credit hundreds of completely redundant FKs between the same two tables as being representative of plausible real-world cases. I modified your new script as attached to get rid of the first problem. Comparing HEAD with HEAD minus commit 100340e2d, in non-assert builds, I get results like this for the 100-foreign-key case (with repeat count 1000 for the data collection script): select code, test, avg(time),stddev(time) from data group by 1,2 order by 1,2; code | test | avg | stddev --------+-------+--------------------+--------------------- head | t1/t2 | 0.065045045045045 | 0.00312962651081508 head | t3/t4 | 0.168561561561562 | 0.00379087132124092 head | t5/t6 | 0.127671671671672 | 0.00326275949269809 head | t7/t8 | 0.391057057057056 | 0.00590249325300915 revert | t1/t2 | 0.0613933933933937 | 0.0032082678131875 revert | t3/t4 | 0.0737507507507501 | 0.00221692725859567 revert | t5/t6 | 0.123759759759759 | 0.00431225386651805 revert | t7/t8 | 0.154082082082081 | 0.00405118420422266 (8 rows) So for the somewhat-credible cases, ie 100 unrelated foreign keys, I get about 3% - 6% slowdown. The 100-duplicate-foreign-keys case does indeed look like about a 2X slowdown, but as I said, I do not think that has anything to do with interesting usage. In any case, the situation I was worried about making better was queries joining many tables, which none of this exercises at all. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/plain; name="fk-perf-run-2.sh"; charset="us-ascii" Content-ID: <27917.1466440274.2@sss.pgh.pa.us> Content-Description: fk-perf-run-2.sh DB=$1 COUNT=$2 for i in `seq 1 $COUNT`; do echo "EXPLAIN ANALYZE SELECT * FROM t1 JOIN t2 USING (a);" done | psql $DB | grep 'Planning' | tail -n +2 | awk '{print "t1/t2\t"$3}' for i in `seq 1 $COUNT`; do echo "EXPLAIN ANALYZE SELECT * FROM t3 JOIN t4 USING (a);" done | psql $DB | grep 'Planning' | tail -n +2 | awk '{print "t3/t4\t"$3}' for i in `seq 1 $COUNT`; do echo "EXPLAIN ANALYZE SELECT * FROM t5 JOIN t6 USING (a,b,c,d);" done | psql $DB | grep 'Planning' | tail -n +2 | awk '{print "t5/t6\t"$3}' for i in `seq 1 $COUNT`; do echo "EXPLAIN ANALYZE SELECT * FROM t7 JOIN t8 USING (a,b,c,d);" done | psql $DB | grep 'Planning' | tail -n +2 | awk '{print "t7/t8\t"$3}' ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--