Re: Nested comparison semantics are unpredictable

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Wesley <richard(at)duckdblabs(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Nested comparison semantics are unpredictable
Date: 2025-08-12 18:12:22
Message-ID: 3409432.1755022342@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Richard Wesley <richard(at)duckdblabs(dot)com> writes:
> I was trying to make our comparison semantics for nested types <https://github.com/duckdb/duckdb/issues/18039> match Postgres, and I found that the semantics of comparisons change when a join is present.

It's not about joins. It's about the syntactic form of the
expression. When you write "ROW(...) = ROW(...)", that goes
through make_row_comparison_op(), which indeed behaves
differently from record_eq(), which is where the comparison
will end up when it looks like "var = var". In particular
"ROW(x) = ROW(y)" is optimized into "x = y" which is why
you get a NULL for "row(0) = row(NULL)". record_eq() is not
allowed to produce a null in such cases, though --- else it
would be unsuitable to use as a btree comparator.

There's a lot of historical baggage and spec-text-lawyering
behind all this, but the short answer is that we're unlikely
to change either behavior.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Dilip Kumar 2025-08-13 04:45:39 Re: BUG #19018: high memory usage and "stack depth limit exceeded", with GiST index on ltree
Previous Message Richard Wesley 2025-08-12 16:16:22 Nested comparison semantics are unpredictable