Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

indexing.c File Reference

#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/index.h"
#include "catalog/indexing.h"
#include "executor/executor.h"
#include "utils/rel.h"
Include dependency graph for indexing.c:

Go to the source code of this file.

Functions

CatalogIndexState CatalogOpenIndexes (Relation heapRel)
void CatalogCloseIndexes (CatalogIndexState indstate)
void CatalogIndexInsert (CatalogIndexState indstate, HeapTuple heapTuple)
void CatalogUpdateIndexes (Relation heapRel, HeapTuple heapTuple)

Function Documentation

void CatalogCloseIndexes ( CatalogIndexState  indstate  ) 
void CatalogIndexInsert ( CatalogIndexState  indstate,
HeapTuple  heapTuple 
)

Definition at line 72 of file indexing.c.

References Assert, ExecDropSingleTupleTableSlot(), ExecStoreTuple(), FormIndexDatum(), HeapTupleIsHeapOnly, i, IndexInfo::ii_ExclusionOps, IndexInfo::ii_Expressions, IndexInfo::ii_Predicate, IndexInfo::ii_ReadyForInserts, index_insert(), InvalidBuffer, MakeSingleTupleTableSlot(), NIL, NULL, RelationData::rd_index, RelationGetDescr, ResultRelInfo::ri_IndexRelationDescs, ResultRelInfo::ri_IndexRelationInfo, ResultRelInfo::ri_NumIndices, ResultRelInfo::ri_RelationDesc, HeapTupleData::t_self, UNIQUE_CHECK_NO, UNIQUE_CHECK_YES, and values.

Referenced by CatalogUpdateIndexes(), copyTemplateDependencies(), InsertPgAttributeTuple(), inv_truncate(), inv_write(), recordMultipleDependencies(), and swap_relation_files().

{
    int         i;
    int         numIndexes;
    RelationPtr relationDescs;
    Relation    heapRelation;
    TupleTableSlot *slot;
    IndexInfo **indexInfoArray;
    Datum       values[INDEX_MAX_KEYS];
    bool        isnull[INDEX_MAX_KEYS];

    /* HOT update does not require index inserts */
    if (HeapTupleIsHeapOnly(heapTuple))
        return;

    /*
     * Get information from the state structure.  Fall out if nothing to do.
     */
    numIndexes = indstate->ri_NumIndices;
    if (numIndexes == 0)
        return;
    relationDescs = indstate->ri_IndexRelationDescs;
    indexInfoArray = indstate->ri_IndexRelationInfo;
    heapRelation = indstate->ri_RelationDesc;

    /* Need a slot to hold the tuple being examined */
    slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
    ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);

    /*
     * for each index, form and insert the index tuple
     */
    for (i = 0; i < numIndexes; i++)
    {
        IndexInfo  *indexInfo;

        indexInfo = indexInfoArray[i];

        /* If the index is marked as read-only, ignore it */
        if (!indexInfo->ii_ReadyForInserts)
            continue;

        /*
         * Expressional and partial indexes on system catalogs are not
         * supported, nor exclusion constraints, nor deferred uniqueness
         */
        Assert(indexInfo->ii_Expressions == NIL);
        Assert(indexInfo->ii_Predicate == NIL);
        Assert(indexInfo->ii_ExclusionOps == NULL);
        Assert(relationDescs[i]->rd_index->indimmediate);

        /*
         * FormIndexDatum fills in its values and isnull parameters with the
         * appropriate values for the column(s) of the index.
         */
        FormIndexDatum(indexInfo,
                       slot,
                       NULL,    /* no expression eval to do */
                       values,
                       isnull);

        /*
         * The index AM does the rest.
         */
        index_insert(relationDescs[i],  /* index relation */
                     values,    /* array of index Datums */
                     isnull,    /* is-null flags */
                     &(heapTuple->t_self),      /* tid of heap tuple */
                     heapRelation,
                     relationDescs[i]->rd_index->indisunique ?
                     UNIQUE_CHECK_YES : UNIQUE_CHECK_NO);
    }

    ExecDropSingleTupleTableSlot(slot);
}

CatalogIndexState CatalogOpenIndexes ( Relation  heapRel  ) 

Definition at line 40 of file indexing.c.

References ExecOpenIndices(), makeNode, ResultRelInfo::ri_RangeTableIndex, ResultRelInfo::ri_RelationDesc, and ResultRelInfo::ri_TrigDesc.

Referenced by AddNewAttributeTuples(), AppendAttributeTuples(), CatalogUpdateIndexes(), copyTemplateDependencies(), inv_truncate(), inv_write(), recordMultipleDependencies(), and swap_relation_files().

{
    ResultRelInfo *resultRelInfo;

    resultRelInfo = makeNode(ResultRelInfo);
    resultRelInfo->ri_RangeTableIndex = 1;      /* dummy */
    resultRelInfo->ri_RelationDesc = heapRel;
    resultRelInfo->ri_TrigDesc = NULL;  /* we don't fire triggers */

    ExecOpenIndices(resultRelInfo);

    return resultRelInfo;
}

void CatalogUpdateIndexes ( Relation  heapRel,
HeapTuple  heapTuple 
)

Definition at line 157 of file indexing.c.

References CatalogCloseIndexes(), CatalogIndexInsert(), and CatalogOpenIndexes().

Referenced by AddEnumLabel(), AddRoleMems(), AggregateCreate(), AlterConstraintNamespaces(), AlterDatabase(), AlterDatabaseOwner(), AlterDomainDefault(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEventTrigger(), AlterEventTriggerOwner_internal(), AlterExtensionNamespace(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner_internal(), AlterForeignServer(), AlterForeignServerOwner_internal(), AlterFunction(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterRelationNamespaceInternal(), AlterRole(), AlterSchemaOwner_internal(), AlterSetting(), AlterTableSpaceOptions(), AlterTSDictionary(), AlterTypeNamespaceInternal(), AlterTypeOwner(), AlterTypeOwnerInternal(), AlterUserMapping(), ApplyExtensionUpdates(), ATExecAddColumn(), ATExecAddOf(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecChangeOwner(), ATExecDropColumn(), ATExecDropConstraint(), ATExecDropInherit(), ATExecDropNotNull(), ATExecDropOf(), ATExecGenericOptions(), ATExecSetNotNull(), ATExecSetOptions(), ATExecSetRelOptions(), ATExecSetStatistics(), ATExecSetStorage(), ATExecSetTableSpace(), ATExecValidateConstraint(), change_owner_fix_column_acls(), changeDependencyFor(), CollationCreate(), ConversionCreate(), create_proc_lang(), create_toast_table(), CreateCast(), CreateComments(), CreateConstraintEntry(), createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreateRole(), CreateSharedComments(), CreateTableSpace(), CreateTrigger(), CreateUserMapping(), DefineOpClass(), DefineQueryRewrite(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), DelRoleMems(), EnableDisableRule(), EnableDisableTrigger(), EnumValuesCreate(), ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), extension_config_remove(), index_build(), index_constraint_create(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertPgAttributeTuple(), InsertPgClassTuple(), InsertRule(), LargeObjectCreate(), MakeConfigurationMapping(), mark_index_clustered(), MergeAttributesIntoExisting(), MergeConstraintsIntoExisting(), MergeWithExistingConstraint(), movedb(), NamespaceCreate(), OperatorCreate(), OperatorShellMake(), OperatorUpd(), pg_extension_config_dump(), ProcedureCreate(), RangeCreate(), reindex_index(), RelationSetNewRelfilenode(), RemoveAttrDefaultById(), RemoveAttributeById(), RemoveConstraintById(), renameatt_internal(), RenameConstraintById(), RenameDatabase(), RenameRelationInternal(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameTypeInternal(), RenumberEnumType(), SetDefaultACL(), SetFunctionArgType(), SetFunctionReturnType(), SetRelationHasSubclass(), SetRelationNumChecks(), SetRelationRuleStatus(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepAddDependency(), shdepChangeDep(), StoreAttrDefault(), StoreCatalogInheritance1(), storeOperators(), storeProcedures(), TypeCreate(), TypeShellMake(), update_attstats(), and UpdateIndexRelation().

{
    CatalogIndexState indstate;

    indstate = CatalogOpenIndexes(heapRel);
    CatalogIndexInsert(indstate, heapTuple);
    CatalogCloseIndexes(indstate);
}