id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	due_date
114	pg版商品全量索引优化	huangzhong		"* 背景
商城oracle版建全量索引时是把将近100万条数据（索引用到的所有字段）全部一次性查询得到，虽然减少了访问数据库的次数，但对应用的压力很大，全量索引时间大概是20分钟。

{{{
presta = con.prepareStatement(getSelectCProductSql(TYPE_ALL));
res = presta.executeQuery();
while (res.next()) {
    Document document;
    try {
	//获取字段值
	smalltypeId = res.getInt(""smalltype_id"");
	price = res.getDouble(""price"");
	onlineFlag = res.getInt(""online_flag"");
	productName = getNoNullStr(res.getString(""product_name""));
        ...
    } catch(Exception e) {
        continue;
    }finally{
        document = null;
    }
}
}}}


* 优化
上述方式在pg上时报内存溢出，后来采用数据库端游标方式进行分页，每页10万条数据，虽然增大了数据库访问次数，但应用压力变小，全量索引时间是12分钟

{{{
con.setAutoCommit(false);
st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
st.setFetchSize(100000);
String sql = getSelectCProductSql(TYPE_ALL);                        
ResultSet rs = st.executeQuery(sql);
while (res.next()) {
    Document document;
    try {
	//获取字段值
	smalltypeId = res.getInt(""smalltype_id"");
	price = res.getDouble(""price"");
	onlineFlag = res.getInt(""online_flag"");
	productName = getNoNullStr(res.getString(""product_name""));
        ...
    } catch(Exception e) {
        continue;
    }finally{
        document = null;
    }
}

}}}
"	defect	new	major	2012年6.0版本	系统相关	6.0		全量索引优化		18/09/2012
