|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * 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 $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -5777,40 +5777,63 @@ btcostestimate(PG_FUNCTION_ARGS)
|
5777 | 5777 | if (found_saop)
|
5778 | 5778 | PG_RETURN_VOID();
|
5779 | 5779 |
|
| 5780 | +MemSet(&vardata,0,sizeof(vardata)); |
| 5781 | + |
5780 | 5782 | if (index->indexkeys[0]!=0)
|
5781 | 5783 | {
|
5782 | 5784 | /* 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; |
5784 | 5789 | Assert(relid!=InvalidOid);
|
5785 | 5790 | 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 | +} |
5786 | 5811 | }
|
5787 | 5812 | else
|
5788 | 5813 | {
|
5789 | 5814 | /* Expression --- maybe there are stats for the index itself */
|
5790 | 5815 | relid=index->indexoid;
|
5791 | 5816 | colnum=1;
|
5792 |
| -} |
5793 |
| - |
5794 |
| -MemSet(&vardata,0,sizeof(vardata)); |
5795 | 5817 |
|
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 | +} |
5814 | 5837 | }
|
5815 | 5838 |
|
5816 | 5839 | if (HeapTupleIsValid(vardata.statsTuple))
|
|