在where条件里面尽量不要使用函数,使用函数会进行遍历 *** 作,
如下:
--不使用时间函数explainanalyseselectc_index_code,sum(off_line_time)asoff_line_timefromresource_camera_info_mergerwheremerger_timebetween'2015-11-03'and'2015-11-11'groupbyc_index_code;HashAggregate(cost=9872.43..9906.05rows=3362wIDth=28)(actualtime=64.240..67.006rows=12243loops=1)GroupKey:c_index_code->SeqScanonresource_camera_info_merger(cost=0.00..9368.59rows=100766wIDth=28)(actualtime=0.011..37.755rows=99377loops=1)Filter:((merger_time>='2015-11-03'::date)AND(merger_time<='2015-11-11'::date))RowsRemovedbyFilter:270996Planningtime:0.158msExecutiontime:67.342ms
--使用时间转换函数explainanalyzeselectc_index_code,sum(off_line_time)asoff_line_timefromresource_camera_info_mergerwheremerger_timebetweento_date('2015-11-03','yyyy-mm-dd')andto_date('2015-11-11','yyyy-mm-dd')groupbyc_index_code;HashAggregate(cost=11724.29..11757.91rows=3362wIDth=28)(actualtime=519.805..522.717rows=12243loops=1)GroupKey:c_index_code->SeqScanonresource_camera_info_merger(cost=0.00..11220.46rows=100766wIDth=28)(actualtime=0.017..490.643rows=99377loops=1)Filter:((merger_time>=to_date('2015-11-03'::text,'yyyy-mm-dd'::text))AND(merger_time<=to_date('2015-11-11'::text,'yyyy-mm-dd'::text)))RowsRemovedbyFilter:270996Planningtime:0.119msExecutiontime:523.208ms总结
以上是内存溢出为你收集整理的PostgreSQL 使用心得(1)全部内容,希望文章能够帮你解决PostgreSQL 使用心得(1)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)