select off of a view going slowly
От | Fran Fabrizio |
---|---|
Тема | select off of a view going slowly |
Дата | |
Msg-id | 3AF6BA23.FAD7CFA9@exchange.webmd.net обсуждение исходный текст |
Ответы |
Re: select off of a view going slowly
|
Список | pgsql-general |
I have a view called error_log. Most selects off of this view will return 0 rows and in fact almost always, the error_log will be completely empty. It's taking almost .2 seconds to run a 'select count from error_log where site_id=1 and host_id=2'. Creating an index on a view would seem counterintuitive, but I tried anyway. Surprisingly, it did create something (\d error_log_index showed the index) but a subsequent \d on the error_log view and on the table it is created from did not show an associated index, and nothing got faster anyway. I've included the EXPLAIN results below, I'm not real good at interpreting them yet, so I'm not real sure what I am looking for. Any ideas? Thanks, Fran monitoring=# \d error_log View "error_log" Attribute | Type | Modifier -----------+---------+---------- count | integer | site_id | bigint | host_id | bigint | View definition: SELECT count(*) AS count, log.site_id, log.host_id FROM log WHE RE (((log.status = 'CRIT'::"varchar") OR (log.status = 'EMERG'::"varchar")) AND (log.tstamp > (now() - '1 00:00'::"interval"))) GROUP BY log.site_id, log.host_i d; monitoring=# explain select count from error_log where site_id=24 and host_id=67 ; NOTICE: QUERY PLAN: Aggregate (cost=18398.08..18398.09 rows=0 width=16) -> Group (cost=18398.08..18398.09 rows=1 width=16) -> Sort (cost=18398.08..18398.08 rows=1 width=16) -> Seq Scan on log (cost=0.00..18398.07 rows=1 width=16) EXPLAIN monitoring=# select count from error_log where site_id=24 and host_id=67; count ------- (0 rows) monitoring=# 010507.11:03:11.320 [6801] StartTransactionCommand 010507.11:03:11.321 [6801] query: select count from error_log where site_id=24 and host_id=67; 010507.11:03:11.321 [6801] ProcessQuery 010507.11:03:12.495 [6801] CommitTransactionCommand
В списке pgsql-general по дате отправления: