Preventing intersection of ranges during page split. Changes are only

optimization, so don't backpatch.
This commit is contained in:
Teodor Sigaev 2009-12-02 13:13:24 +00:00
parent 59ed94ad0c
commit aebc4e67ff
14 changed files with 145 additions and 83 deletions

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.9 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.10 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,13 +57,18 @@ gbt_cashlt(const void *a, const void *b)
static int
gbt_cashkey_cmp(const void *a, const void *b)
{
cashKEY *ia = (cashKEY*)(((Nsrt *) a)->t);
cashKEY *ib = (cashKEY*)(((Nsrt *) b)->t);
if (*(Cash *) &(((Nsrt *) a)->t[0]) > *(Cash *) &(((Nsrt *) b)->t[0]))
return 1;
else if (*(Cash *) &(((Nsrt *) a)->t[0]) < *(Cash *) &(((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.7 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.8 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -73,11 +73,15 @@ gbt_datelt(const void *a, const void *b)
static int
gbt_datekey_cmp(const void *a, const void *b)
{
if (gbt_dategt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return 1;
else if (gbt_datelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return -1;
return 0;
dateKEY *ia = (dateKEY*)(((Nsrt *) a)->t);
dateKEY *ib = (dateKEY*)(((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->lower), DateADTGetDatum(ib->lower)));
if (res == 0)
return DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->upper), DateADTGetDatum(ib->upper)));
return res;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -56,13 +56,18 @@ gbt_float4lt(const void *a, const void *b)
static int
gbt_float4key_cmp(const void *a, const void *b)
{
float4KEY *ia = (float4KEY*)(((Nsrt *) a)->t);
float4KEY *ib = (float4KEY*)(((Nsrt *) b)->t);
if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
return 1;
else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,13 +57,18 @@ gbt_float8lt(const void *a, const void *b)
static int
gbt_float8key_cmp(const void *a, const void *b)
{
float8KEY *ia = (float8KEY*)(((Nsrt *) a)->t);
float8KEY *ib = (float8KEY*)(((Nsrt *) b)->t);
if (*(float8 *) &(((Nsrt *) a)->t[0]) > *(float8 *) &(((Nsrt *) b)->t[0]))
return 1;
else if (*(float8 *) &(((Nsrt *) a)->t[0]) < *(float8 *) &(((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.10 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.11 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -60,13 +60,18 @@ gbt_inetlt(const void *a, const void *b)
static int
gbt_inetkey_cmp(const void *a, const void *b)
{
inetKEY *ia = (inetKEY*)(((Nsrt *) a)->t);
inetKEY *ib = (inetKEY*)(((Nsrt *) b)->t);
if (*(double *) (&((Nsrt *) a)->t[0]) > *(double *) (&((Nsrt *) b)->t[0]))
return 1;
else if (*(double *) (&((Nsrt *) a)->t[0]) < *(double *) (&((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -56,13 +56,18 @@ gbt_int2lt(const void *a, const void *b)
static int
gbt_int2key_cmp(const void *a, const void *b)
{
int16KEY *ia = (int16KEY*)(((Nsrt *) a)->t);
int16KEY *ib = (int16KEY*)(((Nsrt *) b)->t);
if (*(int16 *) (&((Nsrt *) a)->t[0]) > *(int16 *) &(((Nsrt *) b)->t[0]))
return 1;
else if (*(int16 *) &(((Nsrt *) a)->t[0]) < *(int16 *) &(((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,13 +57,18 @@ gbt_int4lt(const void *a, const void *b)
static int
gbt_int4key_cmp(const void *a, const void *b)
{
int32KEY *ia = (int32KEY*)(((Nsrt *) a)->t);
int32KEY *ib = (int32KEY*)(((Nsrt *) b)->t);
if (*(int32 *) &(((Nsrt *) a)->t[0]) > *(int32 *) &(((Nsrt *) b)->t[0]))
return 1;
else if (*(int32 *) &(((Nsrt *) a)->t[0]) < *(int32 *) &(((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,13 +57,18 @@ gbt_int8lt(const void *a, const void *b)
static int
gbt_int8key_cmp(const void *a, const void *b)
{
int64KEY *ia = (int64KEY*)(((Nsrt *) a)->t);
int64KEY *ib = (int64KEY*)(((Nsrt *) b)->t);
if (*(int64 *) &(((Nsrt *) a)->t[0]) > *(int64 *) &(((Nsrt *) b)->t[0]))
return 1;
else if (*(int64 *) &(((Nsrt *) a)->t[0]) < *(int64 *) &(((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.12 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.13 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -65,12 +65,15 @@ gbt_intvlt(const void *a, const void *b)
static int
gbt_intvkey_cmp(const void *a, const void *b)
{
return DatumGetInt32(
DirectFunctionCall2(interval_cmp,
IntervalPGetDatum(((Nsrt *) a)->t),
IntervalPGetDatum(((Nsrt *) b)->t)
)
);
intvKEY *ia = (intvKEY*)(((Nsrt *) a)->t);
intvKEY *ib = (intvKEY*)(((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->lower), IntervalPGetDatum(&ib->lower)));
if (res == 0)
return DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->upper), IntervalPGetDatum(&ib->upper)));
return res;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -63,13 +63,15 @@ gbt_macadlt(const void *a, const void *b)
static int
gbt_macadkey_cmp(const void *a, const void *b)
{
return DatumGetInt32(
DirectFunctionCall2(
macaddr_cmp,
PointerGetDatum(&((Nsrt *) a)->t[0]),
PointerGetDatum(&((Nsrt *) b)->t[0])
)
);
macKEY *ia = (macKEY*)(((Nsrt *) a)->t);
macKEY *ib = (macKEY*)(((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower)));
if (res == 0)
return DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->upper), MacaddrPGetDatum(&ib->upper)));
return res;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,13 +57,18 @@ gbt_oidlt(const void *a, const void *b)
static int
gbt_oidkey_cmp(const void *a, const void *b)
{
oidKEY *ia = (oidKEY*)(((Nsrt *) a)->t);
oidKEY *ib = (oidKEY*)(((Nsrt *) b)->t);
if (*(Oid *) &(((Nsrt *) a)->t[0]) > *(Oid *) &(((Nsrt *) b)->t[0]))
return 1;
else if (*(Oid *) &(((Nsrt *) a)->t[0]) < *(Oid *) &(((Nsrt *) b)->t[0]))
return -1;
return 0;
if (ia->lower == ib->lower)
{
if (ia->upper == ib->upper)
return 0;
return (ia->upper > ib->upper) ? 1 : -1;
}
return (ia->lower > ib->lower) ? 1 : -1;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.16 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.17 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -101,11 +101,15 @@ gbt_timelt(const void *a, const void *b)
static int
gbt_timekey_cmp(const void *a, const void *b)
{
if (gbt_timegt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return 1;
else if (gbt_timelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return -1;
return 0;
timeKEY *ia = (timeKEY*)(((Nsrt *) a)->t);
timeKEY *ib = (timeKEY*)(((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->lower), TimeADTGetDatumFast(ib->lower)));
if (res == 0)
return DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->upper), TimeADTGetDatumFast(ib->upper)));
return res;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.17 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.18 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -99,11 +99,15 @@ gbt_tslt(const void *a, const void *b)
static int
gbt_tskey_cmp(const void *a, const void *b)
{
if (gbt_tsgt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return 1;
else if (gbt_tslt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
return -1;
return 0;
tsKEY *ia = (tsKEY*)(((Nsrt *) a)->t);
tsKEY *ib = (tsKEY*)(((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->lower), TimestampGetDatumFast(ib->lower)));
if (res == 0)
return DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->upper), TimestampGetDatumFast(ib->upper)));
return res;
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.21 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.22 2009/12/02 13:13:24 teodor Exp $
*/
#include "btree_gist.h"
@ -444,8 +444,13 @@ gbt_vsrt_cmp(const void *a, const void *b, void *arg)
GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
const gbtree_vinfo *tinfo = (const gbtree_vinfo *) arg;
int res;
return (*tinfo->f_cmp) (ar.lower, br.lower);
res = (*tinfo->f_cmp) (ar.lower, br.lower);
if (res == 0)
return (*tinfo->f_cmp) (ar.upper, br.upper);
return res;
}
GIST_SPLITVEC *