PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/amapi.h"
#include "access/heapam.h"
#include "access/multixact.h"
#include "access/relscan.h"
#include "access/tableam.h"
#include "access/toast_internals.h"
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_am.h"
#include "catalog/pg_inherits.h"
#include "catalog/toasting.h"
#include "commands/cluster.h"
#include "commands/defrem.h"
#include "commands/progress.h"
#include "commands/tablecmds.h"
#include "commands/vacuum.h"
#include "miscadmin.h"
#include "optimizer/optimizer.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/lmgr.h"
#include "storage/predicate.h"
#include "utils/acl.h"
#include "utils/fmgroids.h"
#include "utils/guc.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_rusage.h"
#include "utils/relmapper.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
struct | RelToCluster |
Functions | |
static void | cluster_multiple_rels (List *rtcs, ClusterParams *params) |
static void | rebuild_relation (Relation OldHeap, Oid indexOid, bool verbose) |
static void | copy_table_data (Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose, bool *pSwapToastByContent, TransactionId *pFreezeXid, MultiXactId *pCutoffMulti) |
static List * | get_tables_to_cluster (MemoryContext cluster_context) |
static List * | get_tables_to_cluster_partitioned (MemoryContext cluster_context, Oid indexOid) |
static bool | cluster_is_permitted_for_relation (Oid relid, Oid userid) |
void | cluster (ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) |
void | cluster_rel (Oid tableOid, Oid indexOid, ClusterParams *params) |
void | check_index_is_clusterable (Relation OldHeap, Oid indexOid, LOCKMODE lockmode) |
void | mark_index_clustered (Relation rel, Oid indexOid, bool is_internal) |
Oid | make_new_heap (Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, char relpersistence, LOCKMODE lockmode) |
static void | swap_relation_files (Oid r1, Oid r2, bool target_is_pg_class, bool swap_toast_by_content, bool is_internal, TransactionId frozenXid, MultiXactId cutoffMulti, Oid *mapped_tables) |
void | finish_heap_swap (Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, bool check_constraints, bool is_internal, TransactionId frozenXid, MultiXactId cutoffMulti, char newrelpersistence) |
Definition at line 499 of file cluster.c.
References IndexAmRoutine::amclusterable, ereport, errcode(), errmsg(), ERROR, heap_attisnull(), index_close(), index_open(), NoLock, RelationData::rd_indam, RelationData::rd_index, RelationData::rd_indextuple, RelationGetRelationName, and RelationGetRelid.
Referenced by ATExecClusterOn(), cluster(), and cluster_rel().
void cluster | ( | ParseState * | pstate, |
ClusterStmt * | stmt, | ||
bool | isTopLevel | ||
) |
Definition at line 107 of file cluster.c.
References AccessExclusiveLock, AccessShareLock, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, check_index_is_clusterable(), CLUOPT_RECHECK, CLUOPT_RECHECK_ISCLUSTERED, CLUOPT_VERBOSE, cluster_multiple_rels(), cluster_rel(), defGetBoolean(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, get_index_isclustered(), get_relname_relid(), get_tables_to_cluster(), get_tables_to_cluster_partitioned(), InvalidOid, lfirst, lfirst_oid, DefElem::location, MemoryContextDelete(), NoLock, OidIsValid, ClusterParams::options, parser_errposition(), PortalContext, PreventInTransactionBlock(), RangeVarCallbackMaintainsTable(), RangeVarGetRelidExtended(), RelationData::rd_rel, RELATION_IS_OTHER_TEMP, RelationGetIndexList(), StartTransactionCommand(), stmt, table_close(), table_open(), and verbose.
Referenced by adjust_data_dir(), check_bin_dir(), check_data_dir(), check_for_connection_status(), check_for_data_types_usage(), check_for_incompatible_polymorphics(), check_for_isn_and_int8_passing_mismatch(), check_for_pg_role_prefix(), check_for_prepared_transactions(), check_for_tables_with_oids(), check_for_user_defined_encoding_conversions(), check_for_user_defined_postfix_ops(), check_is_install_user(), cluster_conn_opts(), connectToServer(), get_bin_version(), get_control_data(), get_db_conn(), get_db_infos(), get_db_rel_and_slot_infos(), get_major_server_version(), get_sock_dir(), get_subscription_count(), get_template0_info(), jsonb_9_4_check_applicable(), old_9_6_invalidate_hash_indexes(), process_query_result(), process_slot(), report_extension_updates(), set_tablespace_directory_suffix(), standard_ProcessUtility(), start_conn(), start_postmaster(), stop_postmaster(), and upgrade_task_run().
Definition at line 1737 of file cluster.c.
References ACL_MAINTAIN, ACLCHECK_OK, ereport, errmsg(), get_rel_name(), pg_class_aclcheck(), and WARNING.
Referenced by cluster_rel(), get_tables_to_cluster(), and get_tables_to_cluster_partitioned().
|
static |
Definition at line 265 of file cluster.c.
References cluster_rel(), CommitTransactionCommand(), GetTransactionSnapshot(), RelToCluster::indexOid, lfirst, PopActiveSnapshot(), PushActiveSnapshot(), StartTransactionCommand(), and RelToCluster::tableOid.
Referenced by cluster().
void cluster_rel | ( | Oid | tableOid, |
Oid | indexOid, | ||
ClusterParams * | params | ||
) |
Definition at line 310 of file cluster.c.
References AccessExclusiveLock, Assert, AtEOXact_GUC(), CHECK_FOR_INTERRUPTS, check_index_is_clusterable(), CheckTableNotInUse(), CLUOPT_RECHECK, CLUOPT_RECHECK_ISCLUSTERED, CLUOPT_VERBOSE, cluster_is_permitted_for_relation(), ereport, errcode(), errmsg(), ERROR, get_index_isclustered(), GetUserIdAndSecContext(), NewGUCNestLevel(), ObjectIdGetDatum(), OidIsValid, ClusterParams::options, pgstat_progress_end_command(), pgstat_progress_start_command(), pgstat_progress_update_param(), PROGRESS_CLUSTER_COMMAND, PROGRESS_CLUSTER_COMMAND_CLUSTER, PROGRESS_CLUSTER_COMMAND_VACUUM_FULL, PROGRESS_COMMAND_CLUSTER, RelationData::rd_rel, rebuild_relation(), relation_close(), RELATION_IS_OTHER_TEMP, RelationIsPopulated, RestrictSearchPath(), SearchSysCacheExists1, SECURITY_RESTRICTED_OPERATION, SetUserIdAndSecContext(), TransferPredicateLocksToHeapRelation(), try_relation_open(), and verbose.
Referenced by cluster(), cluster_multiple_rels(), and vacuum_rel().
|
static |
Definition at line 813 of file cluster.c.
References AccessExclusiveLock, Assert, CacheInvalidateRelcacheByTuple(), CatalogTupleUpdate(), CommandCounterIncrement(), DEBUG2, elog, ereport, errdetail(), errmsg(), ERROR, VacuumCutoffs::FreezeLimit, get_namespace_name(), GETSTRUCT, heap_freetuple(), HeapTupleIsValid, index_close(), index_open(), INFO, InvalidOid, LockRelationOid(), VacuumCutoffs::MultiXactCutoff, MultiXactIdIsValid, MultiXactIdPrecedes(), NoLock, ObjectIdGetDatum(), OidIsValid, VacuumCutoffs::OldestXmin, pg_rusage_init(), pg_rusage_show(), PG_USED_FOR_ASSERTS_ONLY, plan_cluster_use_sort(), RelationData::rd_rel, RelationData::rd_toastoid, RelationGetDescr, RelationGetNamespace, RelationGetNumberOfBlocks, RelationGetRelationName, VacuumCutoffs::relfrozenxid, VacuumCutoffs::relminmxid, RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), table_open(), table_relation_copy_for_cluster(), TransactionIdIsValid, TransactionIdPrecedes(), vacuum_get_cutoffs(), and verbose.
Referenced by rebuild_relation().
void finish_heap_swap | ( | Oid | OIDOldHeap, |
Oid | OIDNewHeap, | ||
bool | is_system_catalog, | ||
bool | swap_toast_by_content, | ||
bool | check_constraints, | ||
bool | is_internal, | ||
TransactionId | frozenXid, | ||
MultiXactId | cutoffMulti, | ||
char | newrelpersistence | ||
) |
Definition at line 1437 of file cluster.c.
References CacheInvalidateCatalog(), CatalogTupleUpdate(), CommandCounterIncrement(), DROP_RESTRICT, elog, ERROR, GETSTRUCT, HeapTupleIsValid, i, NAMEDATALEN, NoLock, ObjectIdGetDatum(), OidIsValid, PERFORM_DELETION_INTERNAL, performDeletion(), pgstat_progress_update_param(), PROGRESS_CLUSTER_PHASE, PROGRESS_CLUSTER_PHASE_FINAL_CLEANUP, PROGRESS_CLUSTER_PHASE_REBUILD_INDEX, PROGRESS_CLUSTER_PHASE_SWAP_REL_FILES, RelationData::rd_rel, REINDEX_REL_CHECK_CONSTRAINTS, REINDEX_REL_FORCE_INDEXES_PERMANENT, REINDEX_REL_FORCE_INDEXES_UNLOGGED, REINDEX_REL_SUPPRESS_INDEX_USE, reindex_relation(), relation_close(), RelationClearMissing(), RelationMapRemoveMapping(), RenameRelationInternal(), ResetRelRewrite(), RowExclusiveLock, SearchSysCacheCopy1, snprintf, swap_relation_files(), HeapTupleData::t_self, table_close(), table_open(), and toast_get_valid_index().
Referenced by ATRewriteTables(), rebuild_relation(), and refresh_by_heap_swap().
|
static |
Definition at line 1635 of file cluster.c.
References AccessShareLock, BoolGetDatum(), BTEqualStrategyNumber, cluster_is_permitted_for_relation(), ForwardScanDirection, GETSTRUCT, GetUserId(), heap_getnext(), RelToCluster::indexOid, lappend(), MemoryContextSwitchTo(), NIL, palloc(), relation_close(), ScanKeyInit(), table_beginscan_catalog(), table_endscan(), table_open(), and RelToCluster::tableOid.
Referenced by cluster().
|
static |
Definition at line 1689 of file cluster.c.
References cluster_is_permitted_for_relation(), find_all_inheritors(), get_rel_relkind(), GetUserId(), IndexGetRelation(), RelToCluster::indexOid, lappend(), lfirst_oid, MemoryContextSwitchTo(), NIL, NoLock, palloc(), and RelToCluster::tableOid.
Referenced by cluster().
Oid make_new_heap | ( | Oid | OIDOldHeap, |
Oid | NewTableSpace, | ||
Oid | NewAccessMethod, | ||
char | relpersistence, | ||
LOCKMODE | lockmode | ||
) |
Definition at line 687 of file cluster.c.
References Assert, CommandCounterIncrement(), elog, ERROR, heap_create_with_catalog(), HeapTupleIsValid, InvalidOid, LookupCreationNamespace(), NAMEDATALEN, NewHeapCreateToastTable(), NIL, NoLock, ObjectIdGetDatum(), OidIsValid, ONCOMMIT_NOOP, RelationData::rd_rel, RelationGetDescr, RelationGetNamespace, RelationIsMapped, ReleaseSysCache(), SearchSysCache1(), snprintf, SysCacheGetAttr(), table_close(), and table_open().
Referenced by ATRewriteTables(), rebuild_relation(), and RefreshMatViewByOid().
Definition at line 559 of file cluster.c.
References CatalogTupleUpdate(), elog, ereport, errcode(), errmsg(), ERROR, get_index_isclustered(), GETSTRUCT, heap_freetuple(), HeapTupleIsValid, InvalidOid, InvokeObjectPostAlterHookArg, lfirst_oid, ObjectIdGetDatum(), OidIsValid, RelationData::rd_rel, RelationGetIndexList(), RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), and table_open().
Referenced by ATExecClusterOn(), ATExecDropCluster(), and rebuild_relation().
Definition at line 632 of file cluster.c.
References AccessExclusiveLock, copy_table_data(), finish_heap_swap(), IsSystemRelation(), make_new_heap(), mark_index_clustered(), NoLock, OidIsValid, RelationData::rd_rel, RelationGetRelid, table_close(), and verbose.
Referenced by cluster_rel().
|
static |
Definition at line 1060 of file cluster.c.
References AccessExclusiveLock, Assert, CacheInvalidateRelcacheByTuple(), CatalogCloseIndexes(), CatalogOpenIndexes(), CatalogTupleUpdateWithInfo(), changeDependencyFor(), ObjectAddress::classId, deleteDependencyRecordsFor(), DEPENDENCY_INTERNAL, elog, ERROR, get_namespace_name(), get_rel_name(), get_rel_namespace(), GETSTRUCT, heap_freetuple(), HeapTupleIsValid, InvalidMultiXactId, InvalidOid, InvalidTransactionId, InvokeObjectPostAlterHookArg, IsSystemClass(), NameStr, NoLock, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, RelationData::rd_createSubid, RelationData::rd_firstRelfilelocatorSubid, RelationData::rd_newRelfilelocatorSubid, recordDependencyOn(), relation_close(), relation_open(), RelationAssumeNewRelfilelocator(), RelationMapOidToFilenumber(), RelationMapUpdateMap(), RelFileNumberIsValid, RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), table_open(), toast_get_valid_index(), TransactionIdIsNormal, and TransactionIdIsValid.
Referenced by finish_heap_swap().