forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8abb3cd
committed
Use the typcache to cache constraints for domain types.
Previously, we cached domain constraints for the life of a query, orreally for the life of the FmgrInfo struct that was used to invokedomain_in() or domain_check(). But plpgsql (and probably other places)are set up to cache such FmgrInfos for the whole lifespan of a session,which meant they could be enforcing really stale sets of constraints.On the other hand, searching pg_constraint once per query gets kind ofexpensive too: testing says that as much as half the runtime of atrivial query such as "SELECT 0::domaintype" went into that.To fix this, delegate the responsibility for tracking a domain'sconstraints to the typcache, which has the infrastructure needed todetect syscache invalidation events that signal possible changes.This not only removes unnecessary repeat reads of pg_constraint,but ensures that we never apply stale constraint data: whatever weuse is the current data according to syscache rules.Unfortunately, the current configuration of the system catalogs meanswe have to flush cached domain-constraint data whenever either pg_typeor pg_constraint changes, which happens rather a lot (eg, creation ordeletion of a temp table will do it). It might be worth rearrangingthings to split pg_constraint into two catalogs, of which the domainconstraint one would probably be very low-traffic. That's a job foranother patch though, and in any case this patch should improve mattersmaterially even with that handicap.This patch makes use of the recently-added memory context reset callbackfeature to manage the lifespan of domain constraint caches, so that wedon't risk deleting a cache that might be in the midst of evaluation.Although this is a bug fix as well as a performance improvement, noback-patch. There haven't been many if any field complaints aboutstale domain constraint checks, so it doesn't seem worth taking therisk of modifying data structures as basic as MemoryContexts in backbranches.1 parentb8a18ad commit8abb3cd
File tree
10 files changed
+547
-181
lines changed- src
- backend
- commands
- executor
- utils
- adt
- cache
- include
- commands
- nodes
- utils
- test/regress
- expected
- sql
10 files changed
+547
-181
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4824 | 4824 |
| |
4825 | 4825 |
| |
4826 | 4826 |
| |
4827 |
| - | |
| 4827 | + | |
4828 | 4828 |
| |
4829 | 4829 |
| |
4830 | 4830 |
| |
| |||
7778 | 7778 |
| |
7779 | 7779 |
| |
7780 | 7780 |
| |
7781 |
| - | |
| 7781 | + | |
7782 | 7782 |
| |
7783 | 7783 |
| |
7784 | 7784 |
| |
|
Lines changed: 0 additions & 127 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
31 | 31 |
| |
32 | 32 |
| |
33 | 33 |
| |
34 |
| - | |
35 |
| - | |
36 | 34 |
| |
37 | 35 |
| |
38 | 36 |
| |
39 | 37 |
| |
40 |
| - | |
41 | 38 |
| |
42 |
| - | |
43 | 39 |
| |
44 | 40 |
| |
45 | 41 |
| |
| |||
59 | 55 |
| |
60 | 56 |
| |
61 | 57 |
| |
62 |
| - | |
63 | 58 |
| |
64 | 59 |
| |
65 | 60 |
| |
66 | 61 |
| |
67 | 62 |
| |
68 | 63 |
| |
69 |
| - | |
70 | 64 |
| |
71 | 65 |
| |
72 | 66 |
| |
| |||
75 | 69 |
| |
76 | 70 |
| |
77 | 71 |
| |
78 |
| - | |
79 | 72 |
| |
80 | 73 |
| |
81 | 74 |
| |
| |||
3081 | 3074 |
| |
3082 | 3075 |
| |
3083 | 3076 |
| |
3084 |
| - | |
3085 |
| - | |
3086 |
| - | |
3087 |
| - | |
3088 |
| - | |
3089 |
| - | |
3090 |
| - | |
3091 |
| - | |
3092 |
| - | |
3093 |
| - | |
3094 |
| - | |
3095 |
| - | |
3096 |
| - | |
3097 |
| - | |
3098 |
| - | |
3099 |
| - | |
3100 |
| - | |
3101 |
| - | |
3102 |
| - | |
3103 |
| - | |
3104 |
| - | |
3105 |
| - | |
3106 |
| - | |
3107 |
| - | |
3108 |
| - | |
3109 |
| - | |
3110 |
| - | |
3111 |
| - | |
3112 |
| - | |
3113 |
| - | |
3114 |
| - | |
3115 |
| - | |
3116 |
| - | |
3117 |
| - | |
3118 |
| - | |
3119 |
| - | |
3120 |
| - | |
3121 |
| - | |
3122 |
| - | |
3123 |
| - | |
3124 |
| - | |
3125 |
| - | |
3126 |
| - | |
3127 |
| - | |
3128 |
| - | |
3129 |
| - | |
3130 |
| - | |
3131 |
| - | |
3132 |
| - | |
3133 |
| - | |
3134 |
| - | |
3135 |
| - | |
3136 |
| - | |
3137 |
| - | |
3138 |
| - | |
3139 |
| - | |
3140 |
| - | |
3141 |
| - | |
3142 |
| - | |
3143 |
| - | |
3144 |
| - | |
3145 |
| - | |
3146 |
| - | |
3147 |
| - | |
3148 |
| - | |
3149 |
| - | |
3150 |
| - | |
3151 |
| - | |
3152 |
| - | |
3153 |
| - | |
3154 |
| - | |
3155 |
| - | |
3156 |
| - | |
3157 |
| - | |
3158 |
| - | |
3159 |
| - | |
3160 |
| - | |
3161 |
| - | |
3162 |
| - | |
3163 |
| - | |
3164 |
| - | |
3165 |
| - | |
3166 |
| - | |
3167 |
| - | |
3168 |
| - | |
3169 |
| - | |
3170 |
| - | |
3171 |
| - | |
3172 |
| - | |
3173 |
| - | |
3174 |
| - | |
3175 |
| - | |
3176 |
| - | |
3177 |
| - | |
3178 |
| - | |
3179 |
| - | |
3180 |
| - | |
3181 |
| - | |
3182 |
| - | |
3183 |
| - | |
3184 |
| - | |
3185 |
| - | |
3186 |
| - | |
3187 |
| - | |
3188 |
| - | |
3189 |
| - | |
3190 |
| - | |
3191 |
| - | |
3192 |
| - | |
3193 |
| - | |
3194 |
| - | |
3195 |
| - | |
3196 |
| - | |
3197 |
| - | |
3198 |
| - | |
3199 |
| - | |
3200 |
| - | |
3201 |
| - | |
3202 |
| - | |
3203 |
| - | |
3204 | 3077 |
| |
3205 | 3078 |
| |
3206 | 3079 |
| |
|
Lines changed: 10 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
44 |
| - | |
45 | 44 |
| |
46 | 45 |
| |
47 | 46 |
| |
| |||
3929 | 3928 |
| |
3930 | 3929 |
| |
3931 | 3930 |
| |
3932 |
| - | |
| 3931 | + | |
| 3932 | + | |
| 3933 | + | |
| 3934 | + | |
3933 | 3935 |
| |
3934 | 3936 |
| |
3935 | 3937 |
| |
| |||
5050 | 5052 |
| |
5051 | 5053 |
| |
5052 | 5054 |
| |
5053 |
| - | |
| 5055 | + | |
| 5056 | + | |
| 5057 | + | |
| 5058 | + | |
| 5059 | + | |
| 5060 | + | |
5054 | 5061 |
| |
5055 | 5062 |
| |
5056 | 5063 |
| |
|
Lines changed: 36 additions & 42 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
15 |
| - | |
16 |
| - | |
17 |
| - | |
18 |
| - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
19 | 18 |
| |
20 | 19 |
| |
21 | 20 |
| |
| |||
33 | 32 |
| |
34 | 33 |
| |
35 | 34 |
| |
36 |
| - | |
37 | 35 |
| |
38 | 36 |
| |
39 | 37 |
| |
40 | 38 |
| |
41 | 39 |
| |
| 40 | + | |
42 | 41 |
| |
43 | 42 |
| |
44 | 43 |
| |
| |||
52 | 51 |
| |
53 | 52 |
| |
54 | 53 |
| |
55 |
| - | |
56 |
| - | |
| 54 | + | |
| 55 | + | |
57 | 56 |
| |
58 | 57 |
| |
59 | 58 |
| |
| |||
63 | 62 |
| |
64 | 63 |
| |
65 | 64 |
| |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
66 | 70 |
| |
67 |
| - | |
68 |
| - | |
69 |
| - | |
| 71 | + | |
| 72 | + | |
70 | 73 |
| |
| 74 | + | |
71 | 75 |
| |
72 |
| - | |
73 | 76 |
| |
74 |
| - | |
75 |
| - | |
| 77 | + | |
76 | 78 |
| |
77 | 79 |
| |
78 | 80 |
| |
| |||
95 | 97 |
| |
96 | 98 |
| |
97 | 99 |
| |
98 |
| - | |
99 |
| - | |
100 |
| - | |
| 100 | + | |
101 | 101 |
| |
102 | 102 |
| |
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
106 | 106 |
| |
107 | 107 |
| |
| 108 | + | |
| 109 | + | |
108 | 110 |
| |
109 | 111 |
| |
110 | 112 |
| |
| |||
118 | 120 |
| |
119 | 121 |
| |
120 | 122 |
| |
121 |
| - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
122 | 127 |
| |
123 | 128 |
| |
124 | 129 |
| |
| |||
215 | 220 |
| |
216 | 221 |
| |
217 | 222 |
| |
218 |
| - | |
| 223 | + | |
| 224 | + | |
219 | 225 |
| |
220 | 226 |
| |
221 |
| - | |
| 227 | + | |
222 | 228 |
| |
223 |
| - | |
224 |
| - | |
225 |
| - | |
226 |
| - | |
| 229 | + | |
| 230 | + | |
227 | 231 |
| |
228 | 232 |
| |
229 |
| - | |
230 |
| - | |
231 |
| - | |
232 | 233 |
| |
233 | 234 |
| |
234 | 235 |
| |
| |||
275 | 276 |
| |
276 | 277 |
| |
277 | 278 |
| |
278 |
| - | |
| 279 | + | |
| 280 | + | |
279 | 281 |
| |
280 | 282 |
| |
281 |
| - | |
| 283 | + | |
282 | 284 |
| |
283 |
| - | |
284 |
| - | |
285 |
| - | |
286 |
| - | |
| 285 | + | |
| 286 | + | |
287 | 287 |
| |
288 | 288 |
| |
289 |
| - | |
290 |
| - | |
291 |
| - | |
292 | 289 |
| |
293 | 290 |
| |
294 | 291 |
| |
| |||
326 | 323 |
| |
327 | 324 |
| |
328 | 325 |
| |
329 |
| - | |
| 326 | + | |
| 327 | + | |
330 | 328 |
| |
331 | 329 |
| |
332 | 330 |
| |
333 |
| - | |
| 331 | + | |
334 | 332 |
| |
335 |
| - | |
336 |
| - | |
337 |
| - | |
| 333 | + | |
338 | 334 |
| |
339 | 335 |
| |
340 | 336 |
| |
341 |
| - | |
342 |
| - | |
343 | 337 |
| |
344 | 338 |
| |
345 | 339 |
| |
|
0 commit comments
Comments
(0)