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

Commit04226b6

Browse files
committed
Tweak planner so that index expressions and predicates are matched to
queries without regard to whether coercions are stated explicitly orimplicitly. Per suggestion from Stephan Szabo.
1 parente1d08fa commit04226b6

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

‎src/backend/nodes/equalfuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.216 2004/03/11 01:47:35 ishii Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.217 2004/03/14 23:41:26 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -231,7 +231,7 @@ _equalFuncExpr(FuncExpr *a, FuncExpr *b)
231231
COMPARE_SCALAR_FIELD(funcretset);
232232

233233
/*
234-
* Special-case COERCE_DONTCARE, so thatpathkeys can build coercion
234+
* Special-case COERCE_DONTCARE, so thatplanner can build coercion
235235
* nodes that are equal() to both explicit and implicit coercions.
236236
*/
237237
if (a->funcformat!=b->funcformat&&
@@ -372,7 +372,7 @@ _equalRelabelType(RelabelType *a, RelabelType *b)
372372
COMPARE_SCALAR_FIELD(resulttypmod);
373373

374374
/*
375-
* Special-case COERCE_DONTCARE, so thatpathkeys can build coercion
375+
* Special-case COERCE_DONTCARE, so thatplanner can build coercion
376376
* nodes that are equal() to both explicit and implicit coercions.
377377
*/
378378
if (a->relabelformat!=b->relabelformat&&
@@ -472,7 +472,7 @@ _equalCoerceToDomain(CoerceToDomain *a, CoerceToDomain *b)
472472
COMPARE_SCALAR_FIELD(resulttypmod);
473473

474474
/*
475-
* Special-case COERCE_DONTCARE, so thatpathkeys can build coercion
475+
* Special-case COERCE_DONTCARE, so thatplanner can build coercion
476476
* nodes that are equal() to both explicit and implicit coercions.
477477
*/
478478
if (a->coercionformat!=b->coercionformat&&

‎src/backend/optimizer/util/clauses.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.163 2004/01/28 00:05:04 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.164 2004/03/14 23:41:27 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -60,6 +60,7 @@ static bool contain_subplans_walker(Node *node, void *context);
6060
staticboolcontain_mutable_functions_walker(Node*node,void*context);
6161
staticboolcontain_volatile_functions_walker(Node*node,void*context);
6262
staticboolcontain_nonstrict_functions_walker(Node*node,void*context);
63+
staticboolset_coercionform_dontcare_walker(Node*node,void*context);
6364
staticNode*eval_const_expressions_mutator(Node*node,List*active_fns);
6465
staticList*simplify_or_arguments(List*args,
6566
bool*haveNull,bool*forceTrue);
@@ -1002,6 +1003,39 @@ CommuteClause(OpExpr *clause)
10021003
lsecond(clause->args)=temp;
10031004
}
10041005

1006+
/*
1007+
* set_coercionform_dontcare: set all CoercionForm fields to COERCE_DONTCARE
1008+
*
1009+
* This is used to make index expressions and index predicates more easily
1010+
* comparable to clauses of queries. CoercionForm is not semantically
1011+
* significant (for cases where it does matter, the significant info is
1012+
* coded into the coercion function arguments) so we can ignore it during
1013+
* comparisons. Thus, for example, an index on "foo::int4" can match an
1014+
* implicit coercion to int4.
1015+
*
1016+
* Caution: the passed expression tree is modified in-place.
1017+
*/
1018+
void
1019+
set_coercionform_dontcare(Node*node)
1020+
{
1021+
(void)set_coercionform_dontcare_walker(node,NULL);
1022+
}
1023+
1024+
staticbool
1025+
set_coercionform_dontcare_walker(Node*node,void*context)
1026+
{
1027+
if (node==NULL)
1028+
return false;
1029+
if (IsA(node,FuncExpr))
1030+
((FuncExpr*)node)->funcformat=COERCE_DONTCARE;
1031+
if (IsA(node,RelabelType))
1032+
((RelabelType*)node)->relabelformat=COERCE_DONTCARE;
1033+
if (IsA(node,CoerceToDomain))
1034+
((CoerceToDomain*)node)->coercionformat=COERCE_DONTCARE;
1035+
returnexpression_tree_walker(node,set_coercionform_dontcare_walker,
1036+
context);
1037+
}
1038+
10051039

10061040
/*--------------------
10071041
* eval_const_expressions
@@ -1766,7 +1800,7 @@ evaluate_function(Oid funcid, Oid result_type, List *args,
17661800
newexpr->funcid=funcid;
17671801
newexpr->funcresulttype=result_type;
17681802
newexpr->funcretset= false;
1769-
newexpr->funcformat=COERCE_EXPLICIT_CALL;/* doesn't matter */
1803+
newexpr->funcformat=COERCE_DONTCARE;/* doesn't matter */
17701804
newexpr->args=args;
17711805

17721806
returnevaluate_expr((Expr*)newexpr,result_type);

‎src/backend/utils/cache/relcache.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.198 2004/02/25 19:41:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.199 2004/03/14 23:41:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2687,6 +2687,12 @@ RelationGetIndexExpressions(Relation relation)
26872687

26882688
result= (List*)eval_const_expressions((Node*)result);
26892689

2690+
/*
2691+
* Also mark any coercion format fields as "don't care", so that the
2692+
* planner can match to both explicit and implicit coercions.
2693+
*/
2694+
set_coercionform_dontcare((Node*)result);
2695+
26902696
/* May as well fix opfuncids too */
26912697
fix_opfuncids((Node*)result);
26922698

@@ -2755,6 +2761,12 @@ RelationGetIndexPredicate(Relation relation)
27552761

27562762
result= (List*)eval_const_expressions((Node*)result);
27572763

2764+
/*
2765+
* Also mark any coercion format fields as "don't care", so that the
2766+
* planner can match to both explicit and implicit coercions.
2767+
*/
2768+
set_coercionform_dontcare((Node*)result);
2769+
27582770
/* Also convert to implicit-AND format */
27592771
result=make_ands_implicit((Expr*)result);
27602772

‎src/include/nodes/primnodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.94 2004/01/07 18:43:36 neilc Exp $
13+
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.95 2004/03/14 23:41:27 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -307,7 +307,7 @@ typedef enum CoercionForm
307307
COERCE_EXPLICIT_CALL,/* display as a function call */
308308
COERCE_EXPLICIT_CAST,/* display as an explicit cast */
309309
COERCE_IMPLICIT_CAST,/* implicit cast, so hide it */
310-
COERCE_DONTCARE/* special case forpathkeys */
310+
COERCE_DONTCARE/* special case forplanner */
311311
}CoercionForm;
312312

313313
/*

‎src/include/optimizer/clauses.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/optimizer/clauses.h,v 1.72 2004/01/05 18:04:39 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/optimizer/clauses.h,v 1.73 2004/03/14 23:41:27 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -63,6 +63,8 @@ extern bool has_distinct_on_clause(Query *query);
6363
externintNumRelids(Node*clause);
6464
externvoidCommuteClause(OpExpr*clause);
6565

66+
externvoidset_coercionform_dontcare(Node*node);
67+
6668
externNode*eval_const_expressions(Node*node);
6769

6870
externboolexpression_tree_walker(Node*node,bool (*walker) (),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp