* Helper routine that copies the keys in the srckeys array into the dstkeys * one, guaranteeing that the datums are fully allocated in the current memory * context. */
| 2000 | * context. |
| 2001 | */ |
| 2002 | static void |
| 2003 | CatCacheCopyKeys(TupleDesc tupdesc, int nkeys, int *attnos, |
| 2004 | Datum *srckeys, Datum *dstkeys) |
| 2005 | { |
| 2006 | int i; |
| 2007 | |
| 2008 | /* |
| 2009 | * XXX: memory and lookup performance could possibly be improved by |
| 2010 | * storing all keys in one allocation. |
| 2011 | */ |
| 2012 | |
| 2013 | for (i = 0; i < nkeys; i++) |
| 2014 | { |
| 2015 | int attnum = attnos[i]; |
| 2016 | Form_pg_attribute att = TupleDescAttr(tupdesc, attnum - 1); |
| 2017 | Datum src = srckeys[i]; |
| 2018 | NameData srcname; |
| 2019 | |
| 2020 | /* |
| 2021 | * Must be careful in case the caller passed a C string where a NAME |
| 2022 | * is wanted: convert the given argument to a correctly padded NAME. |
| 2023 | * Otherwise the memcpy() done by datumCopy() could fall off the end |
| 2024 | * of memory. |
| 2025 | */ |
| 2026 | if (att->atttypid == NAMEOID) |
| 2027 | { |
| 2028 | namestrcpy(&srcname, DatumGetCString(src)); |
| 2029 | src = NameGetDatum(&srcname); |
| 2030 | } |
| 2031 | |
| 2032 | dstkeys[i] = datumCopy(src, |
| 2033 | att->attbyval, |
| 2034 | att->attlen); |
| 2035 | } |
| 2036 | |
| 2037 | } |
| 2038 | |
| 2039 | /* |
| 2040 | * PrepareToInvalidateCacheTuple() |
no test coverage detected