Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fzUQL-0002wV-9m for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Sep 2018 22:12:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fzUQJ-0003tH-KN for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Sep 2018 22:12:47 +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.89) (envelope-from ) id 1fzUQJ-0003tA-99 for pgsql-hackers@lists.postgresql.org; Mon, 10 Sep 2018 22:12:47 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fzUQE-0005VE-F6 for pgsql-hackers@postgresql.org; Mon, 10 Sep 2018 22:12:46 +0000 Received: by mail-wm0-x244.google.com with SMTP id b19-v6so23103112wme.3 for ; Mon, 10 Sep 2018 15:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=VL1KeN/FN/ysrBKhSVGs/aA/wYSO7LXkfj6qIffhSeU=; b=wW0J0oVBtFgsXoXHQ3/kRbotQjL5y9Pa6LoIer+HD4Xp7NnuezZBPSfo2jGEoKbRYL ztvJH6ruqXZHcjHs1+W+LK7t0WSGYedsvSA0Qqi8miNPYVd3EFvvSIicXF0P2YRc97J5 oZVNjwXk3PfW7CKF+aoxSLM0Ib7fbTwd4lxrfOMnT3IHTomgDFjuRhGjj0+LpyFS7kKz 8y8LGABEgu9nvF1Y01beg2ApWwEDcehVh8GSnHUTX9QQgNl/6xX/DwBXbG47nbFuLUje R/6VR2ka1rZBDWuEl5pkoqK3dypASY0ezQjbN6xobA554RZwdUlaTLCeci2f0C86HtsS zzvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=VL1KeN/FN/ysrBKhSVGs/aA/wYSO7LXkfj6qIffhSeU=; b=djnCz7N5ekiFngwKdlJZHECYuBapkN94ZTHnhLLXeAoQAMyrc+T5gF4NJrZcXtPt2f TnAY0kJXl/BirsIpQcWbdpIgYqXFyx0cMzYKA1GpVaKYAw4dowxn+DdKF0T+R6/+C6FB lxpXYCssHB/7H0A+vpH+LSWkn+RvSlIP0MHhGSW+B+4Zmz1WrfEaYMPf4OQ/cIT8qRxE aORpe/yZE1D3i6aCiT2ELarR6SAcNzCVVSqk/2GLx6kYv6U6z8AvMjZlwJcbRQ0MS2GO bgeg5/WCirdT9BxCtZJkT4FIyFBUZ0rtdJ4aVg+XkGraH5AYULn+01KyEb6XSbSKKto+ RICw== X-Gm-Message-State: APzg51AzwtcsUEdITWKGRLV3okS4HgLt3kCzqiUQa8AsFT4MSi0hXrHn lbWch85PDjnnyHvxXUOOMnqLRkYA/R9gakU74ycl79a+VEq0S0cnQ2zK+ypqAuuB3RnTWAcfrku UgI40gEjjbkTRFL1gTKcA6aCwZ8fuHJzQeF9YqWFHeLu2czNSWFHlyGaYJXL/0T6yMVXWateiUU QRey0Wo61T98o= X-Google-Smtp-Source: ANB0VdY5ovm4EYUnTt1rGO6plyEaJZbgv7XUr3gVAIrXIyrgwfnPR5yofZjuXAToduwbOfHxMHMUcw== X-Received: by 2002:a1c:b6d6:: with SMTP id g205-v6mr1951858wmf.17.1536617558964; Mon, 10 Sep 2018 15:12:38 -0700 (PDT) Received: from [10.137.2.19] (ip-86-49-246-165.net.upcbroadband.cz. [86.49.246.165]) by smtp.gmail.com with ESMTPSA id n11-v6sm18475669wra.26.2018.09.10.15.12.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 15:12:37 -0700 (PDT) Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists To: Konstantin Knizhnik , Dean Rasheed Cc: Bruce Momjian , Alvaro Herrera , Andres Freund , Thomas Munro , Mark Dilger , Adrien Nayrat , Pg Hackers References: <49348328-1a02-7e45-e50f-e1d4d0243c5c@2ndquadrant.com> <7d12b5d1-ac77-67e3-c67e-7fcbd3753e9c@2ndquadrant.com> <20180407141201.GA10394@momjian.us> <4416a567-4452-c5fd-7117-5cc7827b5fad@2ndquadrant.com> <80bc98b2-1c43-1fe8-b316-d447bb68cff2@2ndquadrant.com> From: Tomas Vondra Message-ID: <3fcfd5e5-6849-34e6-22ab-1b62d191bedb@2ndquadrant.com> Date: Tue, 11 Sep 2018 00:12:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 07/18/2018 09:32 AM, Konstantin Knizhnik wrote: > > > On 18.07.2018 02:58, Tomas Vondra wrote: >> On 07/18/2018 12:41 AM, Konstantin Knizhnik wrote: >>> ... >>> >>> Teodor Sigaev has proposed an alternative approach for calculating >>> selectivity of multicolumn join or compound index search. >>> Usually DBA creates compound indexes which can be used  by optimizer to >>> build efficient query execution plan based on index search. >>> We can stores statistic for compound keys of such indexes and (as it is >>> done now for functional indexes) and use it to estimate selectivity >>> of clauses. I have implemented this idea and will publish patch in >>> separate thread soon. >>> Now I just want to share some results for the Tomas examples. >>> >>> So for Vanilla Postges without extra statistic  estimated number of rows >>> is about 4 times smaller than real. >>> >> Can you please post plans with parallelism disabled, and perhaps without >> the aggregate? Both makes reading the plans unnecessarily difficult ... > > > Sorry, below are plans with disabled parallel execution on simpler > query(a=1 and b=1): > > explain analyze SELECT count(*) FROM foo WHERE a=1 and b=1; > > > > Vanilla: > >  Aggregate  (cost=11035.86..11035.87 rows=1 width=8) (actual > time=22.746..22.746 rows=1 loops=1) >    ->  Bitmap Heap Scan on foo  (cost=291.35..11001.97 rows=13553 > width=0) (actual time=9.055..18.711 rows=50000 loops=1) >          Recheck Cond: ((a = 1) AND (b = 1)) >          Heap Blocks: exact=222 >          ->  Bitmap Index Scan on foo_a_b_idx  (cost=0.00..287.96 > rows=13553 width=0) (actual time=9.005..9.005 rows=50000 loops=1) >                Index Cond: ((a = 1) AND (b = 1)) > > > ---------------------------------------------------------------------- > > Vanilla + extra statistic (create statistics ab on a,b from foo): > >  Aggregate  (cost=12693.35..12693.36 rows=1 width=8) (actual > time=22.747..22.748 rows=1 loops=1) >    ->  Bitmap Heap Scan on foo  (cost=1490.08..12518.31 rows=70015 > width=0) (actual time=9.399..18.636 rows=50000 loops=1) >          Recheck Cond: ((a = 1) AND (b = 1)) >          Heap Blocks: exact=222 >          ->  Bitmap Index Scan on foo_a_b_idx (cost=0.00..1472.58 > rows=70015 width=0) (actual time=9.341..9.341 rows=50000 loops=1) >                Index Cond: ((a = 1) AND (b = 1)) > > ---------------------------------------------------------------------- > > Multicolumn index statistic: > >  Aggregate  (cost=11946.35..11946.36 rows=1 width=8) (actual > time=25.117..25.117 rows=1 loops=1) >    ->  Bitmap Heap Scan on foo  (cost=1080.47..11819.51 rows=50736 > width=0) (actual time=11.568..21.362 rows=50000 loops=1) >          Recheck Cond: ((a = 1) AND (b = 1)) >          Heap Blocks: exact=222 >          ->  Bitmap Index Scan on foo_a_b_idx (cost=0.00..1067.79 > rows=50736 width=0) (actual time=11.300..11.300 rows=50000 loops=1) >                Index Cond: ((a = 1) AND (b = 1)) > I wonder what happened to this alternative approach, relying on stats from multicolumn indexes ... -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services