Analyze compression and Advisor give different suggestions

0

Hi, I read about ANALYZE COMPRESSION and made this script to analyze and set the recommended compression for all tables, the idea is to run it at night once per month or every 15 days.

I set 3M rows to analyze because there are Tb size tables, so, it seems better than the default 500K.

Something that happened during the last test run is that it set many fields to zstd, and 1/2 days after, Redshift started recommending az64 and bytedict for some of those fields, am I misunderstanding something about how this work? why does the Redshift advisor recommend different settings than analyze compression? Thanks!

[...import...set connection...]
df_tables = pd.read_sql_query('SELECT "table",schema, size, tbl_rows FROM SVV_TABLE_INFO order by size desc',con=con)

for index, row in df_tables.iterrows():
    print(row['schema']+"."+row['table']+" - size: "+str(row['size']))
    df = pd.read_sql_query("ANALYZE COMPRESSION "+ row['schema']+"."+row['table'] + " COMPROWS 3000000", con=con)
    df = df[df.Est_reduction_pct.astype(float) > 9]
    for index2, row2 in df.iterrows():
        try:
            a= "alter table " + row['schema']+"."+row['table'] + " ALTER COLUMN "+ row2['Column'] +" ENCODE " + row2['Encoding'] +";"
            print(a)
            cursor.execute(a)
        except Exception as e:
             print(e)
             con.commit()
已提問 2 年前檢視次數 39 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南