~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to contrib/btree_gist/btree_time.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.15 2008/05/17 01:28:19 adunstan Exp $ 
 
2
 * $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.16 2009/06/11 14:48:50 momjian Exp $
3
3
 */
4
4
#include "btree_gist.h"
5
5
#include "btree_utils_num.h"
10
10
{
11
11
        TimeADT         lower;
12
12
        TimeADT         upper;
13
 
}       timeKEY;
 
13
} timeKEY;
14
14
 
15
15
/*
16
16
** time ops
175
175
        GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
176
176
        TimeADT         query = PG_GETARG_TIMEADT(1);
177
177
        StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
 
178
 
178
179
        /* Oid          subtype = PG_GETARG_OID(3); */
179
180
        bool       *recheck = (bool *) PG_GETARG_POINTER(4);
180
181
        timeKEY    *kkk = (timeKEY *) DatumGetPointer(entry->key);
183
184
        /* All cases served by this function are exact */
184
185
        *recheck = false;
185
186
 
186
 
        key.lower = (GBT_NUMKEY *) & kkk->lower;
187
 
        key.upper = (GBT_NUMKEY *) & kkk->upper;
 
187
        key.lower = (GBT_NUMKEY *) &kkk->lower;
 
188
        key.upper = (GBT_NUMKEY *) &kkk->upper;
188
189
 
189
190
        PG_RETURN_BOOL(
190
191
                                   gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
197
198
        GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
198
199
        TimeTzADT  *query = PG_GETARG_TIMETZADT_P(1);
199
200
        StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
 
201
 
200
202
        /* Oid          subtype = PG_GETARG_OID(3); */
201
203
        bool       *recheck = (bool *) PG_GETARG_POINTER(4);
202
204
        timeKEY    *kkk = (timeKEY *) DatumGetPointer(entry->key);
212
214
        qqq = (query->time + query->zone);
213
215
#endif
214
216
 
215
 
        key.lower = (GBT_NUMKEY *) & kkk->lower;
216
 
        key.upper = (GBT_NUMKEY *) & kkk->upper;
 
217
        key.lower = (GBT_NUMKEY *) &kkk->lower;
 
218
        key.upper = (GBT_NUMKEY *) &kkk->upper;
217
219
 
218
220
        PG_RETURN_BOOL(
219
221
                                   gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo)
244
246
 
245
247
        intr = DatumGetIntervalP(DirectFunctionCall2(
246
248
                                                                                                 time_mi_time,
247
 
                                                                                  TimeADTGetDatumFast(newentry->upper),
248
 
                                                                           TimeADTGetDatumFast(origentry->upper)));
 
249
                                                                                TimeADTGetDatumFast(newentry->upper),
 
250
                                                                         TimeADTGetDatumFast(origentry->upper)));
249
251
        res = INTERVAL_TO_SEC(intr);
250
252
        res = Max(res, 0);
251
253
 
252
254
        intr = DatumGetIntervalP(DirectFunctionCall2(
253
255
                                                                                                 time_mi_time,
254
 
                                                                                 TimeADTGetDatumFast(origentry->lower),
255
 
                                                                                TimeADTGetDatumFast(newentry->lower)));
 
256
                                                                           TimeADTGetDatumFast(origentry->lower),
 
257
                                                                          TimeADTGetDatumFast(newentry->lower)));
256
258
        res2 = INTERVAL_TO_SEC(intr);
257
259
        res2 = Max(res2, 0);
258
260
 
264
266
        {
265
267
                intr = DatumGetIntervalP(DirectFunctionCall2(
266
268
                                                                                                         time_mi_time,
267
 
                                                                                 TimeADTGetDatumFast(origentry->upper),
268
 
                                                                           TimeADTGetDatumFast(origentry->lower)));
 
269
                                                                           TimeADTGetDatumFast(origentry->upper),
 
270
                                                                         TimeADTGetDatumFast(origentry->lower)));
269
271
                *result += FLT_MIN;
270
272
                *result += (float) (res / (res + INTERVAL_TO_SEC(intr)));
271
273
                *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));