* CatalogCacheCreateEntry * Create a new CatCTup entry, copying the given HeapTuple and other * supplied data into it. The new entry initially has refcount 0. */
| 1869 | * supplied data into it. The new entry initially has refcount 0. |
| 1870 | */ |
| 1871 | static CatCTup * |
| 1872 | CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, Datum *arguments, |
| 1873 | uint32 hashValue, Index hashIndex, |
| 1874 | bool negative) |
| 1875 | { |
| 1876 | CatCTup *ct; |
| 1877 | HeapTuple dtp; |
| 1878 | MemoryContext oldcxt; |
| 1879 | |
| 1880 | /* negative entries have no tuple associated */ |
| 1881 | if (ntp) |
| 1882 | { |
| 1883 | int i; |
| 1884 | |
| 1885 | Assert(!negative); |
| 1886 | |
| 1887 | /* |
| 1888 | * If there are any out-of-line toasted fields in the tuple, expand |
| 1889 | * them in-line. This saves cycles during later use of the catcache |
| 1890 | * entry, and also protects us against the possibility of the toast |
| 1891 | * tuples being freed before we attempt to fetch them, in case of |
| 1892 | * something using a slightly stale catcache entry. |
| 1893 | */ |
| 1894 | if (HeapTupleHasExternal(ntp)) |
| 1895 | dtp = toast_flatten_tuple(ntp, cache->cc_tupdesc); |
| 1896 | else |
| 1897 | dtp = ntp; |
| 1898 | |
| 1899 | /* Allocate memory for CatCTup and the cached tuple in one go */ |
| 1900 | oldcxt = MemoryContextSwitchTo(CacheMemoryContext); |
| 1901 | |
| 1902 | ct = (CatCTup *) palloc(sizeof(CatCTup) + |
| 1903 | MAXIMUM_ALIGNOF + dtp->t_len); |
| 1904 | ct->tuple.t_len = dtp->t_len; |
| 1905 | ct->tuple.t_self = dtp->t_self; |
| 1906 | ct->tuple.t_tableOid = dtp->t_tableOid; |
| 1907 | ct->tuple.t_data = (HeapTupleHeader) |
| 1908 | MAXALIGN(((char *) ct) + sizeof(CatCTup)); |
| 1909 | /* copy tuple contents */ |
| 1910 | memcpy((char *) ct->tuple.t_data, |
| 1911 | (const char *) dtp->t_data, |
| 1912 | dtp->t_len); |
| 1913 | MemoryContextSwitchTo(oldcxt); |
| 1914 | |
| 1915 | if (dtp != ntp) |
| 1916 | heap_freetuple(dtp); |
| 1917 | |
| 1918 | /* extract keys - they'll point into the tuple if not by-value */ |
| 1919 | for (i = 0; i < cache->cc_nkeys; i++) |
| 1920 | { |
| 1921 | Datum atp; |
| 1922 | bool isnull; |
| 1923 | |
| 1924 | atp = heap_getattr(&ct->tuple, |
| 1925 | cache->cc_keyno[i], |
| 1926 | cache->cc_tupdesc, |
| 1927 | &isnull); |
| 1928 | Assert(!isnull); |
no test coverage detected