Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit930d2b4

Browse files
committed
Don't use bms_membership() in cases where we don't need to
00b4146 adjusted Bitmapset so that an empty set is always representedas NULL. This makes checking for empty sets far cheaper than it usedto be.There were various places in the code where we'd call bms_membership()to handle the 3 possible BMS_Membership values. For the BMS_SINGLETONcase, we'd also call bms_singleton_member() to find the single set member.This can now be done in a more optimal way by first checking if the set isNULL and then not bothering with bms_membership() and simply callbms_get_singleton_member() instead to find the single member. Thisfunction will return false if there are multiple members in the set.Here we also tidy up some logic in examine_variable() for the singlemember case. There's now no need to call bms_is_member() as we'vealready established that we're working with a singleton Bitmapset, so wecan just check if varRelid matches the singleton member.Reviewed-by: Richard GuoDiscussion:https://postgr.es/m/CAApHDvqW+CxNPcY245GaWiuqkkqgTudtG2ncGvvSjGn2wdTZLA@mail.gmail.com
1 parent75680c3 commit930d2b4

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

‎src/backend/optimizer/plan/initsplan.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,25 +2634,27 @@ distribute_restrictinfo_to_rels(PlannerInfo *root,
26342634
Relidsrelids=restrictinfo->required_relids;
26352635
RelOptInfo*rel;
26362636

2637-
switch (bms_membership(relids))
2637+
if (!bms_is_empty(relids))
26382638
{
2639-
caseBMS_SINGLETON:
2639+
intrelid;
26402640

2641+
if (bms_get_singleton_member(relids,&relid))
2642+
{
26412643
/*
26422644
* There is only one relation participating in the clause, so it
26432645
* is a restriction clause for that relation.
26442646
*/
2645-
rel=find_base_rel(root,bms_singleton_member(relids));
2647+
rel=find_base_rel(root,relid);
26462648

26472649
/* Add clause to rel's restriction list */
26482650
rel->baserestrictinfo=lappend(rel->baserestrictinfo,
26492651
restrictinfo);
26502652
/* Update security level info */
26512653
rel->baserestrict_min_security=Min(rel->baserestrict_min_security,
26522654
restrictinfo->security_level);
2653-
break;
2654-
caseBMS_MULTIPLE:
2655-
2655+
}
2656+
else
2657+
{
26562658
/*
26572659
* The clause is a join clause, since there is more than one rel
26582660
* in its relid set.
@@ -2675,15 +2677,15 @@ distribute_restrictinfo_to_rels(PlannerInfo *root,
26752677
* Add clause to the join lists of all the relevant relations.
26762678
*/
26772679
add_join_clause_to_rels(root,restrictinfo,relids);
2678-
break;
2679-
default:
2680-
2681-
/*
2682-
* clause references no rels, and therefore we have no place to
2683-
*attach it. Shouldn't get here if callers are working properly.
2684-
*/
2685-
elog(ERROR,"cannot cope with variable-free clause");
2686-
break;
2680+
}
2681+
}
2682+
else
2683+
{
2684+
/*
2685+
*clause references no rels, and therefore we have no place to attach
2686+
* it. Shouldn't get here if callers are working properly.
2687+
*/
2688+
elog(ERROR,"cannot cope with variable-free clause");
26872689
}
26882690
}
26892691

‎src/backend/utils/adt/selfuncs.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5028,22 +5028,27 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
50285028

50295029
onerel=NULL;
50305030

5031-
switch (bms_membership(varnos))
5031+
if (bms_is_empty(varnos))
50325032
{
5033-
caseBMS_EMPTY_SET:
5034-
/* No Vars at all ... must be pseudo-constant clause */
5035-
break;
5036-
caseBMS_SINGLETON:
5037-
if (varRelid==0||bms_is_member(varRelid,varnos))
5033+
/* No Vars at all ... must be pseudo-constant clause */
5034+
}
5035+
else
5036+
{
5037+
intrelid;
5038+
5039+
if (bms_get_singleton_member(varnos,&relid))
5040+
{
5041+
if (varRelid==0||varRelid==relid)
50385042
{
5039-
onerel=find_base_rel(root,
5040-
(varRelid ?varRelid :bms_singleton_member(varnos)));
5043+
onerel=find_base_rel(root,relid);
50415044
vardata->rel=onerel;
50425045
node=basenode;/* strip any relabeling */
50435046
}
50445047
/* else treat it as a constant */
5045-
break;
5046-
caseBMS_MULTIPLE:
5048+
}
5049+
else
5050+
{
5051+
/* varnos has multiple relids */
50475052
if (varRelid==0)
50485053
{
50495054
/* treat it as a variable of a join relation */
@@ -5058,7 +5063,7 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
50585063
/* note: no point in expressional-index search here */
50595064
}
50605065
/* else treat it as a constant */
5061-
break;
5066+
}
50625067
}
50635068

50645069
bms_free(varnos);
@@ -6381,17 +6386,14 @@ find_join_input_rel(PlannerInfo *root, Relids relids)
63816386
{
63826387
RelOptInfo*rel=NULL;
63836388

6384-
switch (bms_membership(relids))
6389+
if (!bms_is_empty(relids))
63856390
{
6386-
caseBMS_EMPTY_SET:
6387-
/* should not happen */
6388-
break;
6389-
caseBMS_SINGLETON:
6390-
rel=find_base_rel(root,bms_singleton_member(relids));
6391-
break;
6392-
caseBMS_MULTIPLE:
6391+
intrelid;
6392+
6393+
if (bms_get_singleton_member(relids,&relid))
6394+
rel=find_base_rel(root,relid);
6395+
else
63936396
rel=find_join_rel(root,relids);
6394-
break;
63956397
}
63966398

63976399
if (rel==NULL)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp