|
92 | 92 | #include "tcop/utility.h" |
93 | 93 | #include "utils/acl.h" |
94 | 94 | #include "utils/builtins.h" |
| 95 | +#include "utils/elog.h" |
95 | 96 | #include "utils/fmgroids.h" |
96 | 97 | #include "utils/inval.h" |
97 | 98 | #include "utils/lsyscache.h" |
@@ -13942,9 +13943,50 @@ TryReuseIndex(Oid oldId, IndexStmt *stmt) |
13942 | 13943 | /* If it's a partitioned index, there is no storage to share. */ |
13943 | 13944 | if (irel->rd_rel->relkind != RELKIND_PARTITIONED_INDEX) |
13944 | 13945 | { |
| 13946 | + HeapTuple tuple; |
| 13947 | + Form_pg_am accessMethodForm; |
| 13948 | + IndexAmRoutine *amRoutine; |
| 13949 | + char *accessMethodName; |
| 13950 | + Oid heapRelId = IndexGetRelation(oldId, false); |
| 13951 | + Relation heapRel = table_open(heapRelId, ShareLock); |
| 13952 | + |
13945 | 13953 | stmt->oldNumber = irel->rd_locator.relNumber; |
13946 | 13954 | stmt->oldCreateSubid = irel->rd_createSubid; |
13947 | 13955 | stmt->oldFirstRelfilelocatorSubid = irel->rd_firstRelfilelocatorSubid; |
| 13956 | + |
| 13957 | + |
| 13958 | + /* |
| 13959 | + * look up the access method to call amreuse |
| 13960 | + */ |
| 13961 | + accessMethodName = stmt->accessMethod; |
| 13962 | + tuple = SearchSysCache1(AMNAME, PointerGetDatum(accessMethodName)); |
| 13963 | + if (!HeapTupleIsValid(tuple)) |
| 13964 | + { |
| 13965 | + /* |
| 13966 | + * Hack to provide more-or-less-transparent updating of old RTREE |
| 13967 | + * indexes to GiST: if RTREE is requested and not found, use GIST. |
| 13968 | + */ |
| 13969 | + if (strcmp(accessMethodName, "rtree") == 0) |
| 13970 | + { |
| 13971 | + ereport(NOTICE, |
| 13972 | + (errmsg("substituting access method \"gist\" for obsolete method \"rtree\""))); |
| 13973 | + accessMethodName = "gist"; |
| 13974 | + tuple = SearchSysCache1(AMNAME, PointerGetDatum(accessMethodName)); |
| 13975 | + } |
| 13976 | + |
| 13977 | + if (!HeapTupleIsValid(tuple)) |
| 13978 | + ereport(ERROR, |
| 13979 | + (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 13980 | + errmsg("access method \"%s\" does not exist", |
| 13981 | + accessMethodName))); |
| 13982 | + } |
| 13983 | + accessMethodForm = (Form_pg_am) GETSTRUCT(tuple); |
| 13984 | + amRoutine = GetIndexAmRoutineWithTableAM(heapRel->rd_rel->relam, accessMethodForm->amhandler); |
| 13985 | + table_close(heapRel, NoLock); |
| 13986 | + |
| 13987 | + if(amRoutine->amreuse) { |
| 13988 | + (*amRoutine->amreuse)(irel); |
| 13989 | + } |
13948 | 13990 | } |
13949 | 13991 | index_close(irel, NoLock); |
13950 | 13992 | } |
|
0 commit comments