Thread: FPE on Alpha in Select with PKEY
============================================================================ POSTGRESQL BUG REPORT TEMPLATE ============================================================================ Your name : Adriaan Joubert Your email address : a.joubert@albourne.com System Configuration --------------------- Architecture (example: Intel Pentium) : DEC Alpha Operating System (example: Linux 2.0.26 ELF) : DU 4.0 D PostgreSQL version (example: PostgreSQL-6.4.2) : PostgreSQL-6.4.2 Compiler used (example: gcc 2.8.0) : DEC C V5.6-071 Please enter a FULL description of your problem: ------------------------------------------------ When doing a select with multiple OR's or an IN statement where this involves a primary key, it causes a floating point exception. Creating two tables A and B as follows: CREATE TABLE A ( PRIMARY KEY (a), a int4 NOT NULL, b int4 NOT NULL ); INSERT INTO A values (73,2); INSERT INTO A values (74,2); CREATE TABLE B ( a int4 NOT NULL, b int4 NOT NULL ); INSERT INTO B values (73,2); INSERT INTO B values (74,2); we get the following behaviour tt=> select * from B where a in (73,74); a|b --+- 73|2 74|2 (2 rows) tt=> select * from A where a in (73,74); ERROR: floating point exception! The last floating point operation either exceeded legal ranges or was a divide by zero tt=> select * from A where a=73 or a=74; ERROR: floating point exception! The last floating point operation either exceeded legal ranges or was a divide by zero Please describe a way to repeat the problem. Please try to provide a concise reproducible example, if at all possible: ---------------------------------------------------------------------- See above. If you know how this problem might be fixed, list the solution below: --------------------------------------------------------------------- I know it crashed in create_or_index_paths: following stack-trace 0 0x1200c83b4 in create_or_index_paths(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #1 0x1200c2924 in UnknownProcedure1FromFile134(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #2 0x1200c281c in find_paths(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #3 0x1200cb074 in UnknownProcedure1FromFile147(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #4 0x1200caedc in query_planner(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #5 0x1200cb9bc in union_planner(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #6 0x1200cb75c in planner(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #7 0x12011e3b0 in pg_parse_and_plan(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #8 0x12011e654 in pg_exec_query_dest(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #9 0x12011fffc in PostgresMain(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #10 0x1200b029c in main(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres #11 0x12003b1a8 in __start(0x0, 0x140201e80, 0x1f5, 0x1, 0x4, 0x0) in ./postgres I'm going to have to recompile with debugging switched on to have a better look at it. Anybody have any idea which source file this is in? -- --------------------------------------+------------------------------- Dr Adriaan Joubert | Phone: +357-2-750 652 APL Financial Services (Overseas) Ltd| Fax: +357-2-750 654 3 D. Vikella St | e-mail: a.joubert@albourne.com 1061 Nicosia, CYPRUS | --------------------------------------+-------------------------------
Further to the above: the error occurs on line 136 of the file src/backend/optimizer/path/orindxpath.c which reads > 136 clausenode->selectivity = (Cost) floatVal(selecs); floatVal is a macro #define floatVal(v) (((Value *)v)->val.dval) where value is typedef struct Value { NodeTag type; /* tag appropriately (eg. T_String) */ union ValUnion { char *str; /* string */ long ival; double dval; } val; } Value; The variable selecs is of type list, i.e. typedef struct List { NodeTag type; union { void *ptr_value; int int_value; } elem; struct List *next; } List; The variable selecs is filled in in the routine best_or_subclause_index in orindxpath.c, where the value that is read via the floatVal macro is assigned from a float (called selec as well). So this seems wrong anyway. Unfortunately casting ptr_value to float gives garbage as well: (ladebug) p *(double*)selecs->elem.ptr_value 2.48515019858147e-321 (ladebug) p *(float*)selecs->elem.ptr_value 1.3342e-312 Any ideas? Adriaan
Further to the above: the error occurs on line 136 of the file src/backend/optimizer/path/orindxpath.c > 136 clausenode->selectivity = (Cost) floatVal(selecs); floatVal is a macro #define floatVal(v) (((Value *)v)->val.dval) where value is typedef struct Value { NodeTag type; /* tag appropriately (eg. T_String) */ union ValUnion { char *str; /* string */ long ival; double dval; } val; } Value; The variable selecs is of type list, i.e. typedef struct List { NodeTag type; union { void *ptr_value; int int_value; } elem; struct List *next; } List; The variable selecs is filled in in the routine best_or_subclause_index in orindxpath.c, where the value that is read via the floatVal macro is assigned from a float (called selec as well). So this seems wrong anyway. Unfortunately casting ptr_value to float gives garbage as well: (ladebug) p *(double*)selecs->elem.ptr_value 2.48515019858147e-321 (ladebug) p *(float*)selecs->elem.ptr_value 1.3342e-312 Any ideas? Adriaan
Hi, I seem to have fixed the floating point problem on the Alphas -- at least for my test cases. It requires the following patch at the end of this mail. Could somebody who know postgres a bit better than me please double-check it, and let me know whether it is ok? The regression test seemed to run ok'ish (i.e. no more than before failed). Adriaan *** ./src/backend/optimizer/path/orindxpath.c.orig Mon Sep 21 18:41:27 1998 --- ./src/backend/optimizer/path/orindxpath.c Tue Mar 2 16:25:11 1999 *************** *** 133,139 **** xfunc_get_path_cost((Path) pathnode); } #endif ! clausenode->selectivity = (Cost) floatVal(selecs); t_list = lappend(t_list, pathnode); } } --- 133,139 ---- xfunc_get_path_cost((Path) pathnode); } #endif ! clausenode->selectivity = (Cost) floatVal(selecs->elem.ptr_value); t_list = lappend(t_list, pathnode); } }
Yes. I have an idea. Did you add a column to the table using ALTER TABLE. There was a bug in 6.4.* and earlier that caused this to happend for added columns. Do a vacuum analyze on the table and the problem will go away. Will be fixed in the next release. > Further to the above: the error occurs on line 136 of the file > src/backend/optimizer/path/orindxpath.c > > > 136 clausenode->selectivity = (Cost) floatVal(selecs); > > > > floatVal is a macro > > #define floatVal(v) (((Value *)v)->val.dval) > > where value is > > typedef struct Value > { > NodeTag type; /* tag appropriately > (eg. T_String) */ > union ValUnion > { > char *str; /* string */ > long ival; > double dval; > } val; > } Value; > > The variable selecs is of type list, i.e. > > typedef struct List > { > NodeTag type; > union > { > void *ptr_value; > int int_value; > } elem; > struct List *next; > } List; > > > The variable selecs is filled in in the routine best_or_subclause_index > in orindxpath.c, where the value that is read via the floatVal macro is > assigned from a float (called selec as well). So this seems wrong > anyway. > > Unfortunately casting ptr_value to float gives garbage as well: > > (ladebug) p *(double*)selecs->elem.ptr_value > 2.48515019858147e-321 > (ladebug) p *(float*)selecs->elem.ptr_value > 1.3342e-312 > > > Any ideas? > > Adriaan > > -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026