sql – 优化BETWEEN日期语句
发布时间:2021-03-10 17:25:54 所属栏目:MsSql教程 来源:网络整理
导读:我需要帮助优化PostgreSQL查询,该查询使用带有时间戳字段的BETWEEN子句. 我有2张桌子: ONE(int id_one(PK),datetime cut_time,int f1 . . .) 包含大约3394行 TWO(int id_two(PK),int id_one(FK),int f2 . . .) 包含大约4000000行 在FK id_one和cut_time上
|
我需要帮助优化PostgreSQL查询,该查询使用带有时间戳字段的BETWEEN子句. 我有2张桌子: ONE(int id_one(PK),datetime cut_time,int f1 . . .) 包含大约3394行 TWO(int id_two(PK),int id_one(FK),int f2 . . .) 包含大约4000000行 在FK id_one和cut_time上,PKs id_one和id_two上都有btree索引. 我想执行如下查询: select o.id_one,Date(o.cut_time),o.f1,t.f2 from one o inner join two t ON (o.id_one = t.id_one) where o.cut_time between '2013-01-01' and '2013-01-31'; 此查询在大约7秒内检索大约1.700.000行. 报告分析报告下面报告: "Merge Join (cost=20000000003.53..20000197562.38 rows=1680916 width=24) (actual time=0.017..741.718 rows=1692345 loops=1)" " Merge Cond: (c.coilid = hf.coilid)" " -> Index Scan using pk_coils on coils c (cost=10000000000.00..10000000382.13 rows=1420 width=16) (actual time=0.008..4.539 rows=1404 loops=1)" " Filter: ((cut_time >= '2013-01-01 00:00:00'::timestamp without time zone) AND (cut_time <= '2013-01-31 00:00:00'::timestamp without time zone))" " Rows Removed by Filter: 1990" " -> Index Scan using idx_fk_lf_data on hf_data hf (cost=10000000000.00..10000166145.90 rows=4017625 width=16) (actual time=0.003..392.535 rows=1963386 loops=1)" "Total runtime: 768.473 ms" 不使用timestamp列上的索引.如何优化此查询? 解决方法查询在不到一秒的时间内执行.其他6秒用于服务器和客户端之间的流量.(编辑:我爱制作网_池州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- HTML Table 空白单元格补全的实现方法
- Sql Server的substring(expression, start, length)函数
- sql-server-2008 – SQL Server 2008表现不佳 – 迁移到新服
- sql-server – 如何分配SqlException编号
- 瑞星要开“网上展览会” 发布网络反病毒全攻略
- 美反垃圾邮件:垃圾邮件制造者与ISP开拉锯战
- sql-server – 为什么SQL Server 2008在简单的SQL查询上崩溃
- sql-server – 增量更新后统计信息消失
- sql-server – 在类型/子类型设计模式中实现具有互斥子类的
- 品牌建站:电子商务时代的根源
站长推荐
热点阅读


