v.22.2Improvement

Reimplement _shard_num with shardNum() function to avoid issues

Reimplement _shard_num from constants (see #7624) with shardNum() function (seee #27020), to avoid possible issues (like those that had been found in #16947). #33392 (Azat Khuzhin).
Reimplemented _shard_num constant as the shardNum() function to provide a more reliable and flexible way to obtain the shard number in distributed queries.

Why it matters

The previous use of _shard_num as a constant caused potential issues in distributed queries, including incorrect shard number resolution. By replacing it with the shardNum() function, the feature addresses these problems to ensure correct shard identification and improve query stability in sharded environments.

How to use it

Replace occurrences of the _shard_num constant with the shardNum() function in your SQL queries to obtain the current shard number dynamically. For example:

SELECT shardNum() AS shard_id
FROM distributed_table
WHERE ...

No additional configuration is required.