SQL/JSON: Avoid initializing unnecessary ON ERROR / ON EMPTY steps
authorAmit Langote
Fri, 6 Sep 2024 03:04:29 +0000 (12:04 +0900)
committerAmit Langote
Fri, 6 Sep 2024 03:04:29 +0000 (12:04 +0900)
commite4e27976a687dd641c1c8251fad3a90a08756df8
tree336ed89bf03f0c193f9852f781996739fb8a57af
parent5067c230b8ee42a01cc77dc5745bc3a78f393af3
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