扩展jooq的行值查询

时间:2017-05-15 18:58:44

标签: java sql jooq

使用jooq为MySQL生成查询并检查是否可以扩展由它生成的行值子句,因为mysql无法在行值查询中正确使用索引

例如

DSLContext context = new DefaultDSLContext(SQLDialect.MYSQL);
SelectQuery<Record> select = context.selectQuery();
select.addSelect(field("Col1"));
select.addFrom(table("Table1").as("T1"));
select.addOrderBy(field("Name"), field("Sid"));
select.addSeekAfter(param("p2", "John"), param("p3","123"));
String generated = select.getSQL(ParamType.NAMED);

生成以下查询

where (1 = 1 and (Name, Id) > (:p2, :p3)) order by Name asc, Id asc

但愿意

where Name > :p2 or (Name = :p2 and Id > :p3) order by Name asc, Id asc

1 个答案:

答案 0 :(得分:1)

It's currently (jOOQ 3.9, see #6230) not possible to override this behaviour. You'll have to add an explicit predicate of the form you'd like it to be.