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()
asked 2 years ago39 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions