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 1lP4nr-000665-G6 for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Mar 2021 14:48:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lP4nq-0003Ma-DH for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Mar 2021 14:48:10 +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 1lP4nq-0003MM-35 for pgsql-hackers@lists.postgresql.org; Wed, 24 Mar 2021 14:48:10 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lP4ni-0001Qi-7F for pgsql-hackers@postgresql.org; Wed, 24 Mar 2021 14:48:09 +0000 Received: by mail-ej1-x62d.google.com with SMTP id u9so33324021ejj.7 for ; Wed, 24 Mar 2021 07:48:01 -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=lxf8Bjygh8GP5tmKI3eWysVl/nvbTd+gknEQ9QUMpK8=; b=0JEtqKdC9wFJhlcFPcjR/uqnaoMHltpyOjC6i+lhYTdFWQV/XAqWrbqp6tIPprxvQu Io/YF2jDUWga8Wjvd3UB6c9/zREE66Hh1U1zd2VnTM+QAwcClT+I7wbWvl8azdedE5lt g43UXPe79OMckXIQz4gS9qHSLUri+sAK6z46I1oNGI58DM7C4bvCcC9n3AuggNYXCx3j Iw+ZKhV3iqyPRSF9aMjWdftebs6DE/NA168I0kmbidkZM/HMzNrXLIf0x8TDe+2vJjCL s99bEzgBeSsWR4hsXUY9jLjJCNkZ7paGWiaXAV3H6LQE69aythSEBw5RhLGxhA6gVTep +gOw== 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=lxf8Bjygh8GP5tmKI3eWysVl/nvbTd+gknEQ9QUMpK8=; b=NLrxc33KlReGbQdxoMwk2gTh+NU40/1kqEKhEWu6oaykf1z5QraZ7GUOuAIGXKPtU6 K2iLbJHsDimJCuyUw8hXvp1lgRhvMsjL6Fj3+LN2YErJQ7TWsNzJ7lsQZmIQJAvirlhg QY29GSjzOc7OJELO0FYJ1IDaWMJGZxckoS3ia495u21+BD8U2cuPGG5msL+Czo6Nn2HQ ZPqxgwCSGVB0adpZOiio1Xj1H1JKosSmhdcYgAm2ytqnLQTFsxcmdZpzuLR9/IZrTiDt TBAAHIwcfZoKVMaBjy8MH196HQcRh94H35bhBXYPjBKShbaVOJHe9i9IqZ8RnbPbpH71 cDoQ== X-Gm-Message-State: AOAM532lVtE98vyzryR30U8EWwxary4spPT/JK2qIswGtvKugH6YFFe/ fgpgU5jvnK4tcBjM9ntQbZzsZiwwyyUmsq3Y3ndHjo1KIaEOpBLWjqeJv5hzRe6HD/dZwtTYnEi KnrAUrIQLBQjOTTK4hnVwGlqY0Zx/csyqSB3dle7GBvhmVZgPkodLFpdZGiGmObyLJYvd40VW0D IXOafzVPeeKXPX9ob8Ob7DPVoYy7ijzeutwax+e4eOUT4n4OmxJIg6TW4aECObFzlDwDZ2b2jgo 02yGcWNgSv/miFEta41lOT16Xri27YAOLslxQ== X-Google-Smtp-Source: ABdhPJzxClIAJPsgrL6eB9BxSmgQ4Y3NNGWlv6W6gczM1Awj9tC8BDIOjv6TdW/iNlQBKjeA+7Wn3A== X-Received: by 2002:a17:906:f0c8:: with SMTP id dk8mr4161972ejb.300.1616597280540; Wed, 24 Mar 2021 07:48:00 -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 hy25sm1029043ejc.119.2021.03.24.07.47.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Mar 2021 07:47:59 -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 15:47:54 +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 2:36 PM, Dean Rasheed wrote: > On Wed, 24 Mar 2021 at 10:22, Tomas Vondra > wrote: >> >> Thanks, it seems to be some thinko in handling in PlaceHolderVars, which >> seem to break the code's assumptions about varnos. This fixes it for me, >> but I need to look at it more closely. >> > > I think that makes sense. > 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 ... > Reviewing the docs, I noticed a couple of omissions, and had a few > other suggestions (attached). > Thanks! I'll include that in the next version of the patch. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company