PrefixFilter是将rowkey前缀为指定字符串的数据所有过滤出来并返回给用户。例如:java
Scan scan = new Scan(); scan.setFilter(new PrefixFilter(Bytes.toBytes("def")));
可是hbase的PrefixFilter比较粗暴,并无根据filter作过多的查询优化。上述代码会scan整个区间的数据,获得一条数据就判断其是否符合前缀条件,不符合就读吓一条,直到找到前缀为def的数据。所以,咱们能够指定一下startkey。优化
Scan scan = new Scan();scan.setStartRow(Bytes.toBytes("def")); scan.setFilter(new PrefixFilter(Bytes.toBytes("def")));