Re: [PATCHES] Yet more tsearch refactoring

2007-09-11 Thread Gregory Stark
Teodor Sigaev [EMAIL PROTECTED] writes:

 Did you check it on 64-bit boxes with strict alignment? I remember that was a
 headache for me.

Is there a regression test which would fail if this kind of problem crops up?
Not every developer can test every type of hardware but (aside from believing
the code will work of course) we should at a minimum be certain that the build
farm will detect the problem.

-- 
  Gregory Stark
  EnterpriseDB  http://www.enterprisedb.com

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


[PATCHES] Yet more tsearch refactoring

2007-09-10 Thread Heikki Linnakangas
* Defined new struct WordEntryPosVector that holds a uint16 length and a
variable size array of WordEntries. This replaces the previous
convention of a variable size uint16 array, with the first element
implying the length. WordEntryPosVector has the same layout in memory,
but is more readable in source code. The POSDATAPTR and POSDATALEN
macros are still used, though it would now be more readable to access
the fields in WordEntryPosVector directly.

* Removed needfree field from DocRepresentation. It was always set to false.

* Miscellaneous other commenting and refactoring

-- 
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com
Index: src/backend/utils/adt/tsginidx.c
===
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/backend/utils/adt/tsginidx.c,v
retrieving revision 1.3
diff -c -r1.3 tsginidx.c
*** src/backend/utils/adt/tsginidx.c	7 Sep 2007 16:03:40 -	1.3
--- src/backend/utils/adt/tsginidx.c	10 Sep 2007 12:04:14 -
***
*** 25,37 
  	int32	   *nentries = (int32 *) PG_GETARG_POINTER(1);
  	Datum	   *entries = NULL;
  
! 	*nentries = 0;
  	if (vector-size  0)
  	{
  		int			i;
  		WordEntry  *we = ARRPTR(vector);
  
- 		*nentries = (uint32) vector-size;
  		entries = (Datum *) palloc(sizeof(Datum) * vector-size);
  
  		for (i = 0; i  vector-size; i++)
--- 25,36 
  	int32	   *nentries = (int32 *) PG_GETARG_POINTER(1);
  	Datum	   *entries = NULL;
  
! 	*nentries = vector-size;
  	if (vector-size  0)
  	{
  		int			i;
  		WordEntry  *we = ARRPTR(vector);
  
  		entries = (Datum *) palloc(sizeof(Datum) * vector-size);
  
  		for (i = 0; i  vector-size; i++)
***
*** 134,144 
  
  	if (query-size  0)
  	{
! 		int4		i,
  	j = 0;
  		QueryItem  *item;
  		GinChkVal	gcv;
  
  		gcv.frst = item = GETQUERY(query);
  		gcv.mapped_check = (bool *) palloc(sizeof(bool) * query-size);
  
--- 133,151 
  
  	if (query-size  0)
  	{
! 		int			i,
  	j = 0;
  		QueryItem  *item;
  		GinChkVal	gcv;
  
+ 		/*
+ 		 * check-parameter array has one entry for each value (operand) in the
+ 		 * query. We expand that array into mapped_check, so that there's one
+ 		 * entry in mapped_check for every node in the query, including 
+ 		 * operators, to allow quick lookups in checkcondition_gin. Only the 
+ 		 * entries corresponding operands are actually used.
+ 		 */
+ 
  		gcv.frst = item = GETQUERY(query);
  		gcv.mapped_check = (bool *) palloc(sizeof(bool) * query-size);
  
Index: src/backend/utils/adt/tsgistidx.c
===
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/backend/utils/adt/tsgistidx.c,v
retrieving revision 1.3
diff -c -r1.3 tsgistidx.c
*** src/backend/utils/adt/tsgistidx.c	7 Sep 2007 15:09:56 -	1.3
--- src/backend/utils/adt/tsgistidx.c	10 Sep 2007 15:56:09 -
***
*** 133,152 
  }
  
  static int
! compareint(const void *a, const void *b)
  {
! 	if (*((int4 *) a) == *((int4 *) b))
  		return 0;
! 	return (*((int4 *) a)  *((int4 *) b)) ? 1 : -1;
  }
  
  static int
  uniqueint(int4 *a, int4 l)
  {
  	int4	   *ptr,
  			   *res;
  
! 	if (l == 1)
  		return l;
  
  	ptr = res = a;
--- 133,159 
  }
  
  static int
! compareint(const void *va, const void *vb)
  {
! 	int4 a = *((int4 *) va);
! 	int4 b = *((int4 *) vb);
! 
! 	if (a == b)
  		return 0;
! 	return (a  b) ? 1 : -1;
  }
  
+ /*
+  * Removes duplicates from an array of int4. 'l' is
+  * size of the input array. Returns the new size of the array.
+  */
  static int
  uniqueint(int4 *a, int4 l)
  {
  	int4	   *ptr,
  			   *res;
  
! 	if (l = 1)
  		return l;
  
  	ptr = res = a;
***
*** 570,581 
  } SPLITCOST;
  
  static int
! comparecost(const void *a, const void *b)
  {
! 	if (((SPLITCOST *) a)-cost == ((SPLITCOST *) b)-cost)
  		return 0;
  	else
! 		return (((SPLITCOST *) a)-cost  ((SPLITCOST *) b)-cost) ? 1 : -1;
  }
  
  
--- 577,591 
  } SPLITCOST;
  
  static int
! comparecost(const void *va, const void *vb)
  {
! 	SPLITCOST *a = (SPLITCOST *) va;
! 	SPLITCOST *b = (SPLITCOST *) vb;
! 
! 	if (a-cost == b-cost)
  		return 0;
  	else
! 		return (a-cost  b-cost) ? 1 : -1;
  }
  
  
Index: src/backend/utils/adt/tsrank.c
===
RCS file: /home/hlinnaka/pgcvsrepository/pgsql/src/backend/utils/adt/tsrank.c,v
retrieving revision 1.4
diff -c -r1.4 tsrank.c
*** src/backend/utils/adt/tsrank.c	7 Sep 2007 16:03:40 -	1.4
--- src/backend/utils/adt/tsrank.c	10 Sep 2007 15:56:51 -
***
*** 53,74 
  {
  	WordEntry  *ptr = ARRPTR(t),
  			   *end = (WordEntry *) STRPTR(t);
! 	int			len = 0,
! clen;
  
  	while (ptr  end)
  	{
! 		if ((clen = POSDATALEN(t, ptr)) == 0)
  			len += 1;
  		else
  			len += clen;
  		ptr++;
  	}
  
  	return len;
  }
  
! static int4
  WordECompareQueryItem(char *eval, char *qval, WordEntry *ptr, QueryOperand 

Re: [PATCHES] Yet more tsearch refactoring

2007-09-10 Thread Teodor Sigaev



Heikki Linnakangas wrote:

* Defined new struct WordEntryPosVector that holds a uint16 length and a
variable size array of WordEntries. This replaces the previous
convention of a variable size uint16 array, with the first element
implying the length. WordEntryPosVector has the same layout in memory,
but is more readable in source code. The POSDATAPTR and POSDATALEN
macros are still used, though it would now be more readable to access
the fields in WordEntryPosVector directly.


Did you check it on 64-bit boxes with strict alignment? I remember that was a 
headache for me.


--
Teodor Sigaev   E-mail: [EMAIL PROTECTED]
   WWW: http://www.sigaev.ru/

---(end of broadcast)---
TIP 6: explain analyze is your friend


Re: [PATCHES] Yet more tsearch refactoring

2007-09-10 Thread Heikki Linnakangas
Teodor Sigaev wrote:
 Heikki Linnakangas wrote:
 * Defined new struct WordEntryPosVector that holds a uint16 length and a
 variable size array of WordEntries. This replaces the previous
 convention of a variable size uint16 array, with the first element
 implying the length. WordEntryPosVector has the same layout in memory,
 but is more readable in source code. The POSDATAPTR and POSDATALEN
 macros are still used, though it would now be more readable to access
 the fields in WordEntryPosVector directly.
 
 Did you check it on 64-bit boxes with strict alignment? I remember that
 was a headache for me.

No, I didn't. But I don't see how it would make a difference, the
resulting memory layout is the same AFAICS.

-- 
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

---(end of broadcast)---
TIP 6: explain analyze is your friend