How to drop an Existing Histogram from a ClickHouse Column?

Table of Contents

Introduction

To drop an existing histogram on a ClickHouse column and prevent the Auto Stats gathering job from creating it in the future, you can follow these steps:

  1. Connect to ClickHouse: Open a ClickHouse client or connect to the ClickHouse server using a client tool like clickhouse-client or a SQL IDE that supports ClickHouse.
  2. Check the Existing Histogram: First, check if a histogram exists on the column. You can use the DESCRIBE TABLE command to view the table schema and identify if there is a histogram associated with the column. 

For example:

DESCRIBE TABLE your_table;

Identify the column name that has the histogram.

  1. Drop the Histogram: Once you identify the column with the histogram, you can drop it using the ALTER TABLE command with the MODIFY COLUMN clause. Here’s an example of how you can drop the histogram:
ALTER TABLE your_table MODIFY COLUMN your_column CLEAR HISTOGRAM;

Replace your_table with the name of your table and your_column with the name of the column that has the histogram. The CLEAR HISTOGRAM clause removes the existing histogram on the column.

  1. Disable Auto Stats Gathering: To prevent the Auto Stats gathering job from creating the histogram again in the future, you can disable it by setting the appropriate configuration parameter. Open the ClickHouse configuration file (usually config.xml or clickhouse-server.xml) and locate the <auto_database section. Set the enabled attribute to false as shown below:
<auto_database>
<enabled>false</enabled>
<!-- Other configuration parameters -->
</auto_database>

Save the configuration file and restart the ClickHouse server for the changes to take effect. Disabling the Auto Stats gathering job ensures that histograms are not automatically created for columns in the future.

Conclusion

By following these steps, you can drop an existing histogram on a ClickHouse column and prevent the Auto Stats gathering job from creating it again in the future. Remember to exercise caution when modifying table schemas and make sure to have proper backups of your data before making any changes.

To read more about ClickHouse, do give the following a read

About Shiv Iyer 222 Articles
Open Source Database Systems Engineer with a deep understanding of Optimizer Internals, Performance Engineering, Scalability and Data SRE. Shiv currently is the Founder, Investor, Board Member and CEO of multiple Database Systems Infrastructure Operations companies in the Transaction Processing Computing and ColumnStores ecosystem. He is also a frequent speaker in open source software conferences globally.