SET CONSTANT_FOLDING

SET CONSTANT_FOLDING#

Controls whether Querona evaluates constant expressions once, during query typing, instead of repeatedly at run time. When ON (the default), constant sub-expressions are folded to their value during the baseline and provider typing phases of preprocessing. When OFF, folding is skipped.

Tip

This is an advanced, diagnostics-oriented option, on by default. It affects only how a query is prepared, not its results.

Syntax#

SET CONSTANT_FOLDING { ON | OFF }  [;]

Remarks#

Constant folding simplifies the query tree before execution — for example, reducing a constant arithmetic expression to a single value — so the work is not repeated for every row. The default is ON.

An explicit CAST or CONVERT of a constant to varchar(max), nvarchar(max) or varbinary(max) is not folded, so the expression keeps its max type wherever it runs, including in the SQL that Querona sends to a data source. A folded value would be typed by its length, and functions such as REPLICATE, REPLACE and STUFF truncate a result that is not of a max type to 8000 bytes.

Permissions#

Requires membership in the public role.

Examples#

SET CONSTANT_FOLDING OFF;

See Also#