![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Net Virtual Mailing Lists wrote: Is there a way to create an index that would make this query be efficient and not perform a sequential scan? SELECT count(*) AS count,id FROM sometable GROUP BY id; Indexes cannot be used for retrieving results... .. I've considered creating a rule on this table which would put the results of this into another table anytime it is updated, but I thought there might be an easier way. I don't think that a rule could come useful in this case. IMHO you could use triggers or a materialized view to store the results and speed up things. Best regards -- Matteo Beccati http://phpadsnew.com/ http://phppgads.com/ |
#3
| |||
| |||
|
|
Is there a way to create an index that would make this query be efficient and not perform a sequential scan? SELECT count(*) AS count,id FROM sometable GROUP BY id; .. I've considered creating a rule on this table which would put the results of this into another table anytime it is updated, but I thought there might be an easier way. |
#4
| |||
| |||
|
|
On Saturday November 6 2004 7:34, Net Virtual Mailing Lists wrote: Is there a way to create an index that would make this query be efficient and not perform a sequential scan? SELECT count(*) AS count,id FROM sometable GROUP BY id; .. I've considered creating a rule on this table which would put the results of this into another table anytime it is updated, but I thought there might be an easier way. Since you have no "WHERE" clause and you want to group by id, I believe pgsql has to scan all id values. Those id values are only fully stored in the table, so I don't think so. Ed ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings |
#5
| |||
| |||
|
|
Net Virtual Mailing Lists wrote: Is there a way to create an index that would make this query be efficient and not perform a sequential scan? SELECT count(*) AS count,id FROM sometable GROUP BY id; Indexes cannot be used for retrieving results... |
#6
| |||
| |||
|
|
Is there a way to create an index that would make this query be efficient and not perform a sequential scan? SELECT count(*) AS count,id FROM sometable GROUP BY id; .. I've considered creating a rule on this table which would put the results of this into another table anytime it is updated, but I thought there might be an easier way. |
#7
| |||
| |||
|
|
-----Ursprüngliche Nachricht----- Von: pgsql-general-owner (AT) postgresql (DOT) org [mailto gsql-general-owner (AT) postgresql (DOT) org] Im Auftrag vonNet Virtual Mailing Lists Gesendet: Samstag, 6. November 2004 16:49 An: Matteo Beccati Betreff: Re: [GENERAL] Can this be indexed? I am not clear how to use a trigger for this, I will need to look into that.... It is my understanding that Postgres does not have materialized views though (which I believe would solve this problem nicely) - am I mistaken?... - Greg |
#8
| |||
| |||
|
|
PostgreSQL doesn't provide pre-configured support for materialized views as such, but using some PL/pgSQL and triggers, one can easily implement any kind of materialized view as seen fit for the specific intended purpose (Snapshot, Eager, Lazy, Very Lazy). You may find an excellent tutorial on materialized views with PostgreSQL here: http://jonathangardner.net/PostgreSQ.../matviews.html -----Ursprüngliche Nachricht----- Von: pgsql-general-owner (AT) postgresql (DOT) org [mailto gsql-general-owner (AT) postgresql (DOT) org] Im Auftrag vonNet Virtual Mailing Lists Gesendet: Samstag, 6. November 2004 16:49 An: Matteo Beccati Betreff: Re: [GENERAL] Can this be indexed? I am not clear how to use a trigger for this, I will need to look into that.... It is my understanding that Postgres does not have materialized views though (which I believe would solve this problem nicely) - am I mistaken?... - Greg |
#9
| |||
| |||
|
|
But if you do build an index over "id" then pgsql would only have to do a sequential scan on that index, which might be a lot faster if your table contains a lot of other data, won't it? |
![]() |
| Thread Tools | |
| Display Modes | |
| |