优化 Postgresql 8.x 中时间戳列的查询
假设您有订单表,该表包含一个时间戳列,指示订单的创建时间。正常的查询是获取两个日期之间的订单。有谁知道如何优化此查询,因为在时间戳列上创建索引没有效果,如 EXPLAIN ANALYZE 所示。
Lets suppose you have and orders table, this table contains a timestamp column indicating the creation time of the orders. A normal query would be to obtain the orders between two dates. Does anybody know how to optimize this query because creating an index on the timestamp column has no effect as shown by EXPLAIN ANALYZE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常会使用索引,但前提是表被正确分析(VACUUM ANALYZE 或只是 ANALYZE),并且表大小足够大,索引扫描比顺序扫描更快。
Usually indexes are used, but only if the table is properly analyzed (VACUUM ANALYZE or just ANALYZE), and if the table size is large enough that index scans are faster than sequential scans.
索引应该有效。我怀疑它不适合你,因为你的表要么很小(PostgreSQL 几乎从不使用小表的索引),要么你还没有对其进行分析。
An index should work. I suspect its not working for you because your table is either tiny (PostgreSQL almost never uses indices for tiny tables), or you haven't done an analyze on it.