mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
We have been using the term RelFileNode to refer to either (1) the integer that is used to name the sequence of files for a certain relation within the directory set aside for that tablespace/database combination; or (2) that value plus the OIDs of the tablespace and database; or occasionally (3) the whole series of files created for a relation based on those values. Using the same name for more than one thing is confusing. Replace RelFileNode with RelFileNumber when we're talking about just the single number, i.e. (1) from above, and with RelFileLocator when we're talking about all the things that are needed to locate a relation's files on disk, i.e. (2) from above. In the places where we refer to (3) as a relfilenode, instead refer to "relation storage". Since there is a ton of SQL code in the world that knows about pg_class.relfilenode, don't change the name of that column, or of other SQL-facing things that derive their name from it. On the other hand, do adjust closely-related internal terminology. For example, the structure member names dbNode and spcNode appear to be derived from the fact that the structure itself was called RelFileNode, so change those to dbOid and spcOid. Likewise, various variables with names like rnode and relnode get renamed appropriately, according to how they're being used in context. Hopefully, this is clearer than before. It is also preparation for future patches that intend to widen the relfilenumber fields from its current width of 32 bits. Variables that store a relfilenumber are now declared as type RelFileNumber rather than type Oid; right now, these are the same, but that can now more easily be changed. Dilip Kumar, per an idea from me. Reviewed also by Andres Freund. I fixed some whitespace issues, changed a couple of words in a comment, and made one other minor correction. Discussion: http://postgr.es/m/CA+TgmoamOtXbVAQf9hWFzonUo6bhhjS6toZQd7HZ-pmojtAmag@mail.gmail.com Discussion: http://postgr.es/m/CA+Tgmobp7+7kmi4gkq7Y+4AM9fTvL+O1oQ4-5gFTT+6Ng-dQ=g@mail.gmail.com Discussion: http://postgr.es/m/CAFiTN-vTe79M8uDH1yprOU64MNFE+R3ODRuA+JWf27JbhY4hJw@mail.gmail.com
159 lines
4.6 KiB
C
159 lines
4.6 KiB
C
/*----------------------------------------------------------------------
|
|
*
|
|
* tableamapi.c
|
|
* Support routines for API for Postgres table access methods
|
|
*
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/backend/access/table/tableamapi.c
|
|
*----------------------------------------------------------------------
|
|
*/
|
|
#include "postgres.h"
|
|
|
|
#include "access/heapam.h"
|
|
#include "access/htup_details.h"
|
|
#include "access/tableam.h"
|
|
#include "access/xact.h"
|
|
#include "catalog/pg_am.h"
|
|
#include "catalog/pg_proc.h"
|
|
#include "commands/defrem.h"
|
|
#include "miscadmin.h"
|
|
#include "utils/fmgroids.h"
|
|
#include "utils/memutils.h"
|
|
#include "utils/syscache.h"
|
|
|
|
|
|
/*
|
|
* GetTableAmRoutine
|
|
* Call the specified access method handler routine to get its
|
|
* TableAmRoutine struct, which will be palloc'd in the caller's
|
|
* memory context.
|
|
*/
|
|
const TableAmRoutine *
|
|
GetTableAmRoutine(Oid amhandler)
|
|
{
|
|
Datum datum;
|
|
const TableAmRoutine *routine;
|
|
|
|
datum = OidFunctionCall0(amhandler);
|
|
routine = (TableAmRoutine *) DatumGetPointer(datum);
|
|
|
|
if (routine == NULL || !IsA(routine, TableAmRoutine))
|
|
elog(ERROR, "table access method handler %u did not return a TableAmRoutine struct",
|
|
amhandler);
|
|
|
|
/*
|
|
* Assert that all required callbacks are present. That makes it a bit
|
|
* easier to keep AMs up to date, e.g. when forward porting them to a new
|
|
* major version.
|
|
*/
|
|
Assert(routine->scan_begin != NULL);
|
|
Assert(routine->scan_end != NULL);
|
|
Assert(routine->scan_rescan != NULL);
|
|
Assert(routine->scan_getnextslot != NULL);
|
|
|
|
Assert(routine->parallelscan_estimate != NULL);
|
|
Assert(routine->parallelscan_initialize != NULL);
|
|
Assert(routine->parallelscan_reinitialize != NULL);
|
|
|
|
Assert(routine->index_fetch_begin != NULL);
|
|
Assert(routine->index_fetch_reset != NULL);
|
|
Assert(routine->index_fetch_end != NULL);
|
|
Assert(routine->index_fetch_tuple != NULL);
|
|
|
|
Assert(routine->tuple_fetch_row_version != NULL);
|
|
Assert(routine->tuple_tid_valid != NULL);
|
|
Assert(routine->tuple_get_latest_tid != NULL);
|
|
Assert(routine->tuple_satisfies_snapshot != NULL);
|
|
Assert(routine->index_delete_tuples != NULL);
|
|
|
|
Assert(routine->tuple_insert != NULL);
|
|
|
|
/*
|
|
* Could be made optional, but would require throwing error during
|
|
* parse-analysis.
|
|
*/
|
|
Assert(routine->tuple_insert_speculative != NULL);
|
|
Assert(routine->tuple_complete_speculative != NULL);
|
|
|
|
Assert(routine->multi_insert != NULL);
|
|
Assert(routine->tuple_delete != NULL);
|
|
Assert(routine->tuple_update != NULL);
|
|
Assert(routine->tuple_lock != NULL);
|
|
|
|
Assert(routine->relation_set_new_filelocator != NULL);
|
|
Assert(routine->relation_nontransactional_truncate != NULL);
|
|
Assert(routine->relation_copy_data != NULL);
|
|
Assert(routine->relation_copy_for_cluster != NULL);
|
|
Assert(routine->relation_vacuum != NULL);
|
|
Assert(routine->scan_analyze_next_block != NULL);
|
|
Assert(routine->scan_analyze_next_tuple != NULL);
|
|
Assert(routine->index_build_range_scan != NULL);
|
|
Assert(routine->index_validate_scan != NULL);
|
|
|
|
Assert(routine->relation_size != NULL);
|
|
Assert(routine->relation_needs_toast_table != NULL);
|
|
|
|
Assert(routine->relation_estimate_size != NULL);
|
|
|
|
/* optional, but one callback implies presence of the other */
|
|
Assert((routine->scan_bitmap_next_block == NULL) ==
|
|
(routine->scan_bitmap_next_tuple == NULL));
|
|
Assert(routine->scan_sample_next_block != NULL);
|
|
Assert(routine->scan_sample_next_tuple != NULL);
|
|
|
|
return routine;
|
|
}
|
|
|
|
/* check_hook: validate new default_table_access_method */
|
|
bool
|
|
check_default_table_access_method(char **newval, void **extra, GucSource source)
|
|
{
|
|
if (**newval == '\0')
|
|
{
|
|
GUC_check_errdetail("%s cannot be empty.",
|
|
"default_table_access_method");
|
|
return false;
|
|
}
|
|
|
|
if (strlen(*newval) >= NAMEDATALEN)
|
|
{
|
|
GUC_check_errdetail("%s is too long (maximum %d characters).",
|
|
"default_table_access_method", NAMEDATALEN - 1);
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* If we aren't inside a transaction, or not connected to a database, we
|
|
* cannot do the catalog access necessary to verify the method. Must
|
|
* accept the value on faith.
|
|
*/
|
|
if (IsTransactionState() && MyDatabaseId != InvalidOid)
|
|
{
|
|
if (!OidIsValid(get_table_am_oid(*newval, true)))
|
|
{
|
|
/*
|
|
* When source == PGC_S_TEST, don't throw a hard error for a
|
|
* nonexistent table access method, only a NOTICE. See comments in
|
|
* guc.h.
|
|
*/
|
|
if (source == PGC_S_TEST)
|
|
{
|
|
ereport(NOTICE,
|
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
|
errmsg("table access method \"%s\" does not exist",
|
|
*newval)));
|
|
}
|
|
else
|
|
{
|
|
GUC_check_errdetail("Table access method \"%s\" does not exist.",
|
|
*newval);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|