Thread: bug in numeric log() on 7.1, 7.2.2, 7.2.3

bug in numeric log() on 7.1, 7.2.2, 7.2.3

From
dmarin
Date:
This query never returns:

select log(93094::numeric/92908::numeric);

If I type it in to psql on the three different systems I'm running postgresql
on, the query never returns, I can't cancel it (if I hit ctl-C psql says
"cancel request sent" but I don't get the prompt back), and postmaster (viewed

in top) uses all the idle CPU time. I can still do other queries and such, but

I can't shut down postmaster except with SIGQUIT or SIGKILL (actually, only
SIGKILL works on the solaris system, below).

The problem appears to exist with numeric log. I don't have problems with, for

instance, log(93094::float/92908::float)

The three systems:

(output of: echo "select version();" | psql template1; uname -a)

                                              version
------------------------------------------------------------------------------
----------------------
 PostgreSQL 7.2.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2
(Mandrake Linux 9.0 3.2-1mdk)
(1 row)

Linux gohma.i 2.4.19-16mdk #1 Fri Sep 20 18:15:05 CEST 2002 i686 unknown
unknown GNU/Linux


                           version
-------------------------------------------------------------
 PostgreSQL 7.1.2 on i686-pc-linux-gnu, compiled by GCC 2.96
(1 row)

Linux karma 2.4.18-7mdksmp #1 SMP Sat Mar 16 21:49:18 CET 2002 i686 unknown

(this is a somewhat upgraded Mandrake 8.1 system; I think I compiled
postgresql myself)


                             version
------------------------------------------------------------------
 PostgreSQL 7.2.3 on sparc-sun-solaris2.8, compiled by GCC 2.95.2
(1 row)

SunOS boojum.CS.Berkeley.EDU 5.8 Generic_108528-18 sun4u sparc SUNW,Ultra-5_10


(also compiled from source)

-Dave

P.S. Incidentally, on the solaris system, I also can't use pg_dump at all; no
matter what database I try to dump, I get a bus error:

[dmarin@boojum]$ pg_dump template1;
Bus Error

Is this a known problem, or would you like more information?)

P.P.S. 93094 (the first number in the deadly log expression) is the zip code
of Simi Valley, CA. First the Rodney King riots, now this! :P

Re: bug in numeric log() on 7.1, 7.2.2, 7.2.3

From
Tom Lane
Date:
dmarin <dmarin@uclink.berkeley.edu> writes:
> This query never returns:
> select log(93094::numeric/92908::numeric);

The attached patch against 7.3 seems to take care of the problem.  You
should be able to apply it to 7.2, with possibly some tweaking (the code
needs to go into the loop in ln_var()).

I am unsure whether exp_var() needs a similar defense against roundoff
error.  Have you observed any problems there?

*** src/backend/utils/adt/numeric.c.orig    Tue Mar 11 16:01:33 2003
--- src/backend/utils/adt/numeric.c    Thu Mar 13 19:06:42 2003
***************
*** 3872,3877 ****
--- 3872,3880 ----
              break;

          add_var(result, &elem, result);
+
+         if (elem.weight < (result->weight - 2 * global_rscale))
+             break;
      }

      /* Compensate for argument range reduction, round to caller's rscale */



> P.S. Incidentally, on the solaris system, I also can't use pg_dump at all; no
> matter what database I try to dump, I get a bus error:

> [dmarin@boojum]$ pg_dump template1;
> Bus Error

> Is this a known problem, or would you like more information?)

Which pg_dump version is this?  Where is it crashing exactly (a stack
trace would help)?

            regards, tom lane