MCPcopy Create free account
hub / github.com/apache/cloudberry / generateClonedIndexStmt

Function generateClonedIndexStmt

src/backend/parser/parse_utilcmd.c:1695–2047  ·  view source on GitHub ↗

* Generate an IndexStmt node using information from an already existing index * "source_idx". * * heapRel is stored into the IndexStmt's relation field, but we don't use it * otherwise; some callers pass NULL, if they don't need it to be valid. * (The target relation might not exist yet, so we mustn't try to access it.) * * Attribute numbers in expression Vars are adjusted according to attm

Source from the content-addressed store, hash-verified

1693 * complain if that fails to happen).
1694 */
1695IndexStmt *
1696generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx,
1697 const AttrMap *attmap,
1698 Oid *constraintOid)
1699{
1700 Oid source_relid = RelationGetRelid(source_idx);
1701 HeapTuple ht_idxrel;
1702 HeapTuple ht_idx;
1703 HeapTuple ht_am;
1704 Form_pg_class idxrelrec;
1705 Form_pg_index idxrec;
1706 Form_pg_am amrec;
1707 oidvector *indcollation;
1708 oidvector *indclass;
1709 IndexStmt *index;
1710 List *indexprs;
1711 ListCell *indexpr_item;
1712 Oid indrelid;
1713 Oid constraintId = InvalidOid;
1714 int keyno;
1715 Oid keycoltype;
1716 Datum datum;
1717 bool isnull;
1718
1719 if (constraintOid)
1720 *constraintOid = InvalidOid;
1721
1722 /*
1723 * Fetch pg_class tuple of source index. We can't use the copy in the
1724 * relcache entry because it doesn't include optional fields.
1725 */
1726 ht_idxrel = SearchSysCache1(RELOID, ObjectIdGetDatum(source_relid));
1727 if (!HeapTupleIsValid(ht_idxrel))
1728 elog(ERROR, "cache lookup failed for relation %u", source_relid);
1729 idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel);
1730
1731 /* Fetch pg_index tuple for source index from relcache entry */
1732 ht_idx = source_idx->rd_indextuple;
1733 idxrec = (Form_pg_index) GETSTRUCT(ht_idx);
1734 indrelid = idxrec->indrelid;
1735
1736 /* Fetch the pg_am tuple of the index' access method */
1737 ht_am = SearchSysCache1(AMOID, ObjectIdGetDatum(idxrelrec->relam));
1738 if (!HeapTupleIsValid(ht_am))
1739 elog(ERROR, "cache lookup failed for access method %u",
1740 idxrelrec->relam);
1741 amrec = (Form_pg_am) GETSTRUCT(ht_am);
1742
1743 /* Extract indcollation from the pg_index tuple */
1744 datum = SysCacheGetAttr(INDEXRELID, ht_idx,
1745 Anum_pg_index_indcollation, &isnull);
1746 Assert(!isnull);
1747 indcollation = (oidvector *) DatumGetPointer(datum);
1748
1749 /* Extract indclass from the pg_index tuple */
1750 datum = SysCacheGetAttr(INDEXRELID, ht_idx,
1751 Anum_pg_index_indclass, &isnull);
1752 Assert(!isnull);

Callers 3

DefineRelationFunction · 0.85
expandTableLikeClauseFunction · 0.85

Calls 15

SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
SysCacheGetAttrFunction · 0.85
get_tablespace_nameFunction · 0.85
get_index_constraintFunction · 0.85
deconstruct_arrayFunction · 0.85
DatumGetObjectIdFunction · 0.85
get_namespace_nameFunction · 0.85
makeStringFunction · 0.85
lappendFunction · 0.85
ReleaseSysCacheFunction · 0.85
stringToNodeFunction · 0.85

Tested by

no test coverage detected