SQL/JSON: Avoid initializing unnecessary ON ERROR / ON EMPTY steps
authorAmit Langote
Mon, 9 Sep 2024 02:55:38 +0000 (11:55 +0900)
committerAmit Langote
Mon, 9 Sep 2024 06:59:06 +0000 (15:59 +0900)
commit77aebe9a8d3cccd4c54b43be87a38f2bae614c76
tree4f8c492c61f8457d9e9657b67c6bbb62e8694c7a
parentcd6b2ae3e7f64c881cb0159a2f9fc8d475e06d82
SQL/JSON: Avoid initializing unnecessary ON ERROR / ON EMPTY steps

When the ON ERROR / ON EMPTY behavior is to return NULL, returning
NULL directly from ExecEvalJsonExprPath() suffices. Therefore, there's
no need to create separate steps to check the error/empty flag or
those to evaluate the the constant NULL expression.  This speeds up
common cases because the default ON ERROR / ON EMPTY behavior for
JSON_QUERY() and JSON_VALUE() is to return NULL.  However, these steps
are necessary if the RETURNING type is a domain, as constraints on the
domain may need to be checked.

Reported-by: Jian He
Author: Jian He 
Author: Amit Langote 
Discussion: https://postgr.es/m/CACJufxEo4sUjKCYtda0_qt9tazqqKPmF1cqhW9KBOUeJFqQd2g@mail.gmail.com
Backpatch-through: 17
src/backend/executor/execExpr.c
src/backend/executor/execExprInterp.c