Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为了适配索引需要对查询的参数有顺序的要求,能否在构建查询请求时按照构建参数的顺序最后生成where时按照构建顺序排序? #105

Closed
ShawnaVayne opened this issue Sep 11, 2024 · 8 comments

Comments

@ShawnaVayne
Copy link

比如:
MapBuilder mapBuilder = MapUtils.builder();
mapBuilder.field(T::getA, "A").op(FieldOps.Equal);
mapBuilder.field(T::getB, "B").op(FieldOps.Equal);
生成的sql应该就是:
where a = 'a' and b = 'b'

@troyzhxu
Copy link
Owner

troyzhxu commented Sep 11, 2024

实际上,在索引命中与使用效率方面,where a = 'a' and b = 'b'where b = 'b' and a = 'a' 没有任何区别。

@ShawnaVayne
Copy link
Author

实际上,在索引命中与使用效率方面,where a = 'a' and b = 'b'where b = 'b' and a = 'a' 没有任何区别。

感谢回复,是我描述不够严谨,这里我使用的数据库是Clickhouse,a是我的PARTITION分区键,在查询的时候我希望a能够在执行时在最前面。

@troyzhxu
Copy link
Owner

当前版本,默认不支持,不过可以通过自定义 ParamResolver 组件,并配合 LinkedHashMap 来实现:

var params = MapUtils.builder(new LinkedHashMap<>())
        // 添加参数...
        .build();
// 执行查询

自定义 ParamResolver 思路:继承 DefaultParamResolver, 重写 resolveParamsGroup(Collection<FieldMeta> fieldMetas, Map<String, Object> paraMap) 方法。

@ShawnaVayne
Copy link
Author

当前版本,默认不支持,不过可以通过自定义 ParamResolver 组件,并配合 LinkedHashMap 来实现:

var params = MapUtils.builder(new LinkedHashMap<>())
        // 添加参数...
        .build();
// 执行查询

自定义 ParamResolver 思路:继承 DefaultParamResolver, 重写 resolveParamsGroup(Collection<FieldMeta> fieldMetas, Map<String, Object> paraMap) 方法。
感谢提供解决方案,好人一生平安~

@troyzhxu
Copy link
Owner

下个版本将优化为按 检索实体类 中字段声明的顺序生成条件,例如:

public class UserVO {
     private String name;
     private int age;
}

nameage 都有参数时,将生成 where name = 'xxx' and age = x

这样,是否可以满足你的需求?

@ShawnaVayne
Copy link
Author

下个版本将优化为按 检索实体类 中字段声明的顺序生成条件,例如:

public class UserVO {
     private String name;
     private int age;
}

nameage 都有参数时,将生成 where name = 'xxx' and age = x

这样,是否可以满足你的需求
是可以满足的,会有一个疑问:继承父类的话,父类的字段是更靠前还是更靠后呢?

@troyzhxu
Copy link
Owner

父类的字段是更靠后

@troyzhxu
Copy link
Owner

troyzhxu commented Oct 8, 2024

v4.3.3 已发布:https://github.com/troyzhxu/bean-searcher/releases/tag/v4.3.3

@troyzhxu troyzhxu closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants