v.24.12Improvement

Respect prefer_locahost_replica in distributed INSERT ... SELECT plans

Respect prefer_locahost_replica when building plan for distributed INSERT ... SELECT. #72190 (filimonov).
Respect prefer_localhost_replica setting when building the query plan for distributed INSERT ... SELECT operations in ClickHouse.

Why it matters

This feature ensures that when performing distributed inserts combined with select queries, the planner prioritizes executing on the local replica if prefer_localhost_replica is enabled. This improves query performance and resource utilization by reducing network overhead and data movement.

How to use it

Enable the prefer_localhost_replica setting in the session or server configuration before executing distributed INSERT ... SELECT queries. For example, set the parameter as follows:

SET prefer_localhost_replica = 1;


Then run your distributed INSERT ... SELECT query as usual.