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 1opBkY-0001HB-Io for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Oct 2022 17:05:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1opBkW-0006Nv-1J for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Oct 2022 17:05:28 +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 1opBkV-0006Nl-Hs for pgsql-hackers@lists.postgresql.org; Sun, 30 Oct 2022 17:05:27 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1opBkS-0006W7-12 for pgsql-hackers@lists.postgresql.org; Sun, 30 Oct 2022 17:05:26 +0000 Received: by mail-io1-xd2c.google.com with SMTP id l127so8215214iof.12 for ; Sun, 30 Oct 2022 10:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Ajc4XwGEXQ8D1Q0s9MmBstmF8hBJ1hNsmV1xMDzMORw=; b=kQrfFGEB/22Wna0AxioVMJdapSTW3Y0vFlRQvaQ7AkAb06Eo7PugLeC5xO0pC6ai2l No6vNCT+a3kml5j9vAwTJjPpkT4/YHvluUpERli49/rYpgS+yWvQInlPzlPt2mO50w8D z86nKPSNAq4lrk9cWCre1ENS7IBMf4j02GvOE7Sd9HJKrYXjXsRAEVq6h9nmWcZ8htPF qpVCpwRH2ZsLYiRha/bbY9VEyHIO/OKx2DgpNfPz6RkIxt192qy+oZgu4/IDjcFjeMyL LlcCHPG1GDlisH/QNtFdJDmEQMUsPKcKYdhikLXyvz8z5LfsZAKyelNE1nxkqoXp2xiv MZDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ajc4XwGEXQ8D1Q0s9MmBstmF8hBJ1hNsmV1xMDzMORw=; b=aUK6Ez6atDA0L7psQ185WzA8PfPITTSZkw/biW7ACJKYQ2/sjoE4gp1ndSYQ7QSdWg L531/Y5/Jo1r4LQBb4rbdUOVh3xMg64x7zt57NCsxMs2UcMYi7Fj63vSw+l1lNBPgOZu DibskIoMkXdXk1QUJeUavkelfea1xeI/dU9nfXK+LhFQTV/WXXoPIJcvUOPX9zas3R/g V+KzMZSFqpOpVAVW4IM6o1ekd5gNHftE3+nMslEPXR9wVrh1mphpMTOs9aXcRKTo1+9L WLaL1MxzUwWtaHomThfVfbx+7QKa7DYADwNwhxnKmUT+DcpxXAJBH1vf1WKFHfE+kIB5 ly2Q== X-Gm-Message-State: ACrzQf1SE4+7b6uBgaB6wUiCEaBwnR/zDyLJSe9wrAOSYDiPTx1ffqrw 5aI5q361NyuX5p3Xle6GCwDQVA2A0O7rgA== X-Google-Smtp-Source: AMsMyM4Ko2vb2/jrrFeSPbWgewRFg9WtuyemmAYOVd1Tcbo6G7bdS4n9zdl9SQfVDajHML50nhnClQ== X-Received: by 2002:a6b:b808:0:b0:6c8:eb4a:829a with SMTP id i8-20020a6bb808000000b006c8eb4a829amr4747467iof.30.1667149521874; Sun, 30 Oct 2022 10:05:21 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id l13-20020a92290d000000b002f626355114sm1711170ilg.4.2022.10.30.10.05.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Oct 2022 10:05:21 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 6BFCA8008F8; Sun, 30 Oct 2022 12:05:20 -0500 (CDT) Date: Sun, 30 Oct 2022 12:05:20 -0500 From: Justin Pryzby To: Tomas Vondra Cc: pgsql-hackers@lists.postgresql.org Subject: pg15 inherited stats expressions: cache lookup failed for statistics object Message-ID: <20221030170520.GM16921@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk postgres=# \set QUIET CREATE TABLE stxdinp (i int, j int) PARTITION BY RANGE(i); CREATE TABLE stxdinp1 PARTITION OF stxdinp FOR VALUES FROM (1)TO(10); INSERT INTO stxdinp SELECT generate_series(1,9)a; CREATE STATISTICS stxdp ON i,j FROM stxdinp; ANALYZE stxdinp; explain SELECT i, j, COUNT(1) FROM ONLY stxdinp GROUP BY 1,2; ERROR: cache lookup failed for statistics object 4060843 It's evidently an issue with 269b532ae (Add stxdinherit flag to pg_statistic_ext_data) (gdb) bt #0 pg_re_throw () at elog.c:1795 #1 0x000000000096578a in errfinish (filename=, filename@entry=0xaf0442 "extended_stats.c", lineno=lineno@entry=2467, funcname=funcname@entry=0xaf0720 <__func__.28166> "statext_expressions_load") at elog.c:588 #2 0x00000000007efd07 in statext_expressions_load (stxoid=3914359, inh=, idx=idx@entry=0) at extended_stats.c:2467 #3 0x0000000000913947 in examine_variable (root=root@entry=0x2b5b530, node=node@entry=0x2b88820, varRelid=varRelid@entry=7, vardata=vardata@entry=0x7ffe5baa2f00) at selfuncs.c:5264 #4 0x00000000009141ae in get_restriction_variable (root=root@entry=0x2b5b530, args=args@entry=0x2b88a30, varRelid=varRelid@entry=7, vardata=vardata@entry=0x7ffe5baa2f90, other=other@entry=0x7ffe5baa2f88, varonleft=varonleft@entry=0x7ffe5baa2f87) at selfuncs.c:4848 #5 0x0000000000915535 in eqsel_internal (fcinfo=, negate=negate@entry=false) at selfuncs.c:263 #6 0x00000000009155f6 in eqsel (fcinfo=) at selfuncs.c:226 #7 0x000000000096a373 in FunctionCall4Coll (flinfo=flinfo@entry=0x7ffe5baa3090, collation=collation@entry=0, arg1=arg1@entry=45462832, arg2=arg2@entry=1320, arg3=arg3@entry=45648432, arg4=arg4@entry=7) at fmgr.c:1198 #8 0x000000000096a92a in OidFunctionCall4Coll (functionId=, collation=collation@entry=0, arg1=arg1@entry=45462832, arg2=arg2@entry=1320, arg3=arg3@entry=45648432, arg4=arg4@entry=7) at fmgr.c:1434 #9 0x000000000077e759 in restriction_selectivity (root=root@entry=0x2b5b530, operatorid=operatorid@entry=1320, args=0x2b88a30, inputcollid=0, varRelid=varRelid@entry=7) at plancat.c:1880 #10 0x0000000000728dc9 in clause_selectivity_ext (root=root@entry=0x2b5b530, clause=0x2b889d8, clause@entry=0x2b86e88, varRelid=varRelid@entry=7, jointype=jointype@entry=JOIN_INNER, sjinfo=sjinfo@entry=0x0, use_extended_stats=use_extended_stats@entry=true) at clausesel.c:875 #11 0x00000000007291b6 in clauselist_selectivity_ext (root=root@entry=0x2b5b530, clauses=0x2b88fc0, varRelid=7, jointype=jointype@entry=JOIN_INNER, sjinfo=sjinfo@entry=0x0, use_extended_stats=use_extended_stats@entry=true) at clausesel.c:185 #12 0x000000000072962e in clauselist_selectivity (root=root@entry=0x2b5b530, clauses=, varRelid=, jointype=jointype@entry=JOIN_INNER, sjinfo=sjinfo@entry=0x0) at clausesel.c:108 #13 0x000000000072fb1d in get_parameterized_baserel_size (root=root@entry=0x2b5b530, rel=rel@entry=0x2b73900, param_clauses=param_clauses@entry=0x2b88f68) at costsize.c:5015 #14 0x00000000007836f6 in get_baserel_parampathinfo (root=root@entry=0x2b5b530, baserel=baserel@entry=0x2b73900, required_outer=required_outer@entry=0x2b86478) at relnode.c:1346 #15 0x0000000000776819 in create_seqscan_path (root=root@entry=0x2b5b530, rel=rel@entry=0x2b73900, required_outer=required_outer@entry=0x2b86478, parallel_workers=parallel_workers@entry=0) at pathnode.c:937 #16 0x000000000077a32c in reparameterize_path (root=root@entry=0x2b5b530, path=path@entry=0x2b847b0, required_outer=required_outer@entry=0x2b86478, loop_count=loop_count@entry=1) at pathnode.c:3872 #17 0x00000000007249bc in get_cheapest_parameterized_child_path (root=root@entry=0x2b5b530, rel=, required_outer=required_outer@entry=0x2b86478) at allpaths.c:1996 #18 0x0000000000727619 in add_paths_to_append_rel (root=root@entry=0x2b5b530, rel=rel@entry=0x2b6a6a8, live_childrels=live_childrels@entry=0x2b858e8) at allpaths.c:1597 #19 0x0000000000728084 in set_append_rel_pathlist (root=root@entry=0x2b5b530, rel=rel@entry=0x2b6a6a8, rti=rti@entry=6, rte=rte@entry=0x2b5e1c0) at allpaths.c:1270 #20 0x0000000000727e17 in set_rel_pathlist (root=root@entry=0x2b5b530, rel=0x2b6a6a8, rti=rti@entry=6, rte=0x2b5e1c0) at allpaths.c:483 #21 0x0000000000727f8a in set_base_rel_pathlists (root=root@entry=0x2b5b530) at allpaths.c:355 #22 0x00000000007286fd in make_one_rel (root=root@entry=0x2b5b530, joinlist=joinlist@entry=0x2b6fd98) at allpaths.c:225 #23 0x00000000007512d5 in query_planner (root=root@entry=0x2b5b530, qp_callback=qp_callback@entry=0x75300a , qp_extra=qp_extra@entry=0x7ffe5baa3670) at planmain.c:276 #24 0x00000000007589ec in grouping_planner (root=root@entry=0x2b5b530, tuple_fraction=, tuple_fraction@entry=0) at planner.c:1467 #25 0x000000000075a5f2 in subquery_planner (glob=, parse=parse@entry=0x2b23c08, parent_root=parent_root@entry=0x2736768, hasRecursion=hasRecursion@entry=false, tuple_fraction=) at planner.c:1044 #26 0x0000000000726567 in set_subquery_pathlist (root=root@entry=0x2736768, rel=rel@entry=0x2755f30, rti=rti@entry=6, rte=rte@entry=0x28c9980) at allpaths.c:2589 #27 0x000000000072681c in set_rel_size (root=root@entry=0x2736768, rel=rel@entry=0x2755f30, rti=rti@entry=6, rte=rte@entry=0x28c9980) at allpaths.c:425 #28 0x0000000000726996 in set_base_rel_sizes (root=root@entry=0x2736768) at allpaths.c:326 #29 0x0000000000728663 in make_one_rel (root=root@entry=0x2736768, joinlist=joinlist@entry=0x274d038) at allpaths.c:188 #30 0x00000000007512d5 in query_planner (root=root@entry=0x2736768, qp_callback=qp_callback@entry=0x75300a , qp_extra=qp_extra@entry=0x7ffe5baa39d0) at planmain.c:276 #31 0x00000000007589ec in grouping_planner (root=root@entry=0x2736768, tuple_fraction=, tuple_fraction@entry=0) at planner.c:1467 #32 0x000000000075a5f2 in subquery_planner (glob=glob@entry=0x2483430, parse=parse@entry=0x289c7c8, parent_root=parent_root@entry=0x0, hasRecursion=hasRecursion@entry=false, tuple_fraction=tuple_fraction@entry=0) at planner.c:1044 I think this is what's needed. diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 14e0885f19f..4450f0d682f 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -5240,6 +5240,8 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid, /* skip stats without per-expression stats */ if (info->kind != STATS_EXT_EXPRESSIONS) continue; + if (info->inherit != rte->inh) + continue; pos = 0; foreach(expr_item, info->exprs)