Skip to content

2.27.0.0-b209

@timothy-e timothy-e tagged this 10 Jun 15:15
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/D44528
Assets 2
Loading