Skip to content

Commit aebc4e6

Browse files
committed
Preventing intersection of ranges during page split. Changes are only
optimization, so don't backpatch.
1 parent 59ed94a commit aebc4e6

14 files changed

+145
-83
lines changed

contrib/btree_gist/btree_cash.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.9 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.10 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -57,13 +57,18 @@ gbt_cashlt(const void *a, const void *b)
5757
static int
5858
gbt_cashkey_cmp(const void *a, const void *b)
5959
{
60+
cashKEY *ia = (cashKEY*)(((Nsrt *) a)->t);
61+
cashKEY *ib = (cashKEY*)(((Nsrt *) b)->t);
6062

61-
if (*(Cash *) &(((Nsrt *) a)->t[0]) > *(Cash *) &(((Nsrt *) b)->t[0]))
62-
return 1;
63-
else if (*(Cash *) &(((Nsrt *) a)->t[0]) < *(Cash *) &(((Nsrt *) b)->t[0]))
64-
return -1;
65-
return 0;
63+
if (ia->lower == ib->lower)
64+
{
65+
if (ia->upper == ib->upper)
66+
return 0;
6667

68+
return (ia->upper > ib->upper) ? 1 : -1;
69+
}
70+
71+
return (ia->lower > ib->lower) ? 1 : -1;
6772
}
6873

6974

contrib/btree_gist/btree_date.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.7 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.8 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -73,11 +73,15 @@ gbt_datelt(const void *a, const void *b)
7373
static int
7474
gbt_datekey_cmp(const void *a, const void *b)
7575
{
76-
if (gbt_dategt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
77-
return 1;
78-
else if (gbt_datelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
79-
return -1;
80-
return 0;
76+
dateKEY *ia = (dateKEY*)(((Nsrt *) a)->t);
77+
dateKEY *ib = (dateKEY*)(((Nsrt *) b)->t);
78+
int res;
79+
80+
res = DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->lower), DateADTGetDatum(ib->lower)));
81+
if (res == 0)
82+
return DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->upper), DateADTGetDatum(ib->upper)));
83+
84+
return res;
8185
}
8286

8387

contrib/btree_gist/btree_float4.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -56,13 +56,18 @@ gbt_float4lt(const void *a, const void *b)
5656
static int
5757
gbt_float4key_cmp(const void *a, const void *b)
5858
{
59+
float4KEY *ia = (float4KEY*)(((Nsrt *) a)->t);
60+
float4KEY *ib = (float4KEY*)(((Nsrt *) b)->t);
5961

60-
if (*(float4 *) &(((Nsrt *) a)->t[0]) > *(float4 *) &(((Nsrt *) b)->t[0]))
61-
return 1;
62-
else if (*(float4 *) &(((Nsrt *) a)->t[0]) < *(float4 *) &(((Nsrt *) b)->t[0]))
63-
return -1;
64-
return 0;
62+
if (ia->lower == ib->lower)
63+
{
64+
if (ia->upper == ib->upper)
65+
return 0;
6566

67+
return (ia->upper > ib->upper) ? 1 : -1;
68+
}
69+
70+
return (ia->lower > ib->lower) ? 1 : -1;
6671
}
6772

6873

contrib/btree_gist/btree_float8.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -57,13 +57,18 @@ gbt_float8lt(const void *a, const void *b)
5757
static int
5858
gbt_float8key_cmp(const void *a, const void *b)
5959
{
60+
float8KEY *ia = (float8KEY*)(((Nsrt *) a)->t);
61+
float8KEY *ib = (float8KEY*)(((Nsrt *) b)->t);
6062

61-
if (*(float8 *) &(((Nsrt *) a)->t[0]) > *(float8 *) &(((Nsrt *) b)->t[0]))
62-
return 1;
63-
else if (*(float8 *) &(((Nsrt *) a)->t[0]) < *(float8 *) &(((Nsrt *) b)->t[0]))
64-
return -1;
65-
return 0;
63+
if (ia->lower == ib->lower)
64+
{
65+
if (ia->upper == ib->upper)
66+
return 0;
6667

68+
return (ia->upper > ib->upper) ? 1 : -1;
69+
}
70+
71+
return (ia->lower > ib->lower) ? 1 : -1;
6772
}
6873

6974

contrib/btree_gist/btree_inet.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.10 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.11 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -60,13 +60,18 @@ gbt_inetlt(const void *a, const void *b)
6060
static int
6161
gbt_inetkey_cmp(const void *a, const void *b)
6262
{
63+
inetKEY *ia = (inetKEY*)(((Nsrt *) a)->t);
64+
inetKEY *ib = (inetKEY*)(((Nsrt *) b)->t);
6365

64-
if (*(double *) (&((Nsrt *) a)->t[0]) > *(double *) (&((Nsrt *) b)->t[0]))
65-
return 1;
66-
else if (*(double *) (&((Nsrt *) a)->t[0]) < *(double *) (&((Nsrt *) b)->t[0]))
67-
return -1;
68-
return 0;
66+
if (ia->lower == ib->lower)
67+
{
68+
if (ia->upper == ib->upper)
69+
return 0;
70+
71+
return (ia->upper > ib->upper) ? 1 : -1;
72+
}
6973

74+
return (ia->lower > ib->lower) ? 1 : -1;
7075
}
7176

7277

contrib/btree_gist/btree_int2.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -56,13 +56,18 @@ gbt_int2lt(const void *a, const void *b)
5656
static int
5757
gbt_int2key_cmp(const void *a, const void *b)
5858
{
59+
int16KEY *ia = (int16KEY*)(((Nsrt *) a)->t);
60+
int16KEY *ib = (int16KEY*)(((Nsrt *) b)->t);
5961

60-
if (*(int16 *) (&((Nsrt *) a)->t[0]) > *(int16 *) &(((Nsrt *) b)->t[0]))
61-
return 1;
62-
else if (*(int16 *) &(((Nsrt *) a)->t[0]) < *(int16 *) &(((Nsrt *) b)->t[0]))
63-
return -1;
64-
return 0;
62+
if (ia->lower == ib->lower)
63+
{
64+
if (ia->upper == ib->upper)
65+
return 0;
6566

67+
return (ia->upper > ib->upper) ? 1 : -1;
68+
}
69+
70+
return (ia->lower > ib->lower) ? 1 : -1;
6671
}
6772

6873

contrib/btree_gist/btree_int4.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -57,13 +57,18 @@ gbt_int4lt(const void *a, const void *b)
5757
static int
5858
gbt_int4key_cmp(const void *a, const void *b)
5959
{
60+
int32KEY *ia = (int32KEY*)(((Nsrt *) a)->t);
61+
int32KEY *ib = (int32KEY*)(((Nsrt *) b)->t);
6062

61-
if (*(int32 *) &(((Nsrt *) a)->t[0]) > *(int32 *) &(((Nsrt *) b)->t[0]))
62-
return 1;
63-
else if (*(int32 *) &(((Nsrt *) a)->t[0]) < *(int32 *) &(((Nsrt *) b)->t[0]))
64-
return -1;
65-
return 0;
63+
if (ia->lower == ib->lower)
64+
{
65+
if (ia->upper == ib->upper)
66+
return 0;
6667

68+
return (ia->upper > ib->upper) ? 1 : -1;
69+
}
70+
71+
return (ia->lower > ib->lower) ? 1 : -1;
6772
}
6873

6974

contrib/btree_gist/btree_int8.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -57,13 +57,18 @@ gbt_int8lt(const void *a, const void *b)
5757
static int
5858
gbt_int8key_cmp(const void *a, const void *b)
5959
{
60+
int64KEY *ia = (int64KEY*)(((Nsrt *) a)->t);
61+
int64KEY *ib = (int64KEY*)(((Nsrt *) b)->t);
6062

61-
if (*(int64 *) &(((Nsrt *) a)->t[0]) > *(int64 *) &(((Nsrt *) b)->t[0]))
62-
return 1;
63-
else if (*(int64 *) &(((Nsrt *) a)->t[0]) < *(int64 *) &(((Nsrt *) b)->t[0]))
64-
return -1;
65-
return 0;
63+
if (ia->lower == ib->lower)
64+
{
65+
if (ia->upper == ib->upper)
66+
return 0;
6667

68+
return (ia->upper > ib->upper) ? 1 : -1;
69+
}
70+
71+
return (ia->lower > ib->lower) ? 1 : -1;
6772
}
6873

6974

contrib/btree_gist/btree_interval.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.12 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.13 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -65,12 +65,15 @@ gbt_intvlt(const void *a, const void *b)
6565
static int
6666
gbt_intvkey_cmp(const void *a, const void *b)
6767
{
68-
return DatumGetInt32(
69-
DirectFunctionCall2(interval_cmp,
70-
IntervalPGetDatum(((Nsrt *) a)->t),
71-
IntervalPGetDatum(((Nsrt *) b)->t)
72-
)
73-
);
68+
intvKEY *ia = (intvKEY*)(((Nsrt *) a)->t);
69+
intvKEY *ib = (intvKEY*)(((Nsrt *) b)->t);
70+
int res;
71+
72+
res = DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->lower), IntervalPGetDatum(&ib->lower)));
73+
if (res == 0)
74+
return DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->upper), IntervalPGetDatum(&ib->upper)));
75+
76+
return res;
7477
}
7578

7679

contrib/btree_gist/btree_macaddr.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -63,13 +63,15 @@ gbt_macadlt(const void *a, const void *b)
6363
static int
6464
gbt_macadkey_cmp(const void *a, const void *b)
6565
{
66-
return DatumGetInt32(
67-
DirectFunctionCall2(
68-
macaddr_cmp,
69-
PointerGetDatum(&((Nsrt *) a)->t[0]),
70-
PointerGetDatum(&((Nsrt *) b)->t[0])
71-
)
72-
);
66+
macKEY *ia = (macKEY*)(((Nsrt *) a)->t);
67+
macKEY *ib = (macKEY*)(((Nsrt *) b)->t);
68+
int res;
69+
70+
res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower)));
71+
if (res == 0)
72+
return DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->upper), MacaddrPGetDatum(&ib->upper)));
73+
74+
return res;
7375
}
7476

7577

contrib/btree_gist/btree_oid.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.8 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -57,13 +57,18 @@ gbt_oidlt(const void *a, const void *b)
5757
static int
5858
gbt_oidkey_cmp(const void *a, const void *b)
5959
{
60+
oidKEY *ia = (oidKEY*)(((Nsrt *) a)->t);
61+
oidKEY *ib = (oidKEY*)(((Nsrt *) b)->t);
6062

61-
if (*(Oid *) &(((Nsrt *) a)->t[0]) > *(Oid *) &(((Nsrt *) b)->t[0]))
62-
return 1;
63-
else if (*(Oid *) &(((Nsrt *) a)->t[0]) < *(Oid *) &(((Nsrt *) b)->t[0]))
64-
return -1;
65-
return 0;
63+
if (ia->lower == ib->lower)
64+
{
65+
if (ia->upper == ib->upper)
66+
return 0;
6667

68+
return (ia->upper > ib->upper) ? 1 : -1;
69+
}
70+
71+
return (ia->lower > ib->lower) ? 1 : -1;
6772
}
6873

6974

contrib/btree_gist/btree_time.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.16 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.17 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -101,11 +101,15 @@ gbt_timelt(const void *a, const void *b)
101101
static int
102102
gbt_timekey_cmp(const void *a, const void *b)
103103
{
104-
if (gbt_timegt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
105-
return 1;
106-
else if (gbt_timelt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
107-
return -1;
108-
return 0;
104+
timeKEY *ia = (timeKEY*)(((Nsrt *) a)->t);
105+
timeKEY *ib = (timeKEY*)(((Nsrt *) b)->t);
106+
int res;
107+
108+
res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->lower), TimeADTGetDatumFast(ib->lower)));
109+
if (res == 0)
110+
return DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->upper), TimeADTGetDatumFast(ib->upper)));
111+
112+
return res;
109113
}
110114

111115

contrib/btree_gist/btree_ts.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.17 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.18 2009/12/02 13:13:24 teodor Exp $
33
*/
44
#include "btree_gist.h"
55
#include "btree_utils_num.h"
@@ -99,11 +99,15 @@ gbt_tslt(const void *a, const void *b)
9999
static int
100100
gbt_tskey_cmp(const void *a, const void *b)
101101
{
102-
if (gbt_tsgt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
103-
return 1;
104-
else if (gbt_tslt((void *) &(((Nsrt *) a)->t[0]), (void *) &(((Nsrt *) b)->t[0])))
105-
return -1;
106-
return 0;
102+
tsKEY *ia = (tsKEY*)(((Nsrt *) a)->t);
103+
tsKEY *ib = (tsKEY*)(((Nsrt *) b)->t);
104+
int res;
105+
106+
res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->lower), TimestampGetDatumFast(ib->lower)));
107+
if (res == 0)
108+
return DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->upper), TimestampGetDatumFast(ib->upper)));
109+
110+
return res;
107111
}
108112

109113

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy