+               /* Only plain base relations are permitted */
+               if (rte->rtekind != RTE_RELATION)
+                       return false;

This will even reject simple GROUP BY (RTE_GROUP)

SELECT a.x FROM a JOIN b ... WHERE a.f=1 OR b.g=2 GROUP BY a.x

And there are probably many other interesting query features the patch
could support without problems.


I also want to point out that this can result in queries that
otherwise work on master erroring out with the patch:

CREATE TABLE item (id int PRIMARY KEY, kind text);
CREATE TABLE attr (item_id int, val text, tag int);
INSERT INTO item
  SELECT g, CASE WHEN g % 100 = 0 THEN 'txt' ELSE 'num' END
  FROM generate_series(1, 100000) g;
INSERT INTO attr
  SELECT g, CASE WHEN g % 100 = 0 THEN 'abc' ELSE (g % 500)::text END,
         CASE WHEN g % 100 = 0 THEN 7 ELSE g % 1000 END
  FROM generate_series(1, 100000) g;
CREATE INDEX ON item (kind);
CREATE INDEX ON attr (tag);
ANALYZE item, attr;

SELECT count(*) FROM item i JOIN attr a ON a.item_id = i.id
WHERE i.kind = 'txt' OR (a.val::int = 7 AND a.tag = 7);

Every 'txt' item in this database fails the right side of the OR, but
because the left side is true, the right side is never evaluated.
The evaluation order isn't guaranteed in this case, the documentation
explicitly tells people not to do this. So in that sense, breaking it
isn't wrong, but it is still a noticeable behavior change.


Reply via email to