summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2001-08-04 19:35:32 +0000
committerBruce Momjian2001-08-04 19:35:32 +0000
commitf368c94fd6c170dbcfb348a99aeacae8ef20b6f9 (patch)
tree21a84d650662903b0f897378943dd55b06687b98
parentf8683e8a9c9369d1713e9a13867a0541ac56787e (diff)
1. Fixed error with empty array ( '{}' ),
test data changed to include such data 2. Test a dimension of an array ( we support only one-dimension) Oleg Bartunov
-rw-r--r--contrib/intarray/_int.c39
-rw-r--r--contrib/intarray/data/test__int.data18
2 files changed, 36 insertions, 21 deletions
diff --git a/contrib/intarray/_int.c b/contrib/intarray/_int.c
index 56d15dac011..8a90a77641e 100644
--- a/contrib/intarray/_int.c
+++ b/contrib/intarray/_int.c
@@ -36,7 +36,8 @@
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
-#define ARRISNULL(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 1 )
+#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 )
+#define ARRISVOID(x) ( (x) ? ( ( ARR_NDIM(x) == NDIM ) ? ( ( ARRNELEMS( x ) ) ? 0 : 1 ) : 1 ) : 0 )
#define SORT(x) \
do { \
@@ -300,15 +301,16 @@ g_int_compress(PG_FUNCTION_ARGS)
if (ARRISNULL(r))
{
-#ifdef GIST_DEBUG
- elog(NOTICE, "COMP IN: NULL");
-#endif
- if (r)
- if (r != (ArrayType *) DatumGetPointer(entry->key))
- pfree(r);
-
- gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
+ if ( ARRISVOID(r) ) {
+ ArrayType *out = new_intArrayType( 0 );
+ gistentryinit(*retval, PointerGetDatum(out),
+ entry->rel, entry->page, entry->offset, VARSIZE(out), FALSE);
+ } else {
+ gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
0, FALSE);
+ }
+ if (r) pfree(r);
+
PG_RETURN_POINTER(retval);
}
@@ -371,14 +373,20 @@ g_int_decompress(PG_FUNCTION_ARGS)
else
in = NULL;
- if (entry->bytes < ARR_OVERHEAD(NDIM) || ARRISNULL(in))
+ if (ARRISNULL(in))
{
retval = palloc(sizeof(GISTENTRY));
+ if ( ARRISVOID(in) ) {
+ r = new_intArrayType( 0 );
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
+ } else {
+ gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
+ }
if (in)
if (in != (ArrayType *) DatumGetPointer(entry->key))
pfree(in);
- gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
#ifdef GIST_DEBUG
elog(NOTICE, "DECOMP IN: NULL");
#endif
@@ -1137,10 +1145,17 @@ g_intbig_compress(PG_FUNCTION_ARGS)
if (ARRISNULL(in))
{
+ if ( ARRISVOID(in) ) {
+ r = new_intArrayType( SIGLENINT );
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
+ } else {
+ gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset,
+ 0, FALSE);
+ }
if (in)
if (in != (ArrayType *) DatumGetPointer(entry->key))
pfree(in);
- gistentryinit(*retval, (Datum) 0, entry->rel, entry->page, entry->offset, 0, FALSE);
PG_RETURN_POINTER (retval);
}
diff --git a/contrib/intarray/data/test__int.data b/contrib/intarray/data/test__int.data
index 9750bf03636..b3903d0f33a 100644
--- a/contrib/intarray/data/test__int.data
+++ b/contrib/intarray/data/test__int.data
@@ -4,7 +4,7 @@
{79,83,16,63,32}
{52,41,61,79,94,87}
{76,59,39,36,21}
-\N
+{}
{41,79,76,96,3}
{25,59,5,96,32}
{92,58,12,57}
@@ -57,7 +57,7 @@
{58,1,39,48}
{78,36,70,92}
{43,3,22,95,51}
-\N
+{}
{88,64,25,64,86}
{34,6,49,90,25}
{86,35,13,22}
@@ -76,12 +76,12 @@
{89,11,67,55,73}
{78,39,84,63,62,45}
{50,63,8}
-\N
+{}
{96,36,58,65,96}
{59,86,41,30}
{90,60,39,47,19}
{70,100,73,99}
-\N
+{}
{85,14,39}
{76,53}
{96,38,52,13,87,85}
@@ -95,7 +95,7 @@
{84,93,36,95,34,69}
{66,25,5,40}
{77,6,57,42}
-\N
+{}
{88,81,85,37,12}
{56,73,38}
{70,70,6,19}
@@ -176,7 +176,7 @@
{31,48}
{28,35,18}
{77,55,100,73,57,62}
-\N
+{}
{14,59,53}
{98,3}
{13,56}
@@ -188,7 +188,7 @@
{41,76,39,84,32}
{94,66,47}
{55,28}
-\N
+{}
{94,65,59,20}
{55,50,56,14,58}
{14,94,52,25,69,95}
@@ -203,7 +203,7 @@
{46,69}
{35,54}
{36,79,54}
-\N
+{}
{63,78}
{12,86,52,29,60,30}
{29,27,58,86,42,62}
@@ -215,7 +215,7 @@
{14,85,14,26,3}
{46,71,10,16}
{30,63}
-\N
+{}
{91,30,56}
{46,36,68,91,36,88}
{24,61}