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 1ffZrM-0002ao-5l for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Jul 2018 23:58:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ffZrK-0000UM-Fn for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Jul 2018 23:58:22 +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.89) (envelope-from ) id 1ffZrK-0000UF-1P for pgsql-hackers@lists.postgresql.org; Tue, 17 Jul 2018 23:58:22 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ffZrG-0004RM-IB for pgsql-hackers@postgresql.org; Tue, 17 Jul 2018 23:58:20 +0000 Received: by mail-wr1-x441.google.com with SMTP id v14-v6so2825829wro.5 for ; Tue, 17 Jul 2018 16:58:18 -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=edOrtapXhzJ5bMRJ63DKnGnsfcR/Ncnt15Q4IVqq7QU=; b=jn5w+mz89s8XNTdVOrkFPvSEsOTeXnkGOghmJEls5zeGQ21aYZvMSshmSN28O4qi3H l/FKQEiaKnrmaw1P+PNa7mz0JNVfroXPPw2BV0rQH8PPbwExG66oXc+HCdkaQVyn4QFo VNNtNb7BQLqjGM9oTJGj1HU2CultkKlmLWWJnvwf9Qwl8bMbLaI8MPsq/2tpfE4/ioqu LQhCQw6jIglrmMmwjOOdZXeDANpbgMcOjOYtMmuzta1G/nqzMJDBWQ65Vc7wHZc8Nrec jsD3377K/pbUbw2gUoG16WDQO8pqFPtH86yyFCviU7FQzkAzXuN6AsimxOMjKPD+S0xp IpvQ== 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=edOrtapXhzJ5bMRJ63DKnGnsfcR/Ncnt15Q4IVqq7QU=; b=mD15948IewCTyCFuiraDJXupJAtPJiZ488iZhyELGKlJal8KhOGtstcqiA5TZzOYVq 4kGNEMFRDsh0gSCuyyzw/YAWabit8LufpN66+sJaPbPgD0zQWRGZ6I35c1BH6+UXConH LMlou/btzlqbHdFFuUn8tsrx3RTqwTmAx0MjV5+5GyrZUSOhjt8bAQqnR1lxFsSt0DIb 3WS9VicAyNt57mVx1HWv93c6FeMFC+tlnJMpmJxqh2zb1ooDrmK/ASOzbvjqZ1eiryWA jQsvsCwgMMF0CpUw2aEm9wkpzz4StN+6aZ19zbOJT8CSKWO4cLZ7RP8lniXmxpSFoAne cv2w== X-Gm-Message-State: AOUpUlEX4pzlfpTQn8ld9jF7twWPVdfjAVzgimHc4i1ZObGTzq5DaWVW 0z2G6CVZn8QEDvz8SOuRDuS5LA5LQ6/wKj3BAVijoLsqJuQ90rvO6C1jRczzEEZPldabNfo6VtQ EW5nuBY4zdIAZ5CC22or2nMqprrnjMhRyCDrDrsEJQzg5eoamiE9tirn6HWUO9TbiDYa3JO9WRC rfixH3wmr5 X-Google-Smtp-Source: AAOMgpdNU82MjJxDNKVMn7XVAUsAJHRkfP0FLqWAxpEatVoLATUIFwPXWH6xuZLzTzstD+Cz7lbMHg== X-Received: by 2002:adf:88e3:: with SMTP id g32-v6mr2560052wrg.62.1531871895195; Tue, 17 Jul 2018 16:58:15 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id r125-v6sm1729974wmb.27.2018.07.17.16.58.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 16:58:09 -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: Date: Wed, 18 Jul 2018 01:58:06 +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 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 ... >  postgres=# explain analyze SELECT count(*) FROM foo WHERE a=1 and (b=1 > or b=2); > QUERY PLAN > > -------------------------------------------------------------------------------------------------------------------------------------------- > >  Aggregate  (cost=10964.76..10964.77 rows=1 width=8) (actual > time=49.251..49.251 rows=1 loops=1) >    ->  Bitmap Heap Scan on foo  (cost=513.60..10906.48 rows=23310 > width=0) (actual time=17.368..39.928 rows=90000 loops=1) ok, 23k vs. 90k > > If we add statistic for a and b  columns: > >      create statistics ab on a,b from foo; >      analyze foo; > > then expected results is about 30% larger then real: 120k vs 90k: > Eh? The plan however says 9k vs. 30k ... >                ->  Parallel Bitmap Heap Scan on foo > (cost=2561.33..13424.24 rows=9063 width=0) (actual time=15.551..26.057 > rows=30000 loops=3) ... > With compound index statistic estimation is almost equal to real value: > >    ->  Bitmap Heap Scan on foo  (cost=1880.20..13411.66 rows=23310 > width=0) (actual time=38.776..61.050 rows=90000 loops=1) Well, this says 23k vs. 90k. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services