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 1iTr6l-0007uc-IN for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Nov 2019 17:34:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iTr6j-0004LV-SO for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Nov 2019 17:34:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iTr6j-0004LO-G8 for pgsql-hackers@lists.postgresql.org; Sun, 10 Nov 2019 17:34:37 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iTr6g-00069U-KY for pgsql-hackers@postgresql.org; Sun, 10 Nov 2019 17:34:35 +0000 Received: by mail-lf1-x143.google.com with SMTP id m6so8082794lfl.3 for ; Sun, 10 Nov 2019 09:34:34 -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=VRsN0LRQFIDTEP8iPkWiwPPu0LUyHCPkfaKWKv4KnSk=; b=tLHGehuPHfA13xY6J8AyBgCjzxi2sWlW+hU7VdwAqqZ06shc78/1Ii4KpA/3IBYOnj swdZwh+bOQxjXrFkIJ2X+anK7ZIatMfISI/KdEw9aGWejvOMkfdOukffPwPb6DUlhvpV eXVLGioxnASx49G+M5yObd2WoRmf4pOoQKLfx98RXL3C8GaE/Ogk4AHI/nN/vqqKG/Oa k8sn1tc+qZUd9iHlLRu+X9oH8e55cOeEjkdc0JMPEj82FolII+ABC9ulWyOZRneGSsUv A3h5ZfOvrmAVBopFhFg1gZVy3vdwlBbUyK/LEKwpYeowqfrk9vqQty4gVNwXXq3OI1IV OpsA== 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=VRsN0LRQFIDTEP8iPkWiwPPu0LUyHCPkfaKWKv4KnSk=; b=MTWeppB46WPnX0K3FC5bvleaRfTB208QK+mwwq0w+B7yk4/f8DZvTdTjpj+5mg5BFp mUkePDI8XyZULOJzZhrjTtkhmfsXVp7N6Hm+QyMIJJqg/8kgLmVO0/dZt1kfpL5u4lZD b8lR1fYcjYzn4naBMO89jfez/dn0eWUgG+o/x0IA01mdvNFmgZpSzmNrecWKMlf3tbQ9 wqw8YJ5a/5a/U/9kIB967tILGNmDdIea1W/X2PMm1amTCVnE7ssb6Z8flCcosLy45aHW m534GJZwBAj2xWerAAiUzulsmcV9K/FWIlZRLqODsADn4vdy6yZF1DvBGFroz4Hn+M9e fMOQ== X-Gm-Message-State: APjAAAVi2wMmcFtUKvM6Is7r0hQP62/6egG41n/A0VHDA1OAAq/Vfkcm tfGOOTaGvv4sRbwZXdjGv0C6Cg== X-Google-Smtp-Source: APXvYqxDxcG1gBwImE9gGSf9/D1UJ/NR+18e44GFrxy1xnQtrA8IcQeQnYGQypH+dPIc6P5MD5MxNQ== X-Received: by 2002:ac2:5a11:: with SMTP id q17mr8863000lfn.41.1573407273017; Sun, 10 Nov 2019 09:34:33 -0800 (PST) Received: from localhost ([217.8.174.100]) by smtp.gmail.com with ESMTPSA id t7sm5657738ljg.59.2019.11.10.09.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2019 09:34:30 -0800 (PST) Date: Sun, 10 Nov 2019 18:34:28 +0100 From: Tomas Vondra To: Mark Dilger Cc: PostgreSQL Hackers Subject: Re: Using multiple extended statistics for estimates Message-ID: <20191110173428.w5klequcmb6gawaa@development> References: <20191028152048.jc6pqv5hb7j77ocp@development> <20191106195440.wtxsyhiwdidl37hv@development> <20191106195849.odhhc66xd23hw6hf@development> <97932e1d-53f1-bad3-efc2-1d98cab70727@gmail.com> <0da76f1f-5f9c-3ce3-3ac6-042d2a18430a@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: <0da76f1f-5f9c-3ce3-3ac6-042d2a18430a@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Nov 09, 2019 at 02:32:27PM -0800, Mark Dilger wrote: > > >On 11/9/19 12:33 PM, 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. >> >>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. > >Ok, the attached test passes before applying your patch and fails >afterward owing to the estimates improving and no longer matching the >expected output. To be clear, this confirms your patch working as >expected. > >I haven't seen any crashes in several hours of running different >tests, so I think it looks good. > Yep, thanks for adding the tests. I'll include them into the patch. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services