postgresql/src/backend
Tom Lane 3a02d68a96 Avoid divide-by-zero in regex_selectivity() with long fixed prefix.
Given a regex pattern with a very long fixed prefix (approaching 500
characters), the result of pow(FIXED_CHAR_SEL, fixed_prefix_len) can
underflow to zero.  Typically the preceding selectivity calculation
would have underflowed as well, so that we compute 0/0 and get NaN.
In released branches this leads to an assertion failure later on.
That doesn't happen in HEAD, for reasons I've not explored yet,
but it's surely still a bug.

To fix, just skip the division when the pow() result is zero, so
that we'll (most likely) return a zero selectivity estimate.  In
the edge cases where "sel" didn't yet underflow, perhaps this
isn't desirable, but I'm not sure that the case is worth spending
a lot of effort on.  The results of regex_selectivity_sub() are
barely worth the electrons they're written on anyway :-(

Per report from Alexander Lakhin.  Back-patch to all supported versions.

Discussion: https://postgr.es/m/6de0a0c3-ada9-cd0c-3e4e-2fa9964b41e3@gmail.com
2021-02-12 16:26:47 -05:00
..
access Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:55 +02:00
bootstrap Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
catalog Preserve pg_attribute.attstattarget across REINDEX CONCURRENTLY 2021-02-10 13:09:09 +09:00
commands Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:55 +02:00
executor Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:55 +02:00
foreign Update copyrights for 2020 2020-01-01 12:21:45 -05:00
jit jit: Correct parameter type for generated expression evaluation functions. 2020-12-07 18:33:03 -08:00
lib Use pg_bitutils for HyperLogLog. 2020-07-30 09:17:00 -07:00
libpq Fix up usage of krb_server_keyfile GUC parameter. 2020-12-30 11:38:42 -05:00
main Add PostgreSQL home page to --help output 2020-02-28 13:12:21 +01:00
nodes Ensure that expandTableLikeClause() re-examines the same table. 2020-12-01 14:02:27 -05:00
optimizer Fix error with CREATE PUBLICATION, wal_level=minimal, and new tables. 2021-01-30 00:12:05 -08:00
parser Fix mishandling of column-level SELECT privileges for join aliases. 2021-02-08 10:14:09 -05:00
partitioning Fix hash partition pruning with asymmetric partition sets. 2021-01-28 13:41:55 -05:00
po Translation updates 2021-02-08 17:41:32 +01:00
port Spelling adjustments 2020-06-07 15:06:51 +02:00
postmaster Fix assorted issues in backend's GSSAPI encryption support. 2020-12-28 17:44:17 -05:00
regex Fix ancient bug in parsing of BRE-mode regular expressions. 2021-01-08 12:16:00 -05:00
replication Ensure that a standby is able to follow a primary on a newer timeline. 2021-01-14 12:28:47 +09:00
rewrite Revert "Propagate CTE property flags when copying a CTE list into a rule." 2021-02-07 12:54:08 -05:00
snowball Update copyrights for 2020 2020-01-01 12:21:45 -05:00
statistics Run pgindent with new pg_bsd_indent version 2.1.1. 2020-05-16 11:54:51 -04:00
storage Fix CREATE INDEX CONCURRENTLY for simultaneous prepared transactions. 2021-01-30 00:00:42 -08:00
tcop Avoid crash when rolling back within a prepared statement. 2021-02-03 19:38:29 -05:00
tsearch Avoid possible dangling-pointer access in tsearch_readline_callback. 2020-09-23 11:36:13 -04:00
utils Avoid divide-by-zero in regex_selectivity() with long fixed prefix. 2021-02-12 16:26:47 -05:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Update copyrights for 2020 2020-01-01 12:21:45 -05:00
nls.mk Translation updates 2020-09-14 13:14:53 +02:00