Re: Pull up sublink of type 'NOT NOT (expr)' - Mailing list pgsql-hackers

From Alexey Bashtanov
Subject Re: Pull up sublink of type 'NOT NOT (expr)'
Date
Msg-id 6c5f1271-b443-c616-8cf8-e7de024dab70@imap.cc
Whole thread Raw
In response to Pull up sublink of type 'NOT NOT (expr)'  (Richard Guo <riguo@pivotal.io>)
Responses Re: Pull up sublink of type 'NOT NOT (expr)'  (Richard Guo <riguo@pivotal.io>)
List pgsql-hackers
Hello Richard,

Currently for quals in the form of "NOT NOT (SubLink)", this SubLink would not
be considered when pulling up sublinks. For instance:

gpadmin=# explain select * from a where NOT NOT (a.i in (select b.i from b));
                         QUERY PLAN
-------------------------------------------------------------
 Seq Scan on a  (cost=51.50..85.62 rows=1005 width=8)
   Filter: (hashed SubPlan 1)
   SubPlan 1
     ->  Seq Scan on b  (cost=0.00..44.00 rows=3000 width=4)
(4 rows)


Should we give it a chance, like the attached does?

Sometimes hashed subplan is faster than hash join and than all the other options, as it preserves the order.
Using NOT NOT, one can control whether to use it or not:
https://pgblog.bashtanov.com/2017/12/08/double-negative-and-query-performance/ (test case and results in the bottom of the page).

Surely dirty tricks should not be the way to control the planner, but when breaking them we should probably provide a way to achieve the same result,
ideally making the planner choose the best plan without hints.

Best,
  Alex

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Buildfarm failures for hash indexes: buffer leaks
Next
From: "Vaidyanathaswamy, Anandsaikrishnan"
Date:
Subject: Postgres older version 8.3.7 on ubuntu 14