Skip to content

Commit 5ae2952

Browse files
committed
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.
1 parent 53b4e46 commit 5ae2952

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/backend/access/index/genam.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.71 2008/06/19 00:46:03 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.72 2008/11/06 13:07:08 heikki Exp $
1212
*
1313
* NOTES
1414
* many of the old access method routines have been turned into
@@ -194,16 +194,21 @@ systable_beginscan(Relation heapRelation,
194194
{
195195
int i;
196196

197-
/*
198-
* Change attribute numbers to be index column numbers.
199-
*
200-
* This code could be generalized to search for the index key numbers
201-
* to substitute, but for now there's no need.
202-
*/
197+
/* Change attribute numbers to be index column numbers. */
203198
for (i = 0; i < nkeys; i++)
204199
{
205-
Assert(key[i].sk_attno == irel->rd_index->indkey.values[i]);
206-
key[i].sk_attno = i + 1;
200+
int j;
201+
202+
for (j = 0; j < irel->rd_index->indnatts; j++)
203+
{
204+
if (key[i].sk_attno == irel->rd_index->indkey.values[j])
205+
{
206+
key[i].sk_attno = j + 1;
207+
break;
208+
}
209+
}
210+
if (j == irel->rd_index->indnatts)
211+
elog(ERROR, "column is not in index");
207212
}
208213

209214
sysscan->iscan = index_beginscan(heapRelation, irel,
@@ -352,16 +357,21 @@ systable_beginscan_ordered(Relation heapRelation,
352357
sysscan->heap_rel = heapRelation;
353358
sysscan->irel = indexRelation;
354359

355-
/*
356-
* Change attribute numbers to be index column numbers.
357-
*
358-
* This code could be generalized to search for the index key numbers
359-
* to substitute, but for now there's no need.
360-
*/
360+
/* Change attribute numbers to be index column numbers. */
361361
for (i = 0; i < nkeys; i++)
362362
{
363-
Assert(key[i].sk_attno == indexRelation->rd_index->indkey.values[i]);
364-
key[i].sk_attno = i + 1;
363+
int j;
364+
365+
for (j = 0; j < indexRelation->rd_index->indnatts; j++)
366+
{
367+
if (key[i].sk_attno == indexRelation->rd_index->indkey.values[j])
368+
{
369+
key[i].sk_attno = j + 1;
370+
break;
371+
}
372+
}
373+
if (j == indexRelation->rd_index->indnatts)
374+
elog(ERROR, "column is not in index");
365375
}
366376

367377
sysscan->iscan = index_beginscan(heapRelation, indexRelation,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy