summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2008-11-06 13:07:08 +0000
committerHeikki Linnakangas2008-11-06 13:07:08 +0000
commitf70d72a554249731e2f9c023bd608fb60871cbfa (patch)
treee2b629cca676108aeb864f1d984621fbe3a80ddb
parent36d8a987f9138c6b610cb2532d6cf523b139fd0a (diff)
The logic in systable_beginscan to translate heap attribute numbers to
index column numbers needs to handle the case where you have more than one scankey on the same index column. toast_fetch_datum_slice() needs it.
-rw-r--r--src/backend/access/index/genam.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 9fb6f80742..304676f2e2 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -194,16 +194,21 @@ systable_beginscan(Relation heapRelation,
{
int i;
- /*
- * Change attribute numbers to be index column numbers.
- *
- * This code could be generalized to search for the index key numbers
- * to substitute, but for now there's no need.
- */
+ /* Change attribute numbers to be index column numbers. */
for (i = 0; i < nkeys; i++)
{
- Assert(key[i].sk_attno == irel->rd_index->indkey.values[i]);
- key[i].sk_attno = i + 1;
+ int j;
+
+ for (j = 0; j < irel->rd_index->indnatts; j++)
+ {
+ if (key[i].sk_attno == irel->rd_index->indkey.values[j])
+ {
+ key[i].sk_attno = j + 1;
+ break;
+ }
+ }
+ if (j == irel->rd_index->indnatts)
+ elog(ERROR, "column is not in index");
}
sysscan->iscan = index_beginscan(heapRelation, irel,
@@ -352,16 +357,21 @@ systable_beginscan_ordered(Relation heapRelation,
sysscan->heap_rel = heapRelation;
sysscan->irel = indexRelation;
- /*
- * Change attribute numbers to be index column numbers.
- *
- * This code could be generalized to search for the index key numbers
- * to substitute, but for now there's no need.
- */
+ /* Change attribute numbers to be index column numbers. */
for (i = 0; i < nkeys; i++)
{
- Assert(key[i].sk_attno == indexRelation->rd_index->indkey.values[i]);
- key[i].sk_attno = i + 1;
+ int j;
+
+ for (j = 0; j < indexRelation->rd_index->indnatts; j++)
+ {
+ if (key[i].sk_attno == indexRelation->rd_index->indkey.values[j])
+ {
+ key[i].sk_attno = j + 1;
+ break;
+ }
+ }
+ if (j == indexRelation->rd_index->indnatts)
+ elog(ERROR, "column is not in index");
}
sysscan->iscan = index_beginscan(heapRelation, indexRelation,