Overview
Dynamic parameters work in a similar way as PrepareStatement in databases. You can use question marks (?) as placeholders in an SQL statement to specify dynamic parameters. The engine automatically replaces the placeholders with the values of dynamic parameters.
Dynamic parameters are mainly used to improve the hit rate of cache. If you use dynamic parameters in the SQL statements that are based on the same template, query performance is increased.
You can use dynamic parameters to replace only values. You cannot use dynamic parameters to replace keywords or fields.
Examples
Example 1
SELECT i1, cast(? as bigint) FROM t1 WHERE (i2 > 5 AND d3 < 10.1) OR s5 = ?
The following sample code shows how to specify dynamic parameters:
dynamic_params:[[10, "str5"]]
Example 2
SELECT
price,
title,
compute(
longitude,
latitude,
city_id,
CAST(? AS double),
CAST(? AS double),
CAST(1 AS bigint)
) AS distance
FROM
store,
unnest(store.sub_table)
WHERE
MATCHINDEX('shop', ?)
AND QUERY(name, ?)
dynamic_params:[[119.98844256998,
36.776817017143,
"excellect",
"fruit OR watermelon"]]