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

Commite38a55b

Browse files
committed
Rework examine_opclause_expression to use varonleft
The examine_opclause_expression function needs to return information onwhich side of the operator we found the Var, but the variable was called"isgt" which is rather misleading (it assumes the operator is eitherless-than or greater-than, but it may be equality or something else).Other places in the planner use a variable called "varonleft" for thispurpose, so just adopt the same convention here.The code also assumed we don't care about this flag for equality, as(Var = Const) and (Const = Var) should be the same thing. But that doesnot work for cross-type operators, in which case we need to pass theparameters to the procedure in the right order. So just use the samecode for all types of expressions.This means we don't need to care about the selectivity estimationfunction anymore, at least not in this code. We should only get thesupported cases here (thanks to statext_is_compatible_clause).Reviewed-by: Tom LaneDiscussion:https://postgr.es/m/8736jdhbhc.fsf%40ansel.ydns.euBackpatch-to: 12
1 parent6f40ee4 commite38a55b

File tree

3 files changed

+26
-54
lines changed

3 files changed

+26
-54
lines changed

‎src/backend/statistics/extended_stats.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,15 +1196,15 @@ statext_clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid,
11961196
* returns true, otherwise returns false.
11971197
*
11981198
* Optionally returns pointers to the extracted Var/Const nodes, when passed
1199-
* non-null pointers (varp, cstp andisgtp). Theisgt flag specifies whether
1200-
*the Var node is ontheleft (false) or right (true) side oftheoperator.
1199+
* non-null pointers (varp, cstp andvaronleftp). Thevaronleftp flag specifies
1200+
*on which side oftheoperator we foundtheVar node.
12011201
*/
12021202
bool
1203-
examine_opclause_expression(OpExpr*expr,Var**varp,Const**cstp,bool*isgtp)
1203+
examine_opclause_expression(OpExpr*expr,Var**varp,Const**cstp,bool*varonleftp)
12041204
{
12051205
Var*var;
12061206
Const*cst;
1207-
boolisgt;
1207+
boolvaronleft;
12081208
Node*leftop,
12091209
*rightop;
12101210

@@ -1225,13 +1225,13 @@ examine_opclause_expression(OpExpr *expr, Var **varp, Const **cstp, bool *isgtp)
12251225
{
12261226
var= (Var*)leftop;
12271227
cst= (Const*)rightop;
1228-
isgt=false;
1228+
varonleft=true;
12291229
}
12301230
elseif (IsA(leftop,Const)&&IsA(rightop,Var))
12311231
{
12321232
var= (Var*)rightop;
12331233
cst= (Const*)leftop;
1234-
isgt=true;
1234+
varonleft=false;
12351235
}
12361236
else
12371237
return false;
@@ -1243,8 +1243,8 @@ examine_opclause_expression(OpExpr *expr, Var **varp, Const **cstp, bool *isgtp)
12431243
if (cstp)
12441244
*cstp=cst;
12451245

1246-
if (isgtp)
1247-
*isgtp=isgt;
1246+
if (varonleftp)
1247+
*varonleftp=varonleft;
12481248

12491249
return true;
12501250
}

‎src/backend/statistics/mcv.c

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,18 +1581,15 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
15811581
OpExpr*expr= (OpExpr*)clause;
15821582
FmgrInfoopproc;
15831583

1584-
/* get procedure computing operator selectivity */
1585-
RegProcedureoprrest=get_oprrest(expr->opno);
1586-
15871584
/* valid only after examine_opclause_expression returns true */
15881585
Var*var;
15891586
Const*cst;
1590-
boolisgt;
1587+
boolvaronleft;
15911588

15921589
fmgr_info(get_opcode(expr->opno),&opproc);
15931590

15941591
/* extract the var and const from the expression */
1595-
if (examine_opclause_expression(expr,&var,&cst,&isgt))
1592+
if (examine_opclause_expression(expr,&var,&cst,&varonleft))
15961593
{
15971594
intidx;
15981595

@@ -1629,46 +1626,21 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
16291626
if (RESULT_IS_FINAL(matches[i],is_or))
16301627
continue;
16311628

1632-
switch (oprrest)
1633-
{
1634-
caseF_EQSEL:
1635-
caseF_NEQSEL:
1636-
1637-
/*
1638-
* We don't care about isgt in equality, because
1639-
* it does not matter whether it's (var op const)
1640-
* or (const op var).
1641-
*/
1642-
match=DatumGetBool(FunctionCall2Coll(&opproc,
1643-
DEFAULT_COLLATION_OID,
1644-
cst->constvalue,
1645-
item->values[idx]));
1646-
1647-
break;
1648-
1649-
caseF_SCALARLTSEL:/* column < constant */
1650-
caseF_SCALARLESEL:/* column <= constant */
1651-
caseF_SCALARGTSEL:/* column > constant */
1652-
caseF_SCALARGESEL:/* column >= constant */
1653-
1654-
/*
1655-
* First check whether the constant is below the
1656-
* lower boundary (in that case we can skip the
1657-
* bucket, because there's no overlap).
1658-
*/
1659-
if (isgt)
1660-
match=DatumGetBool(FunctionCall2Coll(&opproc,
1661-
DEFAULT_COLLATION_OID,
1662-
cst->constvalue,
1663-
item->values[idx]));
1664-
else
1665-
match=DatumGetBool(FunctionCall2Coll(&opproc,
1666-
DEFAULT_COLLATION_OID,
1667-
item->values[idx],
1668-
cst->constvalue));
1669-
1670-
break;
1671-
}
1629+
/*
1630+
* First check whether the constant is below the lower
1631+
* boundary (in that case we can skip the bucket, because
1632+
* there's no overlap).
1633+
*/
1634+
if (varonleft)
1635+
match=DatumGetBool(FunctionCall2Coll(&opproc,
1636+
DEFAULT_COLLATION_OID,
1637+
item->values[idx],
1638+
cst->constvalue));
1639+
else
1640+
match=DatumGetBool(FunctionCall2Coll(&opproc,
1641+
DEFAULT_COLLATION_OID,
1642+
cst->constvalue,
1643+
item->values[idx]));
16721644

16731645
/* update the match bitmap with the result */
16741646
matches[i]=RESULT_MERGE(matches[i],is_or,match);

‎src/include/statistics/extended_stats_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows,
9898
intnumattrs,AttrNumber*attnums);
9999

100100
externboolexamine_opclause_expression(OpExpr*expr,Var**varp,
101-
Const**cstp,bool*isgtp);
101+
Const**cstp,bool*varonleftp);
102102

103103
externSelectivitymcv_clauselist_selectivity(PlannerInfo*root,
104104
StatisticExtInfo*stat,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp