Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iTr5l-0007sz-Ol for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Nov 2019 17:33:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iTr5k-0002LZ-Hp for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Nov 2019 17:33:36 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iTr5k-0002LS-8x for pgsql-hackers@lists.postgresql.org; Sun, 10 Nov 2019 17:33:36 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iTr5h-0005DP-Cr for pgsql-hackers@postgresql.org; Sun, 10 Nov 2019 17:33:35 +0000 Received: by mail-lj1-x242.google.com with SMTP id 139so11282161ljf.1 for ; Sun, 10 Nov 2019 09:33:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=z/xvYc2JrgO5NLTuWQuYJ53me3JyeacFqjMfMQrsKXU=; b=IIyYHcVLahxXGcMhTGaOmKpBHueEC+ukiGukj+0Ef7TGicV8lU1v7SuXe0w0D2N6p3 jnqFgXstjnclCIUOW24EY1g9kgq7FhJ0XA1EOBWuZCQYjrQ59hS8jbb7NUC7Wo4zvw/z /Qi9Zy2fAjjR6A0eO9cO2MxRgJyNIYzmHbDy7SYSpjN8YWH0CqoYcb7xVAbW9S6rmoa8 pQzWsNpQOuprfFfXaAJS8JoQB4w6idqYE9+zgTg4BgC6yzNA/vUrmao9ttDgXJgWLURz vwMXgeOOaSo9vZjVKduiwF2mfw8Z1yBT1EB5yb4cvvQgdnIZoOundhC48g7g7ZlzT9s2 Gpbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=z/xvYc2JrgO5NLTuWQuYJ53me3JyeacFqjMfMQrsKXU=; b=BLQKGYdxUrsFPQcF6ddqT1fATSqBENUbEFYeInD0rHvO9OzyOGRd5oJr35BIZji59W qVb9yyRPbh/ce9M0vdtU+GvDDiYAh2hXzuvMv+se+5sTl8EArQjerJ6sN4M5RgW9aXea lkZ9NfKMxgzz9u+KRmWsRLKMEHdmVm3ws0Pb9CDa0/L4g3JqeMf47wqo0qKjvCPAHUjH 6zxgIsRJgxRXvS/b/CVumyndH9WK7qM/iuXwJ8TXtDBbtDo/5NjMkzLJhHs1fAipkqfm 9UOzSr28ILC94+f10Hjyj/waLE0qTjnVbIPGoeLsnNABqRfaT3gzjCkiXzwOGMYggzz4 2AvA== X-Gm-Message-State: APjAAAVHC9foqGAg1KI0cUhxvYWtvAQh/wDroCQBUs2PCOpV6Y5z+HNy AlFBqfPBIzNTISKyYM94PAJQLA== X-Google-Smtp-Source: APXvYqw0xDGaqWshS5xRNb6U45DgRrA5iSfzp5PJILESsn/C8+YBIRxrTcAMqxEHjgXPpBP+fLggRA== X-Received: by 2002:a2e:898a:: with SMTP id c10mr13178161lji.177.1573407212387; Sun, 10 Nov 2019 09:33:32 -0800 (PST) Received: from localhost ([217.8.174.100]) by smtp.gmail.com with ESMTPSA id y7sm2606764ljj.86.2019.11.10.09.33.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2019 09:33:31 -0800 (PST) Date: Sun, 10 Nov 2019 18:33:30 +0100 From: Tomas Vondra To: Mark Dilger Cc: PostgreSQL Hackers Subject: Re: Using multiple extended statistics for estimates Message-ID: <20191110173330.aki2dcpbwnraeo4x@development> References: <20191028152048.jc6pqv5hb7j77ocp@development> <20191106195440.wtxsyhiwdidl37hv@development> <20191106195849.odhhc66xd23hw6hf@development> <97932e1d-53f1-bad3-efc2-1d98cab70727@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <97932e1d-53f1-bad3-efc2-1d98cab70727@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Nov 09, 2019 at 12:33:05PM -0800, Mark Dilger wrote: > > >On 11/6/19 11:58 AM, Tomas Vondra wrote: >>On Wed, Nov 06, 2019 at 08:54:40PM +0100, Tomas Vondra wrote: >>>On Mon, Oct 28, 2019 at 04:20:48PM +0100, Tomas Vondra wrote: >>>>Hi, >>>> >>>>PostgreSQL 10 introduced extended statistics, allowing us to consider >>>>correlation between columns to improve estimates, and PostgreSQL 12 >>>>added support for MCV statistics. But we still had the limitation that >>>>we only allowed using a single extended statistics per relation, i.e. >>>>given a table with two extended stats >>>> >>>> CREATE TABLE t (a int, b int, c int, d int); >>>> CREATE STATISTICS s1 (mcv) ON a, b FROM t; >>>> CREATE STATISTICS s2 (mcv) ON c, d FROM t; >>>> >>>>and a query >>>> >>>> SELECT * FROM t WHERE a = 1 AND b = 1 AND c = 1 AND d = 1; >>>> >>>>we only ever used one of the statistics (and we considered them in a not >>>>particularly well determined order). >>>> >>>>This patch addresses this by using as many extended stats as possible, >>>>by adding a loop to statext_mcv_clauselist_selectivity(). In each step >>>>we pick the "best" applicable statistics (in the sense of covering the >>>>most attributes) and factor it into the oveall estimate. > >Tomas, > >Your patch compiles and passes the regression tests for me on debian >linux under master. > Thanks. >Since your patch does not include modified regression tests, I wrote a >test that I expected to improve under this new code, but running it >both before and after applying your patch, there is no change. Please >find the modified test attached. Am I wrong to expect some change in >this test's output? If so, can you provide a test example that works >differently under your patch? > Those queries are not improved by the patch, because we only support clauses "Var op Const" for now - your tests are using "Var op Var" so that doesn't work. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services