Re-land IMPALA-5393. Use THREAD_LOCAL state for regexp
Re-land IMPALA-5393. Use THREAD_LOCAL state for regexp

This re-lands commit 6e8c330f40da087ca0d8ba844cd9d97a8e60ff67 which was
reverted in d3428a58d8f54d1a64d5aeb1af3f76b7ffcb53d0. The revert was due
to an assumption that this commit depended on the new version of re2
(which was correctly reverted due to a toolchain issue). In fact this
commit does not depend on any toolchain changes.

Original commit message follows
--------------------------------

This changes the built-in regexp-related UDFs to use THREAD_LOCAL
re2::RE instances instead of FRAGMENT_LOCAL.

Although re2::RE is thread-safe, it achieves that thread safety through
a certain amount of locking. Using thread-local regexps improves
performance substantially.

I ran a simple test query:

select sum(l_linenumber) from item_20x where length(regexp_extract(l_shipinstruct, '.*', 0)) > 0

on a table with three underlying parquet files (thus getting 3 scanner
threads). Prior to this change, the query took ~60 seconds and burned
2m16sec CPU time. With this change, it took ~19sec and 43s CPU time. For
a query with more scanner threads, the improvement should be even more
dramatic.

The only potential downside of this change is slightly increased memory
consumption by having one RE instance per thread, but the REs themselves
should be small relative to all of the other per-scanner-thread memory.

Change-Id: I9ae0703efeb2429813b2a712f1accf1b0a4a409e
Reviewed-on: http://gerrit.cloudera.org:8080/12845
Reviewed-by: Lars Volker <4d73c29a4561048ce85fa0051bb7a6d201781159@cloudera.com>
Tested-by: Impala Public Jenkins <039b6b20426ff68ebe492b3021890d8c8fd010c9@cloudera.com>
Reviewed-on: https://gerrit.sjc.cloudera.com/c/cdh/impala/+/49284
Tested-by: Jenkins User <d95b56ce41a2e1ac4cecdd398defd7414407cc08@cloudera.com>
Reviewed-by: Laszlo Gaal <57b770caf3b7d570ebf40813dac2ce5f53722fa7@cloudera.com>
Tested-by: Laszlo Gaal <57b770caf3b7d570ebf40813dac2ce5f53722fa7@cloudera.com>
CDH-Build: Laszlo Gaal <57b770caf3b7d570ebf40813dac2ce5f53722fa7@cloudera.com>
Quasar-L0: Laszlo Gaal <57b770caf3b7d570ebf40813dac2ce5f53722fa7@cloudera.com>

cloudera/Impala,cloudera/Impala,cloudera/Impala,cloudera/Impala,cloudera/Impala,cloudera/Impala,cloudera/Impala