-
Notifications
You must be signed in to change notification settings - Fork 779
Use RelidByRelfilenumberWithTempTables instead of RelidByRelfilenumber #8303
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
Changes from all commits
eb22531
3abbaf4
afef433
5904ee4
e2bfba8
8fd5f4a
f5b7c0a
ab71b7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1993,9 +1993,10 @@ ColumnarNamespaceId(void) | |
| static uint64 | ||
| LookupStorageId(RelFileLocator relfilelocator) | ||
| { | ||
| Oid relationId = RelidByRelfilenumber(RelationTablespace_compat(relfilelocator), | ||
| RelationPhysicalIdentifierNumber_compat( | ||
| relfilelocator)); | ||
| Oid relationId = RelidByRelfilenumberWithTempTables(RelationTablespace_compat( | ||
| relfilelocator), | ||
| RelationPhysicalIdentifierNumber_compat( | ||
| relfilelocator)); | ||
|
|
||
| Relation relation = relation_open(relationId, AccessShareLock); | ||
| uint64 storageId = ColumnarStorageGetStorageId(relation, false); | ||
|
|
@@ -2123,3 +2124,85 @@ GetFirstRowNumberAttrIndexInColumnarStripe(TupleDesc tupleDesc) | |
| ? (Anum_columnar_stripe_first_row_number - 1) | ||
| : tupleDesc->natts - 1; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| * Map a relation's (tablespace, relfilenumber) to a relation's oid and cache | ||
| * the result. | ||
| * PG18 and latest PG minors have excluded temporary tables from RelidByRelfilenumber, | ||
| * so we need to handle them here. | ||
| * Relevant PG commit: https://github.com/postgres/postgres/commit/dcdc95cb4 | ||
| * This function does an extra search if relid is InvalidOid, for temp tables only. | ||
| * Code is mostly copy-paste from PG's RelidByRelfilenumber. | ||
| * Returns InvalidOid if no relation matching the criteria could be found. | ||
| */ | ||
| Oid | ||
| RelidByRelfilenumberWithTempTables(Oid reltablespace, RelFileNumber relfilenumber) | ||
| { | ||
| Oid relid; | ||
|
|
||
| #if PG_VERSION_NUM >= PG_VERSION_16 | ||
| relid = RelidByRelfilenumber(reltablespace, relfilenumber); | ||
| #else | ||
| relid = RelidByRelfilenode(reltablespace, relfilenumber); | ||
| #endif | ||
|
|
||
| if (relid == InvalidOid) | ||
| { | ||
| ScanKeyData skey[2]; | ||
| HeapTuple ntp; | ||
|
|
||
| /* pg_class will show 0 when the value is actually MyDatabaseTableSpace */ | ||
| if (reltablespace == MyDatabaseTableSpace) | ||
| { | ||
| reltablespace = 0; | ||
| } | ||
|
|
||
| /* check for plain relations by looking in pg_class */ | ||
| Relation relation = table_open(RelationRelationId, AccessShareLock); | ||
|
|
||
| ScanKeyInit(&skey[0], | ||
| Anum_pg_class_reltablespace, | ||
| BTEqualStrategyNumber, F_OIDEQ, | ||
| ObjectIdGetDatum(reltablespace)); | ||
| ScanKeyInit(&skey[1], | ||
| Anum_pg_class_relfilenode, | ||
| BTEqualStrategyNumber, F_OIDEQ, | ||
| ObjectIdGetDatum(relfilenumber)); | ||
|
|
||
| SysScanDesc scandesc = systable_beginscan(relation, | ||
| ClassTblspcRelfilenodeIndexId, | ||
| true, | ||
| NULL, | ||
| 2, | ||
| skey); | ||
|
|
||
| bool found = false; | ||
|
|
||
| while (HeapTupleIsValid(ntp = systable_getnext(scandesc))) | ||
| { | ||
| Form_pg_class classform = (Form_pg_class) GETSTRUCT(ntp); | ||
|
|
||
| if (found) | ||
| { | ||
| elog(ERROR, | ||
| "unexpected duplicate for tablespace %u, relfilenumber %u", | ||
| reltablespace, relfilenumber); | ||
| } | ||
| found = true; | ||
|
|
||
| Assert(classform->reltablespace == reltablespace); | ||
| Assert(classform->relfilenode == relfilenumber); | ||
|
|
||
| if (classform->relpersistence == RELPERSISTENCE_TEMP) | ||
| { | ||
| relid = classform->oid; | ||
| } | ||
| } | ||
|
|
||
| systable_endscan(scandesc); | ||
| table_close(relation, AccessShareLock); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything to be said for caching the entry and looking up the cache, as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to cache the entry since Postgres is no longer caching entries for temp tables. There is the disadvantage of scanning |
||
| } | ||
|
|
||
| return relid; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this if statement be wrapped in a PG version check for PG18 ? Or is the ignoring of temp tables backported ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nm, saw its backported to PG13.