【问题标题】:Using SQL hint to Force Index using querydsl使用 SQL 提示使用 querydsl 强制索引
【发布时间】:2016-10-14 07:58:45
【问题描述】:

我们在应用程序中使用 querydsl 和 JPA。以下是我的存储库实现方式:

public interface TestRepository  extends JpaRepository<Test, Long>, QueryDslPredicateExecutor<Test> {   }

我正在使用谓词构建器和可分页对象调用默认的 findAll 方法:

testRepository.findAll(booleanBuilder.getValue(), pageable);

为了解决性能问题,我们需要在特定表上强制索引。现在派生查询如下所示:

SELECT tab1_.id AS id_20_, tab1_.user_type AS user_type2_20_ FROM table1 tab1_

我们希望我们的查询看起来像这样:

SELECT /*+ INDEX(tab1_ MGS_KG1) */ tab1_.id AS id_20_, tab1_.user_type AS user_type2_20_ FROM table1 tab1_

我怎样才能达到同样的效果? (我们使用的是 querydsl-jpa 3.6.7)

谢谢!

【问题讨论】:

    标签: hibernate jpa querydsl


    【解决方案1】:

    你可以使用interceptors

    public String onPrepareStatement(String sql);
    

    如果FROM 包含必要的表,只需调用super 并修改结果SQL 字符串,在SELECT 之后插入您的索引字符串

    【讨论】:

      猜你喜欢
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 2019-10-07
      相关资源
      最近更新 更多