|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.19 1997/09/12 04:07:09 momjian Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/access/common/Attic/heapvalid.c,v 1.20 1997/09/18 14:19:27 momjian Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
14 | 14 |
|
15 | 15 | #include <postgres.h>
|
16 | 16 |
|
17 |
| -#include <fmgr.h> |
18 | 17 | #include <access/heapam.h>
|
19 |
| -#include <access/valid.h> |
20 | 18 | #include <access/xact.h>
|
21 |
| -#include <storage/bufpage.h> |
22 |
| -#include <utils/rel.h> |
23 |
| -#include <utils/tqual.h> |
24 |
| -#include <storage/bufmgr.h> |
25 |
| -#include <utils/builtins.h> |
26 |
| - |
27 |
| -/* ---------------- |
28 |
| - * heap_keytest |
29 |
| - * |
30 |
| - * Test a heap tuple with respect to a scan key. |
31 |
| - * ---------------- |
32 |
| - */ |
33 |
| -bool |
34 |
| -heap_keytest(HeapTuple t, |
35 |
| - TupleDesc tupdesc, |
36 |
| - int nkeys, |
37 |
| - ScanKey keys) |
38 |
| -{ |
39 |
| - bool isnull; |
40 |
| - Datum atp; |
41 |
| - int test; |
42 |
| - |
43 |
| - for (; nkeys--; keys++) |
44 |
| - { |
45 |
| - atp = heap_getattr(t, InvalidBuffer, |
46 |
| - keys->sk_attno, |
47 |
| - tupdesc, |
48 |
| - &isnull); |
49 |
| - |
50 |
| - if (isnull) |
51 |
| - /* XXX eventually should check if SK_ISNULL */ |
52 |
| - return false; |
53 |
| - |
54 |
| - if (keys->sk_flags & SK_ISNULL) |
55 |
| - { |
56 |
| - return (false); |
57 |
| - } |
58 |
| - |
59 |
| - if (keys->sk_func == (func_ptr) oideq) /* optimization */ |
60 |
| - test = (keys->sk_argument == atp); |
61 |
| - else if (keys->sk_flags & SK_COMMUTE) |
62 |
| - test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure, |
63 |
| - keys->sk_argument, atp); |
64 |
| - else |
65 |
| - test = (long) FMGR_PTR2(keys->sk_func, keys->sk_procedure, |
66 |
| - atp, keys->sk_argument); |
67 |
| - |
68 |
| - if (!test == !(keys->sk_flags & SK_NEGATE)) |
69 |
| - return false; |
70 |
| - } |
71 |
| - |
72 |
| - return true; |
73 |
| -} |
74 |
| - |
75 |
| -/* ---------------- |
76 |
| - * heap_tuple_satisfies |
77 |
| - * |
78 |
| - * Returns a valid HeapTuple if it satisfies the timequal and keytest. |
79 |
| - * Returns NULL otherwise. Used to be heap_satisifies (sic) which |
80 |
| - * returned a boolean. It now returns a tuple so that we can avoid doing two |
81 |
| - * PageGetItem's per tuple. |
82 |
| - * |
83 |
| - * Complete check of validity including LP_CTUP and keytest. |
84 |
| - * This should perhaps be combined with valid somehow in the |
85 |
| - * future. (Also, additional rule tests/time range tests.) |
86 |
| - * |
87 |
| - * on 8/21/92 mao says: i rearranged the tests here to do keytest before |
88 |
| - * SatisfiesTimeQual. profiling indicated that even for vacuumed relations, |
89 |
| - * time qual checking was more expensive than key testing. time qual is |
90 |
| - * least likely to fail, too. we should really add the time qual test to |
91 |
| - * the restriction and optimize it in the normal way. this has interactions |
92 |
| - * with joey's expensive function work. |
93 |
| - * ---------------- |
94 |
| - */ |
95 |
| -HeapTuple |
96 |
| -heap_tuple_satisfies(ItemId itemId, |
97 |
| - Relation relation, |
98 |
| - Buffer buffer, |
99 |
| - PageHeader disk_page, |
100 |
| - TimeQual qual, |
101 |
| - int nKeys, |
102 |
| - ScanKey key) |
103 |
| -{ |
104 |
| - HeapTuple tuple, |
105 |
| - result; |
106 |
| - bool res; |
107 |
| - TransactionId old_tmin, |
108 |
| - old_tmax; |
109 |
| - |
110 |
| - if (!ItemIdIsUsed(itemId)) |
111 |
| - return NULL; |
112 |
| - |
113 |
| - tuple = (HeapTuple) PageGetItem((Page) disk_page, itemId); |
114 |
| - |
115 |
| - if (key != NULL) |
116 |
| - res = heap_keytest(tuple, RelationGetTupleDescriptor(relation), |
117 |
| - nKeys, key); |
118 |
| - else |
119 |
| - res = TRUE; |
120 |
| - |
121 |
| - result = (HeapTuple) NULL; |
122 |
| - if (res) |
123 |
| - { |
124 |
| - if (relation->rd_rel->relkind == RELKIND_UNCATALOGED) |
125 |
| - { |
126 |
| - result = tuple; |
127 |
| - } |
128 |
| - else |
129 |
| - { |
130 |
| - old_tmin = tuple->t_tmin; |
131 |
| - old_tmax = tuple->t_tmax; |
132 |
| - res = HeapTupleSatisfiesTimeQual(tuple, qual); |
133 |
| - if (tuple->t_tmin != old_tmin || |
134 |
| - tuple->t_tmax != old_tmax) |
135 |
| - { |
136 |
| - SetBufferCommitInfoNeedsSave(buffer); |
137 |
| - } |
138 |
| - if (res) |
139 |
| - { |
140 |
| - result = tuple; |
141 |
| - } |
142 |
| - } |
143 |
| - } |
144 |
| - |
145 |
| - return result; |
146 |
| -} |
147 | 19 |
|
148 | 20 | /*
|
149 | 21 | * TupleUpdatedByCurXactAndCmd() -- Returns true if this tuple has
|
|
0 commit comments