8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.6 1996/11/13 20:47:57 scrappy Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.7 1996/11/26 02:45:05 bryanh Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -352,26 +352,36 @@ ProcedureOidIndexScan(Relation heapRelation, Oid procId)
352
352
return tuple ;
353
353
}
354
354
355
+
356
+
355
357
HeapTuple
356
358
ProcedureNameIndexScan (Relation heapRelation ,
357
- char * procName ,
358
- int nargs ,
359
- Oid * argTypes )
359
+ char * procName ,
360
+ int nargs ,
361
+ Oid * argTypes )
360
362
{
361
363
Relation idesc ;
362
364
ScanKeyData skey ;
363
- HeapTuple tuple ;
365
+ HeapTuple tuple ; /* tuple being tested */
366
+ HeapTuple return_tuple ; /* The tuple pointer we eventually return */
364
367
IndexScanDesc sd ;
365
368
RetrieveIndexResult indexRes ;
366
369
Buffer buffer ;
367
370
Form_pg_proc pgProcP ;
368
- bool bufferUsed = FALSE;
371
+ bool ScanComplete ;
372
+ /* The index scan is complete, i.e. we've scanned everything there
373
+ is to scan.
374
+ */
375
+ bool FoundMatch ;
376
+ /* In scanning pg_proc, we have found a row that meets our search
377
+ criteria.
378
+ */
369
379
370
380
ScanKeyEntryInitialize (& skey ,
371
- (bits16 )0x0 ,
372
- (AttrNumber )1 ,
373
- (RegProcedure )NameEqualRegProcedure ,
374
- (Datum )procName );
381
+ (bits16 )0x0 ,
382
+ (AttrNumber )1 ,
383
+ (RegProcedure )NameEqualRegProcedure ,
384
+ (Datum )procName );
375
385
376
386
idesc = index_openr (ProcedureNameIndex );
377
387
@@ -382,41 +392,46 @@ ProcedureNameIndexScan(Relation heapRelation,
382
392
* by hand, so that we can check that the other keys match. when
383
393
* multi-key indices are added, they will be used here.
384
394
*/
385
- do {
386
- tuple = (HeapTuple )NULL ;
387
- if (bufferUsed ) {
388
- ReleaseBuffer (buffer );
389
- bufferUsed = FALSE;
390
- }
391
-
392
- indexRes = index_getnext (sd , ForwardScanDirection );
393
- if (indexRes ) {
394
- ItemPointer iptr ;
395
-
396
- iptr = & indexRes -> heap_iptr ;
397
- tuple = heap_fetch (heapRelation , NowTimeQual , iptr , & buffer );
398
- pfree (indexRes );
399
- if (HeapTupleIsValid (tuple )) {
400
- pgProcP = (Form_pg_proc )GETSTRUCT (tuple );
401
- bufferUsed = TRUE;
402
- }
403
- } else
404
- break ;
405
- } while (!HeapTupleIsValid (tuple ) ||
406
- pgProcP -> pronargs != nargs ||
407
- !oid8eq (& (pgProcP -> proargtypes [0 ]), argTypes ));
408
-
409
- if (HeapTupleIsValid (tuple )) {
410
- tuple = heap_copytuple (tuple );
411
- ReleaseBuffer (buffer );
395
+ tuple = (HeapTuple ) NULL ; /* initial value */
396
+ ScanComplete = false; /* Scan hasn't begun yet */
397
+ FoundMatch = false; /* No match yet; haven't even looked. */
398
+ while (!FoundMatch && !ScanComplete ) {
399
+ indexRes = index_getnext (sd , ForwardScanDirection );
400
+ if (indexRes ) {
401
+ ItemPointer iptr ;
402
+
403
+ iptr = & indexRes -> heap_iptr ;
404
+ tuple = heap_fetch (heapRelation , NowTimeQual , iptr , & buffer );
405
+ pfree (indexRes );
406
+ if (HeapTupleIsValid (tuple )) {
407
+ /* Here's a row for a procedure that has the sought procedure
408
+ name. To be a match, though, we need it to have the
409
+ right number and type of arguments too, so we check that
410
+ now.
411
+ */
412
+ pgProcP = (Form_pg_proc )GETSTRUCT (tuple );
413
+ if (pgProcP -> pronargs == nargs &&
414
+ oid8eq (& (pgProcP -> proargtypes [0 ]), argTypes ))
415
+ FoundMatch = true;
416
+ else ReleaseBuffer (buffer );
417
+ }
418
+ } else ScanComplete = true;
412
419
}
420
+
421
+ if (FoundMatch ) {
422
+ Assert (HeapTupleIsValid (tuple ));
423
+ return_tuple = heap_copytuple (tuple );
424
+ ReleaseBuffer (buffer );
425
+ } else return_tuple = (HeapTuple )NULL ;
413
426
414
427
index_endscan (sd );
415
428
index_close (idesc );
416
429
417
- return tuple ;
430
+ return return_tuple ;
418
431
}
419
432
433
+
434
+
420
435
HeapTuple
421
436
ProcedureSrcIndexScan (Relation heapRelation , text * procSrc )
422
437
{
0 commit comments