---
title: "Hive-0.8.1索引的实验 "
author: "thomas0988"
date: "2012-05-19T09:29:02Z"
tags: []
categories: ["数据库"]
slug: "hive-0-8-1"
draft: false
lastmod: "2012-05-19T09:29:02Z"
id: 1535114
url: "https://thomas0988.iteye.com/blog/1535114"
---

先说一个0.7.1和0.8.1的Metastore不兼容

一。外部表的索引。

因为怕麻烦，就继续用之前的table02的数据，在new meta里也叫table02，不过改成了external表。最后的结论是Hive的索引也是支持外部表的。

建立索引，运行。还是6个mapper，不行。

二。建立内部表

CTAS from table02，建立一个内部表table03；

 

重点是，换了0.8.1，

&lt;property&gt;  
  &lt;name&gt;hive.optimize.index.filter&lt;/name&gt;  
  &lt;value&gt;true&lt;/value&gt;  
  &lt;description&gt;Whether to enable automatic use of indexes&lt;/description&gt;  
&lt;/property&gt;

建立了索引:

 

**\[sql]** [view plain](http://blog.csdn.net/liwei_1988/article/details/7346064 "view plain")[copy](http://blog.csdn.net/liwei_1988/article/details/7346064 "copy")[print](http://blog.csdn.net/liwei_1988/article/details/7346064 "print")[?](http://blog.csdn.net/liwei_1988/article/details/7346064 "?")

01. hive&gt; create index table03\_index on table table03(id)
02. &gt; as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'
03. &gt; with deferred rebuild;
04. OK
05. Time taken: 2.221 seconds
06. hive&gt; show tables;
07. OK
08. default\_\_table02\_compact\_index\__
09. default\_\_table03\_table03\_index\__
10. table02
11. table03
12. Time taken: 1.073 seconds
13. hive&gt; dfs -ls /user/hive/warehouse/default\_\_table03\_table03\_index\_\_;
14. hive&gt; dfs -ls /user/hive/warehouse/default\_\_table02\_compact\_index\_\_;
15. Found 1 items
16. -rw-r--r--   1 allen supergroup   74701985 2012-03-12 17:25 /user/hive/warehouse/default\_\_table02\_compact\_index\_\_/000000\_0
17. hive&gt; alter index table03\_index on table03 rebuild;

现在重新query：

 

 

**\[sql]** [view plain](http://blog.csdn.net/liwei_1988/article/details/7346064 "view plain")[copy](http://blog.csdn.net/liwei_1988/article/details/7346064 "copy")[print](http://blog.csdn.net/liwei_1988/article/details/7346064 "print")[?](http://blog.csdn.net/liwei_1988/article/details/7346064 "?")

01. hive&gt; select * from table03 where id=500000;
02. Total MapReduce jobs = 1
03. Launching Job 1 out of 1
04. Number of reduce tasks is set to 0 since there's no reduce operator
05. Starting Job = job\_201203122135\_0003, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job\_201203122135\_0003
06. Kill Command = /home/allen/Hadoop/hadoop-0.20.2/bin/../bin/hadoop job  -Dmapred.job.tracker=localhost:9001 -kill job\_201203122135\_0003
07. Hadoop job information for Stage-1: number of mappers: 2; number of reducers: 0
08. 2012-03-12 21:58:02,283 Stage-1 map = 0%,  reduce = 0%
09. 2012-03-12 21:58:35,932 Stage-1 map = 50%,  reduce = 0%
10. 2012-03-12 21:58:39,057 Stage-1 map = 63%,  reduce = 0%
11. 2012-03-12 21:58:45,216 Stage-1 map = 75%,  reduce = 0%
12. 2012-03-12 21:58:51,407 Stage-1 map = 88%,  reduce = 0%
13. 2012-03-12 21:58:57,667 Stage-1 map = 100%,  reduce = 0%
14. 2012-03-12 21:59:03,798 Stage-1 map = 100%,  reduce = 100%
15. Ended Job = job\_201203122135\_0003
16. MapReduce Jobs Launched:
17. Job 0: Map: 2   HDFS Read: 356889161 HDFS Write: 357 SUCESS
18. Total MapReduce CPU Time Spent: 0 msec
19. OK
20. 500000  A decade ago, many were predicting that Cooke, a New York City prodigy, would become a basketball shoe pitchman and would flaunt his wares and skills at All-Star weekends like the recent aerial show in Orlando, Fla. There was a time, however fleeting, when he was more heralded, or perhaps merely hyped, than any other high school player in America.
21. Time taken: 77.299 seconds

还是不行，再设置一个参数：

 

&lt;property&gt;  
  &lt;name&gt;hive.optimize.index.filter.compact.minsize&lt;/name&gt;  
  &lt;value&gt;5368&lt;/value&gt;  
  &lt;description&gt;Minimum size (in bytes) of the inputs on which a compact index is automatically used.&lt;/description&gt;原来是5368709120  
&lt;/property&gt;  
再次尝试：好了

 

**\[sql]** [view plain](http://blog.csdn.net/liwei_1988/article/details/7346064 "view plain")[copy](http://blog.csdn.net/liwei_1988/article/details/7346064 "copy")[print](http://blog.csdn.net/liwei_1988/article/details/7346064 "print")[?](http://blog.csdn.net/liwei_1988/article/details/7346064 "?")

01. hive&gt; select * from table02 where id=500000;
02. Total MapReduce jobs = 3
03. Launching Job 1 out of 3
04. Number of reduce tasks is set to 0 since there's no reduce operator
05. Starting Job = job\_201203122135\_0010, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job\_201203122135\_0010
06. Kill Command = /home/allen/Hadoop/hadoop-0.20.2/bin/../bin/hadoop job  -Dmapred.job.tracker=localhost:9001 -kill job\_201203122135\_0010
07. Hadoop job information for Stage-3: number of mappers: 1; number of reducers: 0
08. 2012-03-12 22:12:18,347 Stage-3 map = 0%,  reduce = 0%
09. 2012-03-12 22:12:33,834 Stage-3 map = 100%,  reduce = 0%
10. 2012-03-12 22:12:40,078 Stage-3 map = 100%,  reduce = 100%
11. Ended Job = job\_201203122135\_0010
12. Ended Job = -1685536326, job is filtered out (removed at runtime).
13. Moving data to: hdfs://localhost:9000/tmp/hive-allen/hive\_2012-03-12\_22-12-07\_069\_3484347533083360337/-ext-10000
14. Moving data to: hdfs://localhost:9000/tmp/hive-allen/hive\_2012-03-12\_22-12-06\_413\_2863963861844056912/-mr-10002
15. Launching Job 3 out of 3
16. Number of reduce tasks is set to 0 since there's no reduce operator
17. Starting Job = job\_201203122135\_0011, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job\_201203122135\_0011
18. Kill Command = /home/allen/Hadoop/hadoop-0.20.2/bin/../bin/hadoop job  -Dmapred.job.tracker=localhost:9001 -kill job\_201203122135\_0011
19. Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
20. 2012-03-12 22:12:53,124 Stage-1 map = 0%,  reduce = 0%
21. 2012-03-12 22:13:04,590 Stage-1 map = 100%,  reduce = 0%
22. 2012-03-12 22:13:10,897 Stage-1 map = 100%,  reduce = 100%
23. Ended Job = job\_201203122135\_0011
24. MapReduce Jobs Launched:
25. Job 0: Map: 1   HDFS Read: 74706082 HDFS Write: 68 SUCESS
26. Job 1: Map: 1   HDFS Read: 33554431 HDFS Write: 357 SUCESS
27. Total MapReduce CPU Time Spent: 0 msec
28. OK
29. 500000  A decade ago, many were predicting that Cooke, a New York City prodigy, would become a basketball shoe pitchman and would flaunt his wares and skills at All-Star weekends like the recent aerial show in Orlando, Fla. There was a time, however fleeting, when he was more heralded, or perhaps merely hyped, than any other high school player in America.
30. Time taken: 65.212 seconds
31. hive&gt;

问题就是那个启动index的阈值没有设置：hive.optimize.index.filter.compact.minsize

 

[http://blog.csdn.net/liwei\_1988/article/details/7346064](http://blog.csdn.net/liwei_1988/article/details/7346064)