Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rIbKx-009ggR-Ao for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2023 21:21:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rIbJx-009bla-DN for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2023 21:20:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rIbJx-009blA-2d for pgsql-hackers@lists.postgresql.org; Wed, 27 Dec 2023 21:20:09 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rIbJp-00ECXg-80 for pgsql-hackers@postgresql.org; Wed, 27 Dec 2023 21:20:07 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-50e7d6565b5so2271650e87.0 for ; Wed, 27 Dec 2023 13:20:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1703711999; x=1704316799; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=IR4LH7vE0dtDYxCDOJXuJM9MivKZcgJhV9BB/HajstM=; b=bycEbkWtP16jEhCgldAOEC67Z6ZOLiXco05goaTy5Ji9JM/rKGR9Vc3beMgzGVVFvy psMMWrGRgNrVgprtHZ8A/24DwAKVw+b5Zn0vWQjqwmy7T/Myrid0d0N1s1HuH5rM1Y9P 69YAF2fG1AFf2DIyY972iRH+pMOQuYMF4nyGlGNY74is/lJNdy8C0hCPNMETpTCqsqQK Q8Xgzd0kZOvtwwqy+KlbGYmwl2eYPGteEw2CDbMVOy7f5/10Kn7UWWLBz7ubrHxPCK0f 51sYijAClKLJxeC+vTy+phtqV7eVI5aWcFDy+HqLm1unjqfUJ0XG0QgrOIXN+visk8le 9MHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703711999; x=1704316799; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IR4LH7vE0dtDYxCDOJXuJM9MivKZcgJhV9BB/HajstM=; b=KrY8y38TXgSnoImzj56X7xbok5LkacFDsBpvEyXIzCnq37unugytMdNpJP0Ae1xbzV am5dtixipC5IKfhElIItY3U9lYEXbAnx9tqxw4KWaWrUGfPYpO9Rh7y+W4LRECMDZp0p x3r7b6yVd6PBWoP9yUFcgoXSojSI85pznhiJwlD3m7ovZqpLHZFlyYd1p8+qO56ktBOQ n401qtdFqQ4osCBcoWYdZ2qdEpUsAhyRhQyhhWFlZqEHiIhIDS70FMe4khCxsTlFpM7T 23a33U3PPjgYBbCnFf64GCEPanDY4pOyHR/IMrxdhugvZJObEXBv/Ie+yvGxxYGwTlvO CdHg== X-Gm-Message-State: AOJu0Yy/pchJTP2afZwEwXKaKSErxfqnsA2ajekrf6lqI9DHM/QrnTHw TwD3xwI/IKp+Z0ZybGUpSDDn/p5tTlt+ X-Google-Smtp-Source: AGHT+IGkPcDLigvT41pJr/8X1SvBHkZ8gZnlQxeJA3KNm9mWn3/fqRtov5hewGQZF743oTH3PHirzw== X-Received: by 2002:a05:6512:2395:b0:50e:74ea:525c with SMTP id c21-20020a056512239500b0050e74ea525cmr3539262lfv.3.1703711999018; Wed, 27 Dec 2023 13:19:59 -0800 (PST) Received: from [10.137.0.17] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id g6-20020a056402320600b0055410f0d709sm8853839eda.19.2023.12.27.13.19.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Dec 2023 13:19:58 -0800 (PST) Message-ID: <6e92450c-8136-11d4-8f6e-501c693af5c8@enterprisedb.com> Date: Wed, 27 Dec 2023 22:19:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Multidimensional Histograms Content-Language: en-US To: Alexander Cheshev , pgsql-hackers@postgresql.org References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Alexander, We actually had histograms in the early patches adding multivariate statistics [1]. We however ended up removing histograms and only kept the simpler types, for a couple reasons. It might be worth going through the discussion - I'm sure one of the reasons was we needed to limit the scope of the patch, and histograms were much more complex and possibly less useful compared to the other statistics types. Another reason was that the algorithm described in the two papers you reference (1988 paper by DeWitt and the evaluation by Carlson and Sutherland from ~2010) is simple but has pretty obvious weaknesses. It processes the columns one by one - first build bucket on column "a", then splits each bucket into buckets on "b". So it's not symmetrical, and it results in lower accuracy compared to an "ideal" histogram with the same number of buckets (especially for the dimensions split early). This does indeed produce an equi-depth histogram, which seems nice, but the mesh is regular in such a way that any value of the first dimension intersects all buckets on the second dimension. So for example with a histogram of 100x100 buckets on [a,b], any value "a=X" intersects with 100 buckets on "b", each representing 1/10000 of tuples. But we don't know how the tuples are distributed in the tuple - so we end up using 0.5 of the bucket as unbiased estimate, but that can easily add-up in the wrong dimension. However, this is not the only way to build an equi-depth histogram, there are ways to make it more symmetrical. Also, it's not clear equi-depth histograms are ideal with multiple columns. There are papers proposing various other types of histograms (using different criteria to build buckets optimizing a different metric). The most interesting one seems to be V-Optimal histograms - see for example papers [1], [2], [3], [4], [5] and [6]. I'm sure there are more. The drawback of course is that it's more expensive to build such histograms. IIRC the patch tried to do something like V-optimal histograms, but using a greedy algorithm and not the exhaustive stuff described in the various papers. [1] https://www.vldb.org/conf/1998/p275.pdf [2] https://cs-people.bu.edu/mathan/reading-groups/papers-classics/histograms.pdf [3] https://dl.acm.org/doi/pdf/10.1145/304182.304200 [4] http://www.cs.columbia.edu/~gravano/Papers/2001/sigmod01b.pdf [5] https://cs.gmu.edu/~carlotta/publications/vldb090.pdf [6] https://core.ac.uk/download/pdf/82158702.pdf regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company