开发者

Adding views to a vendor-delivered database and performance

开发者 https://www.devze.com 2023-01-04 00:39 出处:网络
We have a vendor delivered database that to this point I have been able to avoid making any database structure changes to. We will be soon directly querying the tables directly for a related project.

We have a vendor delivered database that to this point I have been able to avoid making any database structure changes to. We will be soon directly querying the tables directly for a related project. In order to pull all of the data we need, we will need to create a big SQL statement with multiple unions.

select ... from table1
union
select ... from table2
...
select ... from tableN

Speed is the utmost priority for this project. Would it be quicker to create a view to do the joins then just query this view (and thus making changes to the vendor database) or just run the union statement from our application?

I know the potential problems involved in making changes to the vendor database so thus 开发者_如何转开发why I am looking for feedback.


When it comes to vendor databases I would be very hesitant to make changes to any existing tables. Adding something like a view seems a little safer since you are the only one that will be using it. My biggest concern with the view would be if you ever got an update from your vendor that made changes to your DB and you might lose the view.

I don't think you'd see any performance gains from using the view, unless you used an indexed view. Unfortunately you can't create indexes on a view that is created using a union (at least in SQL Server).

Personally when it comes to putting logic in application vs putting it in the DB I lean towards DB. In my experience these types of changes are easier to deploy and maintain.

If i were in your situation I would go ahead create the view if it will make your life easier. But again, don't expect performance gains.


No a view will not be quicker (except for development time).

What would be quicker is to use UNION ALL if it will work. UNION looks for duplicated records and removes them from the final result. If you know the records by design (such as each table is for a differnt clinet or each table has a differnt date range) cannot be duplicated, UNION ALL not try to DISTINCT the resultset and thus runs much faster.

0

精彩评论

暂无评论...
验证码 换一张
取 消