Re: Removing unneeded self joins - Mailing list pgsql-hackers

From Zhihong Yu
Subject Re: Removing unneeded self joins
Date
Msg-id CALNJ-vTaTkeY3yc=r8MR7XuqvGUAytP=NdFTtOq-Lh1otKmhNQ@mail.gmail.com
Whole thread Raw
In response to Removing unneeded self joins  (Alexander Kuzmenkov <a.kuzmenkov@postgrespro.ru>)
List pgsql-hackers
Hi,
w.r.t. v33-0001-Remove-self-joins.patch :

removes inner join of plane table -> removes inner join of plain table
in an query plan -> in a query plan

+ * Used as the relation_has_unique_index_for,

Since relation_has_unique_index_for() becomes a wrapper of relation_has_unique_index_ext, the above sentence doesn't make much sense. I think you can drop this part.

but if extra_clauses doesn't NULL -> If extra_clauses isn't NULL

+   is_req_equal =
+       (rinfo->required_relids == rinfo->clause_relids) ? true : false;

The above can be simplified to:
  is_req_equal = rinfo->required_relids == rinfo->clause_relids;

+       ListCell *otherCell;
otherCell should be initialized to NULL.

+               if (bms_is_member(k, info->syn_lefthand) &&
+                   !bms_is_member(r, info->syn_lefthand))
+                   jinfo_check = false;
+               else if (bms_is_member(k, info->syn_righthand) &&
+                   !bms_is_member(r, info->syn_righthand))
+                   jinfo_check = false;
+               else if (bms_is_member(r, info->syn_lefthand) &&
+                   !bms_is_member(k, info->syn_lefthand))
+                   jinfo_check = false;

I think the above code can be simplified:

If bms_is_member(k, info->syn_lefthand) ^ bms_is_member(r, info->syn_lefthand) is true, jinfo_check is false.
If bms_is_member(k, info->syn_righthand) ^ bms_is_member(r, info->syn_righthand) is true, jinfo_check is false.
Otherwise jinfo_check is true.

Cheers

pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: Backends stunk in wait event IPC/MessageQueueInternal
Next
From: Andres Freund
Date:
Subject: Re: [RFC] building postgres with meson -v8