pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sami Imseih <samimseih@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Cc: Ewan Young <kdbase.hack@gmail.com>
Subject: Re: Disallow outer-level and WHERE-clause aggregates in GRAPH_TABLE
Date: Sat, 15 Aug 2026 21:18:11 -0400
Message-ID: <290933.1786843091@sss.pgh.pa.us> (raw)
In-Reply-To: <CAA5RZ0twav-cJXFT0mt-jJAjAuNz9jz=nyDM2+CpopJpTs8hEQ@mail.gmail.com>
References: <CAA5RZ0tvdYODLQvYwVzAxUPe5=E3vSe8Zy7TvrQq+syvGKpHSQ@mail.gmail.com>
	<2732076.1786551380@sss.pgh.pa.us>
	<CAA5RZ0sTr_Yt_9_qtt5PyzN-EaRnebXgWDTSgMn1H1Ak5vU-yQ@mail.gmail.com>
	<CAA5RZ0tf2JS4+CcHg7DzE+wSFMu8FK+CdZpT50yXhLabamkyeQ@mail.gmail.com>
	<207328.1786821718@sss.pgh.pa.us>
	<CAA5RZ0twav-cJXFT0mt-jJAjAuNz9jz=nyDM2+CpopJpTs8hEQ@mail.gmail.com>

Sami Imseih <samimseih@gmail.com> writes:
> postgres=# SELECT EXISTS(SELECT nm FROM GRAPH_TABLE (myshop MATCH (c
> IS customers WHERE count(c.customer_id + o.customer_id) > 0) COLUMNS
> (c.name AS nm)) t) FROM customers o;
> ERROR:  Upper-level Var found where not expected

Ouch.

> So, based on your explanation earlier, this led me to find that the
> leveling is still wrong. Specifically, min_varlevel > 0, since the
> level-zero GraphPropertyRef is not accounted for in
> check_agg_arguments_walker. In this case min_varlevel should be 0.

Right, I came to the same conclusion.

> The fix is to teach check_agg_arguments_walker that a GraphPropertyRef
> carries a level, the GRAPH_TABLE's own level. This is safe because a
> GraphPropertyRef can only ever refer to its own GRAPH_TABLE's level
> and can never appear inside a sub-select, so treating it as a level-zero
> reference is always correct.

I find that argument pretty shaky.  If I can write
	MATCH WHERE c.customer_id > 0
why can't I write
	MATCH WHERE (SELECT c.customer_id > 0)
?  I see that that in fact doesn't work, but that seems like a bug
in itself.

More generally, what this suggests to me is that we have a ton of
other bugs-of-omission in places that process Vars and don't know that
a GraphPropertyRef acts like a Var.  So what I'm thinking right now is
that this is a fundamental design error, and that we should nuke
GraphPropertyRef altogether in favor of using a Var that references
the appropriate column of the RTE_GRAPH_TABLE relation.  We have
learned the hard way in the past that you don't want to invent things
that act like Vars but aren't Vars; if you must, you are going to be
doing a heck of a lot of work to patch up everyplace that will need to
know about them.  The hazard here is limited somewhat by the fact that
the planner and executor will never see GraphPropertyRefs, but I'm
afraid that still leaves plenty of scope for bugs (in the rewriter, in
particular).

			regards, tom lane






view thread (14+ messages)  latest in thread

Message-ID: <290933.1786843091@sss.pgh.pa.us>
Permalink:  ../290933.1786843091@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/290933.1786843091@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, samimseih@gmail.com, ashutosh.bapat.oss@gmail.com, kdbase.hack@gmail.com
  Subject: Re: Disallow outer-level and WHERE-clause aggregates in GRAPH_TABLE
  In-Reply-To: <290933.1786843091@sss.pgh.pa.us>
  References: <CAA5RZ0tvdYODLQvYwVzAxUPe5=E3vSe8Zy7TvrQq+syvGKpHSQ@mail.gmail.com> <2732076.1786551380@sss.pgh.pa.us> <CAA5RZ0sTr_Yt_9_qtt5PyzN-EaRnebXgWDTSgMn1H1Ak5vU-yQ@mail.gmail.com> <CAA5RZ0tf2JS4+CcHg7DzE+wSFMu8FK+CdZpT50yXhLabamkyeQ@mail.gmail.com> <207328.1786821718@sss.pgh.pa.us> <CAA5RZ0twav-cJXFT0mt-jJAjAuNz9jz=nyDM2+CpopJpTs8hEQ@mail.gmail.com> <290933.1786843091@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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