Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lP6gJ-0002Jc-Ck for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Mar 2021 16:48:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lP6gI-0003gF-Ac for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Mar 2021 16:48:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lP6gI-0003g8-3m for pgsql-hackers@lists.postgresql.org; Wed, 24 Mar 2021 16:48:30 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lP6gE-0002NX-N4 for pgsql-hackers@postgresql.org; Wed, 24 Mar 2021 16:48:29 +0000 Received: by mail-ej1-x62a.google.com with SMTP id jy13so33989909ejc.2 for ; Wed, 24 Mar 2021 09:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=t7qdtv4ZSG0Yfu2XQyRr/ErZeaoNwsMTCOfx1xtjmT8=; b=q0znAFQ4CKPZ0BUCoy/25SOWOS82aPF2jMYoSi3WLCfZYA6jPcWpXEj18MJ8WU1hiu R+wRejccvvgVjhK2+/zg7eSka61ZQeMUU3NubQGc2516cVinunV8ntiXKfBhfgFfuARi tJEgMIl46DhJfkeIxBuROdlP9Kogp+y0vEyq2vT2NnW5Yh/HdIUnXfoFR8Yk8QoGQeIF CaPqWTsRRWvBvZuok4Jpvxw9EFicU7tK8nOooobLwWLVl2F/LKFftcUzCErjy7z8NYhy NjO//uyF86qF5v1JJSBmwMytZUbJMAmYx+GhlmnF6Jpu5YU2oLxeG0VGJCLzIac9Ut9e kWuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=t7qdtv4ZSG0Yfu2XQyRr/ErZeaoNwsMTCOfx1xtjmT8=; b=BdBhMI2yqLbgrp+ntTJLjEJ4W0gx7g6shp7thWx5c5+hdsYSaAao49kG3OdOQQ7At+ sYDRYP9PZvuKYiKSzzd+guGhk368ehuy5fnY/qyXtNLqMAF877OaoohcCsDq/09RfcG0 SdfjknhZz3mlcyDvsZIkqtEN3uI5TQq/5Nq2il594bGLIOjX7i0ZtfZ30SEIlkiCwNXz wKKInf2+5GE6jWIcv3gyG3rtb3J0w/KKEBIsPU666wcu88yOOVcXAQL2rYy6rpq44qCF 83GAuuxlmpy9GPKganu6TI8tVp8+QIqscE5C3nGkiC+E99P7cN7ugRbQiDgyikWKSIvz tSxw== X-Gm-Message-State: AOAM533uFqKsI/YDzAOO40qxXAq5K8a2Hb/i9kdmyLuekdE1JUqPepq0 IJvSfzhq/7anJmX0NIS3jVkcFS0DRoJ/mrNvRDxpiALUjSdS4BGvAxP7fSFLdJ/LIImdmPUTxev cigvahyPbHx4jPFLDREO0EctWsbT2CqiBohmpuVBYUHnxVtaF6YgPcweIp3F9mAsWixW2B8z3lW InqK0xpd6LoWdFAO+IrabRFbAshXHAU0AWqPBZ+sRj2QrUXSlst6iVycgElIMxExkBZ4FQwpFPQ o19ic9OaDMZ/uysQgZv3laym+YiWbAicI6L2A== X-Google-Smtp-Source: ABdhPJw5/rLDEvjBHfEUhdiCvqmxGDk3XSeyv3sHxf/gtsnY409ibdaDwTUyHbm7mA4MXJZjCgYpAQ== X-Received: by 2002:a17:907:d1b:: with SMTP id gn27mr4608671ejc.227.1616604504490; Wed, 24 Mar 2021 09:48:24 -0700 (PDT) Received: from [10.137.0.20] (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id z9sm1498395edr.75.2021.03.24.09.48.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Mar 2021 09:48:23 -0700 (PDT) Subject: Re: PoC/WIP: Extended statistics on expressions To: Dean Rasheed Cc: Justin Pryzby , PostgreSQL Hackers References: <9f6654b1-ca31-f979-0fe8-137683818273@enterprisedb.com> <20210324081402.GB28335@telsasoft.com> <20210324091708.GC28335@telsasoft.com> <1ff3fc47-8f6e-7839-c3ff-6b694956f92e@enterprisedb.com> From: Tomas Vondra Message-ID: Date: Wed, 24 Mar 2021 17:48:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/24/21 5:28 PM, Dean Rasheed wrote: > On Wed, 24 Mar 2021 at 14:48, Tomas Vondra > wrote: >> >> AFAIK the primary issue here is that the two places disagree. While >> estimate_num_groups does this >> >> varnos = pull_varnos(root, (Node *) varshere); >> if (bms_membership(varnos) == BMS_SINGLETON) >> { ... } >> >> the add_unique_group_expr does this >> >> varnos = pull_varnos(root, (Node *) groupexpr); >> >> That is, one looks at the group expression, while the other look at vars >> extracted from it by pull_var_clause(). Apparently for PlaceHolderVar >> this can differ, causing the crash. >> >> So we need to change one of those places - my fix tweaked the second >> place to also look at the vars, but maybe we should change the other >> place? Or maybe it's not the right fix for PlaceHolderVars ... >> > > I think that it doesn't make any difference which place is changed. > > This is a case of an expression with no stats. With your change, > you'll get a single GroupExprInfo containing a list of > VariableStatData's for each of it's Var's, whereas if you changed it > the other way, you'd get a separate GroupExprInfo for each Var. But I > think they'd both end up being treated the same by > estimate_multivariate_ndistinct(), since there wouldn't be any stats > matching the expression, only the individual Var's. Maybe changing the > first place would be the more bulletproof fix though. > Yeah, I think that's true. I'll do a bit more research / experiments. As for the changes proposed in the create_statistics, do we really want to use univariate / multivariate there? Yes, the terms are correct, but I'm not sure how many people looking at CREATE STATISTICS will understand them. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company