mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-17 19:30:00 +08: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:
parent
a536b2dd80
commit
3976899f29
@ -49,20 +49,20 @@ INPUT = gbtreekey16_in,
|
||||
OUTPUT = gbtreekey16_out
|
||||
);
|
||||
|
||||
CREATE FUNCTION gbtreekey24_in(cstring)
|
||||
RETURNS gbtreekey24
|
||||
CREATE FUNCTION gbtreekey32_in(cstring)
|
||||
RETURNS gbtreekey32
|
||||
AS 'MODULE_PATHNAME', 'gbtreekey_in'
|
||||
LANGUAGE 'c' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION gbtreekey24_out(gbtreekey24)
|
||||
CREATE FUNCTION gbtreekey32_out(gbtreekey32)
|
||||
RETURNS cstring
|
||||
AS 'MODULE_PATHNAME', 'gbtreekey_out'
|
||||
LANGUAGE 'c' WITH (isstrict);
|
||||
|
||||
CREATE TYPE gbtreekey24 (
|
||||
INTERNALLENGTH = 24,
|
||||
INPUT = gbtreekey24_in,
|
||||
OUTPUT = gbtreekey24_out
|
||||
CREATE TYPE gbtreekey32 (
|
||||
INTERNALLENGTH = 32,
|
||||
INPUT = gbtreekey32_in,
|
||||
OUTPUT = gbtreekey32_out
|
||||
);
|
||||
|
||||
CREATE FUNCTION gbtreekey_var_in(cstring)
|
||||
@ -697,7 +697,7 @@ AS 'MODULE_PATHNAME'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbt_intv_union(bytea, internal)
|
||||
RETURNS gbtreekey24
|
||||
RETURNS gbtreekey32
|
||||
AS 'MODULE_PATHNAME'
|
||||
LANGUAGE 'C';
|
||||
|
||||
@ -722,7 +722,7 @@ AS
|
||||
FUNCTION 5 gbt_intv_penalty (internal, internal, internal),
|
||||
FUNCTION 6 gbt_intv_picksplit (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
|
||||
intr2num(const Interval *i)
|
||||
{
|
||||
double ret = 0.0;
|
||||
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);
|
||||
return INTERVAL_TO_SEC(i);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
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);
|
||||
float *result = (float *) PG_GETARG_POINTER(2);
|
||||
Interval *intr;
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
int64 res;
|
||||
|
||||
#else
|
||||
double res;
|
||||
#endif
|
||||
double res2;
|
||||
|
||||
intr = DatumGetIntervalP(DirectFunctionCall2(
|
||||
time_mi_time,
|
||||
P_TimeADTGetDatum(newentry->upper),
|
||||
P_TimeADTGetDatum(origentry->upper)));
|
||||
|
||||
/* see interval_larger */
|
||||
res = Max(intr->time + intr->day * 86400 + intr->month * (30 * 86400), 0);
|
||||
res = INTERVAL_TO_SEC(intr);
|
||||
res = Max(res, 0);
|
||||
|
||||
intr = DatumGetIntervalP(DirectFunctionCall2(
|
||||
time_mi_time,
|
||||
P_TimeADTGetDatum(origentry->lower),
|
||||
P_TimeADTGetDatum(newentry->lower)));
|
||||
res2 = INTERVAL_TO_SEC(intr);
|
||||
res2 = Max(res2, 0);
|
||||
|
||||
/* see interval_larger */
|
||||
res += Max(intr->time + intr->day * 86400 + intr->month * (30 * 86400), 0);
|
||||
res += res2;
|
||||
|
||||
*result = 0.0;
|
||||
|
||||
@ -240,7 +235,7 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
|
||||
P_TimeADTGetDatum(origentry->upper),
|
||||
P_TimeADTGetDatum(origentry->lower)));
|
||||
*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));
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,24 @@ typedef struct
|
||||
} 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,
|
||||
const StrategyNumber *strategy, bool is_leaf,
|
||||
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
|
||||
DETAIL: Creating a shell type definition.
|
||||
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.
|
||||
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
|
||||
DETAIL: Creating a shell type definition.
|
||||
psql:btree_gist.sql:76: NOTICE: argument type gbtreekey_var is only a shell
|
||||
|
Loading…
Reference in New Issue
Block a user