【发布时间】:2013-05-06 15:54:19
【问题描述】:
我有一个大报表表。位图堆扫描步骤耗时 5 秒以上。
有什么我可以做的吗?我向表中添加列,重新索引它使用的索引会有帮助吗?
我对数据进行联合和求和,因此我不会将 500K 记录返回给客户端。
我使用 postgres 9.1。
这里解释一下:
Bitmap Heap Scan on foo_table (cost=24747.45..1339408.81 rows=473986 width=116) (actual time=422.210..5918.037 rows=495747 loops=1)
Recheck Cond: ((foo_id = 72) AND (date >= '2013-04-04 00:00:00'::timestamp without time zone) AND (date <= '2013-05-05 00:00:00'::timestamp without time zone))
Filter: ((foo)::text = 'foooooo'::text)
-> Bitmap Index Scan on foo_table_idx (cost=0.00..24628.96 rows=573023 width=0) (actual time=341.269..341.269 rows=723918 loops=1)
查询:
explain analyze
SELECT CAST(date as date) AS date, foo_id, ....
from foo_table
where foo_id = 72
and date >= '2013-04-04'
and date <= '2013-05-05'
and foo = 'foooooo'
Index def:
Index "public.foo_table_idx"
Column | Type
-------------+-----------------------------
foo_id | bigint
date | timestamp without time zone
btree, for table "public.external_channel_report"
表:foo 是 text 字段,有 4 个不同的值。foo_id 是 bigint,目前有 10K 个不同的值。
【问题讨论】:
-
请发布查询
-
请添加表定义,包括索引。
-
我仍然没有在您的“定义”中看到列
foo的定义。请添加 real 定义。另外:foo的基数是多少? (它在功能上是否依赖于 foo_id?) -
foo 是具有 4 个不同可能值的文本字段。 foo_id 是具有少于 10K 不同值的 bigint
-
可惜你没有使用 9.2,你可以获得更多关于 I/O 和缓冲区访问的数据。
标签: sql postgresql indexing postgresql-performance