前几天看了一篇文章
作者是
码农的第一特征就是相信实验,故postgresql走起
上一篇文章
>>插入1亿条记录,约耗时1个小时
>>无索引查询一条记录耗时为55.7秒
>>有索引查询一条记录耗时小于1秒
1.去官网下载psotgresql :https://www.postgresql.org/
下载最新版本11.1 windows安装,step by step
2.客户端,我选了pgadmin:https://www.pgadmin.org/
下载最新版本v3.6 windows安装,step by step
3.创建新的数据库www
4.创建新表
/* String sql = "CREATE table PERSON " + "(ID INT PRIMARY KEY NOT NulL," + " name TEXT NOT NulL," + " AGE INT NOT NulL," + " ADDRESS CHAR(50)," + " SALARY REAL)"; stmt.executeUpdate(sql);*/5.插入1亿条记录
java clIEnt 依赖包
java程序
public voID postgresqlOneByOneInsert() { try { long start=Sy@R_404_6563@.currentTimeMillis(); Class.forname("org.postgresql.Driver"); Connection connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/www","postgres","root"); PreparedStatement stmt = connection.prepareStatement("INSERT INTO PERSON(ID,name,AGE,ADDRESS,SALARY) values(?,?,?);"); for(int i=0;i<100000000;i++<span>) { stmt.setInt(1,i+1<span>); stmt.setString(2,"mkyong"+<span>i); stmt.setInt(3,i%100<span>); stmt.setString(4,"address"+<span>i); stmt.set<a href="https://m.jb51.cc/tag/float/" target="_blank" >float</a>(5,25000.00f<span>); stmt.executeUpdate(); }
/ String sql = "CREATE table PERSON " +
"(ID INT PRIMARY KEY NOT NulL," +
" SALARY REAL)";
stmt.executeUpdate(sql);/
/ ResultSet rs = stmt.executequery( "SELECT FROM STUDENT;" );
while ( rs.next() ) {
int ID = rs.getInt("sID");
String name = rs.getString("name");
Sy@R_404_6563@.out.println( "ID = " + ID );
Sy@R_404_6563@.out.println( "name = " + name );;
Sy@R_4046563@.out.println();
}
rs.close();*/
stmt.close();
connection.close();
Sy@R4046563@.out.println("耗时:"+(Sy@R404_6563@.currentTimeMillis()-start)+" 毫秒");
} catch<span> (ClassNotFoundException e) { e.<a href="https://www.jb51.cc/tag/printstacktrace/" target="_blank" >printstacktrace</a>(); } catch<span> (<a href="https://www.jb51.cc/tag/sql/" target="_blank" >sql</a>Exception e) { e.<a href="https://www.jb51.cc/tag/printstacktrace/" target="_blank" >printstacktrace</a>(); }}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre>
然后是漫长的时间等待插入完成。
>>插入性能:1亿条记录导入时间耗时:36599195 毫秒~10个小时
>>无索引时读取性能:SELECT * FROM PERSON where name='mkyong90000000'; 9 secs 574 msec
>>有索引时读取性能:create index name_ind on PERSON(name); //创建索引耗时5 min 9 secs. SELECT * FROM PERSON where name='mkyong90000000'; //61ms
小结:
插入性能:mongo的效率为postgresql的10倍
读取性能:无索引时,postgresql是mongo的6倍左右
创建索引:postgrep要快,有索引查询不能确定查询时间差异 总结以上是内存溢出为你收集整理的数据库新秀 postgresql vs mongo 性能PK全部内容,希望文章能够帮你解决数据库新秀 postgresql vs mongo 性能PK所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)