Solved

Postgres Analyze

Posted on 2011-09-06
6
577 Views
Last Modified: 2012-05-12
We have a function that truncates a table (table1), then populates it with several million rows and then inner joins to another table (table2) that also has several million rows.

Is it possible/advisable to ANALYZE table1 within the function? i.e., right after we dump the millions of rows into table1, can we issue an “ANALYZE table1” from within the function before we join it to table2?
0
Comment
Question by:dthansen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Expert Comment

by:earth man2
ID: 36493771
No
Analyze the SQL statements that are causing your bottlneck individually standalone.
0
 
LVL 4

Expert Comment

by:thewild
ID: 36501513
No, you cannot run VACUUM ANALYZE inside a function.
More generally, you cannot run VACUUM inside a transaction block. Since functions are always run in a transaction, VACUUM is not possible inside them.

Instead of a stored procedure, you could run the statements one by one.
0
 

Author Comment

by:dthansen
ID: 36501904
I am not concerned with running VACUUM ANALYZE inside the function, just ANALYZE.

Thanks,
Dean
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 4

Accepted Solution

by:
thewild earned 500 total points
ID: 36502027
Sorry, since you were asking whether it was possible, I thought you meant VACUUM ANALYZE.
ANALYZE is possible inside a procedure.
In your case it is probably recommended.
Have you tried to run EXPLAIN ANALYZE on the query joining your tables with and without running ANALYZE first ?
0
 

Author Comment

by:dthansen
ID: 36502467
One of the tables is a temporary table created function. I'm not sure it is possible to run an EXPLAIN ANALYZE on that table as it is both created and dropped within the function.

Thanks,
Dean
0
 
LVL 22

Expert Comment

by:earth man2
ID: 36515448
create a new stored procedure that creates the data as before but does not delete the table and data.  Then interactively execute the SQL with EXPLAIN ANALYZE
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question