Cartesian product bug? - Mailing list pgsql-general

From Åsmund Kveim Lie
Subject Cartesian product bug?
Date
Msg-id oprxtejkclemun9e@news.postgresql.org
Whole thread Raw
Responses Re: Cartesian product bug?  (Greg Stark <gsstark@mit.edu>)
Re: Cartesian product bug?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi,

We have found a possible bug in 7.3.1. It seems that using CROSS JOIN and
doing plain Cartesian product, listing to tables in the from clause, gives
different results. According to the documentation this should be
equivalent. The following example should explain the problem:

CREATE TABLE a (a1 text, a2 text);
CREATE TABLE b (b1 text, b2 text);
CREATE TABLE c (a1 text, b1 text, c1 text);

INSERT INTO a VALUES('a1', 'a2');
INSERT INTO b VALUES('b1', 'b2');
INSERT INTO c VALUES('a3', 'b1', 'c1');

SELECT * FROM a,b NATURAL JOIN c;
a1 | a2 | b1 | b2 | a1 | c1
----+----+----+----+----+----
  a1 | a2 | b1 | b2 | a3 | c1
(1 row)

SELECT * FROM a CROSS JOIN b NATURAL JOIN c;
a1 | b1 | a2 | b2 | c1
----+----+----+----+----
(0 rows)

These two example queries should give the same result. In the first query,
it seems like it’s doing the natural join between b and c, and then does
the Cartesian product on that result with a. On the second query, it does
as we assume it should, namely does the Cartesian product first.

Is this the correct behavior?

Regards

Åsmund


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

pgsql-general by date:

Previous
From: tj
Date:
Subject: duplicates rejected by index reports PGSQL_FATAL_ERROR
Next
From: swatts@computer-systems.com (Shaun)
Date:
Subject: selecting information from two tables (problem)