pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Cross-Product JOIN?
8+ messages / 4 participants
[nested] [flat]

* Cross-Product JOIN?
@ 2023-05-24 08:22  Atomic_Sheep <atomic.sheep@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Atomic_Sheep @ 2023-05-24 08:22 UTC (permalink / raw)
  To: pgsql-docs@lists.postgresql.org

Hi, I'm reading the documentation and I'm trying to wrap my head
around this statement:

"Finally, NATURAL is a shorthand form of USING: it forms a USING list
consisting of all column
names that appear in both input tables. As with USING, these columns
appear only once in the
output table. If there are no common column names, NATURAL JOIN
behaves like JOIN ...
ON TRUE, producing a cross-product join."

Did it mean cartesian product and not cross-product?





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Cross-Product JOIN?
@ 2023-05-24 13:46  Erik Wienhold <ewie@ewie.name>
  parent: Atomic_Sheep <atomic.sheep@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Erik Wienhold @ 2023-05-24 13:46 UTC (permalink / raw)
  To: Atomic_Sheep <atomic.sheep@gmail.com>; pgsql-docs@lists.postgresql.org

> On 24/05/2023 10:22 CEST Atomic_Sheep <atomic.sheep@gmail.com> wrote:
>
> "Finally, NATURAL is a shorthand form of USING: it forms a USING list
> consisting of all column
> names that appear in both input tables. As with USING, these columns
> appear only once in the
> output table. If there are no common column names, NATURAL JOIN
> behaves like JOIN ...
> ON TRUE, producing a cross-product join."
>
> Did it mean cartesian product and not cross-product?

Cross product means cartesian product in this context.  So technically correct.
Personally, I think it should read cartesian product because cross product is an
overloaded term and cartesian product is used more often in the documentation
overall.

But the same page [0] also uses cross product when talking about grouping sets.

The source code uses cross product in a couple of comments, though.

[0] https://www.postgresql.org/docs/15/queries-table-expressions.html

--
Erik





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Cross-Product JOIN?
@ 2023-05-24 19:10  Erik Wienhold <ewie@ewie.name>
  parent: Erik Wienhold <ewie@ewie.name>
  0 siblings, 2 replies; 8+ messages in thread

From: Erik Wienhold @ 2023-05-24 19:10 UTC (permalink / raw)
  To: Atomic_Sheep <atomic.sheep@gmail.com>; pgsql-docs@lists.postgresql.org

> On 24/05/2023 15:46 CEST Erik Wienhold <ewie@ewie.name> wrote:
>
> Personally, I think it should read cartesian product because cross product is
> an overloaded term and cartesian product is used more often in the documentation
> overall.
>
> But the same page [0] also uses cross product when talking about grouping sets.
>
> [0] https://www.postgresql.org/docs/15/queries-table-expressions.html

Here's a patch that fixes those two places.

--
Erik

Attachments:

  [text/x-patch] 0001-Use-Cartesian-product-consistently-in-docs.patch (1.6K, ../../2053109544.160895.1684955437950@office.mailbox.org/2-0001-Use-Cartesian-product-consistently-in-docs.patch)
  download | inline diff:
From b23bd267ac9c4e79efb472c08dc35737bc8e9ca6 Mon Sep 17 00:00:00 2001
From: Erik Wienhold <ewie@ewie.name>
Date: Wed, 24 May 2023 20:21:47 +0200
Subject: [PATCH] Use Cartesian product consistently in docs

Fixes two places in the docs that use "cross product" instead of the
more common "Cartesian product", used throughout the rest of the docs.
For the NATURAL JOIN without common column names it is easiest to refer
to CROSS JOIN which is already described as the Cartesian product.
---
 doc/src/sgml/queries.sgml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/queries.sgml b/doc/src/sgml/queries.sgml
index 6986ec5c92..a75a241d62 100644
--- a/doc/src/sgml/queries.sgml
+++ b/doc/src/sgml/queries.sgml
@@ -392,7 +392,7 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
         input tables.  As with <literal>USING</literal>, these columns appear
         only once in the output table.  If there are no common
         column names, <literal>NATURAL JOIN</literal> behaves like
-        <literal>JOIN ... ON TRUE</literal>, producing a cross-product join.
+        <literal>CROSS JOIN</literal>.
        </para>
 
        <note>
@@ -1362,7 +1362,7 @@ GROUPING SETS (
 
    <para>
     If multiple grouping items are specified in a single <literal>GROUP BY</literal>
-    clause, then the final list of grouping sets is the cross product of the
+    clause, then the final list of grouping sets is the Cartesian product of the
     individual items.  For example:
 <programlisting>
 GROUP BY a, CUBE (b, c), GROUPING SETS ((d), (e))
-- 
2.40.1



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Cross-Product JOIN?
@ 2023-05-25 04:52  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: Erik Wienhold <ewie@ewie.name>
  1 sibling, 1 reply; 8+ messages in thread

From: Laurenz Albe @ 2023-05-25 04:52 UTC (permalink / raw)
  To: Erik Wienhold <ewie@ewie.name>; Atomic_Sheep <atomic.sheep@gmail.com>; pgsql-docs@lists.postgresql.org

On Wed, 2023-05-24 at 21:10 +0200, Erik Wienhold wrote:
> > On 24/05/2023 15:46 CEST Erik Wienhold <ewie@ewie.name> wrote:
> > 
> > Personally, I think it should read cartesian product because cross product is
> > an overloaded term and cartesian product is used more often in the documentation
> > overall.
> > 
> > But the same page [0] also uses cross product when talking about grouping sets.
> > 
> > [0] https://www.postgresql.org/docs/15/queries-table-expressions.html
> 
> Here's a patch that fixes those two places.

+1

"Cross product" seems to be a misbegotten hybrid of "cross join" and
"Cartesian product".

Since we are talking about Cartesian products: is the term "Cartesian join"
used anywhere?

Yours,
Laurenz Albe





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Cross-Product JOIN?
@ 2023-05-25 06:59  Erik Wienhold <ewie@ewie.name>
  parent: Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 1 reply; 8+ messages in thread

From: Erik Wienhold @ 2023-05-25 06:59 UTC (permalink / raw)
  To: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-docs@lists.postgresql.org

> On 25/05/2023 06:52 CEST Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> On Wed, 2023-05-24 at 21:10 +0200, Erik Wienhold wrote:
> > > On 24/05/2023 15:46 CEST Erik Wienhold <ewie@ewie.name> wrote:
> > >
> > > Personally, I think it should read cartesian product because cross product is
> > > an overloaded term and cartesian product is used more often in the documentation
> > > overall.
> > >
> > > But the same page [0] also uses cross product when talking about grouping sets.
> > >
> > > [0] https://www.postgresql.org/docs/15/queries-table-expressions.html
> >
> > Here's a patch that fixes those two places.
>
> +1
>
> "Cross product" seems to be a misbegotten hybrid of "cross join" and
> "Cartesian product".

Cross product can mean Cartesian product depending on the context. [0]

> Since we are talking about Cartesian products: is the term "Cartesian join"
> used anywhere?

Not in the docs:

	$ git grep -iw cartesian -- doc
	doc/src/sgml/cube.sgml:    the lower-dimensional one is assumed to be a Cartesian projection, i. e., having zeroes
	doc/src/sgml/perform.sgml:   would be inefficient, since the full Cartesian product of A and C
	doc/src/sgml/planstats.sgml:   Cartesian product of the two inputs, multiplied by the
	doc/src/sgml/queries.sgml:    (that is, the Cartesian product of their rows is formed; see below).
	doc/src/sgml/queries.sgml:        <replaceable>T2</replaceable> (i.e., a Cartesian product),
	doc/src/sgml/ref/select.sgml:    specified, the result is the Cartesian product (cross join) of all
	doc/src/sgml/ref/select.sgml:    Cartesian product.
	doc/src/sgml/ref/select.sgml:        Cartesian product (i.e., all combined rows that pass its join
	doc/src/sgml/ref/select.sgml:        They produce a simple Cartesian product, the same result as you get from

but in a few comments:

	$ git grep -i 'cartesian\(\s\+join\|\s*$\)'
	src/backend/optimizer/geqo/geqo_eval.c: * a cartesian join to be performed.  When force is false, do only
	src/backend/optimizer/path/joinrels.c:   * upper level, we must be willing to make a cartesian join of a and b;
	src/backend/optimizer/path/joinrels.c:   * cartesian joins in this case (no bushy).
	src/test/regress/expected/join.out:-- test for ability to use a cartesian join when necessary
	src/test/regress/sql/join.sql:-- test for ability to use a cartesian join when necessary

[0] https://mathworld.wolfram.com/CartesianProduct.html

--
Erik





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Cross-Product JOIN?
@ 2023-05-25 21:46  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: Erik Wienhold <ewie@ewie.name>
  0 siblings, 1 reply; 8+ messages in thread

From: Laurenz Albe @ 2023-05-25 21:46 UTC (permalink / raw)
  To: Erik Wienhold <ewie@ewie.name>; pgsql-docs@lists.postgresql.org

On Thu, 2023-05-25 at 08:59 +0200, Erik Wienhold wrote:
> > Since we are talking about Cartesian products: is the term "Cartesian join"
> > used anywhere?
> 
> Not in the docs:

I was trying to be funny.  The Cartesian product of {Cartesian,cross} and
{product,join} would be {Cartesian product,Cartesian join,cross product,cross join}.

Yours,
Laurenz Albe





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Cross-Product JOIN?
@ 2023-05-25 23:23  Erik Wienhold <ewie@ewie.name>
  parent: Laurenz Albe <laurenz.albe@cybertec.at>
  0 siblings, 0 replies; 8+ messages in thread

From: Erik Wienhold @ 2023-05-25 23:23 UTC (permalink / raw)
  To: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-docs@lists.postgresql.org

> On 25/05/2023 23:46 CEST Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> On Thu, 2023-05-25 at 08:59 +0200, Erik Wienhold wrote:
> > > Since we are talking about Cartesian products: is the term "Cartesian join"
> > > used anywhere?
> >
> > Not in the docs:
>
> I was trying to be funny.  The Cartesian product of {Cartesian,cross} and
> {product,join} would be {Cartesian product,Cartesian join,cross product,cross join}.

And someone beat you to it and apparently planted the joke in the codebase.

(Good one, but unfortunately hard to tell apart from a serious question.)

--
Erik





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Cross-Product JOIN?
@ 2023-09-07 19:48  Bruce Momjian <bruce@momjian.us>
  parent: Erik Wienhold <ewie@ewie.name>
  1 sibling, 0 replies; 8+ messages in thread

From: Bruce Momjian @ 2023-09-07 19:48 UTC (permalink / raw)
  To: Erik Wienhold <ewie@ewie.name>; +Cc: Atomic_Sheep <atomic.sheep@gmail.com>; pgsql-docs@lists.postgresql.org

On Wed, May 24, 2023 at 09:10:37PM +0200, Erik Wienhold wrote:
> > On 24/05/2023 15:46 CEST Erik Wienhold <ewie@ewie.name> wrote:
> >
> > Personally, I think it should read cartesian product because cross product is
> > an overloaded term and cartesian product is used more often in the documentation
> > overall.
> >
> > But the same page [0] also uses cross product when talking about grouping sets.
> >
> > [0] https://www.postgresql.org/docs/15/queries-table-expressions.html
> 
> Here's a patch that fixes those two places.

Patch applied to master, thanks.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Only you can decide what is important to you.





^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2023-09-07 19:48 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-05-24 08:22 Cross-Product JOIN? Atomic_Sheep <atomic.sheep@gmail.com>
2023-05-24 13:46 ` Erik Wienhold <ewie@ewie.name>
2023-05-24 19:10   ` Erik Wienhold <ewie@ewie.name>
2023-05-25 04:52     ` Laurenz Albe <laurenz.albe@cybertec.at>
2023-05-25 06:59       ` Erik Wienhold <ewie@ewie.name>
2023-05-25 21:46         ` Laurenz Albe <laurenz.albe@cybertec.at>
2023-05-25 23:23           ` Erik Wienhold <ewie@ewie.name>
2023-09-07 19:48     ` Bruce Momjian <bruce@momjian.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox