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

Commit6734182

Browse files
committed
Teach eval_const_expressions() to simplify an ArrayCoerceExpr to a constant
when its input is constant and the element coercion function is immutable(or nonexistent, ie, binary-coercible case). This is an oversight in the8.3 implementation of ArrayCoerceExpr, and its result is that certain casesinvolving IN or NOT IN with constants don't get optimized as they should be.Per experimentation with an example from Ow Mun Heng.
1 parent6741688 commit6734182

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

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

Lines changed: 36 additions & 1 deletion
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.264 2008/08/25 22:42:33 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.265 2008/08/26 02:16:31 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -2359,6 +2359,41 @@ eval_const_expressions_mutator(Node *node,
23592359
newexpr->coerceformat=expr->coerceformat;
23602360
return (Node*)newexpr;
23612361
}
2362+
if (IsA(node,ArrayCoerceExpr))
2363+
{
2364+
ArrayCoerceExpr*expr= (ArrayCoerceExpr*)node;
2365+
Expr*arg;
2366+
ArrayCoerceExpr*newexpr;
2367+
2368+
/*
2369+
* Reduce constants in the ArrayCoerceExpr's argument, then build
2370+
* a new ArrayCoerceExpr.
2371+
*/
2372+
arg= (Expr*)eval_const_expressions_mutator((Node*)expr->arg,
2373+
context);
2374+
2375+
newexpr=makeNode(ArrayCoerceExpr);
2376+
newexpr->arg=arg;
2377+
newexpr->elemfuncid=expr->elemfuncid;
2378+
newexpr->resulttype=expr->resulttype;
2379+
newexpr->resulttypmod=expr->resulttypmod;
2380+
newexpr->isExplicit=expr->isExplicit;
2381+
newexpr->coerceformat=expr->coerceformat;
2382+
2383+
/*
2384+
* If constant argument and it's a binary-coercible or immutable
2385+
* conversion, we can simplify it to a constant.
2386+
*/
2387+
if (arg&&IsA(arg,Const)&&
2388+
(!OidIsValid(newexpr->elemfuncid)||
2389+
func_volatile(newexpr->elemfuncid)==PROVOLATILE_IMMUTABLE))
2390+
return (Node*)evaluate_expr((Expr*)newexpr,
2391+
newexpr->resulttype,
2392+
newexpr->resulttypmod);
2393+
2394+
/* Else we must return the partially-simplified node */
2395+
return (Node*)newexpr;
2396+
}
23622397
if (IsA(node,CaseExpr))
23632398
{
23642399
/*----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp