Comments (2)
提的非常好。第一点这块的性能我没有测试过,是把之前用 MyBatis
框架的分页 count
思路拿过来直接用了,你可以把这块的测试截图发一下;第二点属于细节上的优化,可以 fix
;第三点是个大问题,我应该再考虑下不足之处,你说到变成 SQL 的 in
? 是 join
吗?
from anima.
1.目前已知mysql是有性能问题的(粗略测试相差10倍),sqlserver可能做了优化或者测试数据样本不足没发现什么影响
2.细节问题
3.eg:
数据库有 users 表 和 depts表,Java模型上 User 和 Dept 做了双向的关联
查询User列表时做了一个Join操作:
假定查询到了5条users记录
此时会根据User列表循环5次查询depts表,并一一进行封装。
改进建议如下:首先根据查询到的User列表,将User对象和Dept对象做Join关联的字段假定是deptId全部提取到一个set集合,这样Join的字段肯定是少于等于User列表的size的,如下例子假定查询到的users表结果集如下:
uid | dept_id |
---|---|
1 | 1 |
2 | 1 |
3 | 2 |
4 | 3 |
5 | 3 |
- 按原先的Join之后,会发送5条
select * from depts where id = ?
| 参数依次 1,1,2,3,3 的语句,数据库会连接5次,其中有两条还重复(id=1和3的会被重复查询一次) - 如果使用in优化后 只需要发送一条
select * from detps where id in (?,?,?)
| 参数组装好的set集合 [1,2,3],数据库只用连接1次,大大减少了连接数据库的次数,同时查询的结果也会少两条
查询回来后可以直接将Dept使用lambda的group按id分组的到一个map
//Group后的伪Map模型
{
"1":"dept[{id:1}]",
"2":"dept[{id:2}]",
"3":"dept[{id:3}]"
}
然后程序中再循环一次User列表,依次按关联的detpId匹配设置dept对象
from anima.
Related Issues (20)
- 继承了Model的类无法使用Gson转换为JSON HOT 3
- 很看好这个库,强烈支持,望今后持续更新下去!
- 一点疑惑
- 已经开始公司部分程序中使用anima了
- 使用Anima.atomic连接池泄露 HOT 1
- ORACLE 支持
- java.lang.NoClassDefFoundError: com/blade/reflectasm/MethodAccess HOT 1
- 帮忙看一下这个错误是如何引起的 HOT 1
- 0.2.5版本没有isNull()这个接口
- 对模型执行update操作后id属性被置为NULL HOT 2
- 请问在insert时除了save可以BY
- 请问在insert时除了save可以BYSQL HOT 1
- 请问使用这个库可以调用存储过程吗 HOT 1
- 关于methodToFieldName方法,methodName.replace("get", "")问题
- increase value by 1
- Model类为内部类时save会报错
- 动态条件的优化问题 HOT 1
- page()的时候是不是没有设置columnmapping 字段的映射关系?
- Using Anima.deleteBatch get an exception HOT 1
- Got Keys were not fetched from database, Postgresql
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anima.