Perfomance

Please explain, why you use DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(get_key))) to covert to char*. It is a lot of useless conversations. All we need is to get the pointer to char data, simply use VARDATA macros, Example, https://github.com/winlibs/postgresql/blob/master/src/backend/utils/adt/quote.c#L89  
If I left something behind - give me to know.