NOPARAM

Disables the parameterization of constants in a query before a query plan is compiled.

Syntax

NOPARAM (expression)

Arguments

  • expression: any expression. This may be a constant (most common), column name, the result of another function, or a math operation.

Remarks

  • When NOPARAM is used, the constants in a query are not converted into parameters. So, a separate query plan is generated even for the queries with the same structure.

  • Parameterization can only be disabled for constants in a query.

Examples

Example 1: Let us look at few queries and their query plans when NOPARAM function is used. A query plan can be viewed in the QUERY_TEXT field of the information_schema.PLANCACHE table.

For example, the following two queries with different parameter values,

SELECT * from t WHERE x = 5;
SELECT * from t WHERE x = 30;

use the same query plan:

QUERY_TEXT: SELECT * from t WHERE x = @

Whereas, when the constants in these queries are enclosed in NOPARAM, a separate plan is generated for each query. For example, for the following queries,

SELECT * from t WHERE x = NOPARAM(5);
SELECT * from t WHERE x = NOPARAM(30);

different query plans are generated:

QUERY_TEXT: SELECT * from t WHERE x = NOPARAM(5)
QUERY_TEXT: SELECT * from t WHERE x = NOPARAM(30)

Example 2: Let us look at an example where NOPARAM is used for variable offsets. Consider a table orders with two fields orderid and orderdate.

The following queries with different parameter values generate the same query plan, which can be viewed in the QUERY_TEXT field of the information_schema.PLANCACHE table.

SELECT COUNT(orderid) FROM orders WHERE orderdate <= DATE_ADD(CURRENT_DATE(), INTERVAL -30 DAY);
SELECT COUNT(orderid) FROM orders WHERE orderdate <= DATE_ADD(CURRENT_DATE(), INTERVAL -20 DAY);
QUERY_TEXT: SELECT COUNT(orderid) FROM orders WHERE orderdate <= DATE_ADD(CURRENT_DATE(), INTERVAL @ DAY)

Whereas when NOPARAM function is used for the same queries,

SELECT COUNT(orderid) FROM orders WHERE orderdate <= NOPARAM(DATE_ADD(CURRENT_DATE(), INTERVAL -30 DAY));
SELECT COUNT(orderid) FROM orders WHERE orderdate <= NOPARAM(DATE_ADD(CURRENT_DATE(), INTERVAL -20 DAY));

different query plans are generated:

QUERY_TEXT: SELECT COUNT(orderid) FROM orders WHERE orderdate <= NOPARAM(DATE_ADD(CURRENT_DATE(), INTERVAL -30 DAY))
QUERY_TEXT: SELECT COUNT(orderid) FROM orders WHERE orderdate <= NOPARAM(DATE_ADD(CURRENT_DATE(), INTERVAL -20 DAY))

Other examples of NOPARAM function usage:

INSERT INTO t(a) VALUES (NOPARAM(20));
SELECT NOPARAM(x) + NOPARAM(SUM(x)) FROM t;

Last modified: February 23, 2023

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK