|
36 | 36 | #define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
|
37 | 37 | #define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
|
38 | 38 |
|
39 |
| -#define ARRISNULL(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 1 ) |
| 39 | +#define ARRISNULL(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : ( ( ARR_NDIM(x) ) ? (elog(ERROR,"Array is not one-dimentional: %d dimentions", ARR_NDIM(x)),1) : 1 ) ) : 1 ) |
| 40 | +#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 0 ) |
40 | 41 |
|
41 | 42 | #define SORT(x) \
|
42 | 43 | do { \
|
@@ -300,15 +301,16 @@ g_int_compress(PG_FUNCTION_ARGS)
|
300 | 301 |
|
301 | 302 | if (ARRISNULL(r))
|
302 | 303 | {
|
303 |
| -#ifdef GIST_DEBUG |
304 |
| - elog(NOTICE, "COMP IN: NULL"); |
305 |
| -#endif |
306 |
| - if (r) |
307 |
| - if (r != (ArrayType *) DatumGetPointer(entry->key)) |
308 |
| - pfree(r); |
309 |
| - |
310 |
| - gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, |
| 304 | + if ( ARRISVOID(r) ) { |
| 305 | + ArrayType *out = new_intArrayType( 0 ); |
| 306 | + gistentryinit(*retval, PointerGetDatum(out), |
| 307 | + entry->rel, entry->page, entry->offset, VARSIZE(out), FALSE); |
| 308 | + } else { |
| 309 | + gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, |
311 | 310 | 0, FALSE);
|
| 311 | + } |
| 312 | + if (r) pfree(r); |
| 313 | + |
312 | 314 | PG_RETURN_POINTER(retval);
|
313 | 315 | }
|
314 | 316 |
|
@@ -371,14 +373,20 @@ g_int_decompress(PG_FUNCTION_ARGS)
|
371 | 373 | else
|
372 | 374 | in = NULL;
|
373 | 375 |
|
374 |
| - if (entry->bytes < ARR_OVERHEAD(NDIM) || ARRISNULL(in)) |
| 376 | + if (ARRISNULL(in)) |
375 | 377 | {
|
376 | 378 | retval = palloc(sizeof(GISTENTRY));
|
377 | 379 |
|
| 380 | + if ( ARRISVOID(in) ) { |
| 381 | + r = new_intArrayType( 0 ); |
| 382 | + gistentryinit(*retval, PointerGetDatum(r), |
| 383 | + entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); |
| 384 | + } else { |
| 385 | + gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE); |
| 386 | + } |
378 | 387 | if (in)
|
379 | 388 | if (in != (ArrayType *) DatumGetPointer(entry->key))
|
380 | 389 | pfree(in);
|
381 |
| - gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE); |
382 | 390 | #ifdef GIST_DEBUG
|
383 | 391 | elog(NOTICE, "DECOMP IN: NULL");
|
384 | 392 | #endif
|
@@ -1137,10 +1145,17 @@ g_intbig_compress(PG_FUNCTION_ARGS)
|
1137 | 1145 |
|
1138 | 1146 | if (ARRISNULL(in))
|
1139 | 1147 | {
|
| 1148 | + if ( ARRISVOID(in) ) { |
| 1149 | + r = new_intArrayType( SIGLENINT ); |
| 1150 | + gistentryinit(*retval, PointerGetDatum(r), |
| 1151 | + entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); |
| 1152 | + } else { |
| 1153 | + gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, |
| 1154 | + 0, FALSE); |
| 1155 | + } |
1140 | 1156 | if (in)
|
1141 | 1157 | if (in != (ArrayType *) DatumGetPointer(entry->key))
|
1142 | 1158 | pfree(in);
|
1143 |
| - gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE); |
1144 | 1159 | PG_RETURN_POINTER (retval);
|
1145 | 1160 | }
|
1146 | 1161 |
|
|
0 commit comments