Commit 0e51069
committed
[yugabyte#26847] YSQL: Use __thread in regex code
Summary:
PG is designed for use in single-threaded environments, so it often uses static (global) vars. When this code is evaluated as part of expression pushdown, it's executed from a multi-threaded environment, and so the static variables are no longer safe.
`__thread` is a simpler way to denote a thread-local variable in C code. Switching to this format keeps correctness, but makes the changes from PG much smaller.
```
src/lint/diff_file_with_upstream.py src/postgres/src/backend/regex/regc_pg_locale.c | grep -v "yb_switch_fallthrough" | grep -E "<|>"
< /* YB includes */
< #include "pg_yb_utils.h"
<
< static YB_THREAD_LOCAL PG_Locale_Strategy pg_regex_strategy;
< static YB_THREAD_LOCAL pg_locale_t pg_regex_locale;
< static YB_THREAD_LOCAL Oid pg_regex_collation;
> static PG_Locale_Strategy pg_regex_strategy;
> static pg_locale_t pg_regex_locale;
> static Oid pg_regex_collation;
< static YB_THREAD_LOCAL pg_ctype_cache *pg_ctype_cache_list = NULL;
> static pg_ctype_cache *pg_ctype_cache_list = NULL;
```
```
src/lint/diff_file_with_upstream.py src/postgres/src/backend/utils/adt/regexp.c | grep -v "yb_switch_fallthrough" | grep -E "<|>"
< /* YB includes */
< #include "pg_yb_utils.h"
<
< static YB_THREAD_LOCAL int num_res = 0; /* # of cached re's */
< static YB_THREAD_LOCAL cached_re_str re_array[MAX_CACHED_RES]; /* cached re's */
> static int num_res = 0; /* # of cached re's */
> static cached_re_str re_array[MAX_CACHED_RES]; /* cached re's */
```
Jira: DB-16251
Test Plan:
```
./yb_build.sh --cxx-test pgwrapper_pg_mini-test --gtest_filter PgMiniTest.RegexPushdown
./yb_build.sh tsan--cxx-test pgwrapper_pg_mini-test --gtest_filter PgMiniTest.RegexPushdown
```
Reviewers: kfranz
Reviewed By: kfranz
Subscribers: yql, svc_phabricator
Differential Revision: https://phorge.dev.yugabyte.com/D445281 parent 88ee3de commit 0e51069
File tree
8 files changed
+68
-273
lines changed- src
- postgres/src
- backend
- regex
- utils/adt
- tools/pgindent
- yb/yql/pggate
8 files changed
+68
-273
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 112 | + | |
| 113 | + | |
124 | 114 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | 115 | | |
174 | 116 | | |
175 | 117 | | |
| |||
207 | 149 | | |
208 | 150 | | |
209 | 151 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | 152 | | |
215 | 153 | | |
216 | 154 | | |
217 | 155 | | |
218 | 156 | | |
219 | | - | |
| 157 | + | |
220 | 158 | | |
221 | 159 | | |
222 | 160 | | |
| |||
297 | 235 | | |
298 | 236 | | |
299 | 237 | | |
300 | | - | |
| 238 | + | |
301 | 239 | | |
302 | | - | |
303 | | - | |
304 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
305 | 244 | | |
306 | 245 | | |
307 | | - | |
308 | | - | |
| 246 | + | |
| 247 | + | |
309 | 248 | | |
310 | 249 | | |
311 | | - | |
| 250 | + | |
312 | 251 | | |
313 | 252 | | |
314 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
| |||
271 | 270 | | |
272 | 271 | | |
273 | 272 | | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | 273 | | |
278 | 274 | | |
279 | 275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | 24 | | |
43 | 25 | | |
44 | 26 | | |
| |||
50 | 32 | | |
51 | 33 | | |
52 | 34 | | |
53 | | - | |
54 | | - | |
55 | 35 | | |
56 | 36 | | |
57 | 37 | | |
| |||
117 | 97 | | |
118 | 98 | | |
119 | 99 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | 100 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 80 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | 908 | | |
924 | 909 | | |
925 | 910 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2399 | 2399 | | |
2400 | 2400 | | |
2401 | 2401 | | |
2402 | | - | |
2403 | | - | |
2404 | | - | |
2405 | | - | |
2406 | | - | |
2407 | | - | |
2408 | | - | |
2409 | | - | |
2410 | | - | |
2411 | | - | |
2412 | | - | |
2413 | | - | |
2414 | | - | |
2415 | 2402 | | |
2416 | 2403 | | |
2417 | 2404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
870 | 870 | | |
871 | 871 | | |
872 | 872 | | |
873 | | - | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | | - | |
880 | 873 | | |
881 | 874 | | |
882 | 875 | | |
| |||
0 commit comments