Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-21
3
Medium Priority
?
221 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
[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
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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

730 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