Re: possible wierd boolean bug?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
Cc: "Bruce Momjian" <pgman(at)candle(dot)pha(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: possible wierd boolean bug?
Date: 2004-12-15 19:18:50
Message-ID: 5605.1103138330@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com> writes:
> I confirmed the problem on a linux server running beta3...so this
> problem is quite reproducible by running the attached scripts on a
> freshly loaded database.

The attached patch fixes the problem for me.

regards, tom lane

*** src/backend/access/nbtree/nbtutils.c.orig Sun Aug 29 01:06:40 2004
--- src/backend/access/nbtree/nbtutils.c Wed Dec 15 14:00:59 2004
***************
*** 224,234 ****
BTScanOpaque so = (BTScanOpaque) scan->opaque;
int numberOfKeys = scan->numberOfKeys;
int new_numberOfKeys;
ScanKey inkeys;
ScanKey outkeys;
ScanKey cur;
ScanKey xform[BTMaxStrategyNumber];
- bool allEqualSoFar;
bool hasOtherTypeEqual;
Datum test;
int i,
--- 224,234 ----
BTScanOpaque so = (BTScanOpaque) scan->opaque;
int numberOfKeys = scan->numberOfKeys;
int new_numberOfKeys;
+ int numberOfEqualCols;
ScanKey inkeys;
ScanKey outkeys;
ScanKey cur;
ScanKey xform[BTMaxStrategyNumber];
bool hasOtherTypeEqual;
Datum test;
int i,
***************
*** 278,284 ****
* Otherwise, do the full set of pushups.
*/
new_numberOfKeys = 0;
! allEqualSoFar = true;

/*
* Initialize for processing of keys for attr 1.
--- 278,284 ----
* Otherwise, do the full set of pushups.
*/
new_numberOfKeys = 0;
! numberOfEqualCols = 0;

/*
* Initialize for processing of keys for attr 1.
***************
*** 321,327 ****
*/
if (i == numberOfKeys || cur->sk_attno != attno)
{
! bool priorAllEqualSoFar = allEqualSoFar;

/* check input keys are correctly ordered */
if (i < numberOfKeys && cur->sk_attno != attno + 1)
--- 321,327 ----
*/
if (i == numberOfKeys || cur->sk_attno != attno)
{
! int priorNumberOfEqualCols = numberOfEqualCols;

/* check input keys are correctly ordered */
if (i < numberOfKeys && cur->sk_attno != attno + 1)
***************
*** 355,368 ****
xform[BTLessEqualStrategyNumber - 1] = NULL;
xform[BTGreaterEqualStrategyNumber - 1] = NULL;
xform[BTGreaterStrategyNumber - 1] = NULL;
}
else
{
! /*
! * If no "=" for this key, we're done with required keys
! */
! if (!hasOtherTypeEqual)
! allEqualSoFar = false;
}

/* keep only one of <, <= */
--- 355,368 ----
xform[BTLessEqualStrategyNumber - 1] = NULL;
xform[BTGreaterEqualStrategyNumber - 1] = NULL;
xform[BTGreaterStrategyNumber - 1] = NULL;
+ /* track number of attrs for which we have "=" keys */
+ numberOfEqualCols++;
}
else
{
! /* track number of attrs for which we have "=" keys */
! if (hasOtherTypeEqual)
! numberOfEqualCols++;
}

/* keep only one of <, <= */
***************
*** 411,417 ****
* If all attrs before this one had "=", include these keys
* into the required-keys count.
*/
! if (priorAllEqualSoFar)
so->numberOfRequiredKeys = new_numberOfKeys;

/*
--- 411,417 ----
* If all attrs before this one had "=", include these keys
* into the required-keys count.
*/
! if (priorNumberOfEqualCols == attno - 1)
so->numberOfRequiredKeys = new_numberOfKeys;

/*
***************
*** 468,475 ****
* If unique index and we have equality keys for all columns, set
* keys_are_unique flag for higher levels.
*/
! if (allEqualSoFar && relation->rd_index->indisunique &&
! relation->rd_rel->relnatts == new_numberOfKeys)
scan->keys_are_unique = true;
}

--- 468,475 ----
* If unique index and we have equality keys for all columns, set
* keys_are_unique flag for higher levels.
*/
! if (relation->rd_index->indisunique &&
! relation->rd_rel->relnatts == numberOfEqualCols)
scan->keys_are_unique = true;
}

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ed Loehr 2004-12-15 19:23:02 Identifying time of last stat reset via sql
Previous Message Josh Berkus 2004-12-15 18:38:41 Re: [Testperf-general] BufferSync and bgwriter