Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up temp table naming, introduce new functions for readability #451

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/access/heap/heapam.c
Original file line number Diff line number Diff line change
Expand Up @@ -5938,7 +5938,7 @@ heap_inplace_update(Relation relation, HeapTuple tuple)
errmsg("cannot update tuples during a parallel operation")));

/* Don't proceed further if the tuple is for an ENR. We just update there.*/
if (ENRupdateTuple(relation, tuple))
if (ENRUpdateTuple(relation, tuple))
return;

buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(&(tuple->t_self)));
Expand Down
3 changes: 1 addition & 2 deletions src/backend/access/heap/heapam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,7 @@ heapam_relation_set_new_filelocator(Relation rel,
*/
*minmulti = GetOldestMultiXactId();

srel = RelationCreateStorage(*newrlocator, persistence,
(sql_dialect != SQL_DIALECT_TSQL || !RelationIsBBFTableVariable(rel)));
srel = RelationCreateStorage(*newrlocator, persistence, !IsTsqlTableVariable(rel));

/*
* If required, set up an init fork for an unlogged table so that it can
Expand Down
9 changes: 5 additions & 4 deletions src/backend/access/heap/heapam_visibility.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include "utils/builtins.h"
#include "utils/combocid.h"
#include "utils/snapmgr.h"
#include "utils/queryenvironment.h"

table_variable_satisfies_visibility_hook_type table_variable_satisfies_visibility_hook = NULL;
table_variable_satisfies_update_hook_type table_variable_satisfies_update_hook = NULL;
Expand Down Expand Up @@ -468,7 +469,7 @@ HeapTupleSatisfiesUpdate(Relation relation, HeapTuple htup, CommandId curcid,
HeapTupleHeader tuple = htup->t_data;

/* See HeapTupleSatisfiesVisibility why */
if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTableVariable(relation))
timchang514 marked this conversation as resolved.
Show resolved Hide resolved
if (IsTsqlTableVariable(relation))
timchang514 marked this conversation as resolved.
Show resolved Hide resolved
return table_variable_satisfies_update_hook(htup, curcid, buffer);

Assert(ItemPointerIsValid(&htup->t_self));
Expand Down Expand Up @@ -1177,7 +1178,7 @@ HeapTupleSatisfiesVacuum(Relation relation, HeapTuple htup, TransactionId Oldest
HTSV_Result res;

/* See HeapTupleSatisfiesVisibility why */
if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTableVariable(relation))
if (IsTsqlTableVariable(relation))
return table_variable_satisfies_vacuum_hook(htup, OldestXmin, buffer);

res = HeapTupleSatisfiesVacuumHorizon(NULL, htup, buffer, &dead_after);
Expand Down Expand Up @@ -1219,7 +1220,7 @@ HeapTupleSatisfiesVacuumHorizon(Relation relation, HeapTuple htup, Buffer buffer
*dead_after = InvalidTransactionId;

/* See HeapTupleSatisfiesVisibility why */
if (sql_dialect == SQL_DIALECT_TSQL && relation && RelationIsBBFTableVariable(relation))
if (IsTsqlTableVariable(relation))
return table_variable_satisfies_vacuum_horizon_hook(htup, buffer, dead_after);

/*
Expand Down Expand Up @@ -1789,7 +1790,7 @@ HeapTupleSatisfiesVisibility(Relation relation, HeapTuple htup, Snapshot snapsho
* Babelfish extension has a different type of heap table but non-transactional.
* It is not worth introducing a new table AM because the new table still uses heap format.
*/
if (sql_dialect == SQL_DIALECT_TSQL && relation && RelationIsBBFTableVariable(relation))
if (IsTsqlTableVariable(relation))
return table_variable_satisfies_visibility_hook(htup, snapshot, buffer);

switch (snapshot->snapshot_type)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/access/index/genam.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ systable_beginscan(Relation heapRelation,
}

/* Catalog tuples for ENR are not in the on-disk catalogs */
if (ENRgetSystableScan(heapRelation, indexId, nkeys, key, &sysscan->enr_tuplist, &sysscan->enr_tuplist_i, &sysscan->enr_tuplist_flags))
if (ENRGetSystableScan(heapRelation, indexId, nkeys, key, &sysscan->enr_tuplist, &sysscan->enr_tuplist_i, &sysscan->enr_tuplist_flags))
{
sysscan->enr = true;
index_close(sysscan->irel, AccessShareLock);
Expand Down
3 changes: 1 addition & 2 deletions src/backend/catalog/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,7 @@ GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
*/
rlocator.backend = backend;

use_bbf_oid_buffer = (relpersistence == RELPERSISTENCE_TEMP && sql_dialect == SQL_DIALECT_TSQL
&& GetNewTempOidWithIndex_hook && temp_oid_buffer_size > 0);
use_bbf_oid_buffer = (relpersistence == RELPERSISTENCE_TEMP && UseTempOidBuffer());

do
{
Expand Down
2 changes: 1 addition & 1 deletion src/backend/catalog/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
while (HeapTupleIsValid(tup = systable_getnext(scan)))
{
if (scan->enr)
ENRdropTuple(*depRel, tup);
ENRDropTuple(*depRel, tup);
else
CatalogTupleDelete(*depRel, &tup->t_self);
}
Expand Down
15 changes: 7 additions & 8 deletions src/backend/catalog/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ heap_create(const char *relname,
relpersistence,
relfrozenxid, relminmxid);
else if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
RelationCreateStorage(rel->rd_locator, relpersistence,
(sql_dialect != SQL_DIALECT_TSQL || !RelationIsBBFTableVariable(rel)));
RelationCreateStorage(rel->rd_locator, relpersistence, !IsTsqlTableVariable(rel));
else
Assert(false);
}
Expand Down Expand Up @@ -1185,7 +1184,7 @@ heap_create_with_catalog(const char *relname,
MultiXactId relminmxid;
bool is_enr = false;

if (relpersistence == RELPERSISTENCE_TEMP && sql_dialect == SQL_DIALECT_TSQL)
if (IsTsqlTempTable(relpersistence))
{
/*
* in TSQL, temporary table name should start with '#'.
Expand Down Expand Up @@ -1413,7 +1412,7 @@ heap_create_with_catalog(const char *relname,
*
* For temp tables, we use temp OID assignment code here as well.
*/
if (is_enr && useTempOidBuffer())
if (is_enr && UseTempOidBuffer())
{
Relation pg_type;

Expand Down Expand Up @@ -1671,7 +1670,7 @@ DeleteRelationTuple(Oid relid)
elog(ERROR, "cache lookup failed for relation %u", relid);

/* delete the relation tuple from pg_class, and finish up */
if (!ENRdropTuple(pg_class_desc, tup))
if (!ENRDropTuple(pg_class_desc, tup))
CatalogTupleDelete(pg_class_desc, &tup->t_self);

ReleaseSysCache(tup);
Expand Down Expand Up @@ -1761,7 +1760,7 @@ DeleteSystemAttributeTuples(Oid relid)

/* Delete all the matching tuples */
while ((atttup = systable_getnext(scan)) != NULL)
if (!ENRdropTuple(attrel, atttup))
if (!ENRDropTuple(attrel, atttup))
CatalogTupleDelete(attrel, &atttup->t_self);

/* Clean up after the scan */
Expand Down Expand Up @@ -1808,7 +1807,7 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
{
/* System attribute (probably OID) ... just delete the row */

if (!ENRdropTuple(attr_rel, tuple))
if (!ENRDropTuple(attr_rel, tuple))
CatalogTupleDelete(attr_rel, &tuple->t_self);
}
else
Expand Down Expand Up @@ -3099,7 +3098,7 @@ RemoveStatistics(Oid relid, AttrNumber attnum)

/* we must loop even when attnum != 0, in case of inherited stats */
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
if (!ENRdropTuple(pgstatistic, tuple))
if (!ENRDropTuple(pgstatistic, tuple))
CatalogTupleDelete(pgstatistic, &tuple->t_self);

systable_endscan(scan);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ index_create(Relation heapRelation,
* PRIMARY KEYs and/or CONSTRAINTs.
*/
is_enr = (indexRelationName && strlen(indexRelationName) > 0 &&
(indexRelationName[0] == '@' || get_ENR_withoid(currentQueryEnv, heapRelationId, ENR_TSQL_TEMP)));
(indexRelationName[0] == '@' || GetENRTempTableWithOid(heapRelationId)));
}

relkind = partitioned ? RELKIND_PARTITIONED_INDEX : RELKIND_INDEX;
Expand Down Expand Up @@ -2391,7 +2391,7 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
hasexprs = !heap_attisnull(tuple, Anum_pg_index_indexprs,
RelationGetDescr(indexRelation));

if (!ENRdropTuple(indexRelation, tuple))
if (!ENRDropTuple(indexRelation, tuple))
CatalogTupleDelete(indexRelation, &tuple->t_self);

ReleaseSysCache(tuple);
Expand Down
8 changes: 4 additions & 4 deletions src/backend/catalog/indexing.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ CatalogTupleInsert(Relation heapRel, HeapTuple tup)
CatalogTupleCheckConstraints(heapRel, tup);

/* ENR carries catalog tuples themselves. Do not insert, and skip index.*/
if (ENRaddTuple(heapRel, tup))
if (ENRAddTuple(heapRel, tup))
return;

indstate = CatalogOpenIndexes(heapRel);
Expand All @@ -266,7 +266,7 @@ CatalogTupleInsertWithInfo(Relation heapRel, HeapTuple tup,
CatalogTupleCheckConstraints(heapRel, tup);

/* ENR carries catalog tuples themselves. Do not insert, and skip index.*/
if (ENRaddTuple(heapRel, tup))
if (ENRAddTuple(heapRel, tup))
return;

simple_heap_insert(heapRel, tup);
Expand Down Expand Up @@ -353,7 +353,7 @@ CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
CatalogTupleCheckConstraints(heapRel, tup);

/* ENR carries catalog tuples themselves. Do not update, and skip index.*/
if (ENRupdateTuple(heapRel, tup))
if (ENRUpdateTuple(heapRel, tup))
return;

indstate = CatalogOpenIndexes(heapRel);
Expand Down Expand Up @@ -381,7 +381,7 @@ CatalogTupleUpdateWithInfo(Relation heapRel, ItemPointer otid, HeapTuple tup,
CatalogTupleCheckConstraints(heapRel, tup);

/* ENR carries catalog tuples themselves. Do not update.*/
if (ENRupdateTuple(heapRel, tup))
if (ENRUpdateTuple(heapRel, tup))
return;

simple_heap_update(heapRel, otid, tup, &updateIndexes);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/catalog/pg_attrdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ RemoveAttrDefaultById(Oid attrdefId)
myrel = relation_open(myrelid, AccessExclusiveLock);

/* Now we can delete the pg_attrdef row */
if (!ENRdropTuple(attrdef_rel, tuple))
if (!ENRDropTuple(attrdef_rel, tuple))
CatalogTupleDelete(attrdef_rel, &tuple->t_self);

systable_endscan(scan);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/catalog/pg_constraint.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ CreateConstraintEntry(const char *constraintName,
values[i] = (Datum) NULL;
}

if (useTempOidBufferForOid(relId) && isTempNamespace(constraintNamespace))
if (UseTempOidBufferForOid(relId) && isTempNamespace(constraintNamespace))
conOid = GetNewTempOidWithIndex_hook(conDesc, ConstraintOidIndexId,
Anum_pg_constraint_oid);
else
Expand Down Expand Up @@ -647,7 +647,7 @@ RemoveConstraintById(Oid conId)
elog(ERROR, "constraint %u is not of a known type", conId);

/* Fry the constraint itself */
if (!ENRdropTuple(conDesc, tup))
if (!ENRDropTuple(conDesc, tup))
CatalogTupleDelete(conDesc, &tup->t_self);

/* Clean up */
Expand Down
2 changes: 1 addition & 1 deletion src/backend/catalog/pg_depend.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ deleteDependencyRecordsFor(Oid classId, Oid objectId,
((Form_pg_depend) GETSTRUCT(tup))->deptype == DEPENDENCY_EXTENSION)
continue;

if (!ENRdropTuple(depRel, tup))
if (!ENRDropTuple(depRel, tup))
CatalogTupleDelete(depRel, &tup->t_self);
count++;
}
Expand Down
3 changes: 2 additions & 1 deletion src/backend/catalog/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "storage/smgr.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "utils/queryenvironment.h"
#include "utils/rel.h"

/* GUC variables */
Expand Down Expand Up @@ -223,7 +224,7 @@ RelationDropStorage(Relation rel)
* However, we need to unlink the files on explicit DROP TABLE command regardless
* if the transaction state is committing or aborting.
*/
if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTableVariable(rel))
if (IsTsqlTableVariable(rel))
{
pending = (PendingRelDelete *)
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
Expand Down
4 changes: 2 additions & 2 deletions src/backend/catalog/toasting.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
/*
* Create the toast table and its index
*/
if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTableVariable(rel))
if (IsTsqlTableVariable(rel))
pg_toast_prefix = "@pg_toast";
else if (sql_dialect == SQL_DIALECT_TSQL && rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && get_ENR_withoid(currentQueryEnv, rel->rd_id, ENR_TSQL_TEMP))
else if (IsTsqlTempTable(rel->rd_rel->relpersistence) && GetENRTempTableWithOid(rel->rd_id))
pg_toast_prefix = "#pg_toast";

snprintf(toast_relname, sizeof(toast_relname),
Expand Down
6 changes: 3 additions & 3 deletions src/backend/commands/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod,
* We also must ensure that these temp tables are properly named in TSQL
* so that the metadata is properly cleaned up after in this function.
*/
if (sql_dialect == SQL_DIALECT_TSQL && relpersistence == RELPERSISTENCE_TEMP && get_ENR_withoid(currentQueryEnv, OIDOldHeap, ENR_TSQL_TEMP))
if (IsTsqlTempTable(relpersistence) && GetENRTempTableWithOid(OIDOldHeap))
snprintf(NewHeapName, sizeof(NewHeapName), "#pg_temp_%u", OIDOldHeap);
else
snprintf(NewHeapName, sizeof(NewHeapName), "pg_temp_%u", OIDOldHeap);
Expand Down Expand Up @@ -1612,9 +1612,9 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
NoLock);

/* rename the toast table ... */
if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTableVariable(newrel))
if (IsTsqlTableVariable(newrel))
pg_toast_prefix = "@pg_toast";
else if (sql_dialect == SQL_DIALECT_TSQL && newrel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && get_ENR_withoid(currentQueryEnv, newrel->rd_id, ENR_TSQL_TEMP))
else if (IsTsqlTempTable(newrel->rd_rel->relpersistence) && GetENRTempTableWithOid(newrel->rd_id))
pg_toast_prefix = "#pg_toast";

snprintf(NewToastName, NAMEDATALEN, "%s_%u",
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ DeleteSequenceTuple(Oid relid)
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for sequence %u", relid);

if (!ENRdropTuple(rel, tuple))
if (!ENRDropTuple(rel, tuple))
CatalogTupleDelete(rel, &tuple->t_self);

ReleaseSysCache(tuple);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/commands/statscmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ RemoveStatisticsDataById(Oid statsOid, bool inh)
/* We don't know if the data row for inh value exists. */
if (HeapTupleIsValid(tup))
{
if (!ENRdropTuple(relation, tup))
if (!ENRDropTuple(relation, tup))
CatalogTupleDelete(relation, &tup->t_self);

ReleaseSysCache(tup);
Expand Down Expand Up @@ -767,7 +767,7 @@ RemoveStatisticsById(Oid statsOid)

CacheInvalidateRelcacheByRelid(relid);

if (!ENRdropTuple(relation, tup))
if (!ENRDropTuple(relation, tup))
CatalogTupleDelete(relation, &tup->t_self);

ReleaseSysCache(tup);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -13080,7 +13080,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel,

if (scan->enr)
{
ENRdropTuple(depRel, depTup);
ENRDropTuple(depRel, depTup);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/typecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ RemoveTypeById(Oid typeOid)
if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for type %u", typeOid);

if (!ENRdropTuple(relation, tup))
if (!ENRDropTuple(relation, tup))
CatalogTupleDelete(relation, &tup->t_self);

/*
Expand Down
4 changes: 2 additions & 2 deletions src/backend/utils/activity/pgstat_relation.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void
pgstat_create_relation(Relation rel)
{
/* Skip pg_stat */
if (sql_dialect == SQL_DIALECT_TSQL && rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && temp_oid_buffer_size > 0)
if (IsTsqlTempTable(rel->rd_rel->relpersistence) && UseTempOidBuffer())
return;
pgstat_create_transactional(PGSTAT_KIND_RELATION,
rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
Expand All @@ -190,7 +190,7 @@ pgstat_drop_relation(Relation rel)
int nest_level = GetCurrentTransactionNestLevel();
PgStat_TableStatus *pgstat_info;

if (sql_dialect == SQL_DIALECT_TSQL && rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP && temp_oid_buffer_size > 0)
if (IsTsqlTempTable(rel->rd_rel->relpersistence) && UseTempOidBuffer())
return;
pgstat_drop_transactional(PGSTAT_KIND_RELATION,
rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
Expand Down
Loading
Loading