MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 4528|回复: 4
打印 上一主题 下一主题

本条语句如何优化

[复制链接]
跳转到指定楼层
1#
发表于 2009-5-4 16:27:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本条语句如何优化

mysql5+linux(centos)
PreparedStatement prepared = null;
               
                Connection conn = null;
                ResultSet result = null;
                try {
                        conn = DBUtil.getConnection();
                        conn.setAutoCommit(false);
                        
                        prepared = conn.prepareStatement(INSERT_TOKEN_SQL);
                        
                        int size = tokenLst.size();
                        
                        for(Token t: tokenLst){
                                Long disciplinedId = t.getDisciplineId() == null? 0L: t.getDisciplineId();
                                Integer typeId = t.getTypeId() == null? 0:t.getTypeId();
                                Long participantId = t.getParticipantId() == null? 0:t.getParticipantId();
                                
                                if(t.getText().length() >= 100){
                                        System.out.println(t.getText());
                                        continue;
                                }
                                
                                prepared.setInt(1, storyId);
                                prepared.setLong(2, disciplinedId);
                                prepared.setInt(3, typeId);
                                prepared.setString(4, t.getText());
                                prepared.setBoolean(5, t.getIsReservedKeyWord());
                                prepared.setDouble(6, t.getFrequency());
                                prepared.setString(7, t.getHashCode()+"");
                                prepared.setBoolean(8, t.isInHeadLine());
                                prepared.setBoolean(9, t.getIsReservedKeyWord());
                                prepared.setLong(10, participantId);
                                prepared.setString(11, t.getStandardName());
                                prepared.setBoolean(12, t.isTearmParticipant());
                                prepared.setBoolean(13, t.isHomeOrAway());
                                prepared.addBatch();
                        }
                        prepared.executeBatch();
                        
                        conn.commit();
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
                        DBUtil.JDBCUtil(conn, prepared, result);
                }
本表有130万记录 ,现在发现批处理插入1万条记录发现需要 3-5秒。
经过观察该表有主键(id,storyId)其中id是系统自动增长。
问如何调节性能, 可以动索
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享淘帖 顶 踩
2#
发表于 2009-5-5 13:01:48 | 只看该作者
考虑一下批量插入了再一起提交...
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-5-18 10:13 , Processed in 0.065962 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表