What is a good way to optimize a count query in Postgresql?
-
I have a table in postgresql that contains an array which is updated constantly. In my application i need to get the number of rows for which a specific parameter is not present in that array column. My query looks like this: select count(id) from table where not (ARRAY[âparameter valueâ] <@ table.array_column) But when increasing the amount of rows and the amount of executions of that query (several times per second, possibly hundreds or thousands) the performance decreses a lot, it seems to me that the counting in postgresql might have a linear order of execution (Iâm not completely sure of this). Basically my question is: Is there an existing pattern Iâm not aware of that applies to this situation? what would be the best approach for this? Any suggestion you could give me would be really appreciated.
-
Answer:
After using the Explain command as suggested by Steve Lacy i found out that given the current structure of my databse it will always be sequential so im going to have a cache with the most recent count to speed it up a little and execute the query only when necesary
Jeffry Gutierrez at Quora Visit the source
Related Q & A:
- What is a good way to structure mark-up generating code and avoid the example mess?Best solution by Code Review
- What is a good way to advertise enexpensively for a small business? It is handyman work?Best solution by Yahoo! Answers
- What's a good way to let a girl know you are interested in her?Best solution by Yahoo! Answers
- What is a good way to break in a snowboard?Best solution by answers.yahoo.com
- What is a good way to promote a movie?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.