pg15 inherited stats expressions: cache lookup failed for statistics object

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: pg15 inherited stats expressions: cache lookup failed for statistics object
Date: 2022-10-30 17:05:20
Message-ID: 20221030170520.GM16921@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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=<optimized out>, filename(at)entry=0xaf0442 "extended_stats.c", lineno=lineno(at)entry=2467, funcname=funcname(at)entry=0xaf0720 <__func__.28166> "statext_expressions_load") at elog.c:588
#2 0x00000000007efd07 in statext_expressions_load (stxoid=3914359, inh=<optimized out>, idx=idx(at)entry=0) at extended_stats.c:2467
#3 0x0000000000913947 in examine_variable (root=root(at)entry=0x2b5b530, node=node(at)entry=0x2b88820, varRelid=varRelid(at)entry=7, vardata=vardata(at)entry=0x7ffe5baa2f00) at selfuncs.c:5264
#4 0x00000000009141ae in get_restriction_variable (root=root(at)entry=0x2b5b530, args=args(at)entry=0x2b88a30, varRelid=varRelid(at)entry=7, vardata=vardata(at)entry=0x7ffe5baa2f90, other=other(at)entry=0x7ffe5baa2f88,
varonleft=varonleft(at)entry=0x7ffe5baa2f87) at selfuncs.c:4848
#5 0x0000000000915535 in eqsel_internal (fcinfo=<optimized out>, negate=negate(at)entry=false) at selfuncs.c:263
#6 0x00000000009155f6 in eqsel (fcinfo=<optimized out>) at selfuncs.c:226
#7 0x000000000096a373 in FunctionCall4Coll (flinfo=flinfo(at)entry=0x7ffe5baa3090, collation=collation(at)entry=0, arg1=arg1(at)entry=45462832, arg2=arg2(at)entry=1320, arg3=arg3(at)entry=45648432, arg4=arg4(at)entry=7) at fmgr.c:1198
#8 0x000000000096a92a in OidFunctionCall4Coll (functionId=<optimized out>, collation=collation(at)entry=0, arg1=arg1(at)entry=45462832, arg2=arg2(at)entry=1320, arg3=arg3(at)entry=45648432, arg4=arg4(at)entry=7) at fmgr.c:1434
#9 0x000000000077e759 in restriction_selectivity (root=root(at)entry=0x2b5b530, operatorid=operatorid(at)entry=1320, args=0x2b88a30, inputcollid=0, varRelid=varRelid(at)entry=7) at plancat.c:1880
#10 0x0000000000728dc9 in clause_selectivity_ext (root=root(at)entry=0x2b5b530, clause=0x2b889d8, clause(at)entry=0x2b86e88, varRelid=varRelid(at)entry=7, jointype=jointype(at)entry=JOIN_INNER, sjinfo=sjinfo(at)entry=0x0,
use_extended_stats=use_extended_stats(at)entry=true) at clausesel.c:875
#11 0x00000000007291b6 in clauselist_selectivity_ext (root=root(at)entry=0x2b5b530, clauses=0x2b88fc0, varRelid=7, jointype=jointype(at)entry=JOIN_INNER, sjinfo=sjinfo(at)entry=0x0, use_extended_stats=use_extended_stats(at)entry=true)
at clausesel.c:185
#12 0x000000000072962e in clauselist_selectivity (root=root(at)entry=0x2b5b530, clauses=<optimized out>, varRelid=<optimized out>, jointype=jointype(at)entry=JOIN_INNER, sjinfo=sjinfo(at)entry=0x0) at clausesel.c:108
#13 0x000000000072fb1d in get_parameterized_baserel_size (root=root(at)entry=0x2b5b530, rel=rel(at)entry=0x2b73900, param_clauses=param_clauses(at)entry=0x2b88f68) at costsize.c:5015
#14 0x00000000007836f6 in get_baserel_parampathinfo (root=root(at)entry=0x2b5b530, baserel=baserel(at)entry=0x2b73900, required_outer=required_outer(at)entry=0x2b86478) at relnode.c:1346
#15 0x0000000000776819 in create_seqscan_path (root=root(at)entry=0x2b5b530, rel=rel(at)entry=0x2b73900, required_outer=required_outer(at)entry=0x2b86478, parallel_workers=parallel_workers(at)entry=0) at pathnode.c:937
#16 0x000000000077a32c in reparameterize_path (root=root(at)entry=0x2b5b530, path=path(at)entry=0x2b847b0, required_outer=required_outer(at)entry=0x2b86478, loop_count=loop_count(at)entry=1) at pathnode.c:3872
#17 0x00000000007249bc in get_cheapest_parameterized_child_path (root=root(at)entry=0x2b5b530, rel=<optimized out>, required_outer=required_outer(at)entry=0x2b86478) at allpaths.c:1996
#18 0x0000000000727619 in add_paths_to_append_rel (root=root(at)entry=0x2b5b530, rel=rel(at)entry=0x2b6a6a8, live_childrels=live_childrels(at)entry=0x2b858e8) at allpaths.c:1597
#19 0x0000000000728084 in set_append_rel_pathlist (root=root(at)entry=0x2b5b530, rel=rel(at)entry=0x2b6a6a8, rti=rti(at)entry=6, rte=rte(at)entry=0x2b5e1c0) at allpaths.c:1270
#20 0x0000000000727e17 in set_rel_pathlist (root=root(at)entry=0x2b5b530, rel=0x2b6a6a8, rti=rti(at)entry=6, rte=0x2b5e1c0) at allpaths.c:483
#21 0x0000000000727f8a in set_base_rel_pathlists (root=root(at)entry=0x2b5b530) at allpaths.c:355
#22 0x00000000007286fd in make_one_rel (root=root(at)entry=0x2b5b530, joinlist=joinlist(at)entry=0x2b6fd98) at allpaths.c:225
#23 0x00000000007512d5 in query_planner (root=root(at)entry=0x2b5b530, qp_callback=qp_callback(at)entry=0x75300a <standard_qp_callback>, qp_extra=qp_extra(at)entry=0x7ffe5baa3670) at planmain.c:276
#24 0x00000000007589ec in grouping_planner (root=root(at)entry=0x2b5b530, tuple_fraction=<optimized out>, tuple_fraction(at)entry=0) at planner.c:1467
#25 0x000000000075a5f2 in subquery_planner (glob=<optimized out>, parse=parse(at)entry=0x2b23c08, parent_root=parent_root(at)entry=0x2736768, hasRecursion=hasRecursion(at)entry=false, tuple_fraction=<optimized out>) at planner.c:1044
#26 0x0000000000726567 in set_subquery_pathlist (root=root(at)entry=0x2736768, rel=rel(at)entry=0x2755f30, rti=rti(at)entry=6, rte=rte(at)entry=0x28c9980) at allpaths.c:2589
#27 0x000000000072681c in set_rel_size (root=root(at)entry=0x2736768, rel=rel(at)entry=0x2755f30, rti=rti(at)entry=6, rte=rte(at)entry=0x28c9980) at allpaths.c:425
#28 0x0000000000726996 in set_base_rel_sizes (root=root(at)entry=0x2736768) at allpaths.c:326
#29 0x0000000000728663 in make_one_rel (root=root(at)entry=0x2736768, joinlist=joinlist(at)entry=0x274d038) at allpaths.c:188
#30 0x00000000007512d5 in query_planner (root=root(at)entry=0x2736768, qp_callback=qp_callback(at)entry=0x75300a <standard_qp_callback>, qp_extra=qp_extra(at)entry=0x7ffe5baa39d0) at planmain.c:276
#31 0x00000000007589ec in grouping_planner (root=root(at)entry=0x2736768, tuple_fraction=<optimized out>, tuple_fraction(at)entry=0) at planner.c:1467
#32 0x000000000075a5f2 in subquery_planner (glob=glob(at)entry=0x2483430, parse=parse(at)entry=0x289c7c8, parent_root=parent_root(at)entry=0x0, hasRecursion=hasRecursion(at)entry=false, tuple_fraction=tuple_fraction(at)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)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2022-10-30 18:01:55 Re: Code checks for App Devs, using new options for transaction behavior
Previous Message Alvaro Herrera 2022-10-30 15:52:39 Re: Segfault on logical replication to partitioned table with foreign children