mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Fix storage size for btree_gist interval indexes. Fix penalty
calculations for interval and time/timetz to behave sanely for both integer and float timestamps; up to now I think it's been doing something pretty strange...
This commit is contained in:
@ -49,20 +49,20 @@ INPUT = gbtreekey16_in,
|
|||||||
OUTPUT = gbtreekey16_out
|
OUTPUT = gbtreekey16_out
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE FUNCTION gbtreekey24_in(cstring)
|
CREATE FUNCTION gbtreekey32_in(cstring)
|
||||||
RETURNS gbtreekey24
|
RETURNS gbtreekey32
|
||||||
AS 'MODULE_PATHNAME', 'gbtreekey_in'
|
AS 'MODULE_PATHNAME', 'gbtreekey_in'
|
||||||
LANGUAGE 'c' WITH (isstrict);
|
LANGUAGE 'c' WITH (isstrict);
|
||||||
|
|
||||||
CREATE FUNCTION gbtreekey24_out(gbtreekey24)
|
CREATE FUNCTION gbtreekey32_out(gbtreekey32)
|
||||||
RETURNS cstring
|
RETURNS cstring
|
||||||
AS 'MODULE_PATHNAME', 'gbtreekey_out'
|
AS 'MODULE_PATHNAME', 'gbtreekey_out'
|
||||||
LANGUAGE 'c' WITH (isstrict);
|
LANGUAGE 'c' WITH (isstrict);
|
||||||
|
|
||||||
CREATE TYPE gbtreekey24 (
|
CREATE TYPE gbtreekey32 (
|
||||||
INTERNALLENGTH = 24,
|
INTERNALLENGTH = 32,
|
||||||
INPUT = gbtreekey24_in,
|
INPUT = gbtreekey32_in,
|
||||||
OUTPUT = gbtreekey24_out
|
OUTPUT = gbtreekey32_out
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE FUNCTION gbtreekey_var_in(cstring)
|
CREATE FUNCTION gbtreekey_var_in(cstring)
|
||||||
@ -697,7 +697,7 @@ AS 'MODULE_PATHNAME'
|
|||||||
LANGUAGE 'C';
|
LANGUAGE 'C';
|
||||||
|
|
||||||
CREATE FUNCTION gbt_intv_union(bytea, internal)
|
CREATE FUNCTION gbt_intv_union(bytea, internal)
|
||||||
RETURNS gbtreekey24
|
RETURNS gbtreekey32
|
||||||
AS 'MODULE_PATHNAME'
|
AS 'MODULE_PATHNAME'
|
||||||
LANGUAGE 'C';
|
LANGUAGE 'C';
|
||||||
|
|
||||||
@ -722,7 +722,7 @@ AS
|
|||||||
FUNCTION 5 gbt_intv_penalty (internal, internal, internal),
|
FUNCTION 5 gbt_intv_penalty (internal, internal, internal),
|
||||||
FUNCTION 6 gbt_intv_picksplit (internal, internal),
|
FUNCTION 6 gbt_intv_picksplit (internal, internal),
|
||||||
FUNCTION 7 gbt_intv_same (internal, internal, internal),
|
FUNCTION 7 gbt_intv_same (internal, internal, internal),
|
||||||
STORAGE gbtreekey24;
|
STORAGE gbtreekey32;
|
||||||
|
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
|
@ -73,22 +73,14 @@ gbt_intvkey_cmp(const void *a, const void *b)
|
|||||||
static double
|
static double
|
||||||
intr2num(const Interval *i)
|
intr2num(const Interval *i)
|
||||||
{
|
{
|
||||||
double ret = 0.0;
|
return INTERVAL_TO_SEC(i);
|
||||||
struct pg_tm tm;
|
|
||||||
fsec_t fsec;
|
|
||||||
|
|
||||||
interval2tm(*i, &tm, &fsec);
|
|
||||||
ret += (tm.tm_year * 360.0 * 86400.0);
|
|
||||||
ret += (tm.tm_mon * 12.0 * 86400.0);
|
|
||||||
ret += (tm.tm_mday * 86400.0);
|
|
||||||
ret += (tm.tm_hour * 3600.0);
|
|
||||||
ret += (tm.tm_min * 60.0);
|
|
||||||
ret += (tm.tm_sec);
|
|
||||||
ret += (fsec / 1000000.0);
|
|
||||||
|
|
||||||
return (ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* INTERVALSIZE should be the actual size-on-disk of an Interval, as shown
|
||||||
|
* in pg_type. This might be less than sizeof(Interval) if the compiler
|
||||||
|
* insists on adding alignment padding at the end of the struct.
|
||||||
|
*/
|
||||||
#define INTERVALSIZE 16
|
#define INTERVALSIZE 16
|
||||||
|
|
||||||
static const gbtree_ninfo tinfo =
|
static const gbtree_ninfo tinfo =
|
||||||
|
@ -207,29 +207,24 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
|
|||||||
timeKEY *newentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
|
timeKEY *newentry = (timeKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
|
||||||
float *result = (float *) PG_GETARG_POINTER(2);
|
float *result = (float *) PG_GETARG_POINTER(2);
|
||||||
Interval *intr;
|
Interval *intr;
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
|
||||||
int64 res;
|
|
||||||
|
|
||||||
#else
|
|
||||||
double res;
|
double res;
|
||||||
#endif
|
double res2;
|
||||||
|
|
||||||
intr = DatumGetIntervalP(DirectFunctionCall2(
|
intr = DatumGetIntervalP(DirectFunctionCall2(
|
||||||
time_mi_time,
|
time_mi_time,
|
||||||
P_TimeADTGetDatum(newentry->upper),
|
P_TimeADTGetDatum(newentry->upper),
|
||||||
P_TimeADTGetDatum(origentry->upper)));
|
P_TimeADTGetDatum(origentry->upper)));
|
||||||
|
res = INTERVAL_TO_SEC(intr);
|
||||||
/* see interval_larger */
|
res = Max(res, 0);
|
||||||
res = Max(intr->time + intr->day * 86400 + intr->month * (30 * 86400), 0);
|
|
||||||
|
|
||||||
intr = DatumGetIntervalP(DirectFunctionCall2(
|
intr = DatumGetIntervalP(DirectFunctionCall2(
|
||||||
time_mi_time,
|
time_mi_time,
|
||||||
P_TimeADTGetDatum(origentry->lower),
|
P_TimeADTGetDatum(origentry->lower),
|
||||||
P_TimeADTGetDatum(newentry->lower)));
|
P_TimeADTGetDatum(newentry->lower)));
|
||||||
|
res2 = INTERVAL_TO_SEC(intr);
|
||||||
|
res2 = Max(res2, 0);
|
||||||
|
|
||||||
/* see interval_larger */
|
res += res2;
|
||||||
res += Max(intr->time + intr->day * 86400 + intr->month * (30 * 86400), 0);
|
|
||||||
|
|
||||||
*result = 0.0;
|
*result = 0.0;
|
||||||
|
|
||||||
@ -240,7 +235,7 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
|
|||||||
P_TimeADTGetDatum(origentry->upper),
|
P_TimeADTGetDatum(origentry->upper),
|
||||||
P_TimeADTGetDatum(origentry->lower)));
|
P_TimeADTGetDatum(origentry->lower)));
|
||||||
*result += FLT_MIN;
|
*result += FLT_MIN;
|
||||||
*result += (float) (res / ((double) (res + intr->time + intr->day * 86400 + intr->month * (30 * 86400))));
|
*result += (float) (res / (res + INTERVAL_TO_SEC(intr)));
|
||||||
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
|
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,24 @@ typedef struct
|
|||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert an Interval to an approximate equivalent number of seconds
|
||||||
|
* (as a double). Here because we need it for time/timetz as well as
|
||||||
|
* interval. See interval_cmp_internal for comparison.
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
|
#define INTERVAL_TO_SEC(ivp) \
|
||||||
|
(((double) (ivp)->time) / ((double) USECS_PER_SEC) + \
|
||||||
|
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
|
||||||
|
(ivp)->month * (30.0 * SECS_PER_DAY))
|
||||||
|
#else
|
||||||
|
#define INTERVAL_TO_SEC(ivp) \
|
||||||
|
((ivp)->time + \
|
||||||
|
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
|
||||||
|
(ivp)->month * (30.0 * SECS_PER_DAY))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
extern bool gbt_num_consistent(const GBT_NUMKEY_R * key, const void *query,
|
extern bool gbt_num_consistent(const GBT_NUMKEY_R * key, const void *query,
|
||||||
const StrategyNumber *strategy, bool is_leaf,
|
const StrategyNumber *strategy, bool is_leaf,
|
||||||
const gbtree_ninfo * tinfo);
|
const gbtree_ninfo * tinfo);
|
||||||
|
@ -12,9 +12,9 @@ psql:btree_gist.sql:28: NOTICE: argument type gbtreekey8 is only a shell
|
|||||||
psql:btree_gist.sql:39: NOTICE: type "gbtreekey16" is not yet defined
|
psql:btree_gist.sql:39: NOTICE: type "gbtreekey16" is not yet defined
|
||||||
DETAIL: Creating a shell type definition.
|
DETAIL: Creating a shell type definition.
|
||||||
psql:btree_gist.sql:44: NOTICE: argument type gbtreekey16 is only a shell
|
psql:btree_gist.sql:44: NOTICE: argument type gbtreekey16 is only a shell
|
||||||
psql:btree_gist.sql:55: NOTICE: type "gbtreekey24" is not yet defined
|
psql:btree_gist.sql:55: NOTICE: type "gbtreekey32" is not yet defined
|
||||||
DETAIL: Creating a shell type definition.
|
DETAIL: Creating a shell type definition.
|
||||||
psql:btree_gist.sql:60: NOTICE: argument type gbtreekey24 is only a shell
|
psql:btree_gist.sql:60: NOTICE: argument type gbtreekey32 is only a shell
|
||||||
psql:btree_gist.sql:71: NOTICE: type "gbtreekey_var" is not yet defined
|
psql:btree_gist.sql:71: NOTICE: type "gbtreekey_var" is not yet defined
|
||||||
DETAIL: Creating a shell type definition.
|
DETAIL: Creating a shell type definition.
|
||||||
psql:btree_gist.sql:76: NOTICE: argument type gbtreekey_var is only a shell
|
psql:btree_gist.sql:76: NOTICE: argument type gbtreekey_var is only a shell
|
||||||
|
Reference in New Issue
Block a user