Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1d286d

Browse files
committed
Revert: Remove useless self-joins
This commit reverts d3d55ce and subsequent fixes 2b26a69, 93c85db, b44a170, b7f315c, 8a8ed91, b5fb673, 0a93f80, e047783, a7928a5, 5ef34a8, 30b4955, 8c441c0, 028b154, fe09399, 489072a, and 466979e. We are quite late in the release cycle and new bugs continue to appear. Even though we have fixes for all known bugs, there is a risk of throwing many bugs to end users. The plan for self-join elimination would be to do more review and testing, then re-commit in the early v18 cycle. Reported-by: Tom Lane Discussion: https://postgr.es/m/2422119.1714691974%40sss.pgh.pa.us
1 parent 81b2252 commit d1d286d

File tree

14 files changed

+69
-2883
lines changed

14 files changed

+69
-2883
lines changed

doc/src/sgml/config.sgml

-16
Original file line numberDiff line numberDiff line change
@@ -5586,22 +5586,6 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
55865586
</listitem>
55875587
</varlistentry>
55885588

5589-
<varlistentry id="guc-enable_self_join_removal" xreflabel="enable_self_join_removal">
5590-
<term><varname>enable_self_join_removal</varname> (<type>boolean</type>)
5591-
<indexterm>
5592-
<primary><varname>enable_self_join_removal</varname> configuration parameter</primary>
5593-
</indexterm>
5594-
</term>
5595-
<listitem>
5596-
<para>
5597-
Enables or disables the query planner's optimization which analyses
5598-
the query tree and replaces self joins with semantically equivalent
5599-
single scans. Takes into consideration only plain tables.
5600-
The default is <literal>on</literal>.
5601-
</para>
5602-
</listitem>
5603-
</varlistentry>
5604-
56055589
<varlistentry id="guc-enable-seqscan" xreflabel="enable_seqscan">
56065590
<term><varname>enable_seqscan</varname> (<type>boolean</type>)
56075591
<indexterm>

src/backend/optimizer/path/indxpath.c

-39
Original file line numberDiff line numberDiff line change
@@ -3440,22 +3440,6 @@ bool
34403440
relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel,
34413441
List *restrictlist,
34423442
List *exprlist, List *oprlist)
3443-
{
3444-
return relation_has_unique_index_ext(root, rel, restrictlist,
3445-
exprlist, oprlist, NULL);
3446-
}
3447-
3448-
/*
3449-
* relation_has_unique_index_ext
3450-
* Same as relation_has_unique_index_for(), but supports extra_clauses
3451-
* parameter. If extra_clauses isn't NULL, return baserestrictinfo clauses
3452-
* which were used to derive uniqueness.
3453-
*/
3454-
bool
3455-
relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
3456-
List *restrictlist,
3457-
List *exprlist, List *oprlist,
3458-
List **extra_clauses)
34593443
{
34603444
ListCell *ic;
34613445

@@ -3511,7 +3495,6 @@ relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
35113495
{
35123496
IndexOptInfo *ind = (IndexOptInfo *) lfirst(ic);
35133497
int c;
3514-
List *exprs = NIL;
35153498

35163499
/*
35173500
* If the index is not unique, or not immediately enforced, or if it's
@@ -3563,24 +3546,6 @@ relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
35633546
if (match_index_to_operand(rexpr, c, ind))
35643547
{
35653548
matched = true; /* column is unique */
3566-
3567-
if (bms_membership(rinfo->clause_relids) == BMS_SINGLETON)
3568-
{
3569-
MemoryContext oldMemCtx =
3570-
MemoryContextSwitchTo(root->planner_cxt);
3571-
3572-
/*
3573-
* Add filter clause into a list allowing caller to
3574-
* know if uniqueness have made not only by join
3575-
* clauses.
3576-
*/
3577-
Assert(bms_is_empty(rinfo->left_relids) ||
3578-
bms_is_empty(rinfo->right_relids));
3579-
if (extra_clauses)
3580-
exprs = lappend(exprs, rinfo);
3581-
MemoryContextSwitchTo(oldMemCtx);
3582-
}
3583-
35843549
break;
35853550
}
35863551
}
@@ -3623,11 +3588,7 @@ relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
36233588

36243589
/* Matched all key columns of this index? */
36253590
if (c == ind->nkeycolumns)
3626-
{
3627-
if (extra_clauses)
3628-
*extra_clauses = exprs;
36293591
return true;
3630-
}
36313592
}
36323593

36333594
return false;

0 commit comments

Comments
 (0)