Header And Logo

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

Data Structures | Defines | Typedefs | Functions

htup_details.h File Reference

#include "access/htup.h"
#include "access/tupdesc.h"
#include "access/tupmacs.h"
#include "storage/bufpage.h"
Include dependency graph for htup_details.h:

Go to the source code of this file.

Data Structures

struct  HeapTupleFields
struct  DatumTupleFields
struct  HeapTupleHeaderData
struct  MinimalTupleData

Defines

#define MaxTupleAttributeNumber   1664
#define MaxHeapAttributeNumber   1600
#define HEAP_HASNULL   0x0001
#define HEAP_HASVARWIDTH   0x0002
#define HEAP_HASEXTERNAL   0x0004
#define HEAP_HASOID   0x0008
#define HEAP_XMAX_KEYSHR_LOCK   0x0010
#define HEAP_COMBOCID   0x0020
#define HEAP_XMAX_EXCL_LOCK   0x0040
#define HEAP_XMAX_LOCK_ONLY   0x0080
#define HEAP_XMAX_SHR_LOCK   (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)
#define HEAP_LOCK_MASK
#define HEAP_XMIN_COMMITTED   0x0100
#define HEAP_XMIN_INVALID   0x0200
#define HEAP_XMAX_COMMITTED   0x0400
#define HEAP_XMAX_INVALID   0x0800
#define HEAP_XMAX_IS_MULTI   0x1000
#define HEAP_UPDATED   0x2000
#define HEAP_MOVED_OFF   0x4000
#define HEAP_MOVED_IN   0x8000
#define HEAP_MOVED   (HEAP_MOVED_OFF | HEAP_MOVED_IN)
#define HEAP_XACT_MASK   0xFFF0
#define HEAP_XMAX_IS_LOCKED_ONLY(infomask)
#define HEAP_XMAX_IS_SHR_LOCKED(infomask)   (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_SHR_LOCK)
#define HEAP_XMAX_IS_EXCL_LOCKED(infomask)   (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_EXCL_LOCK)
#define HEAP_XMAX_IS_KEYSHR_LOCKED(infomask)   (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_KEYSHR_LOCK)
#define HEAP_XMAX_BITS
#define HEAP_NATTS_MASK   0x07FF
#define HEAP_KEYS_UPDATED   0x2000
#define HEAP_HOT_UPDATED   0x4000
#define HEAP_ONLY_TUPLE   0x8000
#define HEAP2_XACT_MASK   0xE000
#define HEAP_TUPLE_HAS_MATCH   HEAP_ONLY_TUPLE
#define HeapTupleHeaderGetXmin(tup)
#define HeapTupleHeaderSetXmin(tup, xid)
#define HeapTupleHeaderGetUpdateXid(tup)
#define HeapTupleHeaderGetRawXmax(tup)
#define HeapTupleHeaderSetXmax(tup, xid)
#define HeapTupleHeaderGetRawCommandId(tup)
#define HeapTupleHeaderSetCmin(tup, cid)
#define HeapTupleHeaderSetCmax(tup, cid, iscombo)
#define HeapTupleHeaderGetXvac(tup)
#define HeapTupleHeaderSetXvac(tup, xid)
#define HeapTupleHeaderGetDatumLength(tup)   VARSIZE(tup)
#define HeapTupleHeaderSetDatumLength(tup, len)   SET_VARSIZE(tup, len)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderSetTypeId(tup, typeid)
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHeaderSetTypMod(tup, typmod)
#define HeapTupleHeaderGetOid(tup)
#define HeapTupleHeaderSetOid(tup, oid)
#define HeapTupleHeaderIsHotUpdated(tup)
#define HeapTupleHeaderSetHotUpdated(tup)
#define HeapTupleHeaderClearHotUpdated(tup)
#define HeapTupleHeaderIsHeapOnly(tup)
#define HeapTupleHeaderSetHeapOnly(tup)
#define HeapTupleHeaderClearHeapOnly(tup)
#define HeapTupleHeaderHasMatch(tup)
#define HeapTupleHeaderSetMatch(tup)
#define HeapTupleHeaderClearMatch(tup)
#define HeapTupleHeaderGetNatts(tup)   ((tup)->t_infomask2 & HEAP_NATTS_MASK)
#define HeapTupleHeaderSetNatts(tup, natts)
#define BITMAPLEN(NATTS)   (((int)(NATTS) + 7) / 8)
#define MaxHeapTupleSize   (BLCKSZ - MAXALIGN(SizeOfPageHeaderData + sizeof(ItemIdData)))
#define MaxHeapTuplesPerPage
#define MaxAttrSize   (10 * 1024 * 1024)
#define MINIMAL_TUPLE_OFFSET   ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
#define MINIMAL_TUPLE_PADDING   ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
#define MINIMAL_TUPLE_DATA_OFFSET   offsetof(MinimalTupleData, t_infomask2)
#define GETSTRUCT(TUP)   ((char *) ((TUP)->t_data) + (TUP)->t_data->t_hoff)
#define HeapTupleHasNulls(tuple)   (((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0)
#define HeapTupleNoNulls(tuple)   (!((tuple)->t_data->t_infomask & HEAP_HASNULL))
#define HeapTupleHasVarWidth(tuple)   (((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0)
#define HeapTupleAllFixed(tuple)   (!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH))
#define HeapTupleHasExternal(tuple)   (((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
#define HeapTupleIsHotUpdated(tuple)   HeapTupleHeaderIsHotUpdated((tuple)->t_data)
#define HeapTupleSetHotUpdated(tuple)   HeapTupleHeaderSetHotUpdated((tuple)->t_data)
#define HeapTupleClearHotUpdated(tuple)   HeapTupleHeaderClearHotUpdated((tuple)->t_data)
#define HeapTupleIsHeapOnly(tuple)   HeapTupleHeaderIsHeapOnly((tuple)->t_data)
#define HeapTupleSetHeapOnly(tuple)   HeapTupleHeaderSetHeapOnly((tuple)->t_data)
#define HeapTupleClearHeapOnly(tuple)   HeapTupleHeaderClearHeapOnly((tuple)->t_data)
#define HeapTupleGetOid(tuple)   HeapTupleHeaderGetOid((tuple)->t_data)
#define HeapTupleSetOid(tuple, oid)   HeapTupleHeaderSetOid((tuple)->t_data, (oid))
#define fastgetattr(tup, attnum, tupleDesc, isnull)
#define heap_getattr(tup, attnum, tupleDesc, isnull)

Typedefs

typedef struct HeapTupleFields HeapTupleFields
typedef struct DatumTupleFields DatumTupleFields

Functions

Size heap_compute_data_size (TupleDesc tupleDesc, Datum *values, bool *isnull)
void heap_fill_tuple (TupleDesc tupleDesc, Datum *values, bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit)
bool heap_attisnull (HeapTuple tup, int attnum)
Datum nocachegetattr (HeapTuple tup, int attnum, TupleDesc att)
Datum heap_getsysattr (HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
HeapTuple heap_copytuple (HeapTuple tuple)
void heap_copytuple_with_tuple (HeapTuple src, HeapTuple dest)
HeapTuple heap_form_tuple (TupleDesc tupleDescriptor, Datum *values, bool *isnull)
HeapTuple heap_modify_tuple (HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
void heap_deform_tuple (HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
HeapTuple heap_formtuple (TupleDesc tupleDescriptor, Datum *values, char *nulls)
HeapTuple heap_modifytuple (HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, char *replNulls, char *replActions)
void heap_deformtuple (HeapTuple tuple, TupleDesc tupleDesc, Datum *values, char *nulls)
void heap_freetuple (HeapTuple htup)
MinimalTuple heap_form_minimal_tuple (TupleDesc tupleDescriptor, Datum *values, bool *isnull)
void heap_free_minimal_tuple (MinimalTuple mtup)
MinimalTuple heap_copy_minimal_tuple (MinimalTuple mtup)
HeapTuple heap_tuple_from_minimal_tuple (MinimalTuple mtup)
MinimalTuple minimal_tuple_from_heap_tuple (HeapTuple htup)

Define Documentation

#define BITMAPLEN (   NATTS  )     (((int)(NATTS) + 7) / 8)
#define fastgetattr (   tup,
  attnum,
  tupleDesc,
  isnull 
)
Value:
(                                                                   \
    AssertMacro((attnum) > 0),                                      \
    (*(isnull) = false),                                            \
    HeapTupleNoNulls(tup) ?                                         \
    (                                                               \
        (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ?          \
        (                                                           \
            fetchatt((tupleDesc)->attrs[(attnum)-1],                \
                (char *) (tup)->t_data + (tup)->t_data->t_hoff +    \
                    (tupleDesc)->attrs[(attnum)-1]->attcacheoff)    \
        )                                                           \
        :                                                           \
            nocachegetattr((tup), (attnum), (tupleDesc))            \
    )                                                               \
    :                                                               \
    (                                                               \
        att_isnull((attnum)-1, (tup)->t_data->t_bits) ?             \
        (                                                           \
            (*(isnull) = true),                                     \
            (Datum)NULL                                             \
        )                                                           \
        :                                                           \
        (                                                           \
            nocachegetattr((tup), (attnum), (tupleDesc))            \
        )                                                           \
    )                                                               \
)

Definition at line 599 of file htup_details.h.

Referenced by AttrDefaultFetch(), CatalogCacheComputeTupleHashValue(), CheckConstraintFetch(), extractRelOptions(), GetDomainConstraints(), MergeWithExistingConstraint(), pg_get_triggerdef_worker(), RelationBuildTriggers(), RelationGetExclusionInfo(), RelationInitIndexAccessInfo(), toast_fetch_datum(), and toast_fetch_datum_slice().

#define GETSTRUCT (   TUP  )     ((char *) ((TUP)->t_data) + (TUP)->t_data->t_hoff)

Definition at line 536 of file htup_details.h.

Referenced by aclitemout(), add_function_defaults(), AddEnumLabel(), AddRoleMems(), AfterTriggerSetState(), AggregateCreate(), AlterConstraintNamespaces(), AlterDatabaseOwner(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEventTrigger(), AlterEventTriggerOwner_internal(), AlterExtensionNamespace(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner_internal(), AlterForeignServer(), AlterForeignServerOwner_internal(), AlterFunction(), AlterObjectNamespace_internal(), AlterObjectRename_internal(), AlterOpFamily(), AlterRelationNamespaceInternal(), AlterRole(), AlterRoleSet(), AlterSchemaOwner_internal(), AlterSeqNamespaces(), AlterTSDictionary(), AlterTypeNamespaceInternal(), AlterTypeOwner(), AlterTypeOwnerInternal(), ApplyExtensionUpdates(), array_to_json_internal(), assignOperTypes(), assignProcTypes(), ATAddForeignKeyConstraint(), ATExecAddColumn(), ATExecAddInherit(), ATExecAddOf(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecChangeOwner(), ATExecDropColumn(), ATExecDropConstraint(), ATExecDropInherit(), ATExecDropNotNull(), ATExecDropOf(), ATExecGenericOptions(), ATExecSetNotNull(), ATExecSetOptions(), ATExecSetStatistics(), ATExecSetStorage(), ATExecSetTableSpace(), ATExecValidateConstraint(), ATPrepAlterColumnType(), AttrDefaultFetch(), booltestsel(), boot_openrel(), build_coercion_expression(), build_datatype(), build_function_result_tupdesc_t(), BuildEventTriggerCache(), CacheInvalidateHeapTuple(), CacheInvalidateRelcacheByTuple(), calc_arraycontsel(), calc_rangesel(), change_owner_fix_column_acls(), change_owner_recurse_to_sequences(), changeDependencyFor(), check_for_column_name_collision(), check_functional_grouping(), check_of_type(), check_role(), check_session_authorization(), check_TSCurrentConfig(), CheckConstraintFetch(), checkDomainOwner(), checkEnumOwner(), CheckIndexCompatible(), CheckMyDatabase(), CheckRelationOwnership(), checkSharedDependencies(), cluster(), cluster_rel(), CollationIsVisible(), column_privilege_check(), compatible_oper(), compile_plperl_function(), compile_pltcl_function(), composite_to_json(), compute_return_type(), ComputeIndexAttrs(), ConstraintNameIsUsed(), constraints_equivalent(), ConstructTupleDescriptor(), ConversionIsVisible(), count_agg_clauses_walker(), create_toast_table(), CreateCast(), CreateFunction(), CreateTrigger(), decompile_conbin(), DefineCollation(), DefineDomain(), DefineIndex(), DefineOpClass(), DefineQueryRewrite(), DefineTSConfiguration(), DefineType(), deleteDependencyRecordsFor(), deleteDependencyRecordsForClass(), deparseFuncExpr(), deparseOpExpr(), deparseScalarArrayOpExpr(), do_autovacuum(), do_compile(), drop_parent_dependency(), DropConfigurationMapping(), DropRole(), EnableDisableRule(), EnableDisableTrigger(), enum_cmp_internal(), enum_out(), enum_send(), eqjoinsel_inner(), eqjoinsel_semi(), equality_ops_are_compatible(), errdatatype(), estimate_hash_bucketsize(), evaluate_function(), examine_attribute(), examine_parameter_list(), exec_object_restorecon(), ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), ExecInitAgg(), ExecuteDoStmt(), expand_all_col_privileges(), expand_function_arguments(), extract_autovac_opts(), extractRelOptions(), fetch_agg_sort_op(), fetch_fp_info(), find_coercion_pathway(), find_composite_type_dependencies(), find_inheritance_children(), find_language_template(), find_typmod_coercion_function(), FindDefaultConversion(), findDependentObjects(), fixup_whole_row_references(), fmgr_info_C_lang(), fmgr_info_cxt_security(), fmgr_info_other_lang(), fmgr_security_definer(), fmgr_sql_validator(), format_operator_internal(), format_procedure_internal(), format_type_internal(), func_get_detail(), func_strict(), func_volatile(), FuncNameAsType(), FuncnameGetCandidates(), FunctionIsVisible(), generate_collation_name(), generate_function_name(), generate_operator_name(), generate_relation_name(), generateClonedIndexStmt(), get_am_name(), get_array_type(), get_attavgwidth(), get_attname(), get_attnum(), get_attstatsslot(), get_atttype(), get_atttypetypmodcoll(), get_atttypmod(), get_base_element_type(), get_collation(), get_collation_name(), get_commutator(), get_compatible_hash_operators(), get_constraint_index(), get_constraint_name(), get_database_list(), get_database_name(), get_db_info(), get_domain_constraint_oid(), get_element_type(), get_extension_name(), get_extension_schema(), get_func_arg_info(), get_func_cost(), get_func_leakproof(), get_func_name(), get_func_namespace(), get_func_nargs(), get_func_retset(), get_func_rettype(), get_func_rows(), get_func_signature(), get_index_constraint(), get_mergejoin_opfamilies(), get_namespace_name(), get_negator(), get_object_address_type(), get_op_btree_interpretation(), get_op_hash_functions(), get_op_opfamily_properties(), get_op_opfamily_sortfamily(), get_op_opfamily_strategy(), get_opclass(), get_opclass_family(), get_opclass_input_type(), get_opclass_name(), get_opcode(), get_oper_expr(), get_opfamily_member(), get_opfamily_proc(), get_opname(), get_oprjoin(), get_oprrest(), get_ordering_op_for_equality_op(), get_ordering_op_properties(), get_pkey_attnames(), get_range_subtype(), get_rel_name(), get_rel_namespace(), get_rel_oids(), get_rel_relkind(), get_rel_tablespace(), get_rel_type_id(), get_relation_constraint_oid(), get_rels_with_domain(), get_rewrite_oid(), get_rewrite_oid_without_relid(), get_rte_attribute_is_dropped(), get_rte_attribute_type(), get_tables_to_cluster(), get_tablespace_name(), get_typ_typrelid(), get_typbyval(), get_typcollation(), get_typdefault(), get_type_category_preferred(), get_type_io_data(), get_typisdefined(), get_typlen(), get_typlenbyval(), get_typlenbyvalalign(), get_typmodin(), get_typstorage(), get_typtype(), get_variable_numdistinct(), getBaseTypeAndTypmod(), getConstraintTypeDescription(), GetDefaultOpClass(), GetDomainConstraints(), getExtensionOfObject(), GetFdwRoutineByRelId(), GetForeignDataWrapper(), GetForeignServer(), GetForeignTable(), GetIndexOpClass(), getObjectDescription(), getObjectIdentity(), getOpFamilyDescription(), getOpFamilyIdentity(), getOwnedSequences(), getProcedureTypeDescription(), getRelationDescription(), getRelationIdentity(), getRelationTypeDescription(), gettype(), getTypeBinaryInputInfo(), getTypeBinaryOutputInfo(), getTypeInputInfo(), getTypeIOParam(), getTypeOutputInfo(), GetUserNameFromId(), has_createrole_privilege(), has_rolcatupdate(), has_rolinherit(), has_rolreplication(), has_subclass(), hash_ok_operator(), have_createdb_privilege(), heap_truncate_find_FKs(), index_build(), index_check_primary_key(), index_constraint_create(), index_set_state_flags(), index_update_stats(), IndexGetRelation(), IndexSupportsBackwardScan(), init_sql_fcache(), initialize_peragg(), InitializeSessionUserId(), InitPostgres(), inline_function(), inline_set_returning_function(), internal_get_result_type(), inv_getsize(), inv_read(), inv_truncate(), inv_write(), is_admin_of_role(), IsBinaryCoercible(), isObjectPinned(), isSharedObjectPinned(), json_agg_transfn(), load_enum_cache_data(), load_rangetype_info(), load_relcache_init_file(), lookup_collation_cache(), lookup_ts_config_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupAggNameTypeNames(), LookupOpclassInfo(), ltreeparentsel(), make_op(), make_scalar_array_op(), makeConfigurationDependencies(), MakeConfigurationMapping(), makeDictionaryDependencies(), makeOperatorDependencies(), makeParserDependencies(), makeTSTemplateDependencies(), map_sql_table_to_xmlschema(), map_sql_type_to_xml_name(), mark_index_clustered(), MatchNamedCall(), MergeAttributesIntoExisting(), MergeConstraintsIntoExisting(), mergejoinscansel(), MergeWithExistingConstraint(), nulltestsel(), op_hashjoinable(), op_input_types(), op_mergejoinable(), OpClassCacheLookup(), OpclassIsVisible(), OperatorGet(), OperatorIsVisible(), OperatorUpd(), OpernameGetCandidates(), OpernameGetOprid(), OpFamilyCacheLookup(), OpfamilyIsVisible(), oprfuncid(), patternsel(), pg_attribute_aclcheck_all(), pg_attribute_aclmask(), pg_class_aclmask(), pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_aclmask(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_aclmask(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_aclmask(), pg_foreign_server_ownercheck(), pg_get_constraintdef_worker(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_serial_sequence(), pg_get_triggerdef_worker(), pg_get_userbyid(), pg_language_aclmask(), pg_language_ownercheck(), pg_largeobject_aclmask_snapshot(), pg_largeobject_ownercheck(), pg_namespace_aclmask(), pg_namespace_ownercheck(), pg_newlocale_from_collation(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_aclmask(), pg_proc_ownercheck(), pg_relation_filenode(), pg_relation_filepath(), pg_tablespace_aclmask(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_aclmask(), pg_type_ownercheck(), plperl_validator(), plpgsql_compile(), plpgsql_parse_cwordtype(), plpgsql_parse_wordtype(), plpgsql_validator(), plpython_validator(), pltcl_build_tuple_argument(), pltcl_set_tuple_values(), pltcl_trigger_handler(), PLy_input_datum_func2(), PLy_output_datum_func2(), PLy_procedure_create(), PLy_spi_prepare(), prepare_sql_fn_parse_info(), print_function_arguments(), print_function_rettype(), ProcedureCreate(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForRenameAttribute(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), read_seq_tuple(), recheck_cast_function_args(), recomputeNamespacePath(), regclassout(), regconfigout(), regdictionaryout(), regoperout(), regprocout(), regtypeout(), reindex_index(), ReindexDatabase(), RelationBuildDesc(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationBuildTupleDesc(), RelationCacheInitializePhase3(), RelationGetExclusionInfo(), RelationGetIndexList(), relationHasPrimaryKey(), RelationInitIndexAccessInfo(), RelationIsVisible(), RelationReloadIndexInfo(), RelationSetNewRelfilenode(), RemoveAttrDefaultById(), RemoveAttributeById(), RemoveConstraintById(), RemoveFunctionById(), RemoveObjects(), RemoveRewriteRuleById(), RemoveRoleFromObjectACL(), RemoveTriggerById(), RemoveTypeById(), rename_constraint_internal(), renameatt_internal(), RenameConstraintById(), RenameDatabase(), RenameRelationInternal(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), RenameTypeInternal(), RenumberEnumType(), reorder_function_arguments(), ResetSequence(), ri_add_cast_to(), ri_GenerateQual(), ri_GenerateQualCollation(), ri_LoadConstraintInfo(), roles_has_privs_of(), roles_is_member_of(), scalararraysel_containment(), scalarineqsel(), SearchSysCacheAttName(), sepgsql_attribute_post_create(), sepgsql_database_post_create(), sepgsql_proc_post_create(), sepgsql_proc_setattr(), sepgsql_relation_drop(), sepgsql_relation_post_create(), sepgsql_relation_setattr(), sepgsql_schema_post_create(), sequenceIsOwned(), SetFunctionArgType(), SetFunctionReturnType(), SetRelationHasSubclass(), SetRelationNumChecks(), SetRelationRuleStatus(), shdepChangeDep(), shdepDropDependency(), shdepDropOwned(), shdepReassignOwned(), simplify_function(), sort_order_cmp(), SPI_gettype(), StoreAttrDefault(), stringTypeDatum(), superuser_arg(), swap_relation_files(), table_recheck_autovac(), to_json(), transformArrayType(), transformColumnNameList(), transformColumnType(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), triggered_change_notification(), TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), tsquerysel(), TSTemplateIsVisible(), TupleDescInitEntry(), typeByVal(), TypeCreate(), typeidTypeRelid(), typeInheritsFrom(), typeIsOfTypedTable(), TypeIsVisible(), typeLen(), typenameType(), typenameTypeMod(), typeTypeCollation(), typeTypeName(), typeTypeRelid(), vac_truncate_clog(), vac_update_datfrozenxid(), vac_update_relstats(), validateCheckConstraint(), var_eq_const(), var_eq_non_const(), and verify_dictoptions().

#define HEAP2_XACT_MASK   0xE000

Definition at line 229 of file htup_details.h.

#define HEAP_COMBOCID   0x0020

Definition at line 166 of file htup_details.h.

Referenced by HeapTupleHeaderGetCmax(), and HeapTupleHeaderGetCmin().

#define heap_getattr (   tup,
  attnum,
  tupleDesc,
  isnull 
)
Value:
( \
        ((attnum) > 0) ? \
        ( \
            ((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \
            ( \
                (*(isnull) = true), \
                (Datum)NULL \
            ) \
            : \
                fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
        ) \
        : \
            heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
    )

Definition at line 649 of file htup_details.h.

Referenced by AlterDatabaseOwner(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterSetting(), AlterTableSpaceOptions(), ApplySetting(), BuildEventTriggerCache(), change_owner_fix_column_acls(), check_functional_grouping(), comparetup_cluster(), comparetup_heap(), composite_to_json(), copytup_cluster(), copytup_heap(), decompile_conbin(), EventTriggerSQLDropAddObject(), ExecAlterExtensionStmt(), ExecEvalFieldSelect(), ExecGrant_Database(), ExecGrant_Largeobject(), ExecGrant_Tablespace(), ExecGrant_Type(), ExecScanSubPlan(), ExecSetParamPlan(), extension_config_remove(), find_language_template(), GetAttributeByName(), GetAttributeByNum(), GetComment(), GetSecurityLabel(), GetSharedSecurityLabel(), heap_tuple_attr_equals(), pg_extension_config_dump(), pg_identify_object(), pg_largeobject_aclmask_snapshot(), plperl_hash_from_tuple(), pltcl_build_tuple_argument(), pltcl_set_tuple_values(), PLyDict_FromTuple(), readtup_cluster(), readtup_heap(), RelationBuildRuleLock(), RelationGetIndexExpressions(), RelationGetIndexList(), RelationGetIndexPredicate(), RenameRole(), ri_ExtractValues(), ri_KeysEqual(), sepgsql_relation_setattr_extra(), SPI_getbinval(), SPI_getvalue(), std_fetch_func(), SysCacheGetAttr(), and validateDomainConstraint().

#define HEAP_HASEXTERNAL   0x0004

Definition at line 163 of file htup_details.h.

#define HEAP_HASNULL   0x0001

Definition at line 161 of file htup_details.h.

Referenced by heap_fill_tuple(), and heap_page_items().

#define HEAP_HASOID   0x0008
#define HEAP_HASVARWIDTH   0x0002

Definition at line 162 of file htup_details.h.

Referenced by heap_fill_tuple(), and index_form_tuple().

#define HEAP_HOT_UPDATED   0x4000

Definition at line 226 of file htup_details.h.

#define HEAP_KEYS_UPDATED   0x2000
#define HEAP_LOCK_MASK
Value:
(HEAP_XMAX_SHR_LOCK | HEAP_XMAX_EXCL_LOCK | \
                         HEAP_XMAX_KEYSHR_LOCK)

Definition at line 173 of file htup_details.h.

Referenced by compute_new_xmax_infomask().

#define HEAP_MOVED   (HEAP_MOVED_OFF | HEAP_MOVED_IN)
#define HEAP_MOVED_IN   0x8000
#define HEAP_MOVED_OFF   0x4000
#define HEAP_NATTS_MASK   0x07FF

Definition at line 222 of file htup_details.h.

#define HEAP_ONLY_TUPLE   0x8000

Definition at line 227 of file htup_details.h.

#define HEAP_TUPLE_HAS_MATCH   HEAP_ONLY_TUPLE

Definition at line 237 of file htup_details.h.

#define HEAP_UPDATED   0x2000

Definition at line 180 of file htup_details.h.

Referenced by AlterEnum(), heap_update(), and rewrite_heap_tuple().

#define HEAP_XACT_MASK   0xFFF0

Definition at line 189 of file htup_details.h.

Referenced by suppress_redundant_updates_trigger().

#define HEAP_XMAX_BITS
Value:

Definition at line 216 of file htup_details.h.

Referenced by heap_delete(), heap_update(), heap_xlog_delete(), and heap_xlog_update().

#define HEAP_XMAX_COMMITTED   0x0400
#define HEAP_XMAX_EXCL_LOCK   0x0040

Definition at line 167 of file htup_details.h.

Referenced by HeapTupleSatisfiesUpdate(), and HeapTupleSatisfiesVacuum().

#define HEAP_XMAX_INVALID   0x0800
#define HEAP_XMAX_IS_EXCL_LOCKED (   infomask  )     (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_EXCL_LOCK)

Definition at line 210 of file htup_details.h.

Referenced by compute_new_xmax_infomask(), heap_lock_tuple(), and pgrowlocks().

#define HEAP_XMAX_IS_KEYSHR_LOCKED (   infomask  )     (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_KEYSHR_LOCK)
#define HEAP_XMAX_IS_LOCKED_ONLY (   infomask  ) 
#define HEAP_XMAX_IS_MULTI   0x1000
#define HEAP_XMAX_IS_SHR_LOCKED (   infomask  )     (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_SHR_LOCK)

Definition at line 208 of file htup_details.h.

Referenced by compute_new_xmax_infomask(), heap_lock_tuple(), and pgrowlocks().

#define HEAP_XMAX_KEYSHR_LOCK   0x0010
#define HEAP_XMAX_LOCK_ONLY   0x0080
#define HEAP_XMAX_SHR_LOCK   (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)

Definition at line 171 of file htup_details.h.

#define HEAP_XMIN_COMMITTED   0x0100
#define HEAP_XMIN_INVALID   0x0200
#define HeapTupleAllFixed (   tuple  )     (!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH))

Definition at line 551 of file htup_details.h.

#define HeapTupleClearHeapOnly (   tuple  )     HeapTupleHeaderClearHeapOnly((tuple)->t_data)

Definition at line 572 of file htup_details.h.

Referenced by heap_update().

#define HeapTupleClearHotUpdated (   tuple  )     HeapTupleHeaderClearHotUpdated((tuple)->t_data)

Definition at line 563 of file htup_details.h.

Referenced by heap_update().

#define HeapTupleGetOid (   tuple  )     HeapTupleHeaderGetOid((tuple)->t_data)

Definition at line 575 of file htup_details.h.

Referenced by AddEnumLabel(), AfterTriggerSetState(), AlterConstraintNamespaces(), AlterDatabase(), AlterDatabaseOwner(), AlterDomainDropConstraint(), AlterDomainValidateConstraint(), AlterEventTrigger(), AlterEventTriggerOwner(), AlterEventTriggerOwner_internal(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner(), AlterForeignDataWrapperOwner_internal(), AlterForeignServer(), AlterForeignServerOwner(), AlterForeignServerOwner_internal(), AlterObjectOwner_internal(), AlterOpFamily(), AlterRole(), AlterRoleSet(), AlterSchemaOwner(), AlterSchemaOwner_internal(), AlterTableSpaceOptions(), AlterTSConfiguration(), AlterTypeOwner(), ATExecAddColumn(), ATExecAddOf(), ATExecAlterColumnType(), ATExecDropConstraint(), ATExecValidateConstraint(), ATRewriteTable(), boot_openrel(), build_datatype(), CacheInvalidateHeapTuple(), CacheInvalidateRelcacheByTuple(), CatalogCacheComputeTupleHashValue(), check_db_file_conflict(), check_functional_grouping(), check_of_type(), check_role(), check_session_authorization(), checkDomainOwner(), checkEnumOwner(), CheckIndexCompatible(), CollationCreate(), ConversionCreate(), CopyTo(), create_proc_lang(), createdb(), CreateFunction(), decompile_conbin(), DefineDomain(), DefineIndex(), DefineOpClass(), do_autovacuum(), DropConfigurationMapping(), DropRole(), DropTableSpace(), EnableDisableRule(), EnableDisableTrigger(), enum_endpoint(), enum_in(), enum_range_internal(), enum_recv(), exec_object_restorecon(), ExecAlterExtensionStmt(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecuteDoStmt(), find_typed_table_dependencies(), FuncnameGetCandidates(), get_database_list(), get_database_oid(), get_db_info(), get_domain_constraint_oid(), get_extension_oid(), get_opclass_oid(), get_opfamily_oid(), get_rel_oids(), get_relation_constraint_oid(), get_rewrite_oid(), get_rewrite_oid_without_relid(), get_tablespace_oid(), get_trigger_oid(), getConstraintTypeDescription(), GetDefaultOpClass(), GetIndexOpClass(), getRelationsInNamespace(), GetSysCacheOid(), gettype(), getTypeIOParam(), heap_getsysattr(), heap_insert(), heap_modify_tuple(), heap_prepare_insert(), heap_update(), InitializeSessionUserId(), InitPostgres(), InsertRule(), lazy_scan_heap(), load_enum_cache_data(), lookup_C_func(), makeConfigurationDependencies(), MakeConfigurationMapping(), makeDictionaryDependencies(), makeOperatorDependencies(), makeParserDependencies(), makeTSTemplateDependencies(), movedb(), objectsInSchemaToOids(), OpernameGetCandidates(), OpernameGetOprid(), oprid(), pgstat_collect_oids(), PLy_input_datum_func2(), PLy_output_datum_func2(), ProcedureCreate(), record_C_func(), reform_and_rewrite_tuple(), regclassin(), regoperin(), regprocin(), regtypein(), ReindexDatabase(), RelationBuildDesc(), RelationBuildRuleLock(), RelationBuildTriggers(), remove_dbtablespaces(), RemoveAttrDefault(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), SetDefaultACL(), SPI_modifytuple(), toast_flatten_tuple(), transformColumnType(), transformOfType(), TypeCreate(), typenameTypeId(), typenameTypeIdAndMod(), typeTypeId(), vac_truncate_clog(), and validateCheckConstraint().

#define HeapTupleHasExternal (   tuple  )     (((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
#define HeapTupleHasNulls (   tuple  )     (((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0)
#define HeapTupleHasVarWidth (   tuple  )     (((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0)

Definition at line 548 of file htup_details.h.

Referenced by nocachegetattr().

#define HeapTupleHeaderClearHeapOnly (   tup  ) 
Value:
( \
  (tup)->t_infomask2 &= ~HEAP_ONLY_TUPLE \
)

Definition at line 399 of file htup_details.h.

#define HeapTupleHeaderClearHotUpdated (   tup  ) 
Value:
( \
    (tup)->t_infomask2 &= ~HEAP_HOT_UPDATED \
)

Definition at line 384 of file htup_details.h.

Referenced by heap_delete(), heap_freeze_tuple(), heap_lock_tuple(), heap_xlog_delete(), heap_xlog_lock(), and heap_xlog_update().

#define HeapTupleHeaderClearMatch (   tup  ) 
Value:
( \
  (tup)->t_infomask2 &= ~HEAP_TUPLE_HAS_MATCH \
)

Definition at line 414 of file htup_details.h.

Referenced by ExecHashSkewTableInsert(), ExecHashTableInsert(), and ExecHashTableResetMatchFlags().

#define HeapTupleHeaderGetDatumLength (   tup  )     VARSIZE(tup)
#define HeapTupleHeaderGetNatts (   tup  )     ((tup)->t_infomask2 & HEAP_NATTS_MASK)
#define HeapTupleHeaderGetOid (   tup  ) 
Value:
( \
    ((tup)->t_infomask & HEAP_HASOID) ? \
        *((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) \
    : \
        InvalidOid \
)

Definition at line 353 of file htup_details.h.

Referenced by heap_page_items(), suppress_redundant_updates_trigger(), toast_flatten_tuple_attribute(), and toast_insert_or_update().

#define HeapTupleHeaderGetRawCommandId (   tup  ) 
Value:
( \
    (tup)->t_choice.t_heap.t_field3.t_cid \
)

Definition at line 289 of file htup_details.h.

Referenced by heap_getsysattr(), heap_page_items(), HeapTupleHeaderGetCmax(), and HeapTupleHeaderGetCmin().

#define HeapTupleHeaderGetRawXmax (   tup  ) 
#define HeapTupleHeaderGetTypeId (   tup  ) 
#define HeapTupleHeaderGetTypMod (   tup  ) 
#define HeapTupleHeaderGetUpdateXid (   tup  ) 
#define HeapTupleHeaderGetXmin (   tup  ) 
#define HeapTupleHeaderGetXvac (   tup  ) 
#define HeapTupleHeaderHasMatch (   tup  ) 
Value:
( \
  (tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH \
)

Definition at line 404 of file htup_details.h.

Referenced by ExecScanHashTableForUnmatched().

#define HeapTupleHeaderIsHeapOnly (   tup  ) 
Value:
( \
  (tup)->t_infomask2 & HEAP_ONLY_TUPLE \
)

Definition at line 389 of file htup_details.h.

Referenced by heap_get_root_tuples(), and heap_prune_chain().

#define HeapTupleHeaderIsHotUpdated (   tup  ) 
Value:
( \
    ((tup)->t_infomask2 & HEAP_HOT_UPDATED) != 0 && \
    ((tup)->t_infomask & (HEAP_XMIN_INVALID | HEAP_XMAX_INVALID)) == 0 \
)

Definition at line 373 of file htup_details.h.

Referenced by heap_get_root_tuples(), and heap_prune_chain().

#define HeapTupleHeaderSetCmax (   tup,
  cid,
  iscombo 
)
Value:
do { \
    Assert(!((tup)->t_infomask & HEAP_MOVED)); \
    (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \
    if (iscombo) \
        (tup)->t_infomask |= HEAP_COMBOCID; \
    else \
        (tup)->t_infomask &= ~HEAP_COMBOCID; \
} while (0)

Definition at line 303 of file htup_details.h.

Referenced by heap_delete(), heap_update(), heap_xlog_delete(), heap_xlog_lock(), and heap_xlog_update().

#define HeapTupleHeaderSetCmin (   tup,
  cid 
)
Value:
do { \
    Assert(!((tup)->t_infomask & HEAP_MOVED)); \
    (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \
    (tup)->t_infomask &= ~HEAP_COMBOCID; \
} while (0)

Definition at line 295 of file htup_details.h.

Referenced by heap_prepare_insert(), heap_update(), heap_xlog_insert(), heap_xlog_multi_insert(), and heap_xlog_update().

#define HeapTupleHeaderSetDatumLength (   tup,
  len 
)    SET_VARSIZE(tup, len)
#define HeapTupleHeaderSetHeapOnly (   tup  ) 
Value:
( \
  (tup)->t_infomask2 |= HEAP_ONLY_TUPLE \
)

Definition at line 394 of file htup_details.h.

#define HeapTupleHeaderSetHotUpdated (   tup  ) 
Value:
( \
    (tup)->t_infomask2 |= HEAP_HOT_UPDATED \
)

Definition at line 379 of file htup_details.h.

Referenced by heap_xlog_update().

#define HeapTupleHeaderSetMatch (   tup  ) 
Value:
( \
  (tup)->t_infomask2 |= HEAP_TUPLE_HAS_MATCH \
)

Definition at line 409 of file htup_details.h.

Referenced by ExecHashJoin().

#define HeapTupleHeaderSetNatts (   tup,
  natts 
)
Value:
( \
    (tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts) \
)

Definition at line 422 of file htup_details.h.

Referenced by heap_form_minimal_tuple(), heap_form_tuple(), toast_flatten_tuple_attribute(), and toast_insert_or_update().

#define HeapTupleHeaderSetOid (   tup,
  oid 
)
Value:
do { \
    Assert((tup)->t_infomask & HEAP_HASOID); \
    *((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) = (oid); \
} while (0)

Definition at line 361 of file htup_details.h.

Referenced by suppress_redundant_updates_trigger(), toast_flatten_tuple_attribute(), and toast_insert_or_update().

#define HeapTupleHeaderSetTypeId (   tup,
  typeid 
)
Value:
( \
    (tup)->t_choice.t_datum.datum_typeid = (typeid) \
)

Definition at line 338 of file htup_details.h.

Referenced by exec_eval_datum(), ExecEvalWholeRowFast(), ExecEvalWholeRowSlow(), ExecFetchSlotTupleDatum(), heap_form_tuple(), and SPI_returntuple().

#define HeapTupleHeaderSetTypMod (   tup,
  typmod 
)
Value:
( \
    (tup)->t_choice.t_datum.datum_typmod = (typmod) \
)

Definition at line 348 of file htup_details.h.

Referenced by exec_eval_datum(), ExecEvalWholeRowFast(), ExecEvalWholeRowSlow(), ExecFetchSlotTupleDatum(), heap_form_tuple(), and SPI_returntuple().

#define HeapTupleHeaderSetXmax (   tup,
  xid 
)
#define HeapTupleHeaderSetXmin (   tup,
  xid 
)
Value:
( \
    (tup)->t_choice.t_heap.t_xmin = (xid) \
)

Definition at line 251 of file htup_details.h.

Referenced by fill_seq_with_data(), heap_freeze_tuple(), heap_prepare_insert(), heap_update(), heap_xlog_insert(), heap_xlog_multi_insert(), heap_xlog_update(), and RelationReloadIndexInfo().

#define HeapTupleHeaderSetXvac (   tup,
  xid 
)
Value:
do { \
    Assert((tup)->t_infomask & HEAP_MOVED); \
    (tup)->t_choice.t_heap.t_field3.t_xvac = (xid); \
} while (0)

Definition at line 321 of file htup_details.h.

Referenced by heap_freeze_tuple().

#define HeapTupleIsHeapOnly (   tuple  )     HeapTupleHeaderIsHeapOnly((tuple)->t_data)
#define HeapTupleIsHotUpdated (   tuple  )     HeapTupleHeaderIsHotUpdated((tuple)->t_data)

Definition at line 557 of file htup_details.h.

Referenced by heap_hot_search_buffer(), IndexBuildHeapScan(), and lazy_scan_heap().

#define HeapTupleNoNulls (   tuple  )     (!((tuple)->t_data->t_infomask & HEAP_HASNULL))

Definition at line 545 of file htup_details.h.

Referenced by heap_attisnull(), and nocachegetattr().

#define HeapTupleSetHeapOnly (   tuple  )     HeapTupleHeaderSetHeapOnly((tuple)->t_data)

Definition at line 569 of file htup_details.h.

Referenced by heap_update().

#define HeapTupleSetHotUpdated (   tuple  )     HeapTupleHeaderSetHotUpdated((tuple)->t_data)

Definition at line 560 of file htup_details.h.

Referenced by heap_update().

#define HeapTupleSetOid (   tuple,
  oid 
)    HeapTupleHeaderSetOid((tuple)->t_data, (oid))
#define MaxAttrSize   (10 * 1024 * 1024)

Definition at line 469 of file htup_details.h.

Referenced by anybit_typmodin(), and anychar_typmodin().

#define MaxHeapAttributeNumber   1600
#define MaxHeapTupleSize   (BLCKSZ - MAXALIGN(SizeOfPageHeaderData + sizeof(ItemIdData)))
#define MaxHeapTuplesPerPage
#define MaxTupleAttributeNumber   1664
#define MINIMAL_TUPLE_DATA_OFFSET   offsetof(MinimalTupleData, t_infomask2)

Definition at line 507 of file htup_details.h.

Referenced by writetup_heap().

#define MINIMAL_TUPLE_OFFSET   ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)

Definition at line 503 of file htup_details.h.

Referenced by heap_tuple_from_minimal_tuple(), and minimal_tuple_from_heap_tuple().

#define MINIMAL_TUPLE_PADDING   ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF)

Definition at line 505 of file htup_details.h.


Typedef Documentation


Function Documentation

bool heap_attisnull ( HeapTuple  tup,
int  attnum 
)
Size heap_compute_data_size ( TupleDesc  tupleDesc,
Datum values,
bool isnull 
)

Definition at line 84 of file heaptuple.c.

References att_addlength_datum, att_align_datum, ATT_IS_PACKABLE, tupleDesc::attrs, DatumGetPointer, i, tupleDesc::natts, val, VARATT_CAN_MAKE_SHORT, and VARATT_CONVERTED_SHORT_SIZE.

Referenced by heap_form_minimal_tuple(), heap_form_tuple(), index_form_tuple(), toast_flatten_tuple_attribute(), and toast_insert_or_update().

{
    Size        data_length = 0;
    int         i;
    int         numberOfAttributes = tupleDesc->natts;
    Form_pg_attribute *att = tupleDesc->attrs;

    for (i = 0; i < numberOfAttributes; i++)
    {
        Datum       val;

        if (isnull[i])
            continue;

        val = values[i];

        if (ATT_IS_PACKABLE(att[i]) &&
            VARATT_CAN_MAKE_SHORT(DatumGetPointer(val)))
        {
            /*
             * we're anticipating converting to a short varlena header, so
             * adjust length and don't count any alignment
             */
            data_length += VARATT_CONVERTED_SHORT_SIZE(DatumGetPointer(val));
        }
        else
        {
            data_length = att_align_datum(data_length, att[i]->attalign,
                                          att[i]->attlen, val);
            data_length = att_addlength_datum(data_length, att[i]->attlen,
                                              val);
        }
    }

    return data_length;
}

MinimalTuple heap_copy_minimal_tuple ( MinimalTuple  mtup  ) 

Definition at line 1487 of file heaptuple.c.

References palloc(), and MinimalTupleData::t_len.

Referenced by ExecCopySlotMinimalTuple(), and tuplestore_gettupleslot().

{
    MinimalTuple result;

    result = (MinimalTuple) palloc(mtup->t_len);
    memcpy(result, mtup, mtup->t_len);
    return result;
}

HeapTuple heap_copytuple ( HeapTuple  tuple  ) 
void heap_copytuple_with_tuple ( HeapTuple  src,
HeapTuple  dest 
)

Definition at line 605 of file heaptuple.c.

References HeapTupleIsValid, NULL, palloc(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, and HeapTupleData::t_tableOid.

Referenced by CatalogCacheCreateEntry(), exec_eval_datum(), and SearchCatCacheList().

{
    if (!HeapTupleIsValid(src) || src->t_data == NULL)
    {
        dest->t_data = NULL;
        return;
    }

    dest->t_len = src->t_len;
    dest->t_self = src->t_self;
    dest->t_tableOid = src->t_tableOid;
    dest->t_data = (HeapTupleHeader) palloc(src->t_len);
    memcpy((char *) dest->t_data, (char *) src->t_data, src->t_len);
}

void heap_deform_tuple ( HeapTuple  tuple,
TupleDesc  tupleDesc,
Datum values,
bool isnull 
)

Definition at line 886 of file heaptuple.c.

References att_addlength_pointer, att_align_nominal, att_align_pointer, att_isnull, tupleDesc::attrs, fetchatt, HeapTupleHasNulls, HeapTupleHeaderGetNatts, Min, tupleDesc::natts, HeapTupleHeaderData::t_bits, HeapTupleData::t_data, and HeapTupleHeaderData::t_hoff.

Referenced by ATRewriteTable(), CopyTo(), do_convert_tuple(), ExecEvalFieldStore(), heap_deformtuple(), heap_modify_tuple(), hstore_from_record(), hstore_populate_record(), json_populate_record(), populate_recordset_object_end(), record_cmp(), record_eq(), record_out(), record_send(), reform_and_rewrite_tuple(), SPI_modifytuple(), toast_delete(), toast_flatten_tuple(), toast_flatten_tuple_attribute(), and toast_insert_or_update().

{
    HeapTupleHeader tup = tuple->t_data;
    bool        hasnulls = HeapTupleHasNulls(tuple);
    Form_pg_attribute *att = tupleDesc->attrs;
    int         tdesc_natts = tupleDesc->natts;
    int         natts;          /* number of atts to extract */
    int         attnum;
    char       *tp;             /* ptr to tuple data */
    long        off;            /* offset in tuple data */
    bits8      *bp = tup->t_bits;       /* ptr to null bitmap in tuple */
    bool        slow = false;   /* can we use/set attcacheoff? */

    natts = HeapTupleHeaderGetNatts(tup);

    /*
     * In inheritance situations, it is possible that the given tuple actually
     * has more fields than the caller is expecting.  Don't run off the end of
     * the caller's arrays.
     */
    natts = Min(natts, tdesc_natts);

    tp = (char *) tup + tup->t_hoff;

    off = 0;

    for (attnum = 0; attnum < natts; attnum++)
    {
        Form_pg_attribute thisatt = att[attnum];

        if (hasnulls && att_isnull(attnum, bp))
        {
            values[attnum] = (Datum) 0;
            isnull[attnum] = true;
            slow = true;        /* can't use attcacheoff anymore */
            continue;
        }

        isnull[attnum] = false;

        if (!slow && thisatt->attcacheoff >= 0)
            off = thisatt->attcacheoff;
        else if (thisatt->attlen == -1)
        {
            /*
             * We can only cache the offset for a varlena attribute if the
             * offset is already suitably aligned, so that there would be no
             * pad bytes in any case: then the offset will be valid for either
             * an aligned or unaligned value.
             */
            if (!slow &&
                off == att_align_nominal(off, thisatt->attalign))
                thisatt->attcacheoff = off;
            else
            {
                off = att_align_pointer(off, thisatt->attalign, -1,
                                        tp + off);
                slow = true;
            }
        }
        else
        {
            /* not varlena, so safe to use att_align_nominal */
            off = att_align_nominal(off, thisatt->attalign);

            if (!slow)
                thisatt->attcacheoff = off;
        }

        values[attnum] = fetchatt(thisatt, tp + off);

        off = att_addlength_pointer(off, thisatt->attlen, tp + off);

        if (thisatt->attlen <= 0)
            slow = true;        /* can't use attcacheoff anymore */
    }

    /*
     * If tuple doesn't have all the atts indicated by tupleDesc, read the
     * rest as null
     */
    for (; attnum < tdesc_natts; attnum++)
    {
        values[attnum] = (Datum) 0;
        isnull[attnum] = true;
    }
}

void heap_deformtuple ( HeapTuple  tuple,
TupleDesc  tupleDesc,
Datum values,
char *  nulls 
)

Definition at line 998 of file heaptuple.c.

References heap_deform_tuple(), tupleDesc::natts, palloc(), and pfree().

{
    int         natts = tupleDesc->natts;
    bool       *boolNulls = (bool *) palloc(natts * sizeof(bool));
    int         attnum;

    heap_deform_tuple(tuple, tupleDesc, values, boolNulls);

    for (attnum = 0; attnum < natts; attnum++)
        nulls[attnum] = (boolNulls[attnum] ? 'n' : ' ');

    pfree(boolNulls);
}

void heap_fill_tuple ( TupleDesc  tupleDesc,
Datum values,
bool isnull,
char *  data,
Size  data_size,
uint16 infomask,
bits8 bit 
)

Definition at line 133 of file heaptuple.c.

References Assert, att_align_nominal, tupleDesc::attrs, DatumGetCString, DatumGetPointer, HEAP_HASNULL, HEAP_HASVARWIDTH, HIGHBIT, i, tupleDesc::natts, NULL, SET_VARSIZE_SHORT, store_att_byval, val, VARATT_CAN_MAKE_SHORT, VARATT_CONVERTED_SHORT_SIZE, VARATT_IS_EXTERNAL, VARATT_IS_SHORT, VARDATA, VARLENA_ATT_IS_PACKABLE, VARSIZE, VARSIZE_EXTERNAL, and VARSIZE_SHORT.

Referenced by heap_form_minimal_tuple(), heap_form_tuple(), index_form_tuple(), toast_flatten_tuple_attribute(), and toast_insert_or_update().

{
    bits8      *bitP;
    int         bitmask;
    int         i;
    int         numberOfAttributes = tupleDesc->natts;
    Form_pg_attribute *att = tupleDesc->attrs;

#ifdef USE_ASSERT_CHECKING
    char       *start = data;
#endif

    if (bit != NULL)
    {
        bitP = &bit[-1];
        bitmask = HIGHBIT;
    }
    else
    {
        /* just to keep compiler quiet */
        bitP = NULL;
        bitmask = 0;
    }

    *infomask &= ~(HEAP_HASNULL | HEAP_HASVARWIDTH | HEAP_HASEXTERNAL);

    for (i = 0; i < numberOfAttributes; i++)
    {
        Size        data_length;

        if (bit != NULL)
        {
            if (bitmask != HIGHBIT)
                bitmask <<= 1;
            else
            {
                bitP += 1;
                *bitP = 0x0;
                bitmask = 1;
            }

            if (isnull[i])
            {
                *infomask |= HEAP_HASNULL;
                continue;
            }

            *bitP |= bitmask;
        }

        /*
         * XXX we use the att_align macros on the pointer value itself, not on
         * an offset.  This is a bit of a hack.
         */

        if (att[i]->attbyval)
        {
            /* pass-by-value */
            data = (char *) att_align_nominal(data, att[i]->attalign);
            store_att_byval(data, values[i], att[i]->attlen);
            data_length = att[i]->attlen;
        }
        else if (att[i]->attlen == -1)
        {
            /* varlena */
            Pointer     val = DatumGetPointer(values[i]);

            *infomask |= HEAP_HASVARWIDTH;
            if (VARATT_IS_EXTERNAL(val))
            {
                *infomask |= HEAP_HASEXTERNAL;
                /* no alignment, since it's short by definition */
                data_length = VARSIZE_EXTERNAL(val);
                memcpy(data, val, data_length);
            }
            else if (VARATT_IS_SHORT(val))
            {
                /* no alignment for short varlenas */
                data_length = VARSIZE_SHORT(val);
                memcpy(data, val, data_length);
            }
            else if (VARLENA_ATT_IS_PACKABLE(att[i]) &&
                     VARATT_CAN_MAKE_SHORT(val))
            {
                /* convert to short varlena -- no alignment */
                data_length = VARATT_CONVERTED_SHORT_SIZE(val);
                SET_VARSIZE_SHORT(data, data_length);
                memcpy(data + 1, VARDATA(val), data_length - 1);
            }
            else
            {
                /* full 4-byte header varlena */
                data = (char *) att_align_nominal(data,
                                                  att[i]->attalign);
                data_length = VARSIZE(val);
                memcpy(data, val, data_length);
            }
        }
        else if (att[i]->attlen == -2)
        {
            /* cstring ... never needs alignment */
            *infomask |= HEAP_HASVARWIDTH;
            Assert(att[i]->attalign == 'c');
            data_length = strlen(DatumGetCString(values[i])) + 1;
            memcpy(data, DatumGetPointer(values[i]), data_length);
        }
        else
        {
            /* fixed-length pass-by-reference */
            data = (char *) att_align_nominal(data, att[i]->attalign);
            Assert(att[i]->attlen > 0);
            data_length = att[i]->attlen;
            memcpy(data, DatumGetPointer(values[i]), data_length);
        }

        data += data_length;
    }

    Assert((data - start) == data_size);
}

MinimalTuple heap_form_minimal_tuple ( TupleDesc  tupleDescriptor,
Datum values,
bool isnull 
)

Definition at line 1383 of file heaptuple.c.

References tupleDesc::attrs, BITMAPLEN, ereport, errcode(), errmsg(), ERROR, heap_compute_data_size(), heap_fill_tuple(), HeapTupleHeaderSetNatts, i, MAXALIGN, MaxTupleAttributeNumber, tupleDesc::natts, NULL, offsetof, palloc0(), MinimalTupleData::t_bits, MinimalTupleData::t_hoff, MinimalTupleData::t_infomask, MinimalTupleData::t_len, tupleDesc::tdhasoid, toast_flatten_tuple_attribute(), and VARATT_IS_EXTENDED.

Referenced by ExecCopySlotMinimalTuple(), and tuplestore_putvalues().

{
    MinimalTuple tuple;         /* return tuple */
    Size        len,
                data_len;
    int         hoff;
    bool        hasnull = false;
    Form_pg_attribute *att = tupleDescriptor->attrs;
    int         numberOfAttributes = tupleDescriptor->natts;
    int         i;

    if (numberOfAttributes > MaxTupleAttributeNumber)
        ereport(ERROR,
                (errcode(ERRCODE_TOO_MANY_COLUMNS),
                 errmsg("number of columns (%d) exceeds limit (%d)",
                        numberOfAttributes, MaxTupleAttributeNumber)));

    /*
     * Check for nulls and embedded tuples; expand any toasted attributes in
     * embedded tuples.  This preserves the invariant that toasting can only
     * go one level deep.
     *
     * We can skip calling toast_flatten_tuple_attribute() if the attribute
     * couldn't possibly be of composite type.  All composite datums are
     * varlena and have alignment 'd'; furthermore they aren't arrays. Also,
     * if an attribute is already toasted, it must have been sent to disk
     * already and so cannot contain toasted attributes.
     */
    for (i = 0; i < numberOfAttributes; i++)
    {
        if (isnull[i])
            hasnull = true;
        else if (att[i]->attlen == -1 &&
                 att[i]->attalign == 'd' &&
                 att[i]->attndims == 0 &&
                 !VARATT_IS_EXTENDED(values[i]))
        {
            values[i] = toast_flatten_tuple_attribute(values[i],
                                                      att[i]->atttypid,
                                                      att[i]->atttypmod);
        }
    }

    /*
     * Determine total space needed
     */
    len = offsetof(MinimalTupleData, t_bits);

    if (hasnull)
        len += BITMAPLEN(numberOfAttributes);

    if (tupleDescriptor->tdhasoid)
        len += sizeof(Oid);

    hoff = len = MAXALIGN(len); /* align user data safely */

    data_len = heap_compute_data_size(tupleDescriptor, values, isnull);

    len += data_len;

    /*
     * Allocate and zero the space needed.
     */
    tuple = (MinimalTuple) palloc0(len);

    /*
     * And fill in the information.
     */
    tuple->t_len = len;
    HeapTupleHeaderSetNatts(tuple, numberOfAttributes);
    tuple->t_hoff = hoff + MINIMAL_TUPLE_OFFSET;

    if (tupleDescriptor->tdhasoid)      /* else leave infomask = 0 */
        tuple->t_infomask = HEAP_HASOID;

    heap_fill_tuple(tupleDescriptor,
                    values,
                    isnull,
                    (char *) tuple + hoff,
                    data_len,
                    &tuple->t_infomask,
                    (hasnull ? tuple->t_bits : NULL));

    return tuple;
}

HeapTuple heap_form_tuple ( TupleDesc  tupleDescriptor,
Datum values,
bool isnull 
)

Definition at line 628 of file heaptuple.c.

References tupleDesc::attrs, BITMAPLEN, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, heap_compute_data_size(), heap_fill_tuple(), HeapTupleHeaderSetDatumLength, HeapTupleHeaderSetNatts, HeapTupleHeaderSetTypeId, HeapTupleHeaderSetTypMod, HEAPTUPLESIZE, i, ItemPointerSetInvalid, MAXALIGN, MaxTupleAttributeNumber, tupleDesc::natts, NULL, offsetof, palloc0(), HeapTupleHeaderData::t_bits, HeapTupleData::t_data, HeapTupleHeaderData::t_hoff, HeapTupleHeaderData::t_infomask, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, tupleDesc::tdhasoid, tupleDesc::tdtypeid, tupleDesc::tdtypmod, toast_flatten_tuple_attribute(), and VARATT_IS_EXTENDED.

Referenced by aclexplode(), AddEnumLabel(), AddRoleMems(), AggregateCreate(), AlterSetting(), ATRewriteTable(), build_dummy_tuple(), BuildTupleFromCStrings(), CollationCreate(), ConversionCreate(), CopyFrom(), create_proc_lang(), CreateCast(), CreateComments(), CreateConstraintEntry(), createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreateRole(), CreateSharedComments(), CreateTableSpace(), CreateTrigger(), CreateUserMapping(), DefineOpClass(), DefineSequence(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), do_convert_tuple(), each_object_field_end(), elements_array_element_end(), EnumValuesCreate(), exec_move_row(), ExecCopySlotTuple(), ExecEvalFieldStore(), ExecEvalRow(), file_acquire_sample_rows(), heap_formtuple(), heap_modify_tuple(), heap_page_items(), hstore_each(), hstore_populate_record(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertOneTuple(), InsertPgAttributeTuple(), InsertPgClassTuple(), InsertRule(), inv_truncate(), inv_write(), json_populate_record(), LargeObjectCreate(), make_tuple_from_result_row(), make_tuple_from_row(), MakeConfigurationMapping(), NamespaceCreate(), OperatorCreate(), OperatorShellMake(), page_header(), pg_buffercache_pages(), pg_identify_object(), pg_lock_status(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_activity(), pg_timezone_abbrevs(), pg_timezone_names(), pg_xlogfile_name_offset(), pgstatginindex(), plperl_build_tuple_result(), PLyGenericObject_ToComposite(), PLyMapping_ToComposite(), PLySequence_ToComposite(), populate_recordset_object_end(), ProcedureCreate(), RangeCreate(), record_in(), record_recv(), recordMultipleDependencies(), reform_and_rewrite_tuple(), SetDefaultACL(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepAddDependency(), shdepChangeDep(), SPI_modifytuple(), StoreAttrDefault(), StoreCatalogInheritance1(), storeOperators(), storeProcedures(), toast_flatten_tuple(), toast_save_datum(), TypeCreate(), TypeShellMake(), update_attstats(), and UpdateIndexRelation().

{
    HeapTuple   tuple;          /* return tuple */
    HeapTupleHeader td;         /* tuple data */
    Size        len,
                data_len;
    int         hoff;
    bool        hasnull = false;
    Form_pg_attribute *att = tupleDescriptor->attrs;
    int         numberOfAttributes = tupleDescriptor->natts;
    int         i;

    if (numberOfAttributes > MaxTupleAttributeNumber)
        ereport(ERROR,
                (errcode(ERRCODE_TOO_MANY_COLUMNS),
                 errmsg("number of columns (%d) exceeds limit (%d)",
                        numberOfAttributes, MaxTupleAttributeNumber)));

    /*
     * Check for nulls and embedded tuples; expand any toasted attributes in
     * embedded tuples.  This preserves the invariant that toasting can only
     * go one level deep.
     *
     * We can skip calling toast_flatten_tuple_attribute() if the attribute
     * couldn't possibly be of composite type.  All composite datums are
     * varlena and have alignment 'd'; furthermore they aren't arrays. Also,
     * if an attribute is already toasted, it must have been sent to disk
     * already and so cannot contain toasted attributes.
     */
    for (i = 0; i < numberOfAttributes; i++)
    {
        if (isnull[i])
            hasnull = true;
        else if (att[i]->attlen == -1 &&
                 att[i]->attalign == 'd' &&
                 att[i]->attndims == 0 &&
                 !VARATT_IS_EXTENDED(DatumGetPointer(values[i])))
        {
            values[i] = toast_flatten_tuple_attribute(values[i],
                                                      att[i]->atttypid,
                                                      att[i]->atttypmod);
        }
    }

    /*
     * Determine total space needed
     */
    len = offsetof(HeapTupleHeaderData, t_bits);

    if (hasnull)
        len += BITMAPLEN(numberOfAttributes);

    if (tupleDescriptor->tdhasoid)
        len += sizeof(Oid);

    hoff = len = MAXALIGN(len); /* align user data safely */

    data_len = heap_compute_data_size(tupleDescriptor, values, isnull);

    len += data_len;

    /*
     * Allocate and zero the space needed.  Note that the tuple body and
     * HeapTupleData management structure are allocated in one chunk.
     */
    tuple = (HeapTuple) palloc0(HEAPTUPLESIZE + len);
    tuple->t_data = td = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);

    /*
     * And fill in the information.  Note we fill the Datum fields even though
     * this tuple may never become a Datum.
     */
    tuple->t_len = len;
    ItemPointerSetInvalid(&(tuple->t_self));
    tuple->t_tableOid = InvalidOid;

    HeapTupleHeaderSetDatumLength(td, len);
    HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
    HeapTupleHeaderSetTypMod(td, tupleDescriptor->tdtypmod);

    HeapTupleHeaderSetNatts(td, numberOfAttributes);
    td->t_hoff = hoff;

    if (tupleDescriptor->tdhasoid)      /* else leave infomask = 0 */
        td->t_infomask = HEAP_HASOID;

    heap_fill_tuple(tupleDescriptor,
                    values,
                    isnull,
                    (char *) td + hoff,
                    data_len,
                    &td->t_infomask,
                    (hasnull ? td->t_bits : NULL));

    return tuple;
}

HeapTuple heap_formtuple ( TupleDesc  tupleDescriptor,
Datum values,
char *  nulls 
)

Definition at line 740 of file heaptuple.c.

References heap_form_tuple(), i, tupleDesc::natts, palloc(), and pfree().

{
    HeapTuple   tuple;          /* return tuple */
    int         numberOfAttributes = tupleDescriptor->natts;
    bool       *boolNulls = (bool *) palloc(numberOfAttributes * sizeof(bool));
    int         i;

    for (i = 0; i < numberOfAttributes; i++)
        boolNulls[i] = (nulls[i] == 'n');

    tuple = heap_form_tuple(tupleDescriptor, values, boolNulls);

    pfree(boolNulls);

    return tuple;
}

void heap_free_minimal_tuple ( MinimalTuple  mtup  ) 

Definition at line 1475 of file heaptuple.c.

References pfree().

Referenced by ExecClearTuple(), ExecStoreMinimalTuple(), ExecStoreTuple(), and writetup_heap().

{
    pfree(mtup);
}

void heap_freetuple ( HeapTuple  htup  ) 

Definition at line 1365 of file heaptuple.c.

References pfree().

Referenced by acquire_inherited_sample_rows(), acquire_sample_rows(), AddEnumLabel(), AfterTriggerExecute(), AlterDatabaseOwner(), AlterDomainDefault(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEventTrigger(), AlterEventTriggerOwner(), AlterEventTriggerOwner_oid(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner(), AlterForeignDataWrapperOwner_oid(), AlterForeignServer(), AlterForeignServerOwner(), AlterForeignServerOwner_oid(), AlterFunction(), AlterObjectRename_internal(), AlterRelationNamespaceInternal(), AlterRole(), AlterSchemaOwner_internal(), AlterTableSpaceOptions(), AlterTSDictionary(), AlterTypeNamespaceInternal(), AlterUserMapping(), analyze_row_processor(), ATExecAddColumn(), ATExecAddOf(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecChangeOwner(), ATExecDropColumn(), ATExecDropConstraint(), ATExecDropInherit(), ATExecDropOf(), ATExecGenericOptions(), ATExecSetOptions(), ATExecSetRelOptions(), ATExecSetStatistics(), ATExecSetStorage(), ATExecSetTableSpace(), ATExecValidateConstraint(), build_tuplestore_recursively(), CatalogCacheCreateEntry(), change_owner_fix_column_acls(), changeDependencyFor(), CollationCreate(), ConversionCreate(), copy_heap_data(), copyTemplateDependencies(), create_toast_table(), CreateCast(), CreateComments(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreateSharedComments(), CreateTableSpace(), CreateTrigger(), CreateUserMapping(), crosstab(), DefineOpClass(), DefineQueryRewrite(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), EnableDisableRule(), EnableDisableTrigger(), EnumValuesCreate(), EvalPlanQualSetTuple(), examine_attribute(), exec_assign_value(), exec_move_row(), exec_stmt_block(), exec_stmt_return_next(), exec_stmt_return_query(), ExecARDeleteTriggers(), ExecARUpdateTriggers(), ExecBRDeleteTriggers(), ExecBRInsertTriggers(), ExecBRUpdateTriggers(), ExecClearTuple(), ExecIRDeleteTriggers(), ExecIRInsertTriggers(), ExecIRUpdateTriggers(), ExecReScanAgg(), ExecReScanSetOp(), ExecScanSubPlan(), ExecSetParamPlan(), ExecStoreMinimalTuple(), ExecStoreTuple(), file_acquire_sample_rows(), heap_insert(), heap_update(), index_build(), index_constraint_create(), index_update_stats(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertOneTuple(), InsertPgAttributeTuple(), InsertPgClassTuple(), InsertRule(), inv_truncate(), inv_write(), LargeObjectCreate(), MakeConfigurationMapping(), mark_index_clustered(), MergeAttributesIntoExisting(), MergeConstraintsIntoExisting(), OperatorShellMake(), ProcedureCreate(), RangeCreate(), raw_heap_insert(), record_in(), record_recv(), recordMultipleDependencies(), reform_and_rewrite_tuple(), RelationBuildDesc(), RelationReloadIndexInfo(), RelationSetNewRelfilenode(), RemoveConstraintById(), renameatt_internal(), RenameConstraintById(), RenameRelationInternal(), RenameRewriteRule(), RenameSchema(), RenameTypeInternal(), RenumberEnumType(), rewrite_heap_dead_tuple(), rewrite_heap_tuple(), SearchCatCache(), SearchCatCacheList(), SetRelationHasSubclass(), SetRelationNumChecks(), SetRelationRuleStatus(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepAddDependency(), shdepChangeDep(), SPI_freetuple(), StoreAttrDefault(), StoreCatalogInheritance1(), storeOperators(), storeProcedures(), swap_relation_files(), table_recheck_autovac(), toast_save_datum(), TypeShellMake(), update_attstats(), UpdateIndexRelation(), vac_update_datfrozenxid(), writetup_cluster(), and xpath_table().

{
    pfree(htup);
}

Datum heap_getsysattr ( HeapTuple  tup,
int  attnum,
TupleDesc  tupleDesc,
bool isnull 
)

Definition at line 523 of file heaptuple.c.

References Assert, CommandIdGetDatum, elog, ERROR, HeapTupleGetOid, HeapTupleHeaderGetRawCommandId, HeapTupleHeaderGetRawXmax, HeapTupleHeaderGetXmin, MaxCommandIdAttributeNumber, MaxTransactionIdAttributeNumber, MinCommandIdAttributeNumber, MinTransactionIdAttributeNumber, ObjectIdAttributeNumber, ObjectIdGetDatum, PointerGetDatum, SelfItemPointerAttributeNumber, HeapTupleData::t_data, HeapTupleData::t_self, HeapTupleData::t_tableOid, TableOidAttributeNumber, and TransactionIdGetDatum.

Referenced by slot_getattr().

{
    Datum       result;

    Assert(tup);

    /* Currently, no sys attribute ever reads as NULL. */
    *isnull = false;

    switch (attnum)
    {
        case SelfItemPointerAttributeNumber:
            /* pass-by-reference datatype */
            result = PointerGetDatum(&(tup->t_self));
            break;
        case ObjectIdAttributeNumber:
            result = ObjectIdGetDatum(HeapTupleGetOid(tup));
            break;
        case MinTransactionIdAttributeNumber:
            result = TransactionIdGetDatum(HeapTupleHeaderGetXmin(tup->t_data));
            break;
        case MaxTransactionIdAttributeNumber:
            result = TransactionIdGetDatum(HeapTupleHeaderGetRawXmax(tup->t_data));
            break;
        case MinCommandIdAttributeNumber:
        case MaxCommandIdAttributeNumber:

            /*
             * cmin and cmax are now both aliases for the same field, which
             * can in fact also be a combo command id.  XXX perhaps we should
             * return the "real" cmin or cmax if possible, that is if we are
             * inside the originating transaction?
             */
            result = CommandIdGetDatum(HeapTupleHeaderGetRawCommandId(tup->t_data));
            break;
        case TableOidAttributeNumber:
            result = ObjectIdGetDatum(tup->t_tableOid);
            break;
        default:
            elog(ERROR, "invalid attnum: %d", attnum);
            result = 0;         /* keep compiler quiet */
            break;
    }
    return result;
}

HeapTuple heap_modify_tuple ( HeapTuple  tuple,
TupleDesc  tupleDesc,
Datum replValues,
bool replIsnull,
bool doReplace 
)

Definition at line 772 of file heaptuple.c.

References heap_deform_tuple(), heap_form_tuple(), HeapTupleGetOid, HeapTupleSetOid, tupleDesc::natts, palloc(), pfree(), HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleData::t_self, HeapTupleData::t_tableOid, tupleDesc::tdhasoid, and values.

Referenced by AddRoleMems(), AlterDatabase(), AlterDatabaseOwner(), AlterDomainDefault(), AlterForeignDataWrapper(), AlterForeignServer(), AlterFunction(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterRole(), AlterSchemaOwner_internal(), AlterSetting(), AlterTableSpaceOptions(), AlterTSDictionary(), AlterUserMapping(), ApplyExtensionUpdates(), ATExecAlterColumnGenericOptions(), ATExecChangeOwner(), ATExecGenericOptions(), ATExecSetOptions(), ATExecSetRelOptions(), change_owner_fix_column_acls(), copyTemplateDependencies(), create_proc_lang(), CreateComments(), CreateSharedComments(), DelRoleMems(), exec_assign_value(), 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(), heap_modifytuple(), InsertRule(), inv_truncate(), inv_write(), MakeConfigurationMapping(), movedb(), OperatorCreate(), OperatorUpd(), pg_extension_config_dump(), ProcedureCreate(), RenameRole(), SetDefaultACL(), SetSecurityLabel(), SetSharedSecurityLabel(), TypeCreate(), and update_attstats().

{
    int         numberOfAttributes = tupleDesc->natts;
    int         attoff;
    Datum      *values;
    bool       *isnull;
    HeapTuple   newTuple;

    /*
     * allocate and fill values and isnull arrays from either the tuple or the
     * repl information, as appropriate.
     *
     * NOTE: it's debatable whether to use heap_deform_tuple() here or just
     * heap_getattr() only the non-replaced colums.  The latter could win if
     * there are many replaced columns and few non-replaced ones. However,
     * heap_deform_tuple costs only O(N) while the heap_getattr way would cost
     * O(N^2) if there are many non-replaced columns, so it seems better to
     * err on the side of linear cost.
     */
    values = (Datum *) palloc(numberOfAttributes * sizeof(Datum));
    isnull = (bool *) palloc(numberOfAttributes * sizeof(bool));

    heap_deform_tuple(tuple, tupleDesc, values, isnull);

    for (attoff = 0; attoff < numberOfAttributes; attoff++)
    {
        if (doReplace[attoff])
        {
            values[attoff] = replValues[attoff];
            isnull[attoff] = replIsnull[attoff];
        }
    }

    /*
     * create a new tuple from the values and isnull arrays
     */
    newTuple = heap_form_tuple(tupleDesc, values, isnull);

    pfree(values);
    pfree(isnull);

    /*
     * copy the identification info of the old tuple: t_ctid, t_self, and OID
     * (if any)
     */
    newTuple->t_data->t_ctid = tuple->t_data->t_ctid;
    newTuple->t_self = tuple->t_self;
    newTuple->t_tableOid = tuple->t_tableOid;
    if (tupleDesc->tdhasoid)
        HeapTupleSetOid(newTuple, HeapTupleGetOid(tuple));

    return newTuple;
}

HeapTuple heap_modifytuple ( HeapTuple  tuple,
TupleDesc  tupleDesc,
Datum replValues,
char *  replNulls,
char *  replActions 
)

Definition at line 842 of file heaptuple.c.

References heap_modify_tuple(), tupleDesc::natts, palloc(), and pfree().

{
    HeapTuple   result;
    int         numberOfAttributes = tupleDesc->natts;
    bool       *boolNulls = (bool *) palloc(numberOfAttributes * sizeof(bool));
    bool       *boolActions = (bool *) palloc(numberOfAttributes * sizeof(bool));
    int         attnum;

    for (attnum = 0; attnum < numberOfAttributes; attnum++)
    {
        boolNulls[attnum] = (replNulls[attnum] == 'n');
        boolActions[attnum] = (replActions[attnum] == 'r');
    }

    result = heap_modify_tuple(tuple, tupleDesc, replValues, boolNulls, boolActions);

    pfree(boolNulls);
    pfree(boolActions);

    return result;
}

HeapTuple heap_tuple_from_minimal_tuple ( MinimalTuple  mtup  ) 

Definition at line 1506 of file heaptuple.c.

References HEAPTUPLESIZE, ItemPointerSetInvalid, MINIMAL_TUPLE_OFFSET, offsetof, palloc(), HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::t_len, HeapTupleData::t_self, and HeapTupleData::t_tableOid.

Referenced by ExecCopySlotTuple().

{
    HeapTuple   result;
    uint32      len = mtup->t_len + MINIMAL_TUPLE_OFFSET;

    result = (HeapTuple) palloc(HEAPTUPLESIZE + len);
    result->t_len = len;
    ItemPointerSetInvalid(&(result->t_self));
    result->t_tableOid = InvalidOid;
    result->t_data = (HeapTupleHeader) ((char *) result + HEAPTUPLESIZE);
    memcpy((char *) result->t_data + MINIMAL_TUPLE_OFFSET, mtup, mtup->t_len);
    memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_infomask2));
    return result;
}

MinimalTuple minimal_tuple_from_heap_tuple ( HeapTuple  htup  ) 

Definition at line 1528 of file heaptuple.c.

References Assert, MINIMAL_TUPLE_OFFSET, palloc(), HeapTupleData::t_data, MinimalTupleData::t_len, and HeapTupleData::t_len.

Referenced by copytup_heap(), and ExecCopySlotMinimalTuple().

{
    MinimalTuple result;
    uint32      len;

    Assert(htup->t_len > MINIMAL_TUPLE_OFFSET);
    len = htup->t_len - MINIMAL_TUPLE_OFFSET;
    result = (MinimalTuple) palloc(len);
    memcpy(result, (char *) htup->t_data + MINIMAL_TUPLE_OFFSET, len);
    result->t_len = len;
    return result;
}

Datum nocachegetattr ( HeapTuple  tup,
int  attnum,
TupleDesc  att 
)

Definition at line 323 of file heaptuple.c.

References Assert, att_addlength_pointer, att_align_nominal, att_align_pointer, att_isnull, tupleDesc::attrs, byte, fetchatt, HeapTupleHasNulls, HeapTupleHasVarWidth, HeapTupleNoNulls, i, tupleDesc::natts, HeapTupleHeaderData::t_bits, HeapTupleData::t_data, and HeapTupleHeaderData::t_hoff.

{
    HeapTupleHeader tup = tuple->t_data;
    Form_pg_attribute *att = tupleDesc->attrs;
    char       *tp;             /* ptr to data part of tuple */
    bits8      *bp = tup->t_bits;       /* ptr to null bitmap in tuple */
    bool        slow = false;   /* do we have to walk attrs? */
    int         off;            /* current offset within data */

    /* ----------------
     *   Three cases:
     *
     *   1: No nulls and no variable-width attributes.
     *   2: Has a null or a var-width AFTER att.
     *   3: Has nulls or var-widths BEFORE att.
     * ----------------
     */

    attnum--;

    if (!HeapTupleNoNulls(tuple))
    {
        /*
         * there's a null somewhere in the tuple
         *
         * check to see if any preceding bits are null...
         */
        int         byte = attnum >> 3;
        int         finalbit = attnum & 0x07;

        /* check for nulls "before" final bit of last byte */
        if ((~bp[byte]) & ((1 << finalbit) - 1))
            slow = true;
        else
        {
            /* check for nulls in any "earlier" bytes */
            int         i;

            for (i = 0; i < byte; i++)
            {
                if (bp[i] != 0xFF)
                {
                    slow = true;
                    break;
                }
            }
        }
    }

    tp = (char *) tup + tup->t_hoff;

    if (!slow)
    {
        /*
         * If we get here, there are no nulls up to and including the target
         * attribute.  If we have a cached offset, we can use it.
         */
        if (att[attnum]->attcacheoff >= 0)
        {
            return fetchatt(att[attnum],
                            tp + att[attnum]->attcacheoff);
        }

        /*
         * Otherwise, check for non-fixed-length attrs up to and including
         * target.  If there aren't any, it's safe to cheaply initialize the
         * cached offsets for these attrs.
         */
        if (HeapTupleHasVarWidth(tuple))
        {
            int         j;

            for (j = 0; j <= attnum; j++)
            {
                if (att[j]->attlen <= 0)
                {
                    slow = true;
                    break;
                }
            }
        }
    }

    if (!slow)
    {
        int         natts = tupleDesc->natts;
        int         j = 1;

        /*
         * If we get here, we have a tuple with no nulls or var-widths up to
         * and including the target attribute, so we can use the cached offset
         * ... only we don't have it yet, or we'd not have got here.  Since
         * it's cheap to compute offsets for fixed-width columns, we take the
         * opportunity to initialize the cached offsets for *all* the leading
         * fixed-width columns, in hope of avoiding future visits to this
         * routine.
         */
        att[0]->attcacheoff = 0;

        /* we might have set some offsets in the slow path previously */
        while (j < natts && att[j]->attcacheoff > 0)
            j++;

        off = att[j - 1]->attcacheoff + att[j - 1]->attlen;

        for (; j < natts; j++)
        {
            if (att[j]->attlen <= 0)
                break;

            off = att_align_nominal(off, att[j]->attalign);

            att[j]->attcacheoff = off;

            off += att[j]->attlen;
        }

        Assert(j > attnum);

        off = att[attnum]->attcacheoff;
    }
    else
    {
        bool        usecache = true;
        int         i;

        /*
         * Now we know that we have to walk the tuple CAREFULLY.  But we still
         * might be able to cache some offsets for next time.
         *
         * Note - This loop is a little tricky.  For each non-null attribute,
         * we have to first account for alignment padding before the attr,
         * then advance over the attr based on its length.  Nulls have no
         * storage and no alignment padding either.  We can use/set
         * attcacheoff until we reach either a null or a var-width attribute.
         */
        off = 0;
        for (i = 0;; i++)       /* loop exit is at "break" */
        {
            if (HeapTupleHasNulls(tuple) && att_isnull(i, bp))
            {
                usecache = false;
                continue;       /* this cannot be the target att */
            }

            /* If we know the next offset, we can skip the rest */
            if (usecache && att[i]->attcacheoff >= 0)
                off = att[i]->attcacheoff;
            else if (att[i]->attlen == -1)
            {
                /*
                 * We can only cache the offset for a varlena attribute if the
                 * offset is already suitably aligned, so that there would be
                 * no pad bytes in any case: then the offset will be valid for
                 * either an aligned or unaligned value.
                 */
                if (usecache &&
                    off == att_align_nominal(off, att[i]->attalign))
                    att[i]->attcacheoff = off;
                else
                {
                    off = att_align_pointer(off, att[i]->attalign, -1,
                                            tp + off);
                    usecache = false;
                }
            }
            else
            {
                /* not varlena, so safe to use att_align_nominal */
                off = att_align_nominal(off, att[i]->attalign);

                if (usecache)
                    att[i]->attcacheoff = off;
            }

            if (i == attnum)
                break;

            off = att_addlength_pointer(off, att[i]->attlen, tp + off);

            if (usecache && att[i]->attlen <= 0)
                usecache = false;
        }
    }

    return fetchatt(att[attnum], tp + off);
}