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

Commit2dbc0ca

Browse files
committed
Dept of second thoughts: let's make sure that get_index_stats_hook is only
applied to expression indexes, not to plain relations. The original codingin btcostestimate conflated the two cases, but it's not hard to useget_relation_stats_hook instead when we're looking to the underlying relation.
1 parent7b7df9f commit2dbc0ca

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

‎src/backend/utils/adt/selfuncs.c

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.254 2008/09/2819:51:40 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.255 2008/09/2820:42:12 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -5777,40 +5777,63 @@ btcostestimate(PG_FUNCTION_ARGS)
57775777
if (found_saop)
57785778
PG_RETURN_VOID();
57795779

5780+
MemSet(&vardata,0,sizeof(vardata));
5781+
57805782
if (index->indexkeys[0]!=0)
57815783
{
57825784
/* Simple variable --- look to stats for the underlying table */
5783-
relid=getrelid(index->rel->relid,root->parse->rtable);
5785+
RangeTblEntry*rte=planner_rt_fetch(index->rel->relid,root);
5786+
5787+
Assert(rte->rtekind==RTE_RELATION);
5788+
relid=rte->relid;
57845789
Assert(relid!=InvalidOid);
57855790
colnum=index->indexkeys[0];
5791+
5792+
if (get_relation_stats_hook&&
5793+
(*get_relation_stats_hook) (root,rte,colnum,&vardata))
5794+
{
5795+
/*
5796+
* The hook took control of acquiring a stats tuple. If it did
5797+
* supply a tuple, it'd better have supplied a freefunc.
5798+
*/
5799+
if (HeapTupleIsValid(vardata.statsTuple)&&
5800+
!vardata.freefunc)
5801+
elog(ERROR,"no function provided to release variable stats with");
5802+
}
5803+
else
5804+
{
5805+
vardata.statsTuple=SearchSysCache(STATRELATT,
5806+
ObjectIdGetDatum(relid),
5807+
Int16GetDatum(colnum),
5808+
0,0);
5809+
vardata.freefunc=ReleaseSysCache;
5810+
}
57865811
}
57875812
else
57885813
{
57895814
/* Expression --- maybe there are stats for the index itself */
57905815
relid=index->indexoid;
57915816
colnum=1;
5792-
}
5793-
5794-
MemSet(&vardata,0,sizeof(vardata));
57955817

5796-
if (get_index_stats_hook&&
5797-
(*get_index_stats_hook) (root,relid,colnum,&vardata))
5798-
{
5799-
/*
5800-
* The hook took control of acquiring a stats tuple. If it did supply
5801-
* a tuple, it'd better have supplied a freefunc.
5802-
*/
5803-
if (HeapTupleIsValid(vardata.statsTuple)&&
5804-
!vardata.freefunc)
5805-
elog(ERROR,"no function provided to release variable stats with");
5806-
}
5807-
else
5808-
{
5809-
vardata.statsTuple=SearchSysCache(STATRELATT,
5810-
ObjectIdGetDatum(relid),
5811-
Int16GetDatum(colnum),
5812-
0,0);
5813-
vardata.freefunc=ReleaseSysCache;
5818+
if (get_index_stats_hook&&
5819+
(*get_index_stats_hook) (root,relid,colnum,&vardata))
5820+
{
5821+
/*
5822+
* The hook took control of acquiring a stats tuple. If it did
5823+
* supply a tuple, it'd better have supplied a freefunc.
5824+
*/
5825+
if (HeapTupleIsValid(vardata.statsTuple)&&
5826+
!vardata.freefunc)
5827+
elog(ERROR,"no function provided to release variable stats with");
5828+
}
5829+
else
5830+
{
5831+
vardata.statsTuple=SearchSysCache(STATRELATT,
5832+
ObjectIdGetDatum(relid),
5833+
Int16GetDatum(colnum),
5834+
0,0);
5835+
vardata.freefunc=ReleaseSysCache;
5836+
}
58145837
}
58155838

58165839
if (HeapTupleIsValid(vardata.statsTuple))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp