v.22.2Improvement
Reimplement _shard_num with shardNum() function to avoid issues
Reimplement_shard_numfrom constants (see #7624) withshardNum()function (seee #27020), to avoid possible issues (like those that had been found in #16947). #33392 (Azat Khuzhin).
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.