Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
detoast.h83 linesDownload Raw Back to access
1/*-------------------------------------------------------------------------2 *3 * detoast.h4 *	  Access to compressed and external varlena values.5 *6 * Copyright (c) 2000-2023, PostgreSQL Global Development Group7 *8 * src/include/access/detoast.h9 *10 *-------------------------------------------------------------------------11 */12#ifndef DETOAST_H13#define DETOAST_H14 15/*16 * Macro to fetch the possibly-unaligned contents of an EXTERNAL datum17 * into a local "struct varatt_external" toast pointer.  This should be18 * just a memcpy, but some versions of gcc seem to produce broken code19 * that assumes the datum contents are aligned.  Introducing an explicit20 * intermediate "varattrib_1b_e *" variable seems to fix it.21 */22#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr) \23do { \24	varattrib_1b_e *attre = (varattrib_1b_e *) (attr); \25	Assert(VARATT_IS_EXTERNAL(attre)); \26	Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \27	memcpy(&(toast_pointer), VARDATA_EXTERNAL(attre), sizeof(toast_pointer)); \28} while (0)29 30/* Size of an EXTERNAL datum that contains a standard TOAST pointer */31#define TOAST_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_external))32 33/* Size of an EXTERNAL datum that contains an indirection pointer */34#define INDIRECT_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_indirect))35 36/* ----------37 * detoast_external_attr() -38 *39 *		Fetches an external stored attribute from the toast40 *		relation. Does NOT decompress it, if stored external41 *		in compressed format.42 * ----------43 */44extern struct varlena *detoast_external_attr(struct varlena *attr);45 46/* ----------47 * detoast_attr() -48 *49 *		Fully detoasts one attribute, fetching and/or decompressing50 *		it as needed.51 * ----------52 */53extern struct varlena *detoast_attr(struct varlena *attr);54 55/* ----------56 * detoast_attr_slice() -57 *58 *		Fetches only the specified portion of an attribute.59 *		(Handles all cases for attribute storage)60 * ----------61 */62extern struct varlena *detoast_attr_slice(struct varlena *attr,63										  int32 sliceoffset,64										  int32 slicelength);65 66/* ----------67 * toast_raw_datum_size -68 *69 *	Return the raw (detoasted) size of a varlena datum70 * ----------71 */72extern Size toast_raw_datum_size(Datum value);73 74/* ----------75 * toast_datum_size -76 *77 *	Return the storage size of a varlena datum78 * ----------79 */80extern Size toast_datum_size(Datum value);81 82#endif							/* DETOAST_H */83 
codekingpro/portable-devtools · Team Ai