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 1rMcap-005Vlm-3u for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Jan 2024 23:30: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 1rMcZp-000lRo-Ew for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Jan 2024 23:29:09 +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 1rMcZo-000lRg-Vj for pgsql-hackers@lists.postgresql.org; Sun, 07 Jan 2024 23:29:09 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMcZl-000ON0-5d for pgsql-hackers@postgresql.org; Sun, 07 Jan 2024 23:29:06 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40e47dc8b0eso1673905e9.3 for ; Sun, 07 Jan 2024 15:29:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1704670142; x=1705274942; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=1w+YJD7G7VrOuRg+AO0C+moFIv+9XiOwtgbKmr0Fzc0=; b=bubYFAQaZT+1i6ofclJKMfcYwkzolCbh2BjPvdphGooj0zI849m0gEEpho9MDK1ynq 7YdEKpEHDaVUxRa3kbXa4YOx2medl3RIZKCD2WzhPxOxwGzEWmy8QlGdpIxFomv1FM3X FEEskagllOAlBldub9hcT7NiEX4nRM58+KDV9HxtqCeMiPSBj4FtwoDLIvl+4su9jtld +i9T8KW79Dx4Fvww7hB48nvo7Nu3uu9lpqlqSmUUIinNdSPwGqgErlHEkty+QnVbOk2I IkTtPn6VPfI7II86IkeKOmRtvtoIfAGdX5XnbEmq62AqUh2vmgn0C+7sDbqUwAqPy8Ah d8PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704670142; x=1705274942; h=content-transfer-encoding:in-reply-to:from:references:cc: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=1w+YJD7G7VrOuRg+AO0C+moFIv+9XiOwtgbKmr0Fzc0=; b=U3MFXfZnM7WLTL4GzZaTb5jeCxF5DQfyb3bD52NBpqkd2cF1wdxE3w1Nv/QXnK7Pf0 rhSoHCvR0A87svZ1C8iwkQfNIAaeK9mH5lYwLImlEcEjGrvYZRwhU04Totpcwdt16FfL rvMekrK1r5fdBJSGPUo/8J54UV2U1oGuYyaEn7nulAK4/vggxvW+aMz25v2fxM62ihIv 17xRwua/cUwlxY8f4zy5K4cvjCaEEJTMtm+Fax775VVozAJuCuBElnUWBb7LgAbu3ymY WbXCycWFf/xkh/eI0QzmehDwcduqhQ64QUft4ZG9lmhFKw6ki0xbesyxburzu5UcCh7y wCKQ== X-Gm-Message-State: AOJu0Yw5ByCeghcx360lreVAE/X36IvBirsc/mIcz4xzXLq2zohN2YLz UZvVm9H69vTSSCBNDoz8UOjI4hwD/Qpc X-Google-Smtp-Source: AGHT+IE1wLXivWw/Ad7VWE5Lz2f2QdJLVonvoxluHKIEVg6aVzPJU438XUdjL84Rz1Vgg2yqKp+0DQ== X-Received: by 2002:a5d:4309:0:b0:337:5bf0:d92f with SMTP id h9-20020a5d4309000000b003375bf0d92fmr1275199wrq.73.1704670142395; Sun, 07 Jan 2024 15:29:02 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id df18-20020a5d5b92000000b00336a1f6ce7csm6275077wrb.19.2024.01.07.15.29.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 07 Jan 2024 15:29:02 -0800 (PST) Message-ID: <61d1e6b0-914e-4aa3-8a32-ff2cf9e91100@enterprisedb.com> Date: Mon, 8 Jan 2024 00:29:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Multidimensional Histograms Content-Language: en-US To: Alexander Cheshev Cc: pgsql-hackers@postgresql.org References: <6e92450c-8136-11d4-8f6e-501c693af5c8@enterprisedb.com> 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 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