2010-09-21 04:08:53 +08:00
|
|
|
/* contrib/cube/cubedata.h */
|
2006-03-11 12:38:42 +08:00
|
|
|
|
2002-09-12 08:26:00 +08:00
|
|
|
#define CUBE_MAX_DIM (100)
|
2007-02-28 07:48:10 +08:00
|
|
|
|
2001-03-22 12:01:46 +08:00
|
|
|
typedef struct NDBOX
|
|
|
|
{
|
Extend cube on-disk format to pack points more tightly.
If the lower left and upper right corners of a cube are the same, set a
flag in the cube header, and only store one copy of the coordinates. That
cuts the on-disk size into half for the common case that the cube datatype
is used to represent points rather than boxes.
The new format is backwards-compatible with the old one, so pg_upgrade
still works. However, to get the space savings, the data needs to be
rewritten. A simple VACUUM FULL or REINDEX is not enough, as the old
Datums will just be moved to the new heap/index as is. A pg_dump and
reload, or something similar like casting to text and back, will do the
trick.
This patch deliberately doesn't update all the alternative expected output
files, as I don't have access to machines that produce those outputs. I'm
not sure if they are still relevant, but if they are, the buildfarm will
tell us and produce the diff required to fix it. If none of the buildfarm
animals need them, they should be removed altogether.
Patch by Stas Kelvich.
2013-10-22 01:59:42 +08:00
|
|
|
/* varlena header (do not touch directly!) */
|
|
|
|
int32 vl_len_;
|
|
|
|
|
|
|
|
/*----------
|
|
|
|
* Header contains info about NDBOX. For binary compatibility with old
|
|
|
|
* versions, it is defined as "unsigned int".
|
|
|
|
*
|
|
|
|
* Following information is stored:
|
|
|
|
*
|
2014-05-07 00:12:18 +08:00
|
|
|
* bits 0-7 : number of cube dimensions;
|
|
|
|
* bits 8-30 : unused, initialize to zero;
|
|
|
|
* bit 31 : point flag. If set, the upper right coordinates are not
|
Extend cube on-disk format to pack points more tightly.
If the lower left and upper right corners of a cube are the same, set a
flag in the cube header, and only store one copy of the coordinates. That
cuts the on-disk size into half for the common case that the cube datatype
is used to represent points rather than boxes.
The new format is backwards-compatible with the old one, so pg_upgrade
still works. However, to get the space savings, the data needs to be
rewritten. A simple VACUUM FULL or REINDEX is not enough, as the old
Datums will just be moved to the new heap/index as is. A pg_dump and
reload, or something similar like casting to text and back, will do the
trick.
This patch deliberately doesn't update all the alternative expected output
files, as I don't have access to machines that produce those outputs. I'm
not sure if they are still relevant, but if they are, the buildfarm will
tell us and produce the diff required to fix it. If none of the buildfarm
animals need them, they should be removed altogether.
Patch by Stas Kelvich.
2013-10-22 01:59:42 +08:00
|
|
|
* stored, and are implicitly the same as the lower left
|
|
|
|
* coordinates.
|
|
|
|
*----------
|
|
|
|
*/
|
|
|
|
unsigned int header;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable length array. The lower left coordinates for each dimension
|
|
|
|
* come first, followed by upper right coordinates unless the point flag
|
|
|
|
* is set.
|
|
|
|
*/
|
2002-08-30 07:03:58 +08:00
|
|
|
double x[1];
|
2009-06-11 22:49:15 +08:00
|
|
|
} NDBOX;
|
2007-03-08 05:21:12 +08:00
|
|
|
|
Extend cube on-disk format to pack points more tightly.
If the lower left and upper right corners of a cube are the same, set a
flag in the cube header, and only store one copy of the coordinates. That
cuts the on-disk size into half for the common case that the cube datatype
is used to represent points rather than boxes.
The new format is backwards-compatible with the old one, so pg_upgrade
still works. However, to get the space savings, the data needs to be
rewritten. A simple VACUUM FULL or REINDEX is not enough, as the old
Datums will just be moved to the new heap/index as is. A pg_dump and
reload, or something similar like casting to text and back, will do the
trick.
This patch deliberately doesn't update all the alternative expected output
files, as I don't have access to machines that produce those outputs. I'm
not sure if they are still relevant, but if they are, the buildfarm will
tell us and produce the diff required to fix it. If none of the buildfarm
animals need them, they should be removed altogether.
Patch by Stas Kelvich.
2013-10-22 01:59:42 +08:00
|
|
|
#define POINT_BIT 0x80000000
|
2014-05-07 00:12:18 +08:00
|
|
|
#define DIM_MASK 0x7fffffff
|
Extend cube on-disk format to pack points more tightly.
If the lower left and upper right corners of a cube are the same, set a
flag in the cube header, and only store one copy of the coordinates. That
cuts the on-disk size into half for the common case that the cube datatype
is used to represent points rather than boxes.
The new format is backwards-compatible with the old one, so pg_upgrade
still works. However, to get the space savings, the data needs to be
rewritten. A simple VACUUM FULL or REINDEX is not enough, as the old
Datums will just be moved to the new heap/index as is. A pg_dump and
reload, or something similar like casting to text and back, will do the
trick.
This patch deliberately doesn't update all the alternative expected output
files, as I don't have access to machines that produce those outputs. I'm
not sure if they are still relevant, but if they are, the buildfarm will
tell us and produce the diff required to fix it. If none of the buildfarm
animals need them, they should be removed altogether.
Patch by Stas Kelvich.
2013-10-22 01:59:42 +08:00
|
|
|
|
|
|
|
#define IS_POINT(cube) ( ((cube)->header & POINT_BIT) != 0 )
|
2014-05-07 00:12:18 +08:00
|
|
|
#define SET_POINT_BIT(cube) ( (cube)->header |= POINT_BIT )
|
Extend cube on-disk format to pack points more tightly.
If the lower left and upper right corners of a cube are the same, set a
flag in the cube header, and only store one copy of the coordinates. That
cuts the on-disk size into half for the common case that the cube datatype
is used to represent points rather than boxes.
The new format is backwards-compatible with the old one, so pg_upgrade
still works. However, to get the space savings, the data needs to be
rewritten. A simple VACUUM FULL or REINDEX is not enough, as the old
Datums will just be moved to the new heap/index as is. A pg_dump and
reload, or something similar like casting to text and back, will do the
trick.
This patch deliberately doesn't update all the alternative expected output
files, as I don't have access to machines that produce those outputs. I'm
not sure if they are still relevant, but if they are, the buildfarm will
tell us and produce the diff required to fix it. If none of the buildfarm
animals need them, they should be removed altogether.
Patch by Stas Kelvich.
2013-10-22 01:59:42 +08:00
|
|
|
#define DIM(cube) ( (cube)->header & DIM_MASK )
|
2014-05-07 00:12:18 +08:00
|
|
|
#define SET_DIM(cube, _dim) ( (cube)->header = ((cube)->header & ~DIM_MASK) | (_dim) )
|
Extend cube on-disk format to pack points more tightly.
If the lower left and upper right corners of a cube are the same, set a
flag in the cube header, and only store one copy of the coordinates. That
cuts the on-disk size into half for the common case that the cube datatype
is used to represent points rather than boxes.
The new format is backwards-compatible with the old one, so pg_upgrade
still works. However, to get the space savings, the data needs to be
rewritten. A simple VACUUM FULL or REINDEX is not enough, as the old
Datums will just be moved to the new heap/index as is. A pg_dump and
reload, or something similar like casting to text and back, will do the
trick.
This patch deliberately doesn't update all the alternative expected output
files, as I don't have access to machines that produce those outputs. I'm
not sure if they are still relevant, but if they are, the buildfarm will
tell us and produce the diff required to fix it. If none of the buildfarm
animals need them, they should be removed altogether.
Patch by Stas Kelvich.
2013-10-22 01:59:42 +08:00
|
|
|
|
|
|
|
#define LL_COORD(cube, i) ( (cube)->x[i] )
|
|
|
|
#define UR_COORD(cube, i) ( IS_POINT(cube) ? (cube)->x[i] : (cube)->x[(i) + DIM(cube)] )
|
|
|
|
|
|
|
|
#define POINT_SIZE(_dim) (offsetof(NDBOX, x[0]) + sizeof(double)*(_dim))
|
|
|
|
#define CUBE_SIZE(_dim) (offsetof(NDBOX, x[0]) + sizeof(double)*(_dim)*2)
|
|
|
|
|
2007-03-08 05:21:12 +08:00
|
|
|
#define DatumGetNDBOX(x) ((NDBOX*)DatumGetPointer(x))
|
|
|
|
#define PG_GETARG_NDBOX(x) DatumGetNDBOX( PG_DETOAST_DATUM(PG_GETARG_DATUM(x)) )
|
|
|
|
#define PG_RETURN_NDBOX(x) PG_RETURN_POINTER(x)
|