Thread: BUG #12146: Crash when using UNION ALL

BUG #12146: Crash when using UNION ALL

From
me@jandrabek.cz
Date:
The following bug has been logged on the website:

Bug reference:      12146
Logged by:          Jan Drabek
Email address:      me@jandrabek.cz
PostgreSQL version: 9.3.5
Operating system:   OS X 10.10 (via Macports)
Description:

Since 9.3.5 my PostgreSQL crashes when certain pattern in queries appears.
(Version 9.3.4 is not affected.)

After cutting all dependencies and columns from table foo it is only having
one column with BIGINT type.

The query is:
SELECT *
FROM (
       SELECT id
       FROM (
              SELECT id FROM foo
              UNION ALL
              SELECT id FROM foo

            ) t
       UNION ALL

       SELECT id FROM foo
     ) AS eop
  JOIN foo p ON p.id = eop.id

After execution of this query I get this in PostgreSQL log:
LOG:  server process (PID 11935) was terminated by signal 11: Segmentation
fault

However it is reproducible only on my machine (dumping database is of no
good).

Interesting observations:
 - After executing ANALYZE foo; problems disappear (corrupted statistics?)
 - Using UNION instead of UNION ALL makes it work.
 - Duplicating database on my machine (via pgadmin dump and load) doesn't
change this behaviour (i.e. it still crashes even on the newly loaded
database).

However I wasn't able to reproduce problem on different machine.
Any ideas what to do next in order to find the cause? (I tried to use
DEBUG5, but there were nothing interesting in the log).

Thanks
jan Drábek

Re: BUG #12146: Crash when using UNION ALL

From
Tom Lane
Date:
me@jandrabek.cz writes:
> Since 9.3.5 my PostgreSQL crashes when certain pattern in queries appears.
> (Version 9.3.4 is not affected.)

This query looks like it might have been fixed by commit
b2b95de61e2e1c4647fa902c3b946109c55451c4, but that hasn't made it into
any released version yet :-(

            regards, tom lane