/* ---------------- * RelationGetIndexScan -- Create and fill an IndexScanDesc. * * This routine creates an index scan structure and sets its contents * up correctly. This routine calls AMrescan to set up the scan with * the passed key. * * Parameters: * indexRelation -- index relation for scan. * nkeys -- count of scan keys. * key -- array of scan keys to restrict the index scan. * * Returns: * An initialized IndexScanDesc. * ---------------- */ IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, ScanKey key) { IndexScanDesc scan; scan = (IndexScanDesc) palloc(sizeof(IndexScanDescData)); scan->heapRelation = NULL; /* may be set later */ scan->indexRelation = indexRelation; scan->xs_snapshot = SnapshotNow; /* may be set later */ scan->numberOfKeys = nkeys; /* * We allocate the key space here, but the AM is responsible for * actually filling it from the passed key array. */ if (nkeys > 0) scan->keyData = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys); else scan->keyData = NULL; scan->kill_prior_tuple = false; scan->ignore_killed_tuples = true; /* default setting */ scan->keys_are_unique = false; /* may be set by index AM */ scan->got_tuple = false; scan->opaque = NULL; ItemPointerSetInvalid(&scan->currentItemData); ItemPointerSetInvalid(&scan->currentMarkData); ItemPointerSetInvalid(&scan->xs_ctup.t_self); scan->xs_ctup.t_datamcxt = NULL; scan->xs_ctup.t_data = NULL; scan->xs_cbuf = InvalidBuffer; /* mark cached function lookup data invalid; it will be set later */ scan->fn_getnext.fn_oid = InvalidOid; scan->unique_tuple_pos = 0; scan->unique_tuple_mark = 0; pgstat_initstats(&scan->xs_pgstat_info, indexRelation); /* * Let the AM fill in the key and any opaque data it wants. */ index_rescan(scan, key); return scan; }
/* ---------------- * index_openr - open a system index relation specified by name. * * As above, but the relation is specified by an unqualified name; * it is assumed to live in the system catalog namespace. * ---------------- */ Relation index_openr(const char *sysRelationName) { Relation r; r = relation_openr(sysRelationName, NoLock); if (r->rd_rel->relkind != RELKIND_INDEX) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("\"%s\" is not an index", RelationGetRelationName(r)))); pgstat_initstats(&r->pgstat_info, r); return r; }
/* ---------------- * RelationGetIndexScan -- Create and fill an IndexScanDesc. * * This routine creates an index scan structure and sets its contents * up correctly. This routine calls AMrescan to set up the scan with * the passed key. * * Parameters: * indexRelation -- index relation for scan. * nkeys -- count of scan keys. * key -- array of scan keys to restrict the index scan. * * Returns: * An initialized IndexScanDesc. * ---------------- */ IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, ScanKey key) { IndexScanDesc scan; scan = (IndexScanDesc) palloc(sizeof(IndexScanDescData)); scan->heapRelation = NULL; /* may be set later */ scan->indexRelation = indexRelation; scan->xs_snapshot = SnapshotNow; /* may be set later */ scan->numberOfKeys = nkeys; /* * We allocate the key space here, but the AM is responsible for actually * filling it from the passed key array. */ if (nkeys > 0) scan->keyData = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys); else scan->keyData = NULL; scan->is_multiscan = false; /* caller may change this */ scan->kill_prior_tuple = false; scan->ignore_killed_tuples = true; /* default setting */ scan->opaque = NULL; ItemPointerSetInvalid(&scan->currentItemData); ItemPointerSetInvalid(&scan->currentMarkData); ItemPointerSetInvalid(&scan->xs_ctup.t_self); scan->xs_ctup.t_data = NULL; scan->xs_cbuf = InvalidBuffer; pgstat_initstats(&scan->xs_pgstat_info, indexRelation); /* * Let the AM fill in the key and any opaque data it wants. */ index_rescan(scan, key); return scan; }