postgresql/src/backend/utils/adt
Dean Rasheed e54a758d24 Fix corner-case loss of precision in numeric_power().
This fixes a loss of precision that occurs when the first input is
very close to 1, so that its logarithm is very small.

Formerly, during the initial low-precision calculation to estimate the
result weight, the logarithm was computed to a local rscale that was
capped to NUMERIC_MAX_DISPLAY_SCALE (1000). However, the base may be
as close as 1e-16383 to 1, hence its logarithm may be as small as
1e-16383, and so the local rscale needs to be allowed to exceed 16383,
otherwise all precision is lost, leading to a poor choice of rscale
for the full-precision calculation.

Fix this by removing the cap on the local rscale during the initial
low-precision calculation, as we already do in the full-precision
calculation. This doesn't change the fact that the initial calculation
is a low-precision approximation, computing the logarithm to around 8
significant digits, which is very fast, especially when the base is
very close to 1.

Patch by me, reviewed by Alvaro Herrera.

Discussion: https://postgr.es/m/CAEZATCV-Ceu%2BHpRMf416yUe4KKFv%3DtdgXQAe5-7S9tD%3D5E-T1g%40mail.gmail.com
2021-10-06 13:16:51 +01:00
..
.gitignore Revert "Add gitignore entries for jsonpath_gram.h" 2019-03-23 00:19:34 +01:00
acl.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
amutils.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
array_expanded.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
array_selfuncs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
array_typanalyze.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
array_userfuncs.c Prevent integer overflows in array subscripting calculations. 2021-05-10 10:44:38 -04:00
arrayfuncs.c Fix hash_array 2021-09-15 12:15:04 +02:00
arraysubs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
arrayutils.c Prevent integer overflows in array subscripting calculations. 2021-05-10 10:44:38 -04:00
ascii.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
bool.c Clean up some code using "(expr) ? true : false" 2021-09-08 09:44:04 +09:00
cash.c Expose internal function for converting int64 to numeric 2020-09-09 20:16:28 +02:00
char.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
cryptohashfuncs.c Add result size as argument of pg_cryptohash_final() for overflow checks 2021-02-15 10:18:34 +09:00
date.c Make timetz_zone() stable, and correct a bug for DYNTZ abbreviations. 2021-09-06 11:03:56 -04:00
datetime.c interval: round values when spilling to months 2021-08-03 12:10:29 -04:00
datum.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
dbsize.c Teach pg_size_pretty and pg_size_bytes about petabytes 2021-07-09 18:56:00 +12:00
domains.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
encode.c Revert refactoring of hex code to src/common/ 2021-08-19 09:20:13 +09:00
enum.c Rename "enum blacklist" to "uncommitted enums". 2021-01-05 12:38:48 +13:00
expandeddatum.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
expandedrecord.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
float.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
format_type.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
formatting.c Fix out-of-bound memory access for interval -> char conversion 2021-04-12 11:30:50 +09:00
genfile.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
geo_ops.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
geo_selfuncs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
geo_spgist.c Fix more confusion in SP-GiST. 2021-04-04 17:57:07 -04:00
inet_cidr_ntop.c Avoid conflicts with library versions of inet_net_ntop() and friends. 2019-08-18 19:27:23 -04:00
inet_net_pton.c Avoid conflicts with library versions of inet_net_ntop() and friends. 2019-08-18 19:27:23 -04:00
int8.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
int.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
json.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
jsonb_gin.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
jsonb_op.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
jsonb_util.c Implementation of subscripting for jsonb 2021-01-31 23:50:40 +03:00
jsonb.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
jsonbsubs.c Message style improvements 2021-09-16 15:36:44 +02:00
jsonfuncs.c Fix typo 2021-09-08 16:48:51 +02:00
jsonpath_exec.c Fix some typos, grammar and style in docs and comments 2021-02-24 16:13:17 +09:00
jsonpath_gram.y Avoid determining regexp subexpression matches, when possible. 2021-08-09 11:26:34 -04:00
jsonpath_scan.l Update copyright for 2021 2021-01-02 13:06:25 -05:00
jsonpath.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
levenshtein.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
like_match.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
like_support.c Avoid divide-by-zero in regex_selectivity() with long fixed prefix. 2021-02-12 16:26:47 -05:00
like.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
lockfuncs.c Rename debug_invalidate_system_caches_always to debug_discard_caches. 2021-07-13 15:01:01 -04:00
mac8.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
mac.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
Makefile Use "-I." in directories holding Bison parsers, for Oracle compilers. 2021-04-12 19:24:41 -07:00
mcxtfuncs.c Reorder superuser check in pg_log_backend_memory_contexts() 2021-06-08 08:53:12 +09:00
misc.c Do not rely on pgstat.h to indirectly include storage/ headers. 2021-04-02 20:02:47 -07:00
multirangetypes_selfuncs.c Fix wording 2021-08-06 20:55:59 +02:00
multirangetypes.c Message style improvements 2021-09-16 15:36:44 +02:00
name.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
network_gist.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
network_selfuncs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
network_spgist.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
network.c Move src/backend/utils/hash/hashfn.c to src/common 2020-02-27 09:25:41 +05:30
numeric.c Fix corner-case loss of precision in numeric_power(). 2021-10-06 13:16:51 +01:00
numutils.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
oid.c Remove Value node struct 2021-09-09 08:36:53 +02:00
oracle_compat.c Add bytea equivalents of ltrim() and rtrim(). 2021-01-18 15:11:32 -05:00
orderedsetaggs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
partitionfuncs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
pg_locale.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
pg_lsn.c Simplify printing of LSNs 2021-02-23 10:27:02 +01:00
pg_upgrade_support.c Revert per-index collation version tracking feature. 2021-05-07 21:10:11 +12:00
pgstatfuncs.c pgstat: split reporting/fetching of bgwriter and checkpointer stats. 2021-08-04 19:16:04 -07:00
pseudotypes.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
quote.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
rangetypes_gist.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
rangetypes_selfuncs.c Fix wording 2021-08-06 20:55:59 +02:00
rangetypes_spgist.c Fix wording 2021-08-06 20:55:59 +02:00
rangetypes_typanalyze.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
rangetypes.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
regexp.c Let regexp_replace() make use of REG_NOSUB when feasible. 2021-08-09 20:53:25 -04:00
regproc.c Reconsider the handling of procedure OUT parameters. 2021-06-10 17:11:36 -04:00
ri_triggers.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
rowtypes.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
ruleutils.c Fix EXPLAIN to handle SEARCH BREADTH FIRST queries. 2021-09-16 10:45:42 -04:00
selfuncs.c Avoid believing incomplete MCV-only stats in get_variable_range(). 2021-10-01 14:59:35 -04:00
tid.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
timestamp.c Avoid unnecessary division in interval_cmp_value(). 2021-09-26 14:24:03 -04:00
trigfuncs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
tsginidx.c Convert tsginidx.c's GIN indexing logic to fully ternary operation. 2021-02-16 12:07:14 -05:00
tsgistidx.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
tsquery_cleanup.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
tsquery_gist.c Clean up some code using "(expr) ? true : false" 2021-09-08 09:44:04 +09:00
tsquery_op.c Avoid using ambiguous word "non-negative" in error messages. 2021-07-28 01:20:16 +09:00
tsquery_rewrite.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
tsquery_util.c Clean up some code using "(expr) ? true : false" 2021-09-08 09:44:04 +09:00
tsquery.c Improve error message about valid value for distance in phrase operator. 2021-08-25 11:43:56 +09:00
tsrank.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
tsvector_op.c Convert tsginidx.c's GIN indexing logic to fully ternary operation. 2021-02-16 12:07:14 -05:00
tsvector_parser.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
tsvector.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
uuid.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
varbit.c Add bit_count SQL function 2021-03-23 10:13:58 +01:00
varchar.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
varlena.c Revert refactoring of hex code to src/common/ 2021-08-19 09:20:13 +09:00
version.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
windowfuncs.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
xid8funcs.c Fix typo in comments. 2021-09-06 17:03:40 +09:00
xid.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
xml.c Make use of PG_INT64_MAX/PG_INT64_MIN 2021-09-22 07:31:05 +02:00