本文共 6901 字,大约阅读时间需要 23 分钟。
1 ANALYZE TABLE table_name COMPUTE STATISTICS
上面的 SQL 语句可以收集表级的统计信息,例如记录数、表大小(单位是byte)。这里需要注意的是ANALYZE, COMPUTE, and STATISTICS都是保留的关键字,他们已特定的列名为入参,在metastore中保存表级的统计信息。
1 ANALYZE TABLE table_name COMPUTE STATISTICS FOR COLUMNS column-name1, column-name2, ….
需要注意的是在ANALYZE 语句中没必要指定表的每个列-只要指定那些在过滤/join条件或group by等中涉及的列
1 SELECT 2 i_item_id, 3 i_item_desc, 4 s_store_id, 5 s_store_name, 6 sum(ss_net_profit) AS store_sales_profit, 7 sum(sr_net_loss) AS store_returns_loss, 8 sum(cs_net_profit) AS catalog_sales_profit 9 FROM10 store_sales, store_returns, catalog_sales, date_dim d1, date_dim d2, date_dim d3,11 store, item12 WHERE13 d1.d_moy = 414 AND d1.d_year = 200115 AND d1.d_date_sk = ss_sold_date_sk16 AND i_item_sk = ss_item_sk17 AND s_store_sk = ss_store_sk18 AND ss_customer_sk = sr_customer_sk19 AND ss_item_sk = sr_item_sk20 AND ss_ticket_number = sr_ticket_number21 AND sr_returned_date_sk = d2.d_date_sk22 AND d2.d_moy BETWEEN 4 AND 1023 AND d2.d_year = 200124 AND sr_customer_sk = cs_bill_customer_sk25 AND sr_item_sk = cs_item_sk26 AND cs_sold_date_sk = d3.d_date_sk27 AND d3.d_moy BETWEEN 4 AND 1028 AND d3.d_year = 200129 GROUP BY30 i_item_id, i_item_desc, s_store_id, s_store_name31 ORDER BY32 i_item_id, i_item_desc, s_store_id, s_store_name33 LIMIT 100
转载自
英文博客地址
本文转自shishanyuan博客园博客,原文链接: http://www.cnblogs.com/shishanyuan/p/8453587.html ,如需转载请自行联系原作者