Controlling literal parameterization

Adaptive Server version 15.0.1 and later allow you to automatically convert literal values in SQL queries to parameter descriptions (similar to variables).

To enable or disable enable literal autoparam server-wide, use:

sp_configure "enable literal autoparam", [0 | 1]

Where 1 automatically converts literal values to parameter descriptions, and 0 (the default) disables the feature.

Set literal parameterization at the session level using:

set literal_autoparam [off | on]

In versions of Adaptive Server earlier than 15.0.1, two queries that were identical except for one or more literal values resulted in the statement cache storing two separate query plans, or two additional rows, in sysqueryplans. For example, the query plans for these queries were stored separately, even though they are almost identical:

select count(*) from titles where total_sales > 100
select count(*) from titles where total_sales > 200

Examples

If you enable automatic literal parameterization, the SQL text of the select count(*) example referred to above is converted to:

select count(*) from titles where total_sales > @@@V0_INT

Where @@@V0_INT is an internally generated name for the parameter that represents the literal values 100 and 200.

All instances of literal values in the SQL text are replaced by internally generated parameters. For example:

select substring(name, 3, 4) from sysobjects where name in 
    ('systypes', 'syscolumns') 

is transformed to:

select substring(name, 3, 4) from sysobjects where name in
    (@@@V0_VCHAR1,@@@V1_VCHAR1)

Any combination of values that replace the literals, 3, 4, systypes and syscolumns is transformed to the same SQL text with the same parameters and shares the same query plan when you enable the statement cache.

Automatic literal parameterization:

Usage issues for automatic literal parameterization include: