Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUstg-0005oK-4Y for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Nov 2019 13:41:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iUste-0002X7-NW for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Nov 2019 13:41:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUste-0002X0-CX for pgsql-bugs@lists.postgresql.org; Wed, 13 Nov 2019 13:41:22 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iUstb-00088s-8T for pgsql-bugs@lists.postgresql.org; Wed, 13 Nov 2019 13:41:21 +0000 Received: by mail-wr1-x443.google.com with SMTP id z10so2382324wrs.12 for ; Wed, 13 Nov 2019 05:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=BoyKgfY0G466liIalIla0NzR25Ab4OLb+k+yP1q2yAE=; b=P4KXeEjUSLy5G51zH5FSox9iU4BxqSsr7aVyGwcQX6d9K4vmHGVtJPYuk/YQi1vSeB CB05V/I8j/tuND7KGItL0Jo170E/bu3VrZqrSil9SwEJCQ2PzS1sw4O5MyKZylgfyo7j L/oQ8yrV/U3hnBiYnRmY8nDJBUSOS0K9P3u4LhqCctOdlTSKrNvA3zmMEUtKNuSrKCjs c/CsKouP0QqWfbcebl9gcIL25uISC7snnejTCZl0l99j+zFwlGafTL/cr3vcdf1SmMQQ aJMgHOtVxzHT7i8ThS/4q1s0GwvlGHf4RoMoXHW0+QC/7TyNB1sLVGAZtVc8GpyZiyuT xJ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=BoyKgfY0G466liIalIla0NzR25Ab4OLb+k+yP1q2yAE=; b=pz16BIMqk6eY/xMRnG6sRk/n/FeROUzkmjeBRJIvBgkJovMnBTd8L7IEFL7tmPAbuZ 474yw5crHOCZVgHTfvqXivHlH+Zir+1dX66ttR3fLp5Y/sXCbYtlAKPPMHBzUnzIAYjG 4RHD4ou2ajk55MxzrCxJcXge97Gbu+n/PB3ZpE80a3LXvDPkG0j6WMRoyrMLO8uNykXi qJ10JNiRhySPKJxOaC6i9P1fJtZCm1FoFTG+2++ZwDNU1e9J56PjYAb6wnFHdu2PmXHT lqJywXQOJRD2jmCBdroP0abi+DdiOnDUi81Jvyg41i70mSoL26TAjGfU74pdK+O1W4EO PoNA== X-Gm-Message-State: APjAAAXBvrRNsNNQr7WkERT8rJFm/qspRoQBCR5OeATJJk0gl+KDupFo uOQwO2tr5zd3JUtx1/5X6+qffg== X-Google-Smtp-Source: APXvYqx9b949BcOSJT6Bm1nopS4qWuZ1ye50JtyvHm9hoWqqc3y8fYUp/FdbBypiadTG2DSmYNgi2A== X-Received: by 2002:adf:c401:: with SMTP id v1mr2786919wrf.375.1573652477658; Wed, 13 Nov 2019 05:41:17 -0800 (PST) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id l10sm3430222wrg.90.2019.11.13.05.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 05:41:15 -0800 (PST) Date: Wed, 13 Nov 2019 14:41:14 +0100 From: Tomas Vondra To: tuomas.leikola@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16111: Unexpected query compilation error =?utf-8?B?4oCc?= =?utf-8?Q?negative_bitmapset_member_not_allowed=E2=80=9D?= Message-ID: <20191113134114.rxcli5c6zjmryvf6@development> References: <16111-687799584c3a7e73@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="s4b42twheexui5fh" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <16111-687799584c3a7e73@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --s4b42twheexui5fh Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit On Wed, Nov 13, 2019 at 10:42:32AM +0000, PG Bug reporting form wrote: >The following bug has been logged on the website: > >Bug reference: 16111 >Logged by: Tuomas Leikola >Email address: tuomas.leikola@gmail.com >PostgreSQL version: 12.0 >Operating system: windows, linux >Description: > >I’ve been trying to cook up some kind of online reorganizer, which requires >looking at rows’ physical locations and rearranging those that are >suboptimal. In this endeavor, I stumbled on what appears to be a compiler >bug introduced with multivariate statistics. > Yeah, this is a bug in estimate_multivariate_ndistinct, which fails to ignore system attributes :-( The attached patch fixes it, but unfortunatly we've missed this round of minor releases :-( I'll get it pushed in a couple of days. Thanks for the report and the reproducer, very helpful! regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --s4b42twheexui5fh Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="estimate_multivariate_ndistinct.patch" diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 8dddc5eb93..a3cccc455f 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -3592,15 +3592,21 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, /* Determine the attnums we're looking for */ foreach(lc, *varinfos) { + Var *var; GroupVarInfo *varinfo = (GroupVarInfo *) lfirst(lc); Assert(varinfo->rel == rel); - if (IsA(varinfo->var, Var)) - { - attnums = bms_add_member(attnums, - ((Var *) varinfo->var)->varattno); - } + if (!IsA(varinfo->var, Var)) + continue; + + var = (Var *) varinfo->var; + + if (!AttrNumberIsForUserDefinedAttr(var->varattno)) + continue; + + attnums = bms_add_member(attnums, + ((Var *) varinfo->var)->varattno); } /* look for the ndistinct statistics matching the most vars */ --s4b42twheexui5fh--