此内容没有您所选择的语言版本。

5.4. Optimizing the Query Process


Query performance depends on several criteria:
  • The Lucene query.
  • The number of objects loaded: use pagination or index projection where required.
  • The way the Query Module interacts with the Lucene readers defines the appropriate reader strategy.
  • Caching frequently extracted values from the index.

5.4.1. Caching Index Values: FieldCache

The Lucene index identifies matches to queries. Once the query is performed the results must be analyzed to extract useful information. The Lucene-based Query API is used to extract the Class type and the primary key.
Extracting the required values from the index reduces performance. In some cases this may be minor, other cases may require caching.
Requirements depends on the kind of projections being used and in some cases the Class type is not required.
The @CacheFromIndex annotation is used to perform caching on the main metadata fields required by the Lucene-based Query API.
import static org.infinispan.query.annotations.FieldCacheType.CLASS;
import static org.infinispan.query.annotations.FieldCacheType.ID;

@Indexed
@CacheFromIndex( { CLASS, ID } )
public class Essay {
    ...

Copy to Clipboard Toggle word wrap
It is possible to cache Class types and IDs using this annotation:
  • CLASS: The Query Module uses a Lucene FieldCache to improve peformance of the Class type extraction from the index.
    This value is enabled by default. The Lucene-based Query API applies this value when the @CacheFromIndex annotation is not specified.
  • ID: Extracting the primary identifier uses a cache. This method produces the best querying results, however it may reduce performance.

Note

Measure the performance and memory consumption impact after warmup (executing some queries). Performance may improve by enabling Field Caches but this is not always the case.
Using a FieldCache has following two disadvantages:
  • Memory usage: Typically the CLASS cache has lower requirements than the ID cache.
  • Index warmup: When using field caches, the first query on a new index or segment is slower than when caching is disabled.
Some queries may not require a classtype, and ignores the CLASS field cache even when enabled. For example, when targeting a single class, all returned values are of that type.
The ID FieldCache requires the ids of targeted entities to be using a TwoWayFieldBridge. All types being loaded in a specific query must use the fieldname for the id and have ids of the same type. This is evaluated at query execution.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat