diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-07-21 04:15:04 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-07-21 04:15:04 +0000 |
commit | 3976899f295c336b2a40c7fd1b4f1c345a45a446 (patch) | |
tree | 3dce1de87b701bb212a94fc0cfad2ab5ceec82dc /contrib/btree_gist/btree_time.c | |
parent | a536b2dd80f29464b0461e3980043ec4a822e820 (diff) |
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...
Diffstat (limited to 'contrib/btree_gist/btree_time.c')
-rw-r--r-- | contrib/btree_gist/btree_time.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c index 9dc3250cf1c..02f2664349e 100644 --- a/contrib/btree_gist/btree_time.c +++ b/contrib/btree_gist/btree_time.c @@ -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)); } |