Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cOtYg-0001Qc-GZ for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jan 2017 21:57:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cOtYf-0006ry-NT for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jan 2017 21:57:21 +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 1cOtYd-0006qS-RP for pgsql-hackers@postgresql.org; Wed, 04 Jan 2017 21:57:19 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cOtYZ-0006af-7T for pgsql-hackers@postgresql.org; Wed, 04 Jan 2017 21:57:19 +0000 Received: by mail-wm0-x234.google.com with SMTP id c85so233078238wmi.1 for ; Wed, 04 Jan 2017 13:57:14 -0800 (PST) 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=W8SC5oNdPYi6DuBdlElB6WOslLvQkMypMCqydXoC6HE=; b=o13mUzAw6r8bfdzJpX/Ck1S14NuCLw8WDFe2L6g/0hUrjblEGRacTsk85cFqNw12Ib r1FaXPuy0T5Lfj3y0VNkNzVD+DtIdVrUcINviQvk1TN7hUpssyFg7xv3U/UeQC/VEvD5 Ctl2T1zucmdZ6FG9X87F4p2qkEMEgNK1wPhTruzRCEGaTB60WB4eWkV7yKBd4XvsyF/K gk9/k6k94IRBxfURb/BpCxgEMDnQrBSqlW6xLIm0u597LNWHn8fDvERmGp83HVZjTyvq tr2sdEE2vd8p85Q/kVrZsKJ7bfPM7crjT3KxwPynGxC6YfHZvnd8b2It4mSioNyMqR6A l3Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=W8SC5oNdPYi6DuBdlElB6WOslLvQkMypMCqydXoC6HE=; b=tFXItEpsUPKtWIRwx1wwwdceXAnqRZJG3Yqfmxlc3uL3BqNrYadi8K4tRmPEHSsKEk Kieg4VFHVQ4Q/ep6AqUsx3P9sXai5ZoXkHAakYa+t2oxXYsvZtdBFJi98+eI4cLNpf+c uPPcRbDxPRFR2h20mkMKYoXQ5mI8qmrEH/UTO2NWCDt/C3qR3OnTPNuij5mc7BvuQFnn LyoH0zoWZAMrSVaPgT7Za2fsGIIlN0ypGb/qFVhij604EQclj91xJwBYCKSyQZQx64pF a94YKx7E1LnRc1uGSsOZpLdIzZgE3Hg8aBSqITz8WYXyv8aWmbPKmuhHvyC8eZdHh22S EjNQ== X-Gm-Message-State: AIkVDXK/R6bMd9KQrgO+LRsgwfCasLzKvWPowNX8YV/Qea982qIr3W0E3fHZswx4mmyUKWUA1sJ7+kTE2D26Jz3S9hM8fHjaRg4J0U4rjUqYDkzoK8AbXUP4RkSKOBxut9te+23tcDnmyPy70UVwcdgcV4li3D5Bq8trlIrWuOMIwKV0dIXlU3ySLLuQo0l1TU81aiE5x0fS X-Received: by 10.28.134.146 with SMTP id i140mr62364406wmd.100.1483567033352; Wed, 04 Jan 2017 13:57:13 -0800 (PST) Received: from [10.137.2.17] (ip-89-177-46-65.net.upcbroadband.cz. [89.177.46.65]) by smtp.gmail.com with ESMTPSA id ei2sm100404554wjd.47.2017.01.04.13.57.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jan 2017 13:57:12 -0800 (PST) Subject: Re: multivariate statistics (v19) To: Dilip Kumar References: <5d1d62a6-6228-188c-e079-c1be59942168@2ndquadrant.com> <0ce73e37-7be4-8d9f-1ec4-46b0ca1d90c6@2ndquadrant.com> <1c7e4e63-769b-f8ce-f245-85ef4f59fcba@iki.fi> <9f7d5c73-71d6-fbe0-c190-b321db46f88c@iki.fi> <277d9678-7a35-a746-0eb5-41d4bcd4ef55@2ndquadrant.com> <61e71067-9461-d785-b4a6-6e8a08996d5f@2ndquadrant.com> <8508ad05-54b9-f402-e736-e992ea014a32@lab.ntt.co.jp> <72eeb3d5-c406-93b0-8ff8-11b31789f683@2ndquadrant.com> <7c4b2088-5cbd-dfec-0b98-16e5a7db5308@2ndquadrant.com> <696aa95c-2411-9b2b-f36e-65b66bf47c88@2ndquadrant.com> Cc: Amit Langote , Dean Rasheed , Heikki Linnakangas , Michael Paquier , Robert Haas , Tatsuo Ishii , David Steele , Tom Lane , =?UTF-8?Q?=c3=81lvaro_Herrera?= , Petr Jelinek , Jeff Janes , "pgsql-hackers@postgresql.org" From: Tomas Vondra Message-ID: <6f7ff2aa-b2b8-dbde-b39b-a9099f615466@2ndquadrant.com> Date: Wed, 4 Jan 2017 22:57:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; 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 01/04/2017 03:21 PM, Dilip Kumar wrote: > On Wed, Jan 4, 2017 at 8:05 AM, Tomas Vondra > wrote: >> Attached is v22 of the patch series, rebased to current master and fixing >> the reported bug. I haven't made any other changes - the issues reported by >> Petr are mostly minor, so I've decided to wait a bit more for (hopefully) >> other reviews. > > v22 fixes the problem, I reported. In my test, I observed that group > by estimation is much better with ndistinct stat. > > Here is one example: > > postgres=# explain analyze select p_brand, p_type, p_size from part > group by p_brand, p_type, p_size; > QUERY PLAN > ----------------------------------------------------------------------------------------------------------------------- > HashAggregate (cost=37992.00..38992.00 rows=100000 width=36) (actual > time=953.359..1011.302 rows=186607 loops=1) > Group Key: p_brand, p_type, p_size > -> Seq Scan on part (cost=0.00..30492.00 rows=1000000 width=36) > (actual time=0.013..163.672 rows=1000000 loops=1) > Planning time: 0.194 ms > Execution time: 1020.776 ms > (5 rows) > > postgres=# CREATE STATISTICS s2 WITH (ndistinct) on (p_brand, p_type, > p_size) from part; > CREATE STATISTICS > postgres=# analyze part; > ANALYZE > postgres=# explain analyze select p_brand, p_type, p_size from part > group by p_brand, p_type, p_size; > QUERY PLAN > ----------------------------------------------------------------------------------------------------------------------- > HashAggregate (cost=37992.00..39622.46 rows=163046 width=36) (actual > time=935.162..992.944 rows=186607 loops=1) > Group Key: p_brand, p_type, p_size > -> Seq Scan on part (cost=0.00..30492.00 rows=1000000 width=36) > (actual time=0.013..156.746 rows=1000000 loops=1) > Planning time: 0.308 ms > Execution time: 1001.889 ms > > In above example, > Without MVStat-> estimated: 100000 Actual: 186607 > With MVStat-> estimated: 163046 Actual: 186607 > Thanks. Those plans match my experiments with the TPC-H data set, although I've been playing with the smallest scale (1GB). It's not very difficult to make the estimation error arbitrary large, e.g. by using perfectly correlated (identical) columns. regard -- 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