abatis学习笔记(1)----避免N+1 Select
来源:互联网 发布:丁春秋和萧峰 知乎 编辑:程序博客网 时间:2024/05/18 00:12
(一)什么是N+1Select问题
通常的N+1查询(1:1和1:M) <resultMap id="select-product-result" class="product"> 所谓N+1问题即在查询N次父记录的同时查询N次子记录
<result property="id" column="PRD_ID"/>
<result property="description" column="PRD_DESCRIPTION"/>
<result property="category" column="PRD_CAT_ID" select="selectCategory"/>
</resultMap>
select id="selectCategory" parameterClass="int" resultMap="select-category-result">
select * from CATEGORY where CAT_ID = #value#
</select>
<statements>
<select id="selectProduct" parameterClass="int" resultMap="select-product-result">
select * from PRODUCT where PRD_ID = #value#
</select>
(二)解决N+1Select问题 第一种:构建多表连接sql语句 第二种:iBATIS.NET DataMapper 1.1中,添加了groupBy特性用来解决N+1问题 <resultMap class="com.tj_zhongzhixin.entity.Store" id="storeMap" groupBy="sto_id"> groupby属性解决了查询N次父记录的同时查询N次子记录 他只执行一次查询(父查询和子查询同时执行) http://hi.baidu.com/zhifeichuan/
<result property="sto_id" column="sto_id"/>
<result property="sto_name" column="sto_name"/>
<result property="sto_contactphone" column="sto_contactphone"/>
<result property="sto_time" column="sto_time" javaType="string" />
<result property="listQuote" resultMap="getListQuote" />
</resultMap>
<resultMap class="com.tj_zhongzhixin.entity.Quote" id="getListQuote">
<result property="quoId" column="quo_id" />
<result property="quoPrice" column="quo_price" />
</resultMap>
<statement id="selectListStore" resultClass="com.tj_zhongzhixin.entity.Store" resultMap="storeMap" parameterClass="com.tj_zhongzhixin.common.util.PageResult" >
select q.quo_id,q.quo_price,s.sto_id,s.sto_name,s.sto_contactphone,s.sto_time from store as s,quote as q where s.sto_id=q.quo_storeId limit #pageSize# offset #throwRows#
</statement>
- abatis学习笔记(1)----避免N+1 Select
- iBatis学习(五) 避免SELECT N+1
- ibaits-- 避免n+1 select (1:m;m:n)
- abatis
- ibatis 复杂类型属性(自定义类型的属性) 避免n+1次select(1:1)
- n+1 select
- N+1 select problem
- MySql学习笔记1:select语句
- SQL学习笔记1-insert&select
- Oracle学习笔记1—SELECT查询
- Rails中如何避免N+1问题
- Rails中如何避免N+1问题
- Ibatis N:1避免N+1查询的方法
- Hibernate学习笔记-----n+1问题
- Algorithm学习笔记 --- 3n+1问题
- n+1次select查询问题
- Hibernate中N+1次select问题
- NHibernate:N+1 Select查询问题分析
- 团队合作
- 在线翻译小工具开发过程遇到的一些问题
- ZIP 文件 结构
- GrideView 分页
- SEO操作常见的四点不良习惯
- abatis学习笔记(1)----避免N+1 Select
- 简明HTTP协议
- Streaming HTTP 在IE8下不能正常工作
- tomcat下JSTL配置
- Android Post Get 示例
- 继续找工作
- Lua记事
- 尘心百事空,大道自然融。
- 利用Rman搭建物理standby