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

Commite04a390

Browse files
committed
Improve planner's understanding of strictness of type coercions.
PG type coercions are generally strict, ie a NULL input must producea NULL output (or, in domain cases, possibly an error). The planner'sunderstanding of that was a bit incomplete though, so improve it:* Teach contain_nonstrict_functions() that CoerceViaIO can always beconsidered strict. Previously it believed that only if the underlyingI/O functions were marked strict, which is often but not always true.* Teach clause_is_strict_for() that CoerceViaIO, ArrayCoerceExpr,ConvertRowtypeExpr, CoerceToDomain can all be considered strict.Previously it knew nothing about any of them.The main user-visible impact of this is that IS NOT NULL predicatescan be proven to hold from expressions involving casts in more casesthan before, allowing partial indexes with such predicates to be usedwithout extra pushups. This reduces the surprise factor for users,who may well be used to ordinary (function-call-based) casts beingknown to be strict.Per a gripe from Samuel Williams. This doesn't rise to the level ofa bug, IMO, so no back-patch.Discussion:https://postgr.es/m/27571.1550617881@sss.pgh.pa.us
1 parent1571bc0 commite04a390

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,16 @@ contain_nonstrict_functions_walker(Node *node, void *context)
11721172
return true;
11731173
if (IsA(node,FieldStore))
11741174
return true;
1175+
if (IsA(node,CoerceViaIO))
1176+
{
1177+
/*
1178+
* CoerceViaIO is strict regardless of whether the I/O functions are,
1179+
* so just go look at its argument; asking check_functions_in_node is
1180+
* useless expense and could deliver the wrong answer.
1181+
*/
1182+
returncontain_nonstrict_functions_walker((Node*) ((CoerceViaIO*)node)->arg,
1183+
context);
1184+
}
11751185
if (IsA(node,ArrayCoerceExpr))
11761186
{
11771187
/*

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,27 @@ clause_is_strict_for(Node *clause, Node *subexpr)
13521352
return false;
13531353
}
13541354

1355+
/*
1356+
* CoerceViaIO is strict (whether or not the I/O functions it calls are).
1357+
* Likewise, ArrayCoerceExpr is strict for its array argument (regardless
1358+
* of what the per-element expression is), ConvertRowtypeExpr is strict at
1359+
* the row level, and CoerceToDomain is strict too. These are worth
1360+
* checking mainly because it saves us having to explain to users why some
1361+
* type coercions are known strict and others aren't.
1362+
*/
1363+
if (IsA(clause,CoerceViaIO))
1364+
returnclause_is_strict_for((Node*) ((CoerceViaIO*)clause)->arg,
1365+
subexpr);
1366+
if (IsA(clause,ArrayCoerceExpr))
1367+
returnclause_is_strict_for((Node*) ((ArrayCoerceExpr*)clause)->arg,
1368+
subexpr);
1369+
if (IsA(clause,ConvertRowtypeExpr))
1370+
returnclause_is_strict_for((Node*) ((ConvertRowtypeExpr*)clause)->arg,
1371+
subexpr);
1372+
if (IsA(clause,CoerceToDomain))
1373+
returnclause_is_strict_for((Node*) ((CoerceToDomain*)clause)->arg,
1374+
subexpr);
1375+
13551376
return false;
13561377
}
13571378

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp