Skip to content

Commit ef770cb

Browse files
committed
Fixes from Janko Richter <jankorichter@yahoo.de>
- Fix wrong index results on text, char, varchar for multibyte strings - Fix some SIGFPE signals - Add support for infinite timestamps - Because of locale settings, btree_gist can not be a prefix index anymore (for text). Each node holds now just the lower and upper boundary.
1 parent 8f6e8e8 commit ef770cb

27 files changed

+730
-304
lines changed

contrib/btree_gist/btree_bit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ gbt_bit_l2n(GBT_VARKEY * leaf)
9898
static const gbtree_vinfo tinfo =
9999
{
100100
gbt_t_bit,
101-
FALSE,
101+
0,
102102
TRUE,
103103
gbt_bitgt,
104104
gbt_bitge,

contrib/btree_gist/btree_bytea.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ gbt_byteacmp(const bytea *a, const bytea *b)
6565
static const gbtree_vinfo tinfo =
6666
{
6767
gbt_t_bytea,
68-
FALSE,
68+
0,
6969
TRUE,
7070
gbt_byteagt,
7171
gbt_byteage,

contrib/btree_gist/btree_cash.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,10 @@ Datum
125125
gbt_cash_penalty(PG_FUNCTION_ARGS)
126126
{
127127
cashKEY *origentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
128-
cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
129-
float *result = (float *) PG_GETARG_POINTER(2);
128+
cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
129+
float *result = (float *) PG_GETARG_POINTER(2);
130130

131-
Cash res;
132-
133-
*result = 0.0;
134-
135-
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
136-
137-
if (res > 0)
138-
{
139-
*result += FLT_MIN;
140-
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
141-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
142-
}
131+
penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
143132

144133
PG_RETURN_POINTER(result);
145134

contrib/btree_gist/btree_float4.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,7 @@ gbt_float4_penalty(PG_FUNCTION_ARGS)
127127
float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
128128
float *result = (float *) PG_GETARG_POINTER(2);
129129

130-
float4 res;
131-
132-
*result = 0.0;
133-
134-
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
135-
136-
if (res > 0)
137-
{
138-
*result += FLT_MIN;
139-
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
140-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
141-
}
130+
penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
142131

143132
PG_RETURN_POINTER(result);
144133

contrib/btree_gist/btree_float8.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,7 @@ gbt_float8_penalty(PG_FUNCTION_ARGS)
129129
float8KEY *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
130130
float *result = (float *) PG_GETARG_POINTER(2);
131131

132-
float8 res;
133-
134-
*result = 0.0;
135-
136-
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
137-
138-
if (res > 0)
139-
{
140-
*result += FLT_MIN;
141-
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
142-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
143-
}
132+
penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
144133

145134
PG_RETURN_POINTER(result);
146135

contrib/btree_gist/btree_inet.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,8 @@ gbt_inet_penalty(PG_FUNCTION_ARGS)
194194
inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
195195
float *result = (float *) PG_GETARG_POINTER(2);
196196

197-
double res;
198-
199-
*result = 0.0;
200-
201-
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
202-
203-
if (res > 0)
204-
{
205-
*result += FLT_MIN;
206-
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
207-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
208-
}
209-
197+
penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
198+
210199
PG_RETURN_POINTER(result);
211200

212201
}

contrib/btree_gist/btree_int2.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,10 @@ Datum
128128
gbt_int2_penalty(PG_FUNCTION_ARGS)
129129
{
130130
int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
131-
int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
132-
float *result = (float *) PG_GETARG_POINTER(2);
133-
int2 res;
131+
int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
132+
float *result = (float *) PG_GETARG_POINTER(2);
134133

135-
*result = 0.0;
136-
137-
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
138-
139-
if (res > 0)
140-
{
141-
*result += FLT_MIN;
142-
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
143-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
144-
}
134+
penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
145135

146136
PG_RETURN_POINTER(result);
147137
}

contrib/btree_gist/btree_int4.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,10 @@ Datum
126126
gbt_int4_penalty(PG_FUNCTION_ARGS)
127127
{
128128
int32KEY *origentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
129-
int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
130-
float *result = (float *) PG_GETARG_POINTER(2);
131-
int4 res;
132-
133-
*result = 0.0;
134-
135-
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
136-
137-
if (res > 0)
138-
{
139-
*result += FLT_MIN;
140-
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
141-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
142-
}
129+
int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
130+
float *result = (float *) PG_GETARG_POINTER(2);
131+
132+
penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
143133

144134
PG_RETURN_POINTER(result);
145135
}

contrib/btree_gist/btree_int8.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,12 @@ Datum
125125
gbt_int8_penalty(PG_FUNCTION_ARGS)
126126
{
127127
int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
128-
int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
129-
float *result = (float *) PG_GETARG_POINTER(2);
130-
int64 res;
131-
132-
*result = 0.0;
133-
134-
penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
135-
136-
if (res > 0)
137-
{
138-
*result += FLT_MIN;
139-
*result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
140-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
141-
}
128+
int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
129+
float *result = (float *) PG_GETARG_POINTER(2);
142130

131+
penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
132+
143133
PG_RETURN_POINTER(result);
144-
145134
}
146135

147136
Datum

contrib/btree_gist/btree_interval.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,14 @@ gbt_intv_penalty(PG_FUNCTION_ARGS)
203203
intvKEY *newentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
204204
float *result = (float *) PG_GETARG_POINTER(2);
205205
double iorg[2],
206-
inew[2],
207-
res;
206+
inew[2];
208207

209208
iorg[0] = intr2num(&origentry->lower);
210209
iorg[1] = intr2num(&origentry->upper);
211210
inew[0] = intr2num(&newentry->lower);
212211
inew[1] = intr2num(&newentry->upper);
213212

214-
penalty_range_enlarge(iorg[0], iorg[1], inew[0], inew[1]);
215-
216-
*result = 0.0;
217-
218-
if (res > 0)
219-
{
220-
*result += FLT_MIN;
221-
*result += (float) (res / (res + iorg[1] - iorg[0]));
222-
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
223-
}
213+
penalty_num(result,iorg[0],iorg[1],inew[0],inew[1]);
224214

225215
PG_RETURN_POINTER(result);
226216

0 commit comments

Comments
 (0)