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 1rMctT-005XED-TD for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Jan 2024 23:49:28 +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 1rMctS-000qyL-Nl for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Jan 2024 23:49:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMctS-000qyD-Dh for pgsql-hackers@lists.postgresql.org; Sun, 07 Jan 2024 23:49:26 +0000 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMctP-000OVd-Hc for pgsql-hackers@postgresql.org; Sun, 07 Jan 2024 23:49:24 +0000 Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-67f9fac086bso14277396d6.3 for ; Sun, 07 Jan 2024 15:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704671362; x=1705276162; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0iVNDhKEE/e7E/S/vAuDpRe5eVkdnybp2ktceW/7lJQ=; b=naj09ooyP5nQ+yNte3wjJRXlO+MYWA4/IVCs4jiYcCRZz/UHxUiqfe5LOGttKlPXo7 vSD9oxuSibl2v6U8HzNxbusOy6ktNoWf3c5WrXmhmA+8KQmZ3Opdp1ft2ks4zjiLM/XW 3HneYmcnfMkx253qhU5dpecECNvSgtX5sl5EvTX0gGIiP32yIA5o8CphR0lmhKnSnwHq WvSxmW6ET469dtGW456Vq+BarIkhb6q+CnNOTS/GUoZg52E+z5LwAUlqSsrysdhnUoZh eIGfD8/oWVmQPxGceRwBqeYknZU1+7lq1okoBkOqlKQx2OyvTYZs6+7LYPPzfUcsfhrr iV0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704671362; x=1705276162; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0iVNDhKEE/e7E/S/vAuDpRe5eVkdnybp2ktceW/7lJQ=; b=lQflcOvoK4r4L+pxITBLoc0OTW2eudDlWhx1x4mnruC9PtwN1Pzy5Gv3A2hdcNu99G z4UIB6JMW/Lr2zjYTPyCUm2QY7qwzwRBeoL8PjblGxDr4C+zeW5ZGpB9iK0iczaeAdiR RL3iVZ/cy8SHZDtCHN0YsUIZTD8GMLh6tsRo5IcF7qBtslT19wtuvzrKsQAJQgUkbMYb 5RG4yn7MiPV3CPVY+/Gjo3fjnKwUGyTw2+szkyZcGEGc3Z/PDai0euAFPFnfwqHZTXJk YZW0jvLZz30h/VzGlDY3YviIRj19oN1n4s+IS0ZDEU+hmYUvV/uDZc1kQR6cyJGrhisA TFQA== X-Gm-Message-State: AOJu0YxiwrX8Lgn8+2JRZVkSNmAPhdgZFDnsakcFNjBPj0AVKHn1/RjL DwSGXLbHTMDpSLAFqLIvymygKH11HoXALdTf2jg= X-Google-Smtp-Source: AGHT+IFkUFVI9+I1gXudSJ5jjSsgySqANz/ndOvDq66xLeaKvX/3ylqDw4XCJMVRAi2ejcPQV3r2vxJE1uWJGWsCYLo= X-Received: by 2002:ad4:5f0f:0:b0:67f:9aa6:e9c1 with SMTP id fo15-20020ad45f0f000000b0067f9aa6e9c1mr4399257qvb.127.1704671362566; Sun, 07 Jan 2024 15:49:22 -0800 (PST) MIME-Version: 1.0 References: <6e92450c-8136-11d4-8f6e-501c693af5c8@enterprisedb.com> <61d1e6b0-914e-4aa3-8a32-ff2cf9e91100@enterprisedb.com> In-Reply-To: <61d1e6b0-914e-4aa3-8a32-ff2cf9e91100@enterprisedb.com> From: Alexander Cheshev Date: Mon, 8 Jan 2024 00:49:11 +0100 Message-ID: Subject: Re: Multidimensional Histograms To: Tomas Vondra Cc: pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Tomas, > See section 3.2 in this paper (the "view PDF" does not work for me, but > the "source PDF" does download a postscript): I believe that you are referring to a dynamic programming approach. It is a 1-dimensional case! To find an optimal solution in the M-dimensional case is an NP-hard problem. Regards, Alexander Cheshev On Mon, 8 Jan 2024 at 00:29, Tomas Vondra wrote: > > > > On 1/7/24 23:53, Alexander Cheshev wrote: > > Hi Tomas, > > > >> The thing I was proposing is that it should be possible to build > >> histograms with bins adapted to density in the given region. With > >> smaller buckets in areas with high density. So that queries intersect > >> with fewer buckets in low-density parts of the histogram. > > > > This is how Equi-Depth Histogram works. Postgres has maller buckets in > > areas with high density: > > > > values[(i * (nvals - 1)) / (num_hist - 1)] > > > True, but the boundaries are somewhat random. Also, I was referring to > the multi-dimensional case, it wasn't clear to me if the proposal is to > do the same thing. > > >> I don't recall the details of the MHIST-2 scheme, but it's true > >> calculating "perfect" V-optimal histogram would be quadratic O(N^2*B). > > > > In M-dimensional space "perfect" V-Optimal Histogram is an NP-hard > > problem. In other words it is not possible to build it in polynomial > > time. How did you come up with the estimate?! > > > See section 3.2 in this paper (the "view PDF" does not work for me, but > the "source PDF" does download a postscript): > > https://citeseerx.ist.psu.edu/doc_view/pid/35e29cbc2bfe6662653bdae1fb89c091e2ece560 > > >> But that's exactly why greedy/approximate algorithms exist. Yes, it's > >> not going to produce the optimal V-optimal histogram, but so what? > > > > Greedy/approximate algorithm has time complexity O(M*N*B), where M > > equals the number of dimensions. MHIST-2 is a greedy/approximate > > algorithm. > > > >> And how does this compare to the approximate/greedy algorithms, both in > >> terms of construction time and accuracy? > > > > Time complexity of Equi-Depth Histogram has no dependence on B. > > > Really? I'd expect that to build B buckets, the algorithm repeat some > O(M*N) action B-times, roughly. I mean, it needs to pick a dimension by > which to split, then do some calculation on the N tuples, etc. > > Maybe I'm imagining that wrong, though. It's been ages since I looked ad > big-O complexity and/or the histograms. I'd have to play with those > algorithms for a bit again. > > > regards > > -- > Tomas Vondra > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company