In a data warehouse database, you need to carefully choose distribution columns for large tables, because they can affect your database and query performance. If an improper distribution key is used, data skew may occur after data is imported. As a result, the usage of some disks will be much higher than that of other disks, and the cluster may even become read-only. If the hash distribution policy is used and data skew occurs, the I/O performance of some DNs will be poor, affecting the overall query performance. Proper selection and adjustment of distribution columns are critical to table query performance.
If the hash distribution policy is used, you need to check tables to ensure their data is evenly distributed on each DN. Generally, over 5% difference between the amount of data on different DNs is regarded as data skew. If the difference is over 10%, you have to choose another distribution column.
For tables that are not evenly distributed, adjust their distribution columns to reduce data skew and avoid database performance problems.
The distribution column in a hash table must meet the following requirements, which are ranked by priority in descending order:
Run the select version(); statement to query the current database version. Required performance varies according to the version.

In the following statements, table1 is the original table name and table1_new is the new table name. column1 and column2 are distribution column names.
1 2 3 4 | CREATE TABLE IF NOT EXISTS table1_new ( LIKE table1 INCLUDING ALL EXCLUDING DISTRIBUTION) DISTRIBUTE BY HASH (column1, column2); |
1 2 3 4 | START TRANSACTION; LOCK TABLE table1 IN ACCESS EXCLUSIVE MODE; INSERT INTO table1_new SELECT * FROM table1; COMMIT; |
1 2 | SELECT COUNT(*) FROM table1_new; DROP TABLE table1; |
1 | ALTER TABLE table1_new RENAME TO table1; |
1 | SELECT pg_get_tabledef('customer_t1'); |

1 | UPDATE customer_t1 SET c_last_name = 'Jimy' WHERE c_customer_sk = 6885; |

1 | ALTER TABLE customer_t1 DISTRIBUTE BY hash (c_customer_sk); |

1 | UPDATE customer_t1 SET c_last_name = 'Jimy' WHERE c_customer_sk = 6885; |
