Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Do Functions perform better than dynamic (inline) SQL in PostgreSQL?

Posted on 2016-10-21
3
Medium Priority
?
252 Views
Last Modified: 2016-10-21
I'm pretty new to PostgreSQL and have a basic design question I'd like some advice on.

Our company has 1000+ identical schemas defined in our PostgreSQL DB. We have separate Schemas (work places) defined for each of our clients. The overall DB Schema design is something which cannot be altered.

We have to create routines which will gather data from all the schemas and store it in DataTables in a separate (centralized) schema.

One approach would be to write a .Net based app using he npgsql interface. The application would iterate over all the schemas and run dynamic (inline) SQL to return the desired data.

Another approach would be to push all the data gathering routines into PostgreSQL functions. The functions would contain dynamic SQL, accept a schema as parameter, and then run that SQL against the target schema.

Is there any difference in the performance of the two approaches? I'm trying to figure out which approach will be best in terms of performance and maintainability.

Is there a better approach to take?

Thanks, JohnB
0
Comment
Question by:jxbma
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 2000 total points
ID: 41854249
Functions generally perform faster than inline or direct queries. However you have indicated that your functions will be running dynamic SQL so any possibility for enhanced performance through optimization is pretty much out the window.

As far as maintainability is concerned I'd lean toward just doing everything in .NET. It's easier to manage and comment and can easily be placed under source control. Also, it's frequently as fast, sometimes faster if bulk copy is an option, than running queries.
3
 
LVL 1

Author Closing Comment

by:jxbma
ID: 41854270
Thanks for the prompt response.
That's what I kind of figured.

I'm not sure of what the reasoning was behind creating separate schemas (partitioning/isolation of data)?
It certainly makes it more challenging.

JB
0
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41854281
I'm not sure of what the reasoning was behind creating separate schemas (partitioning/isolation of data)?
Yep, that's what comments and documentation are for. There may have been a perfectly good reason but you're left to guess what that might be. Maybe it was a valid reason at the time but the reason is no longer a consideration. Or just maybe that was how the designer decided to do it because that's his style.
1

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

886 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