~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/tsginidx.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:
7
7
 *
8
8
 *
9
9
 * IDENTIFICATION
10
 
 *        $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.15 2009/03/25 22:19:01 tgl Exp $
 
10
 *        $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.16 2009/06/11 14:49:04 momjian Exp $
11
11
 *
12
12
 *-------------------------------------------------------------------------
13
13
 */
22
22
Datum
23
23
gin_cmp_tslexeme(PG_FUNCTION_ARGS)
24
24
{
25
 
        text    *a = PG_GETARG_TEXT_PP(0);
26
 
        text    *b = PG_GETARG_TEXT_PP(1);
27
 
        int     cmp;
 
25
        text       *a = PG_GETARG_TEXT_PP(0);
 
26
        text       *b = PG_GETARG_TEXT_PP(1);
 
27
        int                     cmp;
28
28
 
29
29
        cmp = tsCompareString(
30
 
                                        VARDATA_ANY(a), VARSIZE_ANY_EXHDR(a),
31
 
                                        VARDATA_ANY(b), VARSIZE_ANY_EXHDR(b),
32
 
                                        false );
 
30
                                                  VARDATA_ANY(a), VARSIZE_ANY_EXHDR(a),
 
31
                                                  VARDATA_ANY(b), VARSIZE_ANY_EXHDR(b),
 
32
                                                  false);
33
33
 
34
 
        PG_FREE_IF_COPY(a,0);
35
 
        PG_FREE_IF_COPY(b,1);
36
 
        PG_RETURN_INT32( cmp );
 
34
        PG_FREE_IF_COPY(a, 0);
 
35
        PG_FREE_IF_COPY(b, 1);
 
36
        PG_RETURN_INT32(cmp);
37
37
}
38
38
 
39
39
Datum
40
40
gin_cmp_prefix(PG_FUNCTION_ARGS)
41
41
{
42
 
        text    *a = PG_GETARG_TEXT_PP(0);
43
 
        text    *b = PG_GETARG_TEXT_PP(1);
 
42
        text       *a = PG_GETARG_TEXT_PP(0);
 
43
        text       *b = PG_GETARG_TEXT_PP(1);
 
44
 
44
45
#ifdef NOT_USED
45
46
        StrategyNumber strategy = PG_GETARG_UINT16(2);
46
 
        Pointer  extra_data = PG_GETARG_POINTER(3);
 
47
        Pointer         extra_data = PG_GETARG_POINTER(3);
47
48
#endif
48
 
        int             cmp;
 
49
        int                     cmp;
49
50
 
50
51
        cmp = tsCompareString(
51
 
                                        VARDATA_ANY(a), VARSIZE_ANY_EXHDR(a),
52
 
                                        VARDATA_ANY(b), VARSIZE_ANY_EXHDR(b),
53
 
                                        true );
54
 
 
55
 
        if ( cmp < 0 )
56
 
                cmp = 1;  /* prevent continue scan */
57
 
 
58
 
        PG_FREE_IF_COPY(a,0);
59
 
        PG_FREE_IF_COPY(b,1);
60
 
        PG_RETURN_INT32( cmp );
 
52
                                                  VARDATA_ANY(a), VARSIZE_ANY_EXHDR(a),
 
53
                                                  VARDATA_ANY(b), VARSIZE_ANY_EXHDR(b),
 
54
                                                  true);
 
55
 
 
56
        if (cmp < 0)
 
57
                cmp = 1;                                /* prevent continue scan */
 
58
 
 
59
        PG_FREE_IF_COPY(a, 0);
 
60
        PG_FREE_IF_COPY(b, 1);
 
61
        PG_RETURN_INT32(cmp);
61
62
}
62
63
 
63
64
Datum
95
96
{
96
97
        TSQuery         query = PG_GETARG_TSQUERY(0);
97
98
        int32      *nentries = (int32 *) PG_GETARG_POINTER(1);
 
99
 
98
100
        /* StrategyNumber strategy = PG_GETARG_UINT16(2); */
99
 
        bool      **ptr_partialmatch = (bool**) PG_GETARG_POINTER(3);
100
 
        Pointer   **extra_data = (Pointer **) PG_GETARG_POINTER(4);
 
101
        bool      **ptr_partialmatch = (bool **) PG_GETARG_POINTER(3);
 
102
        Pointer   **extra_data = (Pointer **) PG_GETARG_POINTER(4);
101
103
        Datum      *entries = NULL;
102
 
        bool       *partialmatch;
 
104
        bool       *partialmatch;
103
105
 
104
106
        *nentries = 0;
105
107
 
109
111
                                        j = 0,
110
112
                                        len;
111
113
                QueryItem  *item;
112
 
                bool            use_fullscan=false;
 
114
                bool            use_fullscan = false;
113
115
                int                *map_item_operand;
114
116
 
115
117
                item = clean_NOT(GETQUERY(query), &len);
126
128
                                (*nentries)++;
127
129
 
128
130
                entries = (Datum *) palloc(sizeof(Datum) * (*nentries));
129
 
                partialmatch = *ptr_partialmatch = (bool*) palloc(sizeof(bool) * (*nentries));
 
131
                partialmatch = *ptr_partialmatch = (bool *) palloc(sizeof(bool) * (*nentries));
130
132
 
131
133
                /*
132
 
                 * Make map to convert item's number to corresponding
133
 
                 * operand's (the same, entry's) number. Entry's number
134
 
                 * is used in check array in consistent method. We use
135
 
                 * the same map for each entry.
 
134
                 * Make map to convert item's number to corresponding operand's (the
 
135
                 * same, entry's) number. Entry's number is used in check array in
 
136
                 * consistent method. We use the same map for each entry.
136
137
                 */
137
 
                *extra_data = (Pointer*) palloc0(sizeof(Pointer)*(*nentries));
 
138
                *extra_data = (Pointer *) palloc0(sizeof(Pointer) * (*nentries));
138
139
                map_item_operand = palloc0(sizeof(int) * (query->size + 1));
139
140
 
140
141
                for (i = 0; i < query->size; i++)
145
146
 
146
147
                                txt = cstring_to_text_with_len(GETOPERAND(query) + val->distance,
147
148
                                                                                           val->length);
148
 
                                (*extra_data)[j] = (Pointer)map_item_operand;
 
149
                                (*extra_data)[j] = (Pointer) map_item_operand;
149
150
                                map_item_operand[i] = j;
150
151
                                partialmatch[j] = val->prefix;
151
152
                                entries[j++] = PointerGetDatum(txt);
152
153
                        }
153
154
 
154
 
                if ( use_fullscan )
 
155
                if (use_fullscan)
155
156
                {
156
 
                        (*extra_data)[j] = (Pointer)map_item_operand;
 
157
                        (*extra_data)[j] = (Pointer) map_item_operand;
157
158
                        map_item_operand[i] = j;
158
159
                        entries[j++] = PointerGetDatum(cstring_to_text_with_len("", 0));
159
160
                }
185
186
                *(gcv->need_recheck) = true;
186
187
 
187
188
        /* convert item's number to corresponding entry's (operand's) number */
188
 
        j = gcv->map_item_operand[ ((QueryItem *) val) - gcv->first_item ];
 
189
        j = gcv->map_item_operand[((QueryItem *) val) - gcv->first_item];
189
190
 
190
191
        /* return presence of current entry in indexed value */
191
192
        return gcv->check[j];
195
196
gin_tsquery_consistent(PG_FUNCTION_ARGS)
196
197
{
197
198
        bool       *check = (bool *) PG_GETARG_POINTER(0);
 
199
 
198
200
        /* StrategyNumber strategy = PG_GETARG_UINT16(1); */
199
201
        TSQuery         query = PG_GETARG_TSQUERY(2);
 
202
 
200
203
        /* int32        nkeys = PG_GETARG_INT32(3); */
201
 
        Pointer    *extra_data = (Pointer *) PG_GETARG_POINTER(4);
 
204
        Pointer    *extra_data = (Pointer *) PG_GETARG_POINTER(4);
202
205
        bool       *recheck = (bool *) PG_GETARG_POINTER(5);
203
206
        bool            res = FALSE;
204
207
 
216
219
                 */
217
220
                gcv.first_item = item = GETQUERY(query);
218
221
                gcv.check = check;
219
 
                gcv.map_item_operand = (int*)(extra_data[0]);
 
222
                gcv.map_item_operand = (int *) (extra_data[0]);
220
223
                gcv.need_recheck = recheck;
221
224
 
222
225
                res = TS_execute(