@@ -358,7 +358,7 @@ <H3><a name="9">9</a>) How do I efficiently access information in
358
358
tables from the backend code?</ H3 > < P >
359
359
360
360
You first need to find the tuples(rows) you are interested in. There
361
- are two ways. First, < I > SearchSysCacheTuple ()</ I > and related functions
361
+ are two ways. First, < I > SearchSysCache ()</ I > and related functions
362
362
allow you to query the system catalogs. This is the preferred way to
363
363
access system tables, because the first call to the cache loads the
364
364
needed rows, and future requests can return the results without
@@ -367,15 +367,14 @@ <H3><a name="9">9</a>) How do I efficiently access information in
367
367
< I > src/backend/utils/cache/syscache.c.</ I >
368
368
< I > src/backend/utils/cache/lsyscache.c</ I > contains many column-specific
369
369
cache lookup functions.< P >
370
-
371
- The rows returned are cached-owned versions of the heap rows. They are
372
- invalidated when the base table changes. Because the cache is local to
373
- each backend, you may use the pointer returned from the cache for short
374
- periods without making a copy of the tuple. If you send the pointer
375
- into a large function that will be doing its own cache lookups, it is
376
- possible the cache entry may be flushed, so you should use
377
- < I > SearchSysCacheTupleCopy()</ I > in these cases, and < I > pfree()</ I > the
378
- tuple when you are done.< P >
370
+
371
+ The rows returned are cache-owned versions of the heap rows. Therefore, you
372
+ must not modify or delete the tuple returned by < I > SearchSysCache()</ I > . What
373
+ you < I > should</ I > do is release it with < I > ReleaseSysCache()</ I > when you are
374
+ done using it; this informs the cache that it can discard that tuple if
375
+ necessary. If you neglect to call < I > ReleaseSysCache()</ I > , then the cache
376
+ entry will remain locked in the cache until end of transaction, which is
377
+ tolerable but not very desirable.< P >
379
378
380
379
If you can't use the system cache, you will need to retrieve the data
381
380
directly from the heap table, using the buffer cache that is shared by
@@ -392,12 +391,11 @@ <H3><a name="9">9</a>) How do I efficiently access information in
392
391
You can also use < I > heap_fetch()</ I > to fetch rows by block
393
392
number/offset. While scans automatically lock/unlock rows from the
394
393
buffer cache, with < I > heap_fetch(),</ I > you must pass a < I > Buffer</ I >
395
- pointer, and < I > ReleaseBuffer()</ I > it when completed.
394
+ pointer, and < I > ReleaseBuffer()</ I > it when completed.< P >
396
395
397
396
Once you have the row, you can get data that is common to all tuples,
398
397
like < I > t_self</ I > and < I > t_oid,</ I > by merely accessing the
399
398
< I > HeapTuple</ I > structure entries.
400
-
401
399
If you need a table-specific column, you should take the HeapTuple
402
400
pointer, and use the < I > GETSTRUCT()</ I > macro to access the
403
401
table-specific start of the tuple. You then cast the pointer as a
@@ -411,18 +409,18 @@ <H3><a name="9">9</a>) How do I efficiently access information in
411
409
</ CODE >
412
410
</ PRE >
413
411
414
- You should not directly change < I > live</ I > tuples in this way. The best
415
- way is to use < I > heap_tuplemodify ()</ I > and pass it your palloc'ed
416
- tuple, and the values you want changed. It returns another palloc'ed
412
+ You must not directly change < I > live</ I > tuples in this way. The best
413
+ way is to use < I > heap_modifytuple ()</ I > and pass it your original
414
+ tuple, and the values you want changed. It returns a palloc'ed
417
415
tuple, which you pass to < I > heap_replace().</ I >
418
416
419
417
You can delete tuples by passing the tuple's < I > t_self</ I > to
420
- < I > heap_destroy().</ I > You can use it for < I > heap_update()</ I > too.
418
+ < I > heap_destroy().</ I > You use < I > t_self </ I > for < I > heap_update()</ I > too.
421
419
422
- Remember, tuples can be either system cache versions , which may go away
423
- soon after you get them, buffer cache versions, which go away when
424
- you < I > heap_getnext(), </ I > < I > heap_endscan, </ I > or
425
- < I > ReleaseBuffer()</ I > , in the < I > heap_fetch()</ I > case. Or it may be a
420
+ Remember, tuples can be either system cache copies , which may go away after
421
+ you call < I > ReleaseSysCache() </ I > , or read directly from disk buffers, which
422
+ go away when you < I > heap_getnext()</ I > , < I > heap_endscan</ I > , or
423
+ < I > ReleaseBuffer()</ I > , in the < I > heap_fetch()</ I > case. Or it may be a
426
424
palloc'ed tuple, that you must < I > pfree()</ I > when finished.
427
425
428
426
< H3 > < a name ="10 "> 10</ a > ) What is elog()?</ H3 > < P >
0 commit comments