Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit447dbf7

Browse files
committed
Fix bogus code for extracting extended-statistics data from syscache.
statext_dependencies_load and statext_ndistinct_load were not up to snuff,in addition to being randomly different from each other. In detail:* Deserialize the fetched bytea value before releasing the syscacheentry, not after. This mistake causes visible regression test failureswhen running with -DCATCACHE_FORCE_RELEASE. Since it's not exposed by-DCLOBBER_CACHE_ALWAYS, I think there may be no production hazard hereat present, but it's at least a latent bug.* Use DatumGetByteaPP not DatumGetByteaP to save a detoasting cyclefor short stats values; the deserialize function has to be, and is,prepared for short-header values since its other caller uses PP.* Use a test-and-elog for null stats values in both functions, ratherthan a test-and-elog in one case and an Assert in the other. PerhapsAsserts would be sufficient in both cases, but I don't see a goodargument for them being different.* Minor cosmetic changes to make these functions more visibly alike.Backpatch to v10 where this code came in.Amit Langote, minor additional hacking by meDiscussion:https://postgr.es/m/1349aabb-3a1f-6675-9fc0-65e2ce7491dd@lab.ntt.co.jp
1 parentbcded26 commit447dbf7

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

‎src/backend/statistics/dependencies.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,27 @@ dependency_implies_attribute(MVDependency *dependency, AttrNumber attnum)
631631
MVDependencies*
632632
statext_dependencies_load(Oidmvoid)
633633
{
634+
MVDependencies*result;
634635
boolisnull;
635636
Datumdeps;
636-
HeapTuplehtup=SearchSysCache1(STATEXTOID,ObjectIdGetDatum(mvoid));
637+
HeapTuplehtup;
637638

639+
htup=SearchSysCache1(STATEXTOID,ObjectIdGetDatum(mvoid));
638640
if (!HeapTupleIsValid(htup))
639641
elog(ERROR,"cache lookup failed for statistics object %u",mvoid);
640642

641643
deps=SysCacheGetAttr(STATEXTOID,htup,
642644
Anum_pg_statistic_ext_stxdependencies,&isnull);
643-
Assert(!isnull);
645+
if (isnull)
646+
elog(ERROR,
647+
"requested statistic kind \"%c\" is not yet built for statistics object %u",
648+
STATS_EXT_DEPENDENCIES,mvoid);
649+
650+
result=statext_dependencies_deserialize(DatumGetByteaPP(deps));
644651

645652
ReleaseSysCache(htup);
646653

647-
returnstatext_dependencies_deserialize(DatumGetByteaP(deps));
654+
returnresult;
648655
}
649656

650657
/*

‎src/backend/statistics/mvdistinct.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,27 @@ statext_ndistinct_build(double totalrows, int numrows, HeapTuple *rows,
126126
MVNDistinct*
127127
statext_ndistinct_load(Oidmvoid)
128128
{
129-
boolisnull= false;
129+
MVNDistinct*result;
130+
boolisnull;
130131
Datumndist;
131132
HeapTuplehtup;
132133

133134
htup=SearchSysCache1(STATEXTOID,ObjectIdGetDatum(mvoid));
134-
if (!htup)
135+
if (!HeapTupleIsValid(htup))
135136
elog(ERROR,"cache lookup failed for statistics object %u",mvoid);
136137

137138
ndist=SysCacheGetAttr(STATEXTOID,htup,
138139
Anum_pg_statistic_ext_stxndistinct,&isnull);
139140
if (isnull)
140141
elog(ERROR,
141-
"requested statistic kind%c is not yet built for statistics object %u",
142+
"requested statistic kind\"%c\" is not yet built for statistics object %u",
142143
STATS_EXT_NDISTINCT,mvoid);
143144

145+
result=statext_ndistinct_deserialize(DatumGetByteaPP(ndist));
146+
144147
ReleaseSysCache(htup);
145148

146-
returnstatext_ndistinct_deserialize(DatumGetByteaP(ndist));
149+
returnresult;
147150
}
148151

149152
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp