For increasing performance (e.g. for joins) it is recommended to compute table statics first.
In Hive I can do::
analyze table <table name> compute statistics;
In Impala:
compute stats <table name>;
Does my spark application (reading from hive-tables) also benefit from pre-computed statistics? If yes, which one do I need to run? Are they both saving the stats in the hive metastore? I'm using spark 1.6.1 on Cloudera 5.5.4
Note:
In the Docs of spark 1.6.1 (https://spark.apache.org/docs/1.6.1/sql-programming-guide.html) for the parameter spark.sql.autoBroadcastJoinThreshold
I found a hint:
Note that currently statistics are only supported for Hive Metastore tables where the command ANALYZE TABLE COMPUTE STATISTICS noscan has been run.
From what i understand compute stats on impala is the latest implementation and frees you from tuning hive settings.
From official doc:
Useful link: https://www.cloudera.com/documentation/enterprise/5-5-x/topics/impala_perf_stats.html
This is the upcoming Spark 2.3.0 here (perhaps some of the features have already been released in 2.2.1 or ealier).
It could if Impala or Hive recorded the table statistics (e.g. table size or row count) in a Hive metastore in the table metadata that Spark can read from (and translate to its own Spark statistics for query planning).
You can easily check it out by using
DESCRIBE EXTENDED
SQL command inspark-shell
.ANALYZE TABLE COMPUTE STATISTICS noscan
computes one statistic that Spark uses, i.e. the total size of a table (with no row count metric due tonoscan
option). If Impala and Hive recorded it to a "proper" location, Spark SQL would show it inDESC EXTENDED
.Use
DESC EXTENDED tableName
for table-level statistics and see if you find the ones that were generated by Impala or Hive. If they are inDESC EXTENDED
's output they will be used for optimizing joins (and with cost-based optimization turned on also for aggregations and filters).Column statistics are stored (in a Spark-specific serialized format) in table properties and I really doubt that Impala or Hive could compute the stats and store them in the Spark SQL-compatible format.
I am assuming you are using Hive on Spark (or) Spark-Sql with hive context. If that is the case, you should run analyze in hive.
Analyze table<...> typically needs to run after the table is created or if there are significant inserts/changes. You can do this at the end of your load step itself, if this is a MR or spark job.
At the time of analysis, if you are using hive on spark - please also use the configurations in the link below. You can set this at the session level for each query. I have used the parameters in this link https://cwiki.apache.org/confluence/display/Hive/Hive+on+Spark%3A+Getting+Started in production and it works fine.