pgsql: Avoid determining regexp subexpression matches, when possible.
От | Tom Lane |
---|---|
Тема | pgsql: Avoid determining regexp subexpression matches, when possible. |
Дата | |
Msg-id | E1mD7As-00060G-TA@gemulon.postgresql.org обсуждение исходный текст |
Список | pgsql-committers |
Avoid determining regexp subexpression matches, when possible. Identifying the precise match locations for parenthesized subexpressions is a fairly expensive task given the way our regexp engine works, both at regexp compile time (where we must create an optimized NFA for each parenthesized subexpression) and at runtime (where determining exact match locations requires laborious search). Up to now we've made little attempt to optimize this situation. This patch identifies cases where we know at compile time that we won't need to know subexpression match locations, and teaches the regexp compiler to not bother creating per-subexpression regexps for parenthesis pairs that are not referenced by backrefs elsewhere in the regexp. (To preserve semantics, we obviously still have to pin down the match locations of backref references.) Users could have obtained the same results before this by being careful to write "non capturing" parentheses wherever possible, but few people bother with that. Discussion: https://postgr.es/m/2219936.1628115334@sss.pgh.pa.us Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/0e6aa8747d439bb7f08f95e358f0509c50396785 Modified Files -------------- contrib/pg_trgm/trgm_regexp.c | 6 +- src/backend/regex/regc_lex.c | 5 +- src/backend/regex/regcomp.c | 68 +++++++++++++++++----- src/backend/regex/regexec.c | 36 ++++++++---- src/backend/utils/adt/jsonpath_gram.y | 8 +++ src/backend/utils/adt/regexp.c | 12 +++- src/include/regex/regex.h | 2 +- src/include/regex/regguts.h | 7 ++- .../modules/test_regex/expected/test_regex.out | 42 +++++++++++-- src/test/modules/test_regex/sql/test_regex.sql | 13 ++++- 10 files changed, 154 insertions(+), 45 deletions(-)
В списке pgsql-committers по дате отправления: