diff --git a/docs/en/sql-reference/functions/string-functions.md b/docs/en/sql-reference/functions/string-functions.md index 8ed3b073fa8b9c82d81d5569217fac7b6b305bd5..045b3cd1520998fb80fb03cb337a04cac4042ff0 100644 --- a/docs/en/sql-reference/functions/string-functions.md +++ b/docs/en/sql-reference/functions/string-functions.md @@ -487,4 +487,75 @@ Returns the CRC64 checksum of a string, using CRC-64-ECMA polynomial. The result type is UInt64. +## normalizeQuery {#normalized-query} + +Replaces literals, sequences of literals and complex aliases with placeholders. + +**Syntax** +``` sql +normalizeQuery(x) +``` + +**Parameters** + +- `x` — Sequence of characters. [String](../../sql-reference/data-types/string.md). + +**Returned value(s)** + +- Sequence of characters with placeholders. + +Type: [String](../../sql-reference/data-types/string.md). + +**Example** + +Query: + +``` sql +SELECT normalizeQuery('[1, 2, 3, x]') AS query; +``` + +Result: + +``` text +┌─query────┐ +│ [?.., x] │ +└──────────┘ +``` + +## normalizedQueryHash {#normalized-query-hash} + +Returns identical 64bit hash values without the values of literals for similar queries. It helps to analyze query log. + +**Syntax** + +``` sql +normalizedQueryHash(x) +``` + +**Parameters** + +- `x` — Sequence of characters. [String](../../sql-reference/data-types/string.md). + +**Returned value** + +- Hash value. + +Type: [UInt64](../../sql-reference/data-types/int-uint.md#uint-ranges). + +**Example** + +Query: + +``` sql +SELECT normalizedQueryHash('SELECT 1 AS `xyz`') != normalizedQueryHash('SELECT 1 AS `abc`') AS res; +``` + +Result: + +``` text +┌─res─┐ +│ 1 │ +└─────┘ +``` + [Original article](https://clickhouse.tech/docs/en/query_language/functions/string_functions/) diff --git a/docs/en/sql-reference/functions/url-functions.md b/docs/en/sql-reference/functions/url-functions.md index a76912d90480787b960cc29fa3d540fa78f5a445..fe072531aa460db4c21b36e8ecab8bca3750671d 100644 --- a/docs/en/sql-reference/functions/url-functions.md +++ b/docs/en/sql-reference/functions/url-functions.md @@ -248,86 +248,75 @@ Removes the ‘name’ URL parameter, if present. This function works under the Replaces literals, sequences of literals and complex aliases with placeholders. -**Syntax** (without SELECT) - +**Syntax** ``` sql - +normalizeQuery(x) ``` +!!! note "Note" +SELECT count(*) FROM table WHERE date = '2020-01-02' AND id IN (1, 2, 3) LIMIT 10, 10 +should be replaced to +SELECT count(*) FROM table WHERE date = ? AND id IN (?) LIMIT ? -Alias: ``. (Optional) - -More text (Optional). - -**Parameters** (Optional) +**Parameters** -- `x` — Description. [Type name](relative/path/to/type/dscr.md#type). -- `y` — Description. [Type name](relative/path/to/type/dscr.md#type). +- `x` — Sequence of characters. [String](../../sql-reference/data-types/string.md). **Returned value(s)** -- Returned values list. +- Sequence of characters with placeholders. -Type: [Type](relative/path/to/type/dscr.md#type). +Type: [String](../../sql-reference/data-types/string.md). **Example** -SELECT count(*) FROM table WHERE date = '2020-01-02' AND id IN (1, 2, 3) LIMIT 10, 10 -should be replaced to -SELECT count(*) FROM table WHERE date = ? AND id IN (?) LIMIT ? - Query: ``` sql +SELECT normalizeQuery('[1, 2, 3, x]') AS query; ``` Result: ``` text +┌─query────┐ +│ [?.., x] │ +└──────────┘ ``` ## normalizedQueryHash {#normalized-query-hash} -Returns identical 64bit hash values for similar queries. It helps to analyze query log. -calculate a hash of query structure without the values of literals. +Returns identical 64bit hash values without the values of literals for similar queries. It helps to analyze query log. -**Syntax** (without SELECT) +**Syntax** ``` sql - +normalizedQueryHash(x) ``` -Alias: ``. (Optional) +**Parameters** -More text (Optional). +- `x` — Sequence of characters. [String](../../sql-reference/data-types/string.md). -**Parameters** (Optional) - -- `x` — Description. [Type name](relative/path/to/type/dscr.md#type). -- `y` — Description. [Type name](relative/path/to/type/dscr.md#type). - -**Returned value(s)** +**Returned value** -- Returned values list. +- Hash value. -Type: [Type](relative/path/to/type/dscr.md#type). +Type: [UInt64](../../sql-reference/data-types/int-uint.md#uint-ranges). **Example** -The example must show usage and/or a use cases. The following text contains recommended parts of an example. - -Input table (Optional): - -``` text -``` - Query: ``` sql +SELECT normalizedQueryHash('SELECT 1 AS `xyz`') != normalizedQueryHash('SELECT 1 AS `abc`') AS res; ``` Result: ``` text +┌─res─┐ +│ 1 │ +└─────┘ ``` [Original article](https://clickhouse.tech/docs/en/query_language/functions/url_functions/)