Bug #477 gis test fails on Solaris 8 x86
Submitted: 22 May 2003 12:49 Modified: 31 May 2003 4:27
Reporter: Per-Erik Martin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:Intel Unix with gcc.
Assigned to: Ramil Kalimullin CPU Architecture:Any

[22 May 2003 12:49] Per-Erik Martin
Description:
The gis test fails on a Solaris 8 x86 build from the
mysql-4.1.0-alpha.tar.gz source as shown.
All other tests pass.
The source was downloaded 2003-05-22.

How to repeat:
% gcc -v
Reading specs from /usr/local/lib/gcc-lib/i386-pc-solaris2.8/3.2.2/specs
Configured with: ../configure --disable-nls --with-ld=/usr/ccs/bin/ld --with-as=/usr/ccs/bin/as
Thread model: posix
gcc version 3.2.2
% echo $CC
gcc
% echo $CFLAGS
-O3 -fno-omit-frame-pointer
% echo $CXX
gcc
% echo $CXXFLAGS
-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti
% ./configure --prefix=/usr/local/mysql-4.1 --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --with-named-z-libs=no --with-named-curses-libs=-lcurses --disable-shared
/.../
% make
/.../
% cd mysql-test
% ./mysql-test-run gis
Installing Test Databases
Removing Stale Files
Installing Master Databases
running  ../sql/mysqld --no-defaults --bootstrap --skip-grant-tables     --basedir=. --datadir=./var/master-data --skip-innodb --skip-bdb --language=../sql/share/english/
Installing Slave Databases
running  ../sql/mysqld --no-defaults --bootstrap --skip-grant-tables     --basedir=. --datadir=./var/slave-data --skip-innodb --skip-bdb --language=../sql/share/english/
Manager disabled, skipping manager start.
Loading Standard Test Databases
Starting Tests

 TEST                         USER   SYSTEM  ELAPSED        RESULT
------------------------------------------------------------------------
gis                           ....     ....     ....       [ fail ]

   >> Error at line 145: Result length mismatch<<
Below are the diffs between actual and expected results:
-------------------------------------------------------
*** r/gis.result        Thu Apr  3 15:41:23 2003
--- r/gis.reject        Thu May 22 22:17:43 2003
***************
*** 268,280 ****
  107   0
  SELECT fid, AsText(Centroid(g)) FROM p;
  fid   AsText(Centroid(g))
! 108   POINT(15 15)
! 109   POINT(25.416666666667 25.416666666667)
! 110   POINT(20 10)
  SELECT fid, Area(g) FROM p;
  fid   Area(g)
! 108   100
! 109   2400
  110   450
  SELECT fid, AsText(ExteriorRing(g)) FROM p;
  fid   AsText(ExteriorRing(g))
--- 268,280 ----
  107   0
  SELECT fid, AsText(Centroid(g)) FROM p;
  fid   AsText(Centroid(g))
! 108   POINT(15 -7.1359775397801e+151)
! 109   POINT(25 -7.1359775397801e+151)
! 110   POINT(20 -9.5146367197068e+151)
  SELECT fid, Area(g) FROM p;
  fid   Area(g)
! 108   200
! 109   1050
  110   450
  SELECT fid, AsText(ExteriorRing(g)) FROM p;
  fid   AsText(ExteriorRing(g))
***************
*** 298,311 ****
  116   0
  SELECT fid, AsText(Centroid(g)) FROM mp;
  fid   AsText(Centroid(g))
! 117   POINT(55.588527753042 17.426536064114)
! 118   POINT(55.588527753042 17.426536064114)
  119   POINT(2 2)
  SELECT fid, Area(g) FROM mp;
  fid   Area(g)
! 117   1684.5
! 118   1684.5
! 119   4.5
  SELECT fid, NumGeometries(g) from mpt;
  fid   NumGeometries(g)
  111   4
--- 298,311 ----
  116   0
  SELECT fid, AsText(Centroid(g)) FROM mp;
  fid   AsText(Centroid(g))
! 117   POINT(48.883247089263 13.102199223803)
! 118   POINT(55.222202423378 14.178902352103)
  119   POINT(2 2)
  SELECT fid, Area(g) FROM mp;
  fid   Area(g)
! 117   1205.5
! 118   701.5
! 119   27
  SELECT fid, NumGeometries(g) from mpt;
  fid   NumGeometries(g)
  111   4
-------------------------------------------------------
Please follow the instructions outlined at
http://www.mysql.com/doc/R/e/Reporting_mysqltest_bugs.html
to find the reason to this problem and how to report this.

Aborting. To continue, re-run with '--force'.

Ending Tests
Shutting-down MySQL daemon

Master shutdown finished
Slave shutdown finished
[28 May 2003 4:13] Per-Erik Martin
Compiling the file spatial.cc with -O2 or -O3 makes the gis test fail as shown.
Compiling with -O1 makes it pass.

This can be a compiler bug, but it's also possible that there is some obscure
bug in the function GPolygon::area() that causes the optimizer to mess up,
although it's not obvious what that would be (no warnings are given, even with
-Wall, in this function).
[29 May 2003 4:57] Per-Erik Martin
This has also been repeated on RedHad Linux 7.3 using gcc 2.96, so it's not
a Solarix x86 specific problem.

It turns out that it's the last/innermost variables 'double y' in GPolygon::area() and GPolygon::centroid_xy() respectively that simply do
not get set with higher optimization levels. This can be solved in two
different ways. Either simply declare these variables as "volatile", or
redefining the doubleget macro to use a temporary variable (which is the proposed
fix).

Hypothesis about the cause of this problem:
The use of a union for the unpacking is actually a non-portable trick (although
it's common practice). It's only correct to read the same part of a union that
was last set. Setting one part and reading the other is strictly speaking
undefined. My guess is that the optimizer throws away the assignment since it
doesn't se a reference to the same part later. (It's also possible that the
fact that it's done with a on-the-fly-cast is part of the problem.)
Why only these two functions and only one variable in each?
Probably because it's a combination of the use of doubleget and a fairly large
number of double variables (> 5). Maybe in only happens to variables that
doesn't fit into a register for instance (thus a significant gain if not doing
the assignment at all).
(But, it might still be an obscure compiler bug...)
[31 May 2003 4:27] Michael Widenius
Thank you for your bug report. This issue has been fixed in the latest
development tree for that product. You can find more information about
accessing our development trees at 
    http://www.mysql.com/doc/en/Installing_source_tree.html

This will be fixed in the 4.1.1 release (Will push to 4.1 tree during weekend)