Literal parameterization

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

Adaptive Server version 15.0.1 allows you to automatically convert literal values in SQL queries to parameter descriptions (similar to variables). An sp_configure option supports this feature, which is called enable literal autoparam.

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

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

Where 1 automatically converts literals to parameters, and 0 disables the feature. The default is 0.

You can set literal parameterization at the session level with the set command:

set literal_autoparam [off | on]

Examples

If you enable literal auto parameterization, the SQL text of the earlier select count(*) example queries 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 (@@@V0_VARCHAR, @@@V1_VARCHAR)

is transformed to:

select substring (name, 3, 4) from sysobjects where name in (@@@V0_VARCHAR, @@@V1_VARCHAR)

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

Literal auto parameterization:

Usage issues for literal auto parameterization include: