Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YQho5-0007SX-6e for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Feb 2015 19:39:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YQho4-0000RK-Kt for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Feb 2015 19:39:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YQho2-0000Op-Jm for pgsql-hackers@postgresql.org; Wed, 25 Feb 2015 19:39:38 +0000 Received: from mail-wi0-f172.google.com ([209.85.212.172]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YQhny-0007xy-55 for pgsql-hackers@postgresql.org; Wed, 25 Feb 2015 19:39:37 +0000 Received: by mail-wi0-f172.google.com with SMTP id l15so35920262wiw.5 for ; Wed, 25 Feb 2015 11:39:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=LbSfUnvysfWYDPcNYL4ylseyxgGLxBkIiBFWterM2Ow=; b=Cm4PJzl8TeLeCHrBKJuRBQI+af+pB0irS/fLi6X5I/haprOLYhpG+5jsGxEXga/BfJ sPPpXj7JCpyJdstx1nVnMjoJN9BQYlZGo0PTQL7g8XjBQtzDN2R+BasuSXjAmV16N5QA kJLwrEp/1ET6AJzW7ymXsiRLtg9EZfv27MaNeu7i6fbW96vqzo2Jd67O3dZi9T2z0swq dWjE0sxBlERRKf8yLhL2x1ayH0u72OHm+NN6qVnW7OTCCCgzKt78N4VfFUHZmmu1OUcS 37NI7jfAAhfSet7dBM4vv3iygFzewszY7I/dRu8g20qDDmJTvZRaSp+T7vfLld+MjxVe wLlw== X-Gm-Message-State: ALoCoQlz6knheYmfrtDaowPem7KS/oxkUqakJdpTyyn7/HvBH9d6BXNQUvkc+fHjINsT46iw9SFZjb98Yxjou1Wv0Kp1neGzmG4V8pKRjDV4Vc+qhDcx6Bx28jYOPbVL+qsoMtyhi3vg1IZ4NkWBs0x+kmrOuG9YvEdaBeGMNS5oC423/1gzTVBRVerWw48FTj3SsNRwLrF6 X-Received: by 10.180.108.199 with SMTP id hm7mr42730440wib.5.1424893171848; Wed, 25 Feb 2015 11:39:31 -0800 (PST) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz. [78.45.139.138]) by mx.google.com with ESMTPSA id u18sm66206364wjq.42.2015.02.25.11.39.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 11:39:31 -0800 (PST) Message-ID: <54EE24DC.4000409@2ndquadrant.com> Date: Wed, 25 Feb 2015 20:39:08 +0100 From: Tomas Vondra Organization: 2ndQuadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: pgsql-hackers@postgresql.org Subject: Re: Performance improvement for joins where outer side is unique References: In-Reply-To: Content-Type: text/plain; charset=utf-8 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 David, I've been looking at this patch, mostly because it seems like a great starting point for improving estimation for joins on multi-column FKs. Currently we do this: CREATE TABLE parent (a INT, b INT, PRIMARY KEY (a,b)); CREATE TABLE child (a INT, b INT, FOREIGN KEY (a,b) REFERENCES parent (a,b)); INSERT INTO parent SELECT i, i FROM generate_series(1,1000000) s(i); INSERT INTO child SELECT i, i FROM generate_series(1,1000000) s(i); ANALYZE; EXPLAIN SELECT * FROM parent JOIN child USING (a,b); QUERY PLAN --------------------------------------------------------------------- Hash Join (cost=33332.00..66978.01 rows=1 width=8) Hash Cond: ((parent.a = child.a) AND (parent.b = child.b)) -> Seq Scan on parent (cost=0.00..14425.00 rows=1000000 width=8) -> Hash (cost=14425.00..14425.00 rows=1000000 width=8) -> Seq Scan on child (cost=0.00..14425.00 rows=1000000 width=8) (5 rows) Which is of course non-sense, because we know it's a join on FK, so the join will produce 1M rows (just like the child table). This seems like a rather natural extension of what you're doing in this patch, except that it only affects the optimizer and not the executor. Do you have any plans in this direction? If not, I'll pick this up as I do have that on my TODO. 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