* Initialize table access method support for a table like relation */
| 1852 | * Initialize table access method support for a table like relation |
| 1853 | */ |
| 1854 | void |
| 1855 | RelationInitTableAccessMethod(Relation relation) |
| 1856 | { |
| 1857 | HeapTuple tuple; |
| 1858 | Form_pg_am aform; |
| 1859 | |
| 1860 | if (relation->rd_rel->relkind == RELKIND_SEQUENCE) |
| 1861 | { |
| 1862 | /* |
| 1863 | * Sequences are currently accessed like heap tables, but it doesn't |
| 1864 | * seem prudent to show that in the catalog. So just overwrite it |
| 1865 | * here. |
| 1866 | */ |
| 1867 | relation->rd_amhandler = F_HEAP_TABLEAM_HANDLER; |
| 1868 | } |
| 1869 | else if (IsCatalogRelation(relation)) |
| 1870 | { |
| 1871 | /* |
| 1872 | * Avoid doing a syscache lookup for catalog tables. |
| 1873 | */ |
| 1874 | Assert(relation->rd_rel->relam == HEAP_TABLE_AM_OID); |
| 1875 | relation->rd_amhandler = F_HEAP_TABLEAM_HANDLER; |
| 1876 | } |
| 1877 | else |
| 1878 | { |
| 1879 | /* |
| 1880 | * Look up the table access method, save the OID of its handler |
| 1881 | * function. |
| 1882 | */ |
| 1883 | Assert(relation->rd_rel->relam != InvalidOid); |
| 1884 | tuple = SearchSysCache1(AMOID, |
| 1885 | ObjectIdGetDatum(relation->rd_rel->relam)); |
| 1886 | if (!HeapTupleIsValid(tuple)) |
| 1887 | elog(ERROR, "cache lookup failed for access method %u", |
| 1888 | relation->rd_rel->relam); |
| 1889 | aform = (Form_pg_am) GETSTRUCT(tuple); |
| 1890 | relation->rd_amhandler = aform->amhandler; |
| 1891 | ReleaseSysCache(tuple); |
| 1892 | /* |
| 1893 | * Cloudberry: append-optimized relations should not have a valid |
| 1894 | * relfrozenxid. |
| 1895 | */ |
| 1896 | Assert (!RelationStorageIsAO(relation) || |
| 1897 | !TransactionIdIsValid(relation->rd_rel->relfrozenxid)); |
| 1898 | } |
| 1899 | |
| 1900 | /* |
| 1901 | * Now we can fetch the table AM's API struct |
| 1902 | */ |
| 1903 | InitTableAmRoutine(relation); |
| 1904 | } |
| 1905 | |
| 1906 | /* |
| 1907 | * formrdesc |
no test coverage detected